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.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)) {

View File

@ -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<>();