refactor(系统设置): 优化测试资源池删除
This commit is contained in:
parent
2052fe9600
commit
7cb592955c
|
@ -11,5 +11,9 @@ public enum ResourceStatusEnum {
|
|||
/**
|
||||
* 有效
|
||||
*/
|
||||
VALID
|
||||
VALID,
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
DELETE
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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<LoadTest> 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<TestResourcePool> testResourcePools = testResourcePoolMapper.selectByExample(example);
|
||||
List<TestResourcePoolDTO> testResourcePoolDTOS = new ArrayList<>();
|
||||
|
|
Loading…
Reference in New Issue