From 7e2a1004df33d956ac239a8f32efcf3ca7920e58 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 17 Oct 2024 18:29:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E8=B5=84=E6=BA=90=E6=B1=A0=E5=AE=B9=E9=87=8F=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=BB=98=E8=AE=A4=E6=98=BE=E7=A4=BA=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/TestResourcePoolService.java | 22 ++++++++++++++++++- .../TestResourcePoolControllerTests.java | 9 ++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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