fix (接口自动化):多节点均衡分配处理
This commit is contained in:
parent
48fce1b194
commit
1540e573ab
|
@ -16,7 +16,6 @@ import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.config.JmeterProperties;
|
import io.metersphere.config.JmeterProperties;
|
||||||
import io.metersphere.config.KafkaConfig;
|
|
||||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||||
import io.metersphere.dto.NodeDTO;
|
import io.metersphere.dto.NodeDTO;
|
||||||
import io.metersphere.i18n.Translator;
|
import io.metersphere.i18n.Translator;
|
||||||
|
@ -33,7 +32,6 @@ import org.apache.jorphan.collections.HashTree;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.kafka.core.KafkaTemplate;
|
import org.springframework.kafka.core.KafkaTemplate;
|
||||||
import org.springframework.kafka.support.SendResult;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
@ -176,12 +174,12 @@ public class JMeterService {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
SendResult result = kafkaTemplate.send(KafkaConfig.EXEC_TOPIC, JSON.toJSONString(runRequest)).get();
|
// SendResult result = kafkaTemplate.send(KafkaConfig.EXEC_TOPIC, JSON.toJSONString(runRequest)).get();
|
||||||
if (result != null) {
|
// if (result != null) {
|
||||||
LogUtil.debug("获取ack 结果:" + result.getRecordMetadata());
|
// LogUtil.debug("获取ack 结果:" + result.getRecordMetadata());
|
||||||
}
|
// }
|
||||||
kafkaTemplate.flush();
|
// kafkaTemplate.flush();
|
||||||
// this.send(runRequest,config,reportId);
|
this.send(runRequest, config, reportId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (MessageCache.cache.get(config.getAmassReport()) != null
|
if (MessageCache.cache.get(config.getAmassReport()) != null
|
||||||
|
@ -192,7 +190,7 @@ public class JMeterService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(RunRequest runRequest, RunModeConfig config, String reportId) {
|
public synchronized void send(RunRequest runRequest, RunModeConfig config, String reportId) {
|
||||||
try {
|
try {
|
||||||
int index = (int) (Math.random() * config.getTestResources().size());
|
int index = (int) (Math.random() * config.getTestResources().size());
|
||||||
JvmInfoDTO jvmInfoDTO = config.getTestResources().get(index);
|
JvmInfoDTO jvmInfoDTO = config.getTestResources().get(index);
|
||||||
|
@ -201,21 +199,17 @@ public class JMeterService {
|
||||||
NodeDTO node = JSON.parseObject(configuration, NodeDTO.class);
|
NodeDTO node = JSON.parseObject(configuration, NodeDTO.class);
|
||||||
String nodeIp = node.getIp();
|
String nodeIp = node.getIp();
|
||||||
Integer port = node.getPort();
|
Integer port = node.getPort();
|
||||||
try {
|
String uri = String.format(BASE_URL + "/jmeter/api/start", nodeIp, port);
|
||||||
String uri = String.format(BASE_URL + "/jmeter/api/start", nodeIp, port);
|
ResponseEntity<String> result = restTemplate.postForEntity(uri, runRequest, String.class);
|
||||||
ResponseEntity<String> result = restTemplate.postForEntity(uri, runRequest, String.class);
|
if (result == null || !StringUtils.equals("SUCCESS", result.getBody())) {
|
||||||
if (result == null || !StringUtils.equals("SUCCESS", result.getBody())) {
|
// 清理零时报告
|
||||||
// 清理零时报告
|
ApiScenarioReportService apiScenarioReportService = CommonBeanFactory.getBean(ApiScenarioReportService.class);
|
||||||
ApiScenarioReportService apiScenarioReportService = CommonBeanFactory.getBean(ApiScenarioReportService.class);
|
apiScenarioReportService.delete(reportId);
|
||||||
apiScenarioReportService.delete(reportId);
|
MSException.throwException("执行失败:" + result);
|
||||||
MSException.throwException("执行失败:" + result);
|
if (MessageCache.cache.get(config.getAmassReport()) != null
|
||||||
if (MessageCache.cache.get(config.getAmassReport()) != null
|
&& MessageCache.cache.get(config.getAmassReport()).getReportIds() != null) {
|
||||||
&& MessageCache.cache.get(config.getAmassReport()).getReportIds() != null) {
|
MessageCache.cache.get(config.getAmassReport()).getReportIds().remove(reportId);
|
||||||
MessageCache.cache.get(config.getAmassReport()).getReportIds().remove(reportId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
MSException.throwException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (MessageCache.cache.get(config.getAmassReport()) != null
|
if (MessageCache.cache.get(config.getAmassReport()) != null
|
||||||
|
|
|
@ -33,7 +33,11 @@ public class ResourcePoolCalculation {
|
||||||
private static final String BASE_URL = "http://%s:%d";
|
private static final String BASE_URL = "http://%s:%d";
|
||||||
|
|
||||||
private JvmInfoDTO getNodeJvmInfo(String uri) {
|
private JvmInfoDTO getNodeJvmInfo(String uri) {
|
||||||
return restTemplate.getForObject(uri, JvmInfoDTO.class);
|
try {
|
||||||
|
return restTemplate.getForObject(uri, JvmInfoDTO.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestResource getPool(String resourcePoolId) {
|
public TestResource getPool(String resourcePoolId) {
|
||||||
|
|
Loading…
Reference in New Issue