From 1bf00efb416bea676033c39688ca7ff1a8eb9758 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 20 Apr 2021 15:56:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E7=A6=81=E7=94=A8=E8=B5=84=E6=BA=90=E6=B1=A0=E6=97=B6?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=98=AF=E5=90=A6=E6=9C=89=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=AD=A3=E5=9C=A8=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestResourcePoolController.java | 6 +++ .../io/metersphere/dto/UpdatePoolDTO.java | 15 ++++++++ .../service/TestResourcePoolService.java | 34 +++++++++++++++++ .../settings/system/TestResourcePool.vue | 38 +++++++++++++++++++ frontend/src/i18n/en-US.js | 1 + frontend/src/i18n/zh-CN.js | 1 + frontend/src/i18n/zh-TW.js | 1 + 7 files changed, 96 insertions(+) create mode 100644 backend/src/main/java/io/metersphere/dto/UpdatePoolDTO.java diff --git a/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java b/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java index ad281b7ed5..6ee74d790a 100644 --- a/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java +++ b/backend/src/main/java/io/metersphere/controller/TestResourcePoolController.java @@ -7,6 +7,7 @@ import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest; import io.metersphere.dto.TestResourcePoolDTO; +import io.metersphere.dto.UpdatePoolDTO; import io.metersphere.service.TestResourcePoolService; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; @@ -43,6 +44,11 @@ public class TestResourcePoolController { testResourcePoolService.updateTestResourcePoolStatus(poolId, status); } + @GetMapping("/check/use/{poolId}") + public UpdatePoolDTO checkHaveTestUsePool(@PathVariable String poolId) { + return testResourcePoolService.checkHaveTestUsePool(poolId); + } + @PostMapping("list/{goPage}/{pageSize}") public Pager> listResourcePools(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryResourcePoolRequest request) { Page page = PageHelper.startPage(goPage, pageSize, true); diff --git a/backend/src/main/java/io/metersphere/dto/UpdatePoolDTO.java b/backend/src/main/java/io/metersphere/dto/UpdatePoolDTO.java new file mode 100644 index 0000000000..9272568c03 --- /dev/null +++ b/backend/src/main/java/io/metersphere/dto/UpdatePoolDTO.java @@ -0,0 +1,15 @@ +package io.metersphere.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class UpdatePoolDTO { + + /** + * 禁用资源池时,";" 连接多个使用该资源池的性能测试名称 + */ + private String testName; + private Boolean haveTestUsePool = false; +} diff --git a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java index aabc1146c7..bcf2ee6f97 100644 --- a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java +++ b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java @@ -4,14 +4,17 @@ import io.metersphere.base.domain.*; import io.metersphere.base.mapper.LoadTestMapper; import io.metersphere.base.mapper.TestResourceMapper; import io.metersphere.base.mapper.TestResourcePoolMapper; +import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.constants.ResourcePoolTypeEnum; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest; import io.metersphere.dto.TestResourcePoolDTO; +import io.metersphere.dto.UpdatePoolDTO; import io.metersphere.i18n.Translator; import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -39,6 +42,8 @@ public class TestResourcePoolService { private TestResourceMapper testResourceMapper; @Resource private NodeResourcePoolService nodeResourcePoolService; + @Resource + private LoadTestMapper loadTestMapper; public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePool) { checkTestResourcePool(testResourcePool); @@ -111,6 +116,35 @@ public class TestResourcePoolService { } } + /** + * 禁用资源池时,检查是否有测试正在使用 + * @param poolId 资源池ID + * @return UpdatePoolDTO + */ + public UpdatePoolDTO checkHaveTestUsePool(String poolId) { + TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(poolId); + if (testResourcePool == null) { + MSException.throwException("Resource Pool not found."); + } + UpdatePoolDTO result = new UpdatePoolDTO(); + StringBuilder builder = new StringBuilder(); + LoadTestExample loadTestExample = new LoadTestExample(); + loadTestExample.createCriteria().andTestResourcePoolIdEqualTo(poolId); + List loadTests = loadTestMapper.selectByExample(loadTestExample); + if (CollectionUtils.isNotEmpty(loadTests)) { + loadTests.forEach(loadTest -> { + String testStatus = loadTest.getStatus(); + if (StringUtils.equalsAny(testStatus, PerformanceTestStatus.Starting.name(), + PerformanceTestStatus.Running.name(), PerformanceTestStatus.Reporting.name())) { + builder.append(loadTest.getName()).append("; "); + result.setHaveTestUsePool(true); + } + }); + } + result.setTestName(builder.toString()); + return result; + } + public List listResourcePools(QueryResourcePoolRequest request) { TestResourcePoolExample example = new TestResourcePoolExample(); TestResourcePoolExample.Criteria criteria = example.createCriteria(); diff --git a/frontend/src/business/components/settings/system/TestResourcePool.vue b/frontend/src/business/components/settings/system/TestResourcePool.vue index d4cdb562dd..e6634e5eb0 100644 --- a/frontend/src/business/components/settings/system/TestResourcePool.vue +++ b/frontend/src/business/components/settings/system/TestResourcePool.vue @@ -221,6 +221,10 @@ export default { type: [ {required: true, message: this.$t('test_resource_pool.select_pool_type'), trigger: 'blur'} ] + }, + updatePool: { + testName: '', + haveTestUsePool: false } }; }, @@ -408,6 +412,40 @@ export default { changeSwitch(row) { this.result.loading = true; this.$info(this.$t('test_resource_pool.check_in'), 1000); + if (row.status === 'VALID') { + this.updatePoolStatus(row); + return false; + } + // 禁用时检查是否有正在使用该资源池的性能测试 + if (row.status === 'INVALID') { + this.checkHaveTestUsePool(row).then(() => { + if (this.updatePool && this.updatePool.haveTestUsePool) { + this.$confirm(this.$t('test_resource_pool.update_prompt', [this.updatePool.testName]), this.$t('commons.prompt'), { + confirmButtonText: this.$t('commons.confirm'), + cancelButtonText: this.$t('commons.cancel'), + type: 'warning' + }).then(() => { + this.updatePoolStatus(row); + }).catch(() => { + row.status = 'VALID'; + this.result.loading = false; + this.$info(this.$t('commons.cancel')); + }); + } else { + this.updatePoolStatus(row); + } + }) + } + }, + checkHaveTestUsePool(row) { + return new Promise((resolve) => { + this.$get('/testresourcepool/check/use/' + row.id, result => { + this.updatePool = result.data; + resolve(); + }) + }); + }, + updatePoolStatus(row) { this.$get('/testresourcepool/update/' + row.id + '/' + row.status) .then(() => { this.$success(this.$t('test_resource_pool.status_change_success')); diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 5f4b86bf1e..248463d9a7 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -1504,6 +1504,7 @@ export default { cannot_empty: 'Resource pool cannot be empty', fill_the_data: 'Please complete the data', delete_prompt: 'This operation will permanently delete the resource pool, continue?', + update_prompt: '{0} The other tests are using this resource pool. Disabling the monitoring part that may affect the report. Do you want to continue?', status_change_success: 'Successfully changed the status!', status_change_failed: 'Failed to change the status, resource pool is invalid!', check_in: 'Check in', diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 9ca6a601ad..4f4fd0e234 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -1521,6 +1521,7 @@ export default { cannot_empty: '资源池不能为空', fill_the_data: '请完善数据', delete_prompt: '此操作将永久删除该资源池, 是否继续?', + update_prompt: '{0} 等测试正在使用此资源池,禁用可能会影响报告的监控部分,是否继续?', status_change_success: '状态修改成功!', status_change_failed: '状态修改失败, 校验不通过!', check_in: '校验中', diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 83ec96245b..79201af402 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -1506,6 +1506,7 @@ export default { cannot_empty: '資源池不能為空', fill_the_data: '請完善數據', delete_prompt: '此操作將永久刪除該資源池, 是否繼續?', + update_prompt: '{0} 等測試正在使用此資源池,禁用可能會影響報告的監控部分,是否繼續?', status_change_success: '狀態修改成功!', status_change_failed: '狀態修改失敗, 校驗不通過!', check_in: '校驗中',