diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/TestResourcePoolService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/TestResourcePoolService.java index 72e7cf97c3..3b8ee5ab7b 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/TestResourcePoolService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/TestResourcePoolService.java @@ -297,10 +297,30 @@ public class TestResourcePoolService { } public ResourcePoolNodeMetric getTestResourcePoolCapacityDetail(TestResourcePoolCapacityRequest request) { + ResourcePoolNodeMetric resourcePoolNodeMetric = new ResourcePoolNodeMetric(); TestResourcePool testResourcePool = testResourcePoolMapper.selectByPrimaryKey(request.getPoolId()); if (testResourcePool == null || !testResourcePool.getEnable() || testResourcePool.getDeleted()) { 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; } } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestResourcePoolControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestResourcePoolControllerTests.java index 2cecfdb022..ec77922c96 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestResourcePoolControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TestResourcePoolControllerTests.java @@ -685,6 +685,15 @@ class TestResourcePoolControllerTests extends BaseTest { testResourcePool.setEnable(true); testResourcePool.setDeleted(true); 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