From fb92bba0ed35399c7a9c5ff4cc3760f6e85d55c7 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 20 Apr 2020 16:00:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8A=A5=E5=91=8A=E6=97=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/service/ReportService.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/service/ReportService.java b/backend/src/main/java/io/metersphere/service/ReportService.java index 17b2f047fa..38c2e88c92 100644 --- a/backend/src/main/java/io/metersphere/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/service/ReportService.java @@ -1,14 +1,16 @@ package io.metersphere.service; -import io.metersphere.base.domain.LoadTestReport; -import io.metersphere.base.domain.LoadTestReportExample; -import io.metersphere.base.domain.LoadTestReportWithBLOBs; +import io.metersphere.base.domain.*; +import io.metersphere.base.mapper.LoadTestMapper; import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.controller.request.ReportRequest; import io.metersphere.dto.ReportDTO; +import io.metersphere.engine.Engine; +import io.metersphere.engine.EngineFactory; import io.metersphere.report.JtlResolver; import io.metersphere.report.base.ChartsData; import io.metersphere.report.base.Errors; @@ -31,6 +33,8 @@ public class ReportService { private LoadTestReportMapper loadTestReportMapper; @Resource private ExtLoadTestReportMapper extLoadTestReportMapper; + @Resource + private LoadTestMapper loadTestMapper; public List getRecentReportList(ReportRequest request) { LoadTestReportExample example = new LoadTestReportExample(); @@ -46,9 +50,38 @@ public class ReportService { } public void deleteReport(String reportId) { + if (StringUtils.isBlank(reportId)) { + MSException.throwException("report id cannot be null"); + } + + LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId); + LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(loadTestReport.getTestId()); + + LogUtil.info("Delete report started, report ID: %s" + reportId); + + final Engine engine = EngineFactory.createEngine(loadTest); + if (engine == null) { + MSException.throwException(String.format("Delete report fail. create engine fail,report ID:%s", reportId)); + } + + String reportStatus = loadTestReport.getStatus(); + boolean isRunning = StringUtils.equals(reportStatus, PerformanceTestStatus.Running.name()); + boolean isStarting = StringUtils.equals(reportStatus, PerformanceTestStatus.Starting.name()); + boolean isError = StringUtils.equals(reportStatus, PerformanceTestStatus.Error.name()); + if (isRunning || isStarting || isError) { + LogUtil.info("Start stop engine, report status: %s" + reportStatus); + stopEngine(loadTest, engine); + } + loadTestReportMapper.deleteByPrimaryKey(reportId); } + private void stopEngine(LoadTestWithBLOBs loadTest, Engine engine) { + engine.stop(); + loadTest.setStatus(PerformanceTestStatus.Saved.name()); + loadTestMapper.updateByPrimaryKeySelective(loadTest); + } + public ReportDTO getReportTestAndProInfo(String reportId) { return extLoadTestReportMapper.getReportTestAndProInfo(reportId); }