fix(接口测试): 修复使用K8S资源池执行接口测试,对应SA无权限时报告被清除问题
This commit is contained in:
parent
1800b4bf06
commit
1eecc12b54
|
@ -5,11 +5,9 @@ import io.metersphere.api.exec.queue.ExecThreadPoolExecutor;
|
|||
import io.metersphere.api.exec.utils.GenerateHashTreeUtil;
|
||||
import io.metersphere.api.jmeter.utils.ServerConfig;
|
||||
import io.metersphere.api.jmeter.utils.SmoothWeighted;
|
||||
import io.metersphere.api.service.ApiScenarioReportService;
|
||||
import io.metersphere.api.service.RemakeReportService;
|
||||
import io.metersphere.base.domain.TestResource;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.config.JmeterProperties;
|
||||
import io.metersphere.config.KafkaConfig;
|
||||
|
@ -128,10 +126,9 @@ public class JMeterService {
|
|||
final Engine engine = EngineFactory.createApiEngine(request);
|
||||
engine.start();
|
||||
} catch (Exception e) {
|
||||
RemakeReportService apiScenarioReportService = CommonBeanFactory.getBean(RemakeReportService.class);
|
||||
apiScenarioReportService.testEnded(request, e.getMessage());
|
||||
LoggerUtil.error("调用K8S执行请求[ " + request.getTestId() + " ] 失败:", e);
|
||||
ApiScenarioReportService apiScenarioReportService = CommonBeanFactory.getBean(ApiScenarioReportService.class);
|
||||
apiScenarioReportService.delete(request.getReportId());
|
||||
MSException.throwException(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
this.send(request);
|
||||
|
|
|
@ -130,7 +130,7 @@ public class ApiScenarioReportService {
|
|||
return scenarioReport;
|
||||
}
|
||||
|
||||
public APIScenarioReportResult get(String reportId,boolean selectReportContent) {
|
||||
public APIScenarioReportResult get(String reportId, boolean selectReportContent) {
|
||||
ApiDefinitionExecResult result = definitionExecResultMapper.selectByPrimaryKey(reportId);
|
||||
if (result != null) {
|
||||
APIScenarioReportResult reportResult = new APIScenarioReportResult();
|
||||
|
@ -144,7 +144,7 @@ public class ApiScenarioReportService {
|
|||
APIScenarioReportResult reportResult = extApiScenarioReportMapper.get(reportId);
|
||||
if (reportResult != null) {
|
||||
if (reportResult.getReportVersion() != null && reportResult.getReportVersion() > 1) {
|
||||
reportResult.setContent(JSON.toJSONString(apiScenarioReportStructureService.assembleReport(reportId,selectReportContent)));
|
||||
reportResult.setContent(JSON.toJSONString(apiScenarioReportStructureService.assembleReport(reportId, selectReportContent)));
|
||||
} else {
|
||||
ApiScenarioReportDetail detail = apiScenarioReportDetailMapper.selectByPrimaryKey(reportId);
|
||||
if (detail != null && reportResult != null) {
|
||||
|
@ -848,7 +848,7 @@ public class ApiScenarioReportService {
|
|||
} else if (errorReportResultSize > 0) {
|
||||
status = ExecuteResult.errorReportResult.name();
|
||||
} else {
|
||||
status = ScenarioStatus.Success.name();
|
||||
status = requestResults.isEmpty() ? ScenarioStatus.Error.name() : ScenarioStatus.Success.name();
|
||||
}
|
||||
|
||||
if (dto != null && dto.getArbitraryData() != null && dto.getArbitraryData().containsKey("TIMEOUT") && (Boolean) dto.getArbitraryData().get("TIMEOUT")) {
|
||||
|
|
|
@ -540,6 +540,10 @@ public class ApiScenarioReportStructureService {
|
|||
List<ApiScenarioReportStructureWithBLOBs> reportStructureWithBLOBs = mapper.selectByExampleWithBLOBs(structureExample);
|
||||
|
||||
ApiScenarioReportDTO reportDTO = new ApiScenarioReportDTO();
|
||||
// 写入控制台信息
|
||||
if (CollectionUtils.isNotEmpty(reportStructureWithBLOBs)) {
|
||||
reportDTO.setConsole(reportStructureWithBLOBs.get(0).getConsole());
|
||||
}
|
||||
// 组装报告
|
||||
if (CollectionUtils.isNotEmpty(reportStructureWithBLOBs) && CollectionUtils.isNotEmpty(reportResults)) {
|
||||
ApiScenarioReportStructureWithBLOBs scenarioReportStructure = reportStructureWithBLOBs.get(0);
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package io.metersphere.api.service;
|
||||
|
||||
import io.metersphere.api.dto.automation.ScenarioStatus;
|
||||
import io.metersphere.api.exec.queue.PoolExecBlockingQueueUtil;
|
||||
import io.metersphere.api.jmeter.FixedCapacityUtils;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.cache.JMeterEngineCache;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
|
@ -10,6 +13,7 @@ import io.metersphere.commons.utils.CommonBeanFactory;
|
|||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.dto.JmeterRunRequestDTO;
|
||||
import io.metersphere.dto.ResultDTO;
|
||||
import io.metersphere.utils.LoggerUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -155,4 +159,35 @@ public class RemakeReportService {
|
|||
report.setStatus(APITestStatus.Error.name());
|
||||
apiScenarioReportMapper.updateByPrimaryKeySelective(report);
|
||||
}
|
||||
|
||||
public void testEnded(JmeterRunRequestDTO request, String errorMsg) {
|
||||
try {
|
||||
ResultDTO dto = new ResultDTO();
|
||||
BeanUtils.copyBean(dto, request);
|
||||
dto.setQueueId(request.getQueueId());
|
||||
dto.setTestId(request.getTestId());
|
||||
|
||||
if (JMeterEngineCache.runningEngine.containsKey(dto.getReportId())) {
|
||||
JMeterEngineCache.runningEngine.remove(dto.getReportId());
|
||||
}
|
||||
LoggerUtil.info("进入异常结果处理报告【" + dto.getReportId() + " 】" + dto.getRunMode() + " 整体执行完成");
|
||||
// 全局并发队列
|
||||
PoolExecBlockingQueueUtil.offer(dto.getReportId());
|
||||
String consoleMsg = FixedCapacityUtils.getJmeterLogger(dto.getReportId());
|
||||
dto.setConsole(consoleMsg + "\n" + errorMsg);
|
||||
// 整体执行结束更新资源状态
|
||||
CommonBeanFactory.getBean(TestResultService.class).testEnded(dto);
|
||||
|
||||
if (StringUtils.isNotEmpty(dto.getQueueId())) {
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto);
|
||||
}
|
||||
// 更新测试计划报告
|
||||
if (StringUtils.isNotEmpty(dto.getTestPlanReportId())) {
|
||||
LoggerUtil.info("Check Processing Test Plan report status:" + dto.getQueueId() + "," + dto.getTestId());
|
||||
CommonBeanFactory.getBean(ApiExecutionQueueService.class).testPlanReportTestEnded(dto.getTestPlanReportId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LoggerUtil.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue