diff --git a/backend/src/main/java/io/metersphere/commons/constants/ResourceStatusEnum.java b/backend/src/main/java/io/metersphere/commons/constants/ResourceStatusEnum.java index 7830ac83a8..812148daac 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/ResourceStatusEnum.java +++ b/backend/src/main/java/io/metersphere/commons/constants/ResourceStatusEnum.java @@ -11,5 +11,9 @@ public enum ResourceStatusEnum { /** * 有效 */ - VALID + VALID, + /** + * 删除 + */ + DELETE } diff --git a/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java b/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java index f6eda2e823..73b3b50833 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java +++ b/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java @@ -8,6 +8,7 @@ import io.metersphere.base.domain.TestResource; import io.metersphere.base.domain.TestResourcePool; import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.constants.ResourcePoolTypeEnum; +import io.metersphere.commons.constants.ResourceStatusEnum; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.config.JmeterProperties; @@ -55,13 +56,16 @@ public abstract class AbstractEngine implements Engine { MSException.throwException("Resource Pool ID is empty"); } TestResourcePool resourcePool = testResourcePoolService.getResourcePool(resourcePoolId); - if (resourcePool == null) { + if (resourcePool == null || StringUtils.equals(resourcePool.getStatus(), ResourceStatusEnum.DELETE.name())) { MSException.throwException("Resource Pool is empty"); } if (!ResourcePoolTypeEnum.K8S.name().equals(resourcePool.getType()) && !ResourcePoolTypeEnum.NODE.name().equals(resourcePool.getType())) { MSException.throwException("Invalid Resource Pool type."); } + if (!StringUtils.equals(resourcePool.getStatus(), ResourceStatusEnum.VALID.name())) { + MSException.throwException("Resource Pool Status is not VALID"); + } // image String image = resourcePool.getImage(); if (StringUtils.isNotEmpty(image)) { diff --git a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java index b76bd9021d..bca5686ebd 100644 --- a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java +++ b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java @@ -24,8 +24,7 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; -import static io.metersphere.commons.constants.ResourceStatusEnum.INVALID; -import static io.metersphere.commons.constants.ResourceStatusEnum.VALID; +import static io.metersphere.commons.constants.ResourceStatusEnum.*; /** * @author dongbin @@ -39,8 +38,6 @@ public class TestResourcePoolService { @Resource private TestResourceMapper testResourceMapper; @Resource - private LoadTestMapper loadTestMapper; - @Resource private NodeResourcePoolService nodeResourcePoolService; public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePool) { @@ -55,25 +52,7 @@ 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) { - LoadTestExample example = new LoadTestExample(); - example.createCriteria() - .andTestResourcePoolIdEqualTo(testResourcePoolId); - List loadTests = loadTestMapper.selectByExample(example); - StringBuilder loadTestNames = new StringBuilder(); - if (loadTests.size() > 0) { - for (LoadTest loadTest : loadTests) { - loadTestNames = loadTestNames.append(loadTest.getName()).append(","); - } - String str = loadTestNames.substring(0, loadTestNames.length() - 1); - MSException.throwException(Translator.get("load_test") + " " + str + " " + Translator.get("test_resource_pool_is_use")); - } + updateTestResourcePoolStatus(testResourcePoolId, DELETE.name()); } public void updateTestResourcePool(TestResourcePoolDTO testResourcePool) { @@ -109,8 +88,8 @@ public class TestResourcePoolService { } testResourcePool.setUpdateTime(System.currentTimeMillis()); testResourcePool.setStatus(status); - // 禁用资源池 - if (INVALID.name().equals(status)) { + // 禁用/删除 资源池 + if (INVALID.name().equals(status) || DELETE.name().equals(status)) { testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool); return; } @@ -140,6 +119,7 @@ public class TestResourcePoolService { if (StringUtils.isNotBlank(request.getStatus())) { criteria.andStatusEqualTo(request.getStatus()); } + criteria.andStatusNotEqualTo(DELETE.name()); example.setOrderByClause("update_time desc"); List testResourcePools = testResourcePoolMapper.selectByExample(example); List testResourcePoolDTOS = new ArrayList<>();