refactor(性能测试): 优化查询资源池列表时长

--bug=1021932 --user=刘瑞斌 【性能测试】查看测试压力配置等待时间太长 https://www.tapd.cn/55049933/s/1329677
This commit is contained in:
CaptainB 2023-02-01 12:06:54 +08:00 committed by 刘瑞斌
parent 884fb9e5a8
commit 2c3aed1252
2 changed files with 2 additions and 75 deletions

View File

@ -1,24 +1,16 @@
package io.metersphere.xpack.resourcepool.service;
import io.metersphere.base.mapper.TestResourcePoolMapper;
import io.metersphere.commons.constants.ResourcePoolTypeEnum;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.TestResourcePoolDTO;
import io.metersphere.quota.service.BaseQuotaService;
import io.metersphere.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.service.BaseTestResourcePoolService;
import io.metersphere.service.NodeResourcePoolService;
import io.metersphere.xpack.resourcepool.engine.KubernetesResourcePoolService;
import org.apache.commons.lang3.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static io.metersphere.commons.constants.ResourceStatusEnum.INVALID;
import static io.metersphere.commons.constants.ResourceStatusEnum.VALID;
@Service
@ -26,10 +18,6 @@ public class ValidQuotaResourcePoolService {
@Resource
private BaseTestResourcePoolService baseTestResourcePoolService;
@Resource
private NodeResourcePoolService nodeResourcePoolService;
@Resource
private TestResourcePoolMapper testResourcePoolMapper;
@Resource
private BaseQuotaService baseQuotaService;
public List<TestResourcePoolDTO> listValidQuotaResourcePools() {
@ -44,37 +32,8 @@ public class ValidQuotaResourcePoolService {
return list;
}
private boolean validateTestResourcePool(TestResourcePoolDTO testResourcePool) {
if (StringUtils.equalsIgnoreCase(testResourcePool.getType(), ResourcePoolTypeEnum.K8S.name())) {
KubernetesResourcePoolService resourcePoolService = CommonBeanFactory.getBean(KubernetesResourcePoolService.class);
if (resourcePoolService == null) {
return false;
}
return resourcePoolService.validate(testResourcePool);
}
return nodeResourcePoolService.validate(testResourcePool);
}
public List<TestResourcePoolDTO> listValidResourcePools() {
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
List<TestResourcePoolDTO> testResourcePools = baseTestResourcePoolService.listResourcePools(request);
// 重新校验 pool
for (TestResourcePoolDTO pool : testResourcePools) {
// 手动设置成无效的, 排除
if (INVALID.name().equals(pool.getStatus())) {
continue;
}
try {
validateTestResourcePool(pool);
} catch (Throwable e) {
LogUtil.error(e.getMessage(), e);
pool.setStatus(INVALID.name());
pool.setUpdateTime(System.currentTimeMillis());
testResourcePoolMapper.updateByPrimaryKeySelective(pool);
}
}
request.setStatus(VALID.name());
return baseTestResourcePoolService.listResourcePools(request);
}

View File

@ -22,13 +22,13 @@ import io.metersphere.log.vo.system.SystemReference;
import io.metersphere.quota.service.BaseQuotaService;
import io.metersphere.request.resourcepool.QueryResourcePoolRequest;
import io.metersphere.xpack.resourcepool.engine.KubernetesResourcePoolService;
import jakarta.annotation.Resource;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import jakarta.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Collectors;
@ -200,44 +200,12 @@ public class TestResourcePoolService {
return nodeResourcePoolService.validate(testResourcePool);
}
public TestResourcePool getResourcePool(String resourcePoolId) {
return testResourcePoolMapper.selectByPrimaryKey(resourcePoolId);
}
public List<TestResourcePoolDTO> listValidResourcePools() {
QueryResourcePoolRequest request = new QueryResourcePoolRequest();
List<TestResourcePoolDTO> testResourcePools = listResourcePools(request);
// 重新校验 pool
for (TestResourcePoolDTO pool : testResourcePools) {
// 手动设置成无效的, 排除
if (INVALID.name().equals(pool.getStatus())) {
continue;
}
try {
validateTestResourcePool(pool);
} catch (Throwable e) {
LogUtil.error(e.getMessage(), e);
pool.setStatus(INVALID.name());
pool.setUpdateTime(System.currentTimeMillis());
testResourcePoolMapper.updateByPrimaryKeySelective(pool);
}
}
request.setStatus(VALID.name());
return listResourcePools(request);
}
public List<TestResourcePoolDTO> listValidQuotaResourcePools() {
return filterQuota(listValidResourcePools());
}
private List<TestResourcePoolDTO> filterQuota(List<TestResourcePoolDTO> list) {
Set<String> pools = baseQuotaService.getQuotaResourcePools();
if (!pools.isEmpty()) {
return list.stream().filter(pool -> pools.contains(pool.getId())).collect(Collectors.toList());
}
return list;
}
public String getLogDetails(String id) {
TestResourcePool pool = testResourcePoolMapper.selectByPrimaryKey(id);
if (pool != null) {