From ea5375a3a9e9d9ca8a041167b1054b43fae69920 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 26 Jan 2022 17:46:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E9=98=9F=E5=88=97=E5=BC=82=E5=B8=B8=E4=BF=9D?= =?UTF-8?q?=E6=8A=A4=E6=B8=85=E7=90=86=E5=A4=B1=E8=B4=A5=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/api/jmeter/JMeterService.java | 7 ------- .../api/service/ApiJmeterFileService.java | 12 ++++++++---- .../api/service/RemakeReportService.java | 19 ++++++++----------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index 05ad757c59..31e8dddad9 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -1,7 +1,6 @@ package io.metersphere.api.jmeter; import com.alibaba.fastjson.JSON; -import io.metersphere.api.dto.RunRequest; import io.metersphere.api.exec.queue.ExecThreadPoolExecutor; import io.metersphere.api.exec.utils.GenerateHashTreeUtil; import io.metersphere.api.service.ApiScenarioReportService; @@ -155,18 +154,12 @@ public class JMeterService { ResponseEntity result = restTemplate.postForEntity(uri, request, String.class); if (result == null || !StringUtils.equals("SUCCESS", result.getBody())) { RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class); - RunRequest runRequest = new RunRequest(); - runRequest.setTestId(request.getTestId()); - runRequest.setRunMode(request.getRunMode()); remakeReportService.remake(request); LoggerUtil.error("发送请求[ " + request.getTestId() + " ] 到" + uri + " 节点执行失败"); LoggerUtil.info(result.getBody()); } } catch (Exception e) { RemakeReportService remakeReportService = CommonBeanFactory.getBean(RemakeReportService.class); - RunRequest runRequest = new RunRequest(); - runRequest.setTestId(request.getTestId()); - runRequest.setRunMode(request.getRunMode()); remakeReportService.remake(request); LoggerUtil.error("发送请求[ " + request.getTestId() + " ] 执行失败:" + e.getMessage()); LoggerUtil.error(e); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java b/backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java index f9b35325a7..1089d7cd44 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiJmeterFileService.java @@ -11,7 +11,6 @@ import io.metersphere.base.mapper.ApiExecutionQueueDetailMapper; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.TestPlanApiScenarioMapper; import io.metersphere.commons.constants.ApiRunMode; -import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.LogUtil; @@ -70,7 +69,7 @@ public class ApiJmeterFileService { if (detail != null && StringUtils.isNotEmpty(detail.getEvnMap())) { envMap = JSON.parseObject(detail.getEvnMap(), Map.class); } - HashTree hashTree; + HashTree hashTree = null; if (StringUtils.equalsAnyIgnoreCase(runMode, ApiRunMode.DEFINITION.name(), ApiRunMode.JENKINS_API_PLAN.name(), ApiRunMode.API_PLAN.name(), ApiRunMode.SCHEDULE_API_PLAN.name(), ApiRunMode.MANUAL_PLAN.name())) { hashTree = apiScenarioSerialService.generateHashTree(remoteTestId, reportId, runMode, envMap); } else { @@ -78,7 +77,8 @@ public class ApiJmeterFileService { scenario = apiScenarioMapper.selectByPrimaryKey(remoteTestId); } if (scenario == null) { - MSException.throwException("未找到执行场景。"); + // 清除队列 + executionQueueDetailMapper.deleteByPrimaryKey(queueId); } if (envMap != null && !envMap.isEmpty()) { planEnvMap = envMap; @@ -92,7 +92,11 @@ public class ApiJmeterFileService { planEnvMap = environmentGroupProjectService.getEnvMap(envGroupId); } } - hashTree = GenerateHashTreeUtil.generateHashTree(scenario, reportId, planEnvMap, reportType); + try { + hashTree = GenerateHashTreeUtil.generateHashTree(scenario, reportId, planEnvMap, reportType); + } catch (Exception e) { + executionQueueDetailMapper.deleteByPrimaryKey(queueId); + } } return zipFilesToByteArray((reportId + "_" + remoteTestId), hashTree); } diff --git a/backend/src/main/java/io/metersphere/api/service/RemakeReportService.java b/backend/src/main/java/io/metersphere/api/service/RemakeReportService.java index bcc7799e23..780a196192 100644 --- a/backend/src/main/java/io/metersphere/api/service/RemakeReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/RemakeReportService.java @@ -8,7 +8,6 @@ import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; -import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.JmeterRunRequestDTO; import io.metersphere.dto.ResultDTO; import org.apache.commons.lang3.StringUtils; @@ -109,16 +108,14 @@ public class RemakeReportService { } } // 处理队列 - if (StringUtils.equals(request.getReportType(), RunModeConstants.SET_REPORT.toString())) { - ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample(); - example.createCriteria().andQueueIdEqualTo(request.getQueueId()).andTestIdEqualTo(request.getTestId()); - CommonBeanFactory.getBean(ApiExecutionQueueDetailMapper.class).deleteByExample(example); - ResultDTO dto = new ResultDTO(); - BeanUtils.copyBean(dto, request); - dto.setQueueId(request.getQueueId()); - dto.setTestId(request.getTestId()); - CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto); - } + ApiExecutionQueueDetailExample example = new ApiExecutionQueueDetailExample(); + example.createCriteria().andQueueIdEqualTo(request.getQueueId()).andTestIdEqualTo(request.getTestId()); + CommonBeanFactory.getBean(ApiExecutionQueueDetailMapper.class).deleteByExample(example); + ResultDTO dto = new ResultDTO(); + BeanUtils.copyBean(dto, request); + dto.setQueueId(request.getQueueId()); + dto.setTestId(request.getTestId()); + CommonBeanFactory.getBean(ApiExecutionQueueService.class).queueNext(dto); } catch (Exception e) { LogUtil.error(e); }