diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TestResourcePoolController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TestResourcePoolController.java index 87b327a712..bca8f8a1f2 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TestResourcePoolController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TestResourcePoolController.java @@ -3,13 +3,18 @@ package io.metersphere.system.controller; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.dto.pool.ResourcePoolNodeMetric; import io.metersphere.sdk.util.BeanUtils; +import io.metersphere.system.dto.pool.TestResourcePoolCapacityRequest; import io.metersphere.system.dto.pool.TestResourcePoolDTO; import io.metersphere.system.dto.pool.TestResourcePoolRequest; import io.metersphere.system.dto.pool.TestResourcePoolReturnDTO; import io.metersphere.system.dto.sdk.QueryResourcePoolRequest; +import io.metersphere.system.dto.taskhub.TaskHubItemDTO; +import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; +import io.metersphere.system.service.BaseTaskHubService; import io.metersphere.system.service.TestResourcePoolService; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; @@ -17,6 +22,7 @@ import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; +import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -30,6 +36,8 @@ public class TestResourcePoolController { @Resource private TestResourcePoolService testResourcePoolService; + @Resource + private BaseTaskHubService baseTaskHubService; @PostMapping("/update") @Operation(summary = "系统设置-系统-资源池-更新资源池") @@ -58,6 +66,27 @@ public class TestResourcePoolController { return testResourcePoolService.getTestResourcePoolDetail(testResourcePoolId); } + @PostMapping("/capacity/detail") + @Operation(summary = "系统-资源池-查看资源池详细") + @RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ) + public ResourcePoolNodeMetric getTestResourcePoolCapacityDetail(@Validated @RequestBody TestResourcePoolCapacityRequest request) { + return testResourcePoolService.getTestResourcePoolCapacityDetail(request); + } + + @PostMapping("/capacity/task/list") + @Operation(summary = "系统-资源池-查看资源池详细") + @RequiresPermissions(PermissionConstants.SYSTEM_TEST_RESOURCE_POOL_READ) + public Pager> getCaseTaskItemList(@Validated @RequestBody TestResourcePoolCapacityRequest request) { + TaskHubItemRequest taskHubItemRequest = new TaskHubItemRequest(); + BeanUtils.copyBean(taskHubItemRequest, request); + taskHubItemRequest.setResourcePoolIds(List.of(request.getPoolId())); + if (StringUtils.isNotBlank(request.getIp()) && StringUtils.isNotBlank(request.getPort())) { + String node = new StringBuilder().append(request.getIp()).append(":").append(request.getPort()).toString(); + taskHubItemRequest.setResourcePoolNodes(List.of(node)); + } + return baseTaskHubService.getCaseTaskItemList(taskHubItemRequest, null, null); + } + diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/pool/TestResourcePoolCapacityRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/pool/TestResourcePoolCapacityRequest.java new file mode 100644 index 0000000000..1110f43ea5 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/pool/TestResourcePoolCapacityRequest.java @@ -0,0 +1,26 @@ +package io.metersphere.system.dto.pool; + +import io.metersphere.system.dto.sdk.BasePageRequest; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +/** + * @author guoyuqi + */ +@Data +public class TestResourcePoolCapacityRequest extends BasePageRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "资源池id") + private String poolId; + + @Schema(description = "节点IP") + private String ip; + + @Schema(description = "节点端口") + private String port; +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml index dc849f80ab..1cec1c2f59 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml @@ -6,32 +6,7 @@ SELECT exec_task_item.*, exec_task.num, exec_task.task_name, exec_task.trigger_mode FROM exec_task_item inner join exec_task on exec_task_item.task_id = exec_task.id - - - and ( - exec_task.num like concat('%', #{request.keyword},'%') - or exec_task_item.resource_name like concat('%', #{request.keyword},'%') - ) - - - and exec_task_item.organization_id = #{orgId} - - - and exec_task_item.project_id = #{projectId} - - - and exec_task_item.resource_pool_id in - - #{request.resourcePoolId} - - - - and exec_task_item.resource_pool_node in - - #{request.resourcePoolNode} - - - + + + + + and exec_task_item.organization_id = #{orgId} + + + and ( + exec_task.num like concat('%', #{request.keyword},'%') + or exec_task_item.resource_name like concat('%', #{request.keyword},'%') + ) + + + and exec_task_item.project_id = #{projectId} + + + and exec_task_item.resource_pool_id in + + #{resourcePoolId} + + + + and exec_task_item.resource_pool_node in + + #{resourcePoolNode} + + + + + + + + + + + + + + + + and exec_task_item.status in + + + + + and exec_task_item.result in + + + + + + + + \ No newline at end of file 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 3a824e751b..54c13ee9b1 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 @@ -164,7 +164,7 @@ public class TestResourcePoolService { for (TestResourceNodeDTO testResourceNodeDTO : testResourceDTO.getNodesList()) { maxConcurrentNumber = maxConcurrentNumber + testResourceNodeDTO.getConcurrentNumber(); //TODO: 调接口获取剩余并发 - ResourcePoolNodeMetric nodeMetric = getNodeMetric(); + ResourcePoolNodeMetric nodeMetric = getNodeMetric(testResourceNodeDTO.getIp(), testResourceNodeDTO.getPort()); if (nodeMetric != null) { concurrentNumber = concurrentNumber + (nodeMetric.getConcurrentNumber() == null ? 0 :nodeMetric.getConcurrentNumber()); occupiedConcurrentNumber = occupiedConcurrentNumber +(nodeMetric.getOccupiedConcurrentNumber() == null ? 0 :nodeMetric.getOccupiedConcurrentNumber()); @@ -181,10 +181,10 @@ public class TestResourcePoolService { return testResourcePoolDTOS; } - public ResourcePoolNodeMetric getNodeMetric() { + public ResourcePoolNodeMetric getNodeMetric(String ip, String port) { ResourcePoolNodeMetric resourcePoolNodeMetric = new ResourcePoolNodeMetric(); try { - ResultHolder body = TaskRunnerClient.get(poolControllerUrl); + ResultHolder body = TaskRunnerClient.get(String.format(poolControllerUrl, ip, port)); if (body == null) { return null; } @@ -307,4 +307,7 @@ public class TestResourcePoolService { return testResourcePoolOrganizationMapper.countByExample(example) >= 1; } + public ResourcePoolNodeMetric getTestResourcePoolCapacityDetail(TestResourcePoolCapacityRequest request) { + return getNodeMetric(request.getIp(), request.getPort()); + } } 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 c96292b63b..80d2825fac 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 @@ -73,6 +73,9 @@ class TestResourcePoolControllerTests extends BaseTest { private static final String TEST_RESOURCE_POOL_ADD = "/test/resource/pool/add"; private static final String TEST_RESOURCE_POOL_UPDATE = "/test/resource/pool/update"; + private static final String TEST_RESOURCE_POOL_CAPACITY_LIST = "/test/resource/pool/capacity/task/list"; + private static final String TEST_RESOURCE_POOL_CAPACITY_DETAIL = "/test/resource/pool/capacity/detail"; + private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError(); @@ -632,4 +635,47 @@ class TestResourcePoolControllerTests extends BaseTest { return testResourcePoolDTO; } + @Test + @Order(18) + public void getTestResourcePoolCapacityDetail() throws Exception { + TestResourcePoolCapacityRequest request = new TestResourcePoolCapacityRequest(); + request.setPoolId("test_pool_1"); + request.setIp("172.16.200.8"); + request.setPort("8082"); + this.requestPost(TEST_RESOURCE_POOL_CAPACITY_DETAIL, request); + request.setCurrent(1); + request.setPageSize(10); + MvcResult mvcResult = this.requestPostWithOkAndReturn(TEST_RESOURCE_POOL_CAPACITY_DETAIL, request); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } + + @Test + @Order(19) + public void getSystemTaskItemPage() throws Exception { + TestResourcePoolCapacityRequest request = new TestResourcePoolCapacityRequest(); + request.setPoolId("test_pool_1"); + request.setIp("172.16.200.8"); + request.setPort("8082"); + request.setCurrent(1); + request.setPageSize(10); + MvcResult mvcResult = this.requestPostWithOkAndReturn(TEST_RESOURCE_POOL_CAPACITY_LIST, request); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + request.setIp(null); + request.setPort(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); + } + } \ No newline at end of file