From 250f7dd894d461ce1d7cc912f4d7a7ee8a4b4b43 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Sat, 12 Oct 2024 15:50:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=8E=B7=E5=8F=96=E8=B5=84=E6=BA=90=E6=B1=A0?= =?UTF-8?q?=E4=B8=8B=E6=8B=89=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SystemTaskHubController.java | 25 +++++++-- .../dto/taskhub/ResourcePoolOptionsDTO.java | 21 +++++++ .../taskhub/request/TaskHubItemRequest.java | 6 +- .../system/mapper/ExtExecTaskItemMapper.xml | 13 ++++- .../system/service/BaseTaskHubService.java | 56 +++++++++++++++++-- .../BaseTaskHubControllerTests.java | 21 +++++-- 6 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ResourcePoolOptionsDTO.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 f25a171def..e061f1dd03 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,6 +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; @@ -16,10 +17,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -61,4 +59,23 @@ public class SystemTaskHubController { public List calculateRate(@RequestBody List ids) { return baseTaskHubService.calculateRate(ids, null, null); } + + + @GetMapping("/resource-pool/options") + @Operation(summary = "系统-任务中心-获取资源池下拉选项") + public List getUserProject() { + return baseTaskHubService.getResourcePoolOptions(); + } + + //TODO 检查节点状态 + + //TODO 组织&项目 获取资源池下拉选项 + + //TODO 系统&组织&项目 任务按钮操作:删除 停止 失败重跑 查看报告 批量删除 批量停止 批量失败重跑 + + + //TODO 系统&组织&项目 任务详情按钮操作:查看 停止 批量停止 + + + //TODO 系统&组织&项目 后台任务操作:删除 批量开启 批量关闭 } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ResourcePoolOptionsDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ResourcePoolOptionsDTO.java new file mode 100644 index 0000000000..2b35ec1da9 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/ResourcePoolOptionsDTO.java @@ -0,0 +1,21 @@ +package io.metersphere.system.dto.taskhub; + +import io.metersphere.system.dto.sdk.OptionDTO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author wx + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class ResourcePoolOptionsDTO extends OptionDTO { + + @Schema(description = "资源池节点") + private List children = new ArrayList<>(); + +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/request/TaskHubItemRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/request/TaskHubItemRequest.java index c00c160f43..87252e934f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/request/TaskHubItemRequest.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/request/TaskHubItemRequest.java @@ -6,6 +6,7 @@ import lombok.Data; import java.io.Serial; import java.io.Serializable; +import java.util.List; /** * @author wx @@ -20,5 +21,8 @@ public class TaskHubItemRequest extends BasePageRequest implements Serializable private String taskId; @Schema(description = "资源池id") - private String resourcePoolId; + private List resourcePoolIds; + + @Schema(description = "资源池节点") + private List resourcePoolNodes; } 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 986ea339a1..099010796d 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 @@ -18,8 +18,17 @@ and exec_task_item.project_id = #{projectId} - - and exec_task_item.resource_pool_id = #{request.resourcePoolId} + + and exec_task_item.resource_pool_id in + + #{request.resourcePoolId} + + + + and exec_task_item.resource_pool_node in + + #{request.resourcePoolNode} + 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 f9e8220708..36dc4560b5 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 @@ -2,14 +2,15 @@ package io.metersphere.system.service; import com.github.pagehelper.Page; import com.github.pagehelper.page.PageMethod; -import io.metersphere.plan.mapper.TestPlanMapper; import io.metersphere.sdk.constants.ExecStatus; import io.metersphere.sdk.constants.ResultStatus; +import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.SubListUtils; -import io.metersphere.system.domain.ExecTask; -import io.metersphere.system.domain.ExecTaskItem; +import io.metersphere.system.domain.*; +import io.metersphere.system.dto.pool.TestResourceDTO; 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; @@ -55,7 +56,9 @@ public class BaseTaskHubService { @Resource private ExtExecTaskItemMapper extExecTaskItemMapper; @Resource - private TestPlanMapper testPlanMapper; + private TestResourcePoolMapper testResourcePoolMapper; + @Resource + private TestResourcePoolBlobMapper testResourcePoolBlobMapper; /** * 系统-获取执行任务列表 @@ -216,4 +219,49 @@ public class BaseTaskHubService { return responseList; } + + /** + * 获取所有资源池及节点下拉选项 + * + * @return + */ + public List getResourcePoolOptions() { + //获取全部资源池 + TestResourcePoolExample example = new TestResourcePoolExample(); + example.createCriteria().andDeletedEqualTo(false); + List allResourcePools = testResourcePoolMapper.selectByExample(example); + List ids = allResourcePools.stream().map(TestResourcePool::getId).toList(); + //获取全部资源池节点 + TestResourcePoolBlobExample blobExample = new TestResourcePoolBlobExample(); + blobExample.createCriteria().andIdIn(ids); + List testResourcePoolBlobs = testResourcePoolBlobMapper.selectByExampleWithBLOBs(blobExample); + Map> poolMap = testResourcePoolBlobs.stream().collect(Collectors.groupingBy(TestResourcePoolBlob::getId)); + + return handleOptions(allResourcePools, poolMap); + + } + + private List handleOptions(List allResourcePools, Map> poolMap) { + List options = new ArrayList<>(); + allResourcePools.forEach(item -> { + ResourcePoolOptionsDTO optionsDTO = new ResourcePoolOptionsDTO(); + optionsDTO.setId(item.getId()); + optionsDTO.setName(item.getName()); + if (poolMap.containsKey(item.getId())) { + TestResourcePoolBlob first = poolMap.get(item.getId()).getFirst(); + TestResourceDTO testResourceDTO = JSON.parseObject(new String(first.getConfiguration()), TestResourceDTO.class); + List children = new ArrayList<>(); + testResourceDTO.getNodesList().forEach(node -> { + OptionDTO childrenDTO = new OptionDTO(); + childrenDTO.setId(node.getIp().concat(":").concat(node.getPort())); + childrenDTO.setName(node.getIp().concat(":").concat(node.getPort())); + children.add(childrenDTO); + }); + optionsDTO.setChildren(children); + } + options.add(optionsDTO); + }); + return options; + } + } 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 83a43f3a9e..d93aff78d5 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 @@ -35,6 +35,7 @@ public class BaseTaskHubControllerTests extends BaseTest { public static final String SYSTEM_SCHEDULE_TASK_PAGE = "/system/task-center/schedule/page"; 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"; @Test @Order(1) @@ -97,7 +98,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", "2"); MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_STATISTICS, ids); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); @@ -106,6 +107,20 @@ public class BaseTaskHubControllerTests extends BaseTest { Assertions.assertNotNull(resultHolder); } + /** + * 系统获取资源池下拉选项 + */ + @Test + @Order(3) + public void getSystemResourcePoolOptions() throws Exception { + MvcResult mvcResult = this.requestGetWithOkAndReturn(SYSTEM_RESOURCE_POOL_OPTIONS); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } + /** * 组织任务中心测试用例 @@ -173,7 +188,7 @@ public class BaseTaskHubControllerTests extends BaseTest { @Test @Order(4) public void getOrgStatistics() throws Exception { - List ids = List.of("1","2"); + List ids = List.of("1", "2"); MvcResult mvcResult = this.requestPostWithOkAndReturn(ORG_STATISTICS, ids); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); @@ -183,8 +198,6 @@ public class BaseTaskHubControllerTests extends BaseTest { } - - @Test @Order(21) public void testInsert() throws Exception {