refactor(系统管理): 资源池容量详情默认显示全部节点的

This commit is contained in:
guoyuqi 2024-10-17 18:29:59 +08:00 committed by Craftsman
parent 53c9c36230
commit 7e2a1004df
2 changed files with 30 additions and 1 deletions

View File

@ -297,10 +297,30 @@ public class TestResourcePoolService {
} }
public ResourcePoolNodeMetric getTestResourcePoolCapacityDetail(TestResourcePoolCapacityRequest request) { public ResourcePoolNodeMetric getTestResourcePoolCapacityDetail(TestResourcePoolCapacityRequest request) {
ResourcePoolNodeMetric resourcePoolNodeMetric = new ResourcePoolNodeMetric();
TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(request.getPoolId()); TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(request.getPoolId());
if (testResourcePool == null || !testResourcePool.getEnable() || testResourcePool.getDeleted()) { if (testResourcePool == null || !testResourcePool.getEnable() || testResourcePool.getDeleted()) {
return null; return null;
} }
return getNodeMetric(request.getIp(), request.getPort()); if (StringUtils.isBlank(request.getIp())) {
TestResourcePoolBlob testResourcePoolBlob = testResourcePoolBlobMapper.selectByPrimaryKey(request.getPoolId());
byte[] configuration = testResourcePoolBlob.getConfiguration();
String testResourceDTOStr = new String(configuration);
TestResourceDTO testResourceDTO = JSON.parseObject(testResourceDTOStr, TestResourceDTO.class);
if (CollectionUtils.isNotEmpty(testResourceDTO.getNodesList())) {
int concurrentNumber = 0;
int occupiedConcurrentNumber = 0;
for (TestResourceNodeDTO testResourceNodeDTO : testResourceDTO.getNodesList()) {
ResourcePoolNodeMetric nodeMetric = getNodeMetric(testResourceNodeDTO.getIp(), testResourceNodeDTO.getPort());
concurrentNumber = concurrentNumber + nodeMetric.getConcurrentNumber();
occupiedConcurrentNumber = occupiedConcurrentNumber + nodeMetric.getOccupiedConcurrentNumber();
}
resourcePoolNodeMetric.setConcurrentNumber(concurrentNumber);
resourcePoolNodeMetric.setOccupiedConcurrentNumber(occupiedConcurrentNumber);
}
} else {
resourcePoolNodeMetric = getNodeMetric(request.getIp(), request.getPort());
}
return resourcePoolNodeMetric;
} }
} }

View File

@ -685,6 +685,15 @@ class TestResourcePoolControllerTests extends BaseTest {
testResourcePool.setEnable(true); testResourcePool.setEnable(true);
testResourcePool.setDeleted(true); testResourcePool.setDeleted(true);
testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool); testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool);
request.setPoolId("test_pool_1");
request.setIp(null);
mvcResult = this.requestPostWithOkAndReturn(TEST_RESOURCE_POOL_CAPACITY_LIST, request);
// 获取返回值
returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
} }
@Test @Test