Merge remote-tracking branch 'origin/master'

This commit is contained in:
Captain.B 2021-02-04 17:54:11 +08:00
commit 264ec0e412
3 changed files with 15 additions and 27 deletions

View File

@ -11,5 +11,9 @@ public enum ResourceStatusEnum {
/** /**
* 有效 * 有效
*/ */
VALID VALID,
/**
* 删除
*/
DELETE
} }

View File

@ -8,6 +8,7 @@ import io.metersphere.base.domain.TestResource;
import io.metersphere.base.domain.TestResourcePool; import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.constants.PerformanceTestStatus;
import io.metersphere.commons.constants.ResourcePoolTypeEnum; import io.metersphere.commons.constants.ResourcePoolTypeEnum;
import io.metersphere.commons.constants.ResourceStatusEnum;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.config.JmeterProperties; import io.metersphere.config.JmeterProperties;
@ -55,13 +56,16 @@ public abstract class AbstractEngine implements Engine {
MSException.throwException("Resource Pool ID is empty"); MSException.throwException("Resource Pool ID is empty");
} }
TestResourcePool resourcePool = testResourcePoolService.getResourcePool(resourcePoolId); TestResourcePool resourcePool = testResourcePoolService.getResourcePool(resourcePoolId);
if (resourcePool == null) { if (resourcePool == null || StringUtils.equals(resourcePool.getStatus(), ResourceStatusEnum.DELETE.name())) {
MSException.throwException("Resource Pool is empty"); MSException.throwException("Resource Pool is empty");
} }
if (!ResourcePoolTypeEnum.K8S.name().equals(resourcePool.getType()) if (!ResourcePoolTypeEnum.K8S.name().equals(resourcePool.getType())
&& !ResourcePoolTypeEnum.NODE.name().equals(resourcePool.getType())) { && !ResourcePoolTypeEnum.NODE.name().equals(resourcePool.getType())) {
MSException.throwException("Invalid Resource Pool type."); MSException.throwException("Invalid Resource Pool type.");
} }
if (!StringUtils.equals(resourcePool.getStatus(), ResourceStatusEnum.VALID.name())) {
MSException.throwException("Resource Pool Status is not VALID");
}
// image // image
String image = resourcePool.getImage(); String image = resourcePool.getImage();
if (StringUtils.isNotEmpty(image)) { if (StringUtils.isNotEmpty(image)) {

View File

@ -24,8 +24,7 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static io.metersphere.commons.constants.ResourceStatusEnum.INVALID; import static io.metersphere.commons.constants.ResourceStatusEnum.*;
import static io.metersphere.commons.constants.ResourceStatusEnum.VALID;
/** /**
* @author dongbin * @author dongbin
@ -39,8 +38,6 @@ public class TestResourcePoolService {
@Resource @Resource
private TestResourceMapper testResourceMapper; private TestResourceMapper testResourceMapper;
@Resource @Resource
private LoadTestMapper loadTestMapper;
@Resource
private NodeResourcePoolService nodeResourcePoolService; private NodeResourcePoolService nodeResourcePoolService;
public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePool) { public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePool) {
@ -55,25 +52,7 @@ public class TestResourcePoolService {
} }
public void deleteTestResourcePool(String testResourcePoolId) { public void deleteTestResourcePool(String testResourcePoolId) {
// check test is Running Starting Error updateTestResourcePoolStatus(testResourcePoolId, DELETE.name());
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"));
}
} }
public void updateTestResourcePool(TestResourcePoolDTO testResourcePool) { public void updateTestResourcePool(TestResourcePoolDTO testResourcePool) {
@ -109,8 +88,8 @@ public class TestResourcePoolService {
} }
testResourcePool.setUpdateTime(System.currentTimeMillis()); testResourcePool.setUpdateTime(System.currentTimeMillis());
testResourcePool.setStatus(status); testResourcePool.setStatus(status);
// 禁用资源池 // 禁用/删除 资源池
if (INVALID.name().equals(status)) { if (INVALID.name().equals(status) || DELETE.name().equals(status)) {
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool); testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
return; return;
} }
@ -140,6 +119,7 @@ public class TestResourcePoolService {
if (StringUtils.isNotBlank(request.getStatus())) { if (StringUtils.isNotBlank(request.getStatus())) {
criteria.andStatusEqualTo(request.getStatus()); criteria.andStatusEqualTo(request.getStatus());
} }
criteria.andStatusNotEqualTo(DELETE.name());
example.setOrderByClause("update_time desc"); example.setOrderByClause("update_time desc");
List<TestResourcePool> testResourcePools = testResourcePoolMapper.selectByExample(example); List<TestResourcePool> testResourcePools = testResourcePoolMapper.selectByExample(example);
List<TestResourcePoolDTO> testResourcePoolDTOS = new ArrayList<>(); List<TestResourcePoolDTO> testResourcePoolDTOS = new ArrayList<>();