From 394bd7aa20709ed7bf41c44fcffc3b6850a363e0 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Mon, 14 Oct 2024 11:36:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B1=A0=E8=8A=82=E7=82=B9=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SystemTaskHubController.java | 13 ++++--- .../dto/taskhub/ResourcePoolStatusDTO.java | 25 ++++++++++++++ .../system/mapper/ExtExecTaskItemMapper.java | 2 ++ .../system/mapper/ExtExecTaskItemMapper.xml | 7 ++++ .../system/service/BaseTaskHubService.java | 34 ++++++++++++++++--- .../service/NodeResourcePoolService.java | 2 +- .../BaseTaskHubControllerTests.java | 18 +++++++++- 7 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ResourcePoolStatusDTO.java diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java index 99bd836215..f6c9015216 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java @@ -2,10 +2,7 @@ package io.metersphere.system.controller; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.dto.sdk.BasePageRequest; -import io.metersphere.system.dto.taskhub.ResourcePoolOptionsDTO; -import io.metersphere.system.dto.taskhub.TaskHubDTO; -import io.metersphere.system.dto.taskhub.TaskHubItemDTO; -import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO; +import io.metersphere.system.dto.taskhub.*; import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse; import io.metersphere.system.service.BaseTaskHubService; @@ -15,6 +12,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; +import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -68,6 +66,13 @@ public class SystemTaskHubController { return baseTaskHubService.getResourcePoolOptions(); } + @PostMapping("/resource-pool/status") + @Operation(summary = "任务详情节点状态接口") + @RequiresPermissions(value = {PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ, PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ, PermissionConstants.PROJECT_CASE_TASK_CENTER_READ}, logical = Logical.OR) + @Parameter(name = "ids", description = "详情ID集合", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) + public List resourcePoolStatus(@RequestBody List ids) { + return baseTaskHubService.getResourcePoolStatus(ids); + } //TODO 检查节点状态 //TODO 系统&组织&项目 任务按钮操作:删除 停止 失败重跑 查看报告 批量删除 批量停止 批量失败重跑 diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ResourcePoolStatusDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ResourcePoolStatusDTO.java new file mode 100644 index 0000000000..77621d95e6 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ResourcePoolStatusDTO.java @@ -0,0 +1,25 @@ +package io.metersphere.system.dto.taskhub; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serial; +import java.io.Serializable; + +/** + * @author wx + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class ResourcePoolStatusDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "详情的id") + private String id; + + @Schema(description = "状态 (true 正常 false 异常)") + private boolean status; +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java index 302fa07731..1240f349db 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java @@ -16,4 +16,6 @@ public interface ExtExecTaskItemMapper { List selectList(@Param("request") TaskHubItemRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId); List selectItemByTaskIds(@Param("taskIds") List taskIds, @Param("orgId") String orgId, @Param("projectId") String projectId); + + List selectPoolNodeByIds(@Param("ids") List ids); } 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 2dd1d6181f..b1c5f3cbfd 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 @@ -49,4 +49,11 @@ + + \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java index 1d4a2f141f..299cc3d964 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java @@ -11,12 +11,10 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.SubListUtils; import io.metersphere.system.domain.*; import io.metersphere.system.dto.pool.TestResourceDTO; +import io.metersphere.system.dto.pool.TestResourceNodeDTO; import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.sdk.OptionDTO; -import io.metersphere.system.dto.taskhub.ResourcePoolOptionsDTO; -import io.metersphere.system.dto.taskhub.TaskHubDTO; -import io.metersphere.system.dto.taskhub.TaskHubItemDTO; -import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO; +import io.metersphere.system.dto.taskhub.*; import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse; import io.metersphere.system.mapper.*; @@ -68,6 +66,8 @@ public class BaseTaskHubService { private ExtResourcePoolMapper extResourcePoolMapper; @Resource private ProjectTestResourcePoolMapper projectTestResourcePoolMapper; + @Resource + private NodeResourcePoolService nodeResourcePoolService; /** * 系统-获取执行任务列表 @@ -316,4 +316,30 @@ public class BaseTaskHubService { } return null; } + + public List getResourcePoolStatus(List ids) { + List statusDTOS = new ArrayList<>(); + List itemList = extExecTaskItemMapper.selectPoolNodeByIds(ids); + Map> poolNodeMap = itemList.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolNode)); + poolNodeMap.forEach((k, v) -> { + String[] split = k.split(":"); + TestResourceNodeDTO node = new TestResourceNodeDTO(); + boolean status = false; + try { + node.setIp(split[0]); + node.setPort(split[1]); + status = nodeResourcePoolService.validateNode(node); + } catch (Exception e) { + status = false; + } + boolean finalStatus = status; + v.forEach(item -> { + ResourcePoolStatusDTO poolStatusDTO = new ResourcePoolStatusDTO(); + poolStatusDTO.setId(item.getId()); + poolStatusDTO.setStatus(finalStatus); + statusDTOS.add(poolStatusDTO); + }); + }); + return statusDTOS; + } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/NodeResourcePoolService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/NodeResourcePoolService.java index 863c2ea7c3..2badd0b0e0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/NodeResourcePoolService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/NodeResourcePoolService.java @@ -78,7 +78,7 @@ public class NodeResourcePoolService { } } - private boolean validateNode(TestResourceNodeDTO node) { + public boolean validateNode(TestResourceNodeDTO node) { try { ResultHolder body = TaskRunnerClient.get(String.format(nodeControllerUrl, node.getIp(), node.getPort())); if (body == null) { diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java index 290ff68d28..549e2bd6f9 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java @@ -36,6 +36,7 @@ public class BaseTaskHubControllerTests extends BaseTest { public static final String SYSTEM_TASK_ITEM_PAGE = "/system/task-center/exec-task/item/page"; public static final String SYSTEM_STATISTICS = "/system/task-center/exec-task/statistics"; public static final String SYSTEM_RESOURCE_POOL_OPTIONS = "/system/task-center/resource-pool/options"; + public static final String SYSTEM_RESOURCE_POOL_STATUS = "/system/task-center/resource-pool/status"; @Test @Order(1) @@ -98,7 +99,7 @@ public class BaseTaskHubControllerTests extends BaseTest { @Test @Order(3) public void getStatistics() throws Exception { - List ids = List.of("1", "2"); + List ids = List.of("1"); MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_STATISTICS, ids); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); @@ -121,6 +122,21 @@ public class BaseTaskHubControllerTests extends BaseTest { Assertions.assertNotNull(resultHolder); } + /** + * 校验资源池节点状态 + */ + @Test + @Order(3) + public void getResourcePoolStatus() throws Exception { + List ids = List.of("1"); + MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_RESOURCE_POOL_STATUS, ids); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } + /** * 组织任务中心测试用例