refactor(性能测试): 禁用资源池时检查是否有测试正在使用
This commit is contained in:
parent
c7863df110
commit
1bf00efb41
|
@ -7,6 +7,7 @@ import io.metersphere.commons.utils.PageUtils;
|
||||||
import io.metersphere.commons.utils.Pager;
|
import io.metersphere.commons.utils.Pager;
|
||||||
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
|
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
|
||||||
import io.metersphere.dto.TestResourcePoolDTO;
|
import io.metersphere.dto.TestResourcePoolDTO;
|
||||||
|
import io.metersphere.dto.UpdatePoolDTO;
|
||||||
import io.metersphere.service.TestResourcePoolService;
|
import io.metersphere.service.TestResourcePoolService;
|
||||||
import org.apache.shiro.authz.annotation.Logical;
|
import org.apache.shiro.authz.annotation.Logical;
|
||||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||||
|
@ -43,6 +44,11 @@ public class TestResourcePoolController {
|
||||||
testResourcePoolService.updateTestResourcePoolStatus(poolId, status);
|
testResourcePoolService.updateTestResourcePoolStatus(poolId, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/check/use/{poolId}")
|
||||||
|
public UpdatePoolDTO checkHaveTestUsePool(@PathVariable String poolId) {
|
||||||
|
return testResourcePoolService.checkHaveTestUsePool(poolId);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("list/{goPage}/{pageSize}")
|
@PostMapping("list/{goPage}/{pageSize}")
|
||||||
public Pager<List<TestResourcePoolDTO>> listResourcePools(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryResourcePoolRequest request) {
|
public Pager<List<TestResourcePoolDTO>> listResourcePools(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryResourcePoolRequest request) {
|
||||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package io.metersphere.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class UpdatePoolDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 禁用资源池时,";" 连接多个使用该资源池的性能测试名称
|
||||||
|
*/
|
||||||
|
private String testName;
|
||||||
|
private Boolean haveTestUsePool = false;
|
||||||
|
}
|
|
@ -4,14 +4,17 @@ import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.LoadTestMapper;
|
import io.metersphere.base.mapper.LoadTestMapper;
|
||||||
import io.metersphere.base.mapper.TestResourceMapper;
|
import io.metersphere.base.mapper.TestResourceMapper;
|
||||||
import io.metersphere.base.mapper.TestResourcePoolMapper;
|
import io.metersphere.base.mapper.TestResourcePoolMapper;
|
||||||
|
import io.metersphere.commons.constants.PerformanceTestStatus;
|
||||||
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
|
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
|
||||||
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.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
|
import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest;
|
||||||
import io.metersphere.dto.TestResourcePoolDTO;
|
import io.metersphere.dto.TestResourcePoolDTO;
|
||||||
|
import io.metersphere.dto.UpdatePoolDTO;
|
||||||
import io.metersphere.i18n.Translator;
|
import io.metersphere.i18n.Translator;
|
||||||
import org.apache.commons.beanutils.BeanUtils;
|
import org.apache.commons.beanutils.BeanUtils;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -39,6 +42,8 @@ public class TestResourcePoolService {
|
||||||
private TestResourceMapper testResourceMapper;
|
private TestResourceMapper testResourceMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private NodeResourcePoolService nodeResourcePoolService;
|
private NodeResourcePoolService nodeResourcePoolService;
|
||||||
|
@Resource
|
||||||
|
private LoadTestMapper loadTestMapper;
|
||||||
|
|
||||||
public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePool) {
|
public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePool) {
|
||||||
checkTestResourcePool(testResourcePool);
|
checkTestResourcePool(testResourcePool);
|
||||||
|
@ -111,6 +116,35 @@ public class TestResourcePoolService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 禁用资源池时,检查是否有测试正在使用
|
||||||
|
* @param poolId 资源池ID
|
||||||
|
* @return UpdatePoolDTO
|
||||||
|
*/
|
||||||
|
public UpdatePoolDTO checkHaveTestUsePool(String poolId) {
|
||||||
|
TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(poolId);
|
||||||
|
if (testResourcePool == null) {
|
||||||
|
MSException.throwException("Resource Pool not found.");
|
||||||
|
}
|
||||||
|
UpdatePoolDTO result = new UpdatePoolDTO();
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
LoadTestExample loadTestExample = new LoadTestExample();
|
||||||
|
loadTestExample.createCriteria().andTestResourcePoolIdEqualTo(poolId);
|
||||||
|
List<LoadTest> loadTests = loadTestMapper.selectByExample(loadTestExample);
|
||||||
|
if (CollectionUtils.isNotEmpty(loadTests)) {
|
||||||
|
loadTests.forEach(loadTest -> {
|
||||||
|
String testStatus = loadTest.getStatus();
|
||||||
|
if (StringUtils.equalsAny(testStatus, PerformanceTestStatus.Starting.name(),
|
||||||
|
PerformanceTestStatus.Running.name(), PerformanceTestStatus.Reporting.name())) {
|
||||||
|
builder.append(loadTest.getName()).append("; ");
|
||||||
|
result.setHaveTestUsePool(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
result.setTestName(builder.toString());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public List<TestResourcePoolDTO> listResourcePools(QueryResourcePoolRequest request) {
|
public List<TestResourcePoolDTO> listResourcePools(QueryResourcePoolRequest request) {
|
||||||
TestResourcePoolExample example = new TestResourcePoolExample();
|
TestResourcePoolExample example = new TestResourcePoolExample();
|
||||||
TestResourcePoolExample.Criteria criteria = example.createCriteria();
|
TestResourcePoolExample.Criteria criteria = example.createCriteria();
|
||||||
|
|
|
@ -221,6 +221,10 @@ export default {
|
||||||
type: [
|
type: [
|
||||||
{required: true, message: this.$t('test_resource_pool.select_pool_type'), trigger: 'blur'}
|
{required: true, message: this.$t('test_resource_pool.select_pool_type'), trigger: 'blur'}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
updatePool: {
|
||||||
|
testName: '',
|
||||||
|
haveTestUsePool: false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -408,6 +412,40 @@ export default {
|
||||||
changeSwitch(row) {
|
changeSwitch(row) {
|
||||||
this.result.loading = true;
|
this.result.loading = true;
|
||||||
this.$info(this.$t('test_resource_pool.check_in'), 1000);
|
this.$info(this.$t('test_resource_pool.check_in'), 1000);
|
||||||
|
if (row.status === 'VALID') {
|
||||||
|
this.updatePoolStatus(row);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 禁用时检查是否有正在使用该资源池的性能测试
|
||||||
|
if (row.status === 'INVALID') {
|
||||||
|
this.checkHaveTestUsePool(row).then(() => {
|
||||||
|
if (this.updatePool && this.updatePool.haveTestUsePool) {
|
||||||
|
this.$confirm(this.$t('test_resource_pool.update_prompt', [this.updatePool.testName]), this.$t('commons.prompt'), {
|
||||||
|
confirmButtonText: this.$t('commons.confirm'),
|
||||||
|
cancelButtonText: this.$t('commons.cancel'),
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
this.updatePoolStatus(row);
|
||||||
|
}).catch(() => {
|
||||||
|
row.status = 'VALID';
|
||||||
|
this.result.loading = false;
|
||||||
|
this.$info(this.$t('commons.cancel'));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.updatePoolStatus(row);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
checkHaveTestUsePool(row) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.$get('/testresourcepool/check/use/' + row.id, result => {
|
||||||
|
this.updatePool = result.data;
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
},
|
||||||
|
updatePoolStatus(row) {
|
||||||
this.$get('/testresourcepool/update/' + row.id + '/' + row.status)
|
this.$get('/testresourcepool/update/' + row.id + '/' + row.status)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$success(this.$t('test_resource_pool.status_change_success'));
|
this.$success(this.$t('test_resource_pool.status_change_success'));
|
||||||
|
|
|
@ -1504,6 +1504,7 @@ export default {
|
||||||
cannot_empty: 'Resource pool cannot be empty',
|
cannot_empty: 'Resource pool cannot be empty',
|
||||||
fill_the_data: 'Please complete the data',
|
fill_the_data: 'Please complete the data',
|
||||||
delete_prompt: 'This operation will permanently delete the resource pool, continue?',
|
delete_prompt: 'This operation will permanently delete the resource pool, continue?',
|
||||||
|
update_prompt: '{0} The other tests are using this resource pool. Disabling the monitoring part that may affect the report. Do you want to continue?',
|
||||||
status_change_success: 'Successfully changed the status!',
|
status_change_success: 'Successfully changed the status!',
|
||||||
status_change_failed: 'Failed to change the status, resource pool is invalid!',
|
status_change_failed: 'Failed to change the status, resource pool is invalid!',
|
||||||
check_in: 'Check in',
|
check_in: 'Check in',
|
||||||
|
|
|
@ -1521,6 +1521,7 @@ export default {
|
||||||
cannot_empty: '资源池不能为空',
|
cannot_empty: '资源池不能为空',
|
||||||
fill_the_data: '请完善数据',
|
fill_the_data: '请完善数据',
|
||||||
delete_prompt: '此操作将永久删除该资源池, 是否继续?',
|
delete_prompt: '此操作将永久删除该资源池, 是否继续?',
|
||||||
|
update_prompt: '{0} 等测试正在使用此资源池,禁用可能会影响报告的监控部分,是否继续?',
|
||||||
status_change_success: '状态修改成功!',
|
status_change_success: '状态修改成功!',
|
||||||
status_change_failed: '状态修改失败, 校验不通过!',
|
status_change_failed: '状态修改失败, 校验不通过!',
|
||||||
check_in: '校验中',
|
check_in: '校验中',
|
||||||
|
|
|
@ -1506,6 +1506,7 @@ export default {
|
||||||
cannot_empty: '資源池不能為空',
|
cannot_empty: '資源池不能為空',
|
||||||
fill_the_data: '請完善數據',
|
fill_the_data: '請完善數據',
|
||||||
delete_prompt: '此操作將永久刪除該資源池, 是否繼續?',
|
delete_prompt: '此操作將永久刪除該資源池, 是否繼續?',
|
||||||
|
update_prompt: '{0} 等測試正在使用此資源池,禁用可能會影響報告的監控部分,是否繼續?',
|
||||||
status_change_success: '狀態修改成功!',
|
status_change_success: '狀態修改成功!',
|
||||||
status_change_failed: '狀態修改失敗, 校驗不通過!',
|
status_change_failed: '狀態修改失敗, 校驗不通過!',
|
||||||
check_in: '校驗中',
|
check_in: '校驗中',
|
||||||
|
|
Loading…
Reference in New Issue