This commit is contained in:
chenjianxing 2021-02-05 10:57:05 +08:00
commit 21678d4a77
5 changed files with 22 additions and 68 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

@ -1,37 +0,0 @@
package io.metersphere.performance.job;
import com.fit2cloud.quartz.anno.QuartzScheduled;
import io.metersphere.base.domain.LoadTestReport;
import io.metersphere.base.domain.LoadTestReportDetailExample;
import io.metersphere.base.domain.LoadTestReportExample;
import io.metersphere.base.mapper.LoadTestReportDetailMapper;
import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.commons.constants.PerformanceTestStatus;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
@Component
public class LoadTestReportDetailCleanJob {
@Resource
private LoadTestReportDetailMapper loadTestReportDetailMapper;
@Resource
private LoadTestReportMapper loadTestReportMapper;
/**
* 每天处理一次清理任务
*/
@QuartzScheduled(cron = "0 0 1 * * ?")
public void cleanCompletedTestDetail() {
LoadTestReportExample example = new LoadTestReportExample();
example.createCriteria().andStatusEqualTo(PerformanceTestStatus.Completed.name());
List<LoadTestReport> loadTestReports = loadTestReportMapper.selectByExample(example);
loadTestReports.forEach(report -> {
// 清理文件
LoadTestReportDetailExample example2 = new LoadTestReportDetailExample();
example2.createCriteria().andReportIdEqualTo(report.getId());
loadTestReportDetailMapper.deleteByExample(example2);
});
}
}

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

View File

@ -270,10 +270,13 @@
this.singleLoading = true;
this.singleRunId = row.id;
row.request.name = row.id;
row.request.useEnvironment = this.environment.id;
this.runData.push(row.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
this.$get('/api/definition/get/' + row.request.id, response => {
row.request.path = response.data.path; // pathpath
row.request.useEnvironment = this.environment.id;
this.runData.push(row.request);
/*触发执行操作*/
this.reportId = getUUID().substring(0, 8);
});
},
batchRun() {