fix(系统管理): 补充资源池剩余并发数数据获取

This commit is contained in:
guoyuqi 2024-10-15 19:08:35 +08:00 committed by Craftsman
parent 504691496e
commit 49af0211e3
3 changed files with 40 additions and 16 deletions

View File

@ -19,7 +19,7 @@ public class TestResourcePoolDTO extends TestResourcePool {
private int maxConcurrentNumber; private int maxConcurrentNumber;
@Schema(description = "剩余并发数") @Schema(description = "剩余并发数")
private Boolean lastConcurrentNumber;; private int lastConcurrentNumber;;
@Schema(description = "组织名称集合") @Schema(description = "组织名称集合")
private List<String> orgNames; private List<String> orgNames;

View File

@ -3,11 +3,10 @@ package io.metersphere.system.service;
import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.HttpMethodConstants;
import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.constants.OperationLogConstants;
import io.metersphere.sdk.constants.ResourcePoolTypeEnum; import io.metersphere.sdk.constants.ResourcePoolTypeEnum;
import io.metersphere.sdk.dto.pool.ResourcePoolNodeMetric;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.*;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.*; import io.metersphere.system.domain.*;
import io.metersphere.system.dto.pool.*; import io.metersphere.system.dto.pool.*;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
@ -17,6 +16,7 @@ import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.mapper.*; import io.metersphere.system.mapper.*;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.TaskRunnerClient;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
@ -48,6 +48,8 @@ public class TestResourcePoolService {
@Resource @Resource
private ExtResourcePoolMapper extResourcePoolMapper; private ExtResourcePoolMapper extResourcePoolMapper;
private final static String poolControllerUrl = "http://%s:%s/metric";
public void checkAndSaveOrgRelation(TestResourcePool testResourcePool, String id, TestResourceDTO testResourceDTO) { public void checkAndSaveOrgRelation(TestResourcePool testResourcePool, String id, TestResourceDTO testResourceDTO) {
//防止前端传入的应用组织为空 //防止前端传入的应用组织为空
@ -156,20 +158,47 @@ public class TestResourcePoolService {
} }
//获取最大并发 //获取最大并发
if (StringUtils.equalsIgnoreCase(pool.getType(), ResourcePoolTypeEnum.NODE.getName())) { if (StringUtils.equalsIgnoreCase(pool.getType(), ResourcePoolTypeEnum.NODE.getName())) {
int maxConcurrentNumber = 0;
int concurrentNumber = 0; int concurrentNumber = 0;
int occupiedConcurrentNumber = 0;
for (TestResourceNodeDTO testResourceNodeDTO : testResourceDTO.getNodesList()) { for (TestResourceNodeDTO testResourceNodeDTO : testResourceDTO.getNodesList()) {
concurrentNumber = concurrentNumber+testResourceNodeDTO.getConcurrentNumber(); maxConcurrentNumber = maxConcurrentNumber + testResourceNodeDTO.getConcurrentNumber();
//TODO 调接口获取剩余并发
ResourcePoolNodeMetric nodeMetric = getNodeMetric();
if (nodeMetric != null) {
concurrentNumber = concurrentNumber + (nodeMetric.getConcurrentNumber() == null ? 0 :nodeMetric.getConcurrentNumber());
occupiedConcurrentNumber = occupiedConcurrentNumber +(nodeMetric.getOccupiedConcurrentNumber() == null ? 0 :nodeMetric.getOccupiedConcurrentNumber());
} }
testResourcePoolDTO.setMaxConcurrentNumber(concurrentNumber); }
testResourcePoolDTO.setLastConcurrentNumber(concurrentNumber-occupiedConcurrentNumber);
testResourcePoolDTO.setMaxConcurrentNumber(maxConcurrentNumber);
} else { } else {
testResourcePoolDTO.setMaxConcurrentNumber(testResourceDTO.getConcurrentNumber()); testResourcePoolDTO.setMaxConcurrentNumber(testResourceDTO.getConcurrentNumber());
} }
//TODO 调接口获取剩余并发
testResourcePoolDTOS.add(testResourcePoolDTO); testResourcePoolDTOS.add(testResourcePoolDTO);
}); });
return testResourcePoolDTOS; return testResourcePoolDTOS;
} }
public ResourcePoolNodeMetric getNodeMetric() {
ResourcePoolNodeMetric resourcePoolNodeMetric = new ResourcePoolNodeMetric();
try {
ResultHolder body = TaskRunnerClient.get(poolControllerUrl);
if (body == null) {
return null;
}
if (body.getData() != null && StringUtils.equalsIgnoreCase("OK", body.getData().toString())) {
return null;
}
resourcePoolNodeMetric = JSON.parseObject(JSON.toJSONString(body.getData()), ResourcePoolNodeMetric.class);
} catch (Exception e) {
LogUtils.error(e.getMessage(), e);
}
return resourcePoolNodeMetric;
}
public void checkTestResourcePool(TestResourcePool testResourcePool) { public void checkTestResourcePool(TestResourcePool testResourcePool) {
String resourcePoolName = testResourcePool.getName(); String resourcePoolName = testResourcePool.getName();
TestResourcePoolExample example = new TestResourcePoolExample(); TestResourcePoolExample example = new TestResourcePoolExample();

View File

@ -632,9 +632,4 @@ class TestResourcePoolControllerTests extends BaseTest {
return testResourcePoolDTO; return testResourcePoolDTO;
} }
@Test
void resourceEnumName() throws Exception {
System.out.println(ResourcePoolTypeEnum.K8S.getName());
}
} }