diff --git a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java index 8aa2c6977f..1e271b6796 100644 --- a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java +++ b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java @@ -1,12 +1,11 @@ package io.metersphere.service; import com.alibaba.fastjson.JSON; -import io.metersphere.base.domain.TestResource; -import io.metersphere.base.domain.TestResourceExample; -import io.metersphere.base.domain.TestResourcePool; -import io.metersphere.base.domain.TestResourcePoolExample; +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.ResourceStatusEnum; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; @@ -27,6 +26,7 @@ import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; @@ -49,6 +49,8 @@ public class TestResourcePoolService { private TestResourceMapper testResourceMapper; @Resource private RestTemplate restTemplate; + @Resource + private LoadTestMapper loadTestMapper; public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePool) { checkTestResourcePool(testResourcePool); @@ -62,10 +64,23 @@ public class TestResourcePoolService { } public void deleteTestResourcePool(String testResourcePoolId) { + // check test is Running Starting Error + checkTestStatus(testResourcePoolId); deleteTestResource(testResourcePoolId); testResourcePoolMapper.deleteByPrimaryKey(testResourcePoolId); } + public void checkTestStatus(String testResourcePoolId) { + List list = Arrays.asList(PerformanceTestStatus.Running, PerformanceTestStatus.Starting, PerformanceTestStatus.Error); + LoadTestExample example = new LoadTestExample(); + example.createCriteria() + .andTestResourcePoolIdEqualTo(testResourcePoolId) + .andStatusIn(list); + if (loadTestMapper.countByExample(example) > 0) { + MSException.throwException(Translator.get("test_resource_pool_is_use")); + } + } + public void updateTestResourcePool(TestResourcePoolDTO testResourcePool) { checkTestResourcePool(testResourcePool); testResourcePool.setUpdateTime(System.currentTimeMillis()); diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 44edb7220a..2561a45caa 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -47,6 +47,7 @@ workspace_not_exists=Workspace is not exists test_resource_pool_id_is_null=Test Resource Pool ID cannot be null test_resource_pool_name_is_null=Test Resource Pool name cannot be null test_resource_pool_name_already_exists=The test resource pool name already exists +test_resource_pool_is_use=The test resource pool is in use and cannot be deleted #project project_name_is_null=Project name cannot be null project_name_already_exists=The project name already exists diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index d8d305cc00..e38870fe54 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -47,6 +47,7 @@ workspace_not_exists=工作空间不存在 test_resource_pool_id_is_null=资源池ID不能为空 test_resource_pool_name_is_null=资源池名称不能为空 test_resource_pool_name_already_exists=资源池名称已存在 +test_resource_pool_is_use=资源池正在使用中,无法删除 #project project_name_is_null=项目名称不能为空 project_name_already_exists=项目名称已存在 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index f0453f2c57..ab308ab39c 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -47,6 +47,7 @@ workspace_not_exists=工作空間不存在 test_resource_pool_id_is_null=資源池ID不能為空 test_resource_pool_name_is_null=資源池名稱不能為空 test_resource_pool_name_already_exists=資源池名稱已存在 +test_resource_pool_is_use=資源池正在使用中,無法刪除 #project project_name_is_null=項目名稱不能為空 project_name_already_exists=項目名稱已存在 diff --git a/frontend/src/business/components/settings/system/TestResourcePool.vue b/frontend/src/business/components/settings/system/TestResourcePool.vue index 7f0005a255..4c50fc6b0b 100644 --- a/frontend/src/business/components/settings/system/TestResourcePool.vue +++ b/frontend/src/business/components/settings/system/TestResourcePool.vue @@ -294,10 +294,10 @@ cancelButtonText: this.$t('commons.cancel'), type: 'warning' }).then(() => { - this.result = this.$get(`/testresourcepool/delete/${row.id}`).then(() => { + this.result = this.$get(`/testresourcepool/delete/${row.id}`,() => { this.initTableData(); + this.$success(this.$t('commons.delete_success')); }); - this.$success(this.$t('commons.delete_success')); }).catch(() => { this.$info(this.$t('commons.delete_cancel')); });