From 492dca961c8f7e1368faa4b78e280da9bbd2e2f7 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Mon, 27 Jul 2020 13:25:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95=E6=98=AF=E5=90=A6=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PerformanceTestController.java | 6 ++-- .../service/PerformanceTestService.java | 16 +++++++-- .../performance/service/ReportService.java | 9 ++++- .../websocket/ReportWebSocket.java | 3 ++ .../report/PerformanceReportView.vue | 35 ++++++++++++------- .../test/EditPerformanceTestPlan.vue | 1 - frontend/src/i18n/en-US.js | 6 +++- frontend/src/i18n/zh-CN.js | 5 ++- frontend/src/i18n/zh-TW.js | 6 +++- 9 files changed, 64 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java index b0520ec039..39001b136f 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java @@ -102,9 +102,9 @@ public class PerformanceTestController { return performanceTestService.run(request); } - @GetMapping("stop/{reportId}") - public void stopTest(@PathVariable String reportId) { - performanceTestService.stopTest(reportId); + @GetMapping("stop/{reportId}/{forceStop}") + public void stopTest(@PathVariable String reportId, @PathVariable boolean forceStop) { + performanceTestService.stopTest(reportId, forceStop); } @GetMapping("/file/metadata/{testId}") diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 29c3a51090..2c58f48aee 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -401,7 +401,19 @@ public class PerformanceTestService { scheduleService.addOrUpdateCronJob(request, PerformanceTestJob.getJobKey(request.getResourceId()), PerformanceTestJob.getTriggerKey(request.getResourceId()), PerformanceTestJob.class); } - public void stopTest(String reportId) { - reportService.deleteReport(reportId); + public void stopTest(String reportId, boolean forceStop) { + if (forceStop) { + reportService.deleteReport(reportId); + } else { + LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(reportId); + LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(loadTestReport.getTestId()); + final Engine engine = EngineFactory.createEngine(loadTest); + if (engine == null) { + MSException.throwException(String.format("Stop report fail. create engine fail,report ID:%s", reportId)); + } + reportService.stopEngine(loadTest, engine); + // 停止测试之后设置报告的状态 + reportService.updateStatus(reportId, PerformanceTestStatus.Completed.name()); + } } } diff --git a/backend/src/main/java/io/metersphere/performance/service/ReportService.java b/backend/src/main/java/io/metersphere/performance/service/ReportService.java index bb9b58cc8e..5c3e366ae8 100644 --- a/backend/src/main/java/io/metersphere/performance/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/performance/service/ReportService.java @@ -99,7 +99,7 @@ public class ReportService { loadTestReportMapper.deleteByPrimaryKey(reportId); } - private void stopEngine(LoadTestWithBLOBs loadTest, Engine engine) { + public void stopEngine(LoadTestWithBLOBs loadTest, Engine engine) { engine.stop(); loadTest.setStatus(PerformanceTestStatus.Saved.name()); loadTestMapper.updateByPrimaryKeySelective(loadTest); @@ -239,4 +239,11 @@ public class ReportService { public LoadTestReport getReport(String reportId) { return loadTestReportMapper.selectByPrimaryKey(reportId); } + + public void updateStatus(String reportId, String status) { + LoadTestReport report = new LoadTestReport(); + report.setId(reportId); + report.setStatus(status); + loadTestReportMapper.updateByPrimaryKeySelective(report); + } } diff --git a/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java b/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java index 4e4429d600..639abeb640 100644 --- a/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java +++ b/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java @@ -84,6 +84,9 @@ public class ReportWebSocket { session.close(); break; } + if (!session.isOpen()) { + return; + } if (PerformanceTestStatus.Running.name().equals(report.getStatus())) { session.getBasicRemote().sendText("refresh-" + this.refresh++); } diff --git a/frontend/src/business/components/performance/report/PerformanceReportView.vue b/frontend/src/business/components/performance/report/PerformanceReportView.vue index 926d479e7e..2db660c33f 100644 --- a/frontend/src/business/components/performance/report/PerformanceReportView.vue +++ b/frontend/src/business/components/performance/report/PerformanceReportView.vue @@ -15,7 +15,7 @@ + @click="dialogFormVisible=true"> {{$t('report.test_stop_now')}} + +

+

+ +
@@ -103,7 +113,8 @@ title: 'Logging', report: {}, isReadOnly: false, - websocket: null + websocket: null, + dialogFormVisible: false, } }, methods: { @@ -171,18 +182,16 @@ this.minutes = '0'; this.seconds = '0'; }, - stopTest(reportId) { - this.$confirm(this.$t('report.test_stop_now_confirm'), '', { - confirmButtonText: this.$t('commons.confirm'), - cancelButtonText: this.$t('commons.cancel'), - type: 'warning' - }).then(() => { - this.result = this.$get('/performance/stop/' + reportId, () => { - this.$success(this.$t('report.test_stop_success')); + stopTest(forceStop) { + this.result = this.$get('/performance/stop/' + this.reportId + '/' + forceStop, () => { + this.$success(this.$t('report.test_stop_success')); + this.$set(this.report, "refresh", Math.random()); // 触发刷新 + this.$set(this.report, "status", 'Completed'); + if (forceStop) { this.$router.push('/performance/report/all'); - }) - }).catch(() => { - }); + } + }) + this.dialogFormVisible = false; }, rerun(testId) { this.$confirm(this.$t('report.test_rerun_confirm'), '', { diff --git a/frontend/src/business/components/performance/test/EditPerformanceTestPlan.vue b/frontend/src/business/components/performance/test/EditPerformanceTestPlan.vue index 44b9d511ee..34da329f74 100644 --- a/frontend/src/business/components/performance/test/EditPerformanceTestPlan.vue +++ b/frontend/src/business/components/performance/test/EditPerformanceTestPlan.vue @@ -184,7 +184,6 @@ this.testPlan.id = response.data; this.$success(this.$t('commons.save_success')); this.result = this.$post(this.runPath, {id: this.testPlan.id, triggerMode: 'MANUAL'}, (response) => { - this.$success(this.$t('load_test.is_running')) let reportId = response.data; this.$router.push({path: '/performance/report/view/' + reportId}) }) diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 6bb00926c8..324e84b21a 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -261,7 +261,11 @@ export default { start_status: 'The test is in the beginning state, we will automatically display it on the page after we generate the report!', run_status: 'The test is running, please check the report later!', user_name: 'Creator', - project_name: 'Project Name' + project_name: 'Project Name', + force_stop_tips: 'Terminating the servers will immediately kill the servers and the JTL files will be lost.', + stop_tips: 'A Graceful shutdown will archive the JTL files and then stop the servers.', + force_stop_btn: 'Terminating', + stop_btn: 'Graceful shutdown', }, load_test: { operating: 'Operating', diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index c4f8404a98..03ef679a3c 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -260,7 +260,10 @@ export default { run_status: '测试处于运行状态,请稍后查看报告!', user_name: '创建人', project_name: '所属项目', - + force_stop_tips: '强制停止测试会立刻结束当前测试并删除报告数据', + stop_tips: '停止测试会结束当前测试并保留报告数据', + force_stop_btn: '强制停止', + stop_btn: '停止', }, load_test: { operating: '操作', diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index ffd6f8c4f4..d5a24140a0 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -259,7 +259,11 @@ export default { start_status: '測試處於開始狀態, 我們生成報告後會自動展示到頁面上!', run_status: '測試處於運行狀態,請稍後查看報告!', user_name: '創建人', - project_name: '所屬項目' + project_name: '所屬項目', + force_stop_tips: '強制停止測試會立刻結束當前測試並刪除報告數據', + stop_tips: '停止測試會結束當前測試並保留報告數據', + force_stop_btn: '強制停止', + stop_btn: '停止', }, load_test: { operating: '操作',