feat(任务中心): 资源池节点状态检查

This commit is contained in:
WangXu10 2024-10-14 11:36:45 +08:00 committed by Craftsman
parent 1007d7f4eb
commit 394bd7aa20
7 changed files with 91 additions and 10 deletions

View File

@ -2,10 +2,7 @@ package io.metersphere.system.controller;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.taskhub.ResourcePoolOptionsDTO; import io.metersphere.system.dto.taskhub.*;
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.request.TaskHubItemRequest; import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse; import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse;
import io.metersphere.system.service.BaseTaskHubService; 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.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -68,6 +66,13 @@ public class SystemTaskHubController {
return baseTaskHubService.getResourcePoolOptions(); 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<ResourcePoolStatusDTO> resourcePoolStatus(@RequestBody List<String> ids) {
return baseTaskHubService.getResourcePoolStatus(ids);
}
//TODO 检查节点状态 //TODO 检查节点状态
//TODO 系统&组织&项目 任务按钮操作删除 停止 失败重跑 查看报告 批量删除 批量停止 批量失败重跑 //TODO 系统&组织&项目 任务按钮操作删除 停止 失败重跑 查看报告 批量删除 批量停止 批量失败重跑

View File

@ -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;
}

View File

@ -16,4 +16,6 @@ public interface ExtExecTaskItemMapper {
List<TaskHubItemDTO> selectList(@Param("request") TaskHubItemRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId); List<TaskHubItemDTO> selectList(@Param("request") TaskHubItemRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId);
List<ExecTaskItem> selectItemByTaskIds(@Param("taskIds") List<String> taskIds, @Param("orgId") String orgId, @Param("projectId") String projectId); List<ExecTaskItem> selectItemByTaskIds(@Param("taskIds") List<String> taskIds, @Param("orgId") String orgId, @Param("projectId") String projectId);
List<ExecTaskItem> selectPoolNodeByIds(@Param("ids") List<String> ids);
} }

View File

@ -49,4 +49,11 @@
</if> </if>
</select> </select>
<select id="selectPoolNodeByIds" resultType="io.metersphere.system.domain.ExecTaskItem">
select id, resource_pool_node from exec_task_item where id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper> </mapper>

View File

@ -11,12 +11,10 @@ import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.SubListUtils; import io.metersphere.sdk.util.SubListUtils;
import io.metersphere.system.domain.*; import io.metersphere.system.domain.*;
import io.metersphere.system.dto.pool.TestResourceDTO; 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.BasePageRequest;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.taskhub.ResourcePoolOptionsDTO; import io.metersphere.system.dto.taskhub.*;
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.request.TaskHubItemRequest; import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse; import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse;
import io.metersphere.system.mapper.*; import io.metersphere.system.mapper.*;
@ -68,6 +66,8 @@ public class BaseTaskHubService {
private ExtResourcePoolMapper extResourcePoolMapper; private ExtResourcePoolMapper extResourcePoolMapper;
@Resource @Resource
private ProjectTestResourcePoolMapper projectTestResourcePoolMapper; private ProjectTestResourcePoolMapper projectTestResourcePoolMapper;
@Resource
private NodeResourcePoolService nodeResourcePoolService;
/** /**
* 系统-获取执行任务列表 * 系统-获取执行任务列表
@ -316,4 +316,30 @@ public class BaseTaskHubService {
} }
return null; return null;
} }
public List<ResourcePoolStatusDTO> getResourcePoolStatus(List<String> ids) {
List<ResourcePoolStatusDTO> statusDTOS = new ArrayList<>();
List<ExecTaskItem> itemList = extExecTaskItemMapper.selectPoolNodeByIds(ids);
Map<String, List<ExecTaskItem>> 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;
}
} }

View File

@ -78,7 +78,7 @@ public class NodeResourcePoolService {
} }
} }
private boolean validateNode(TestResourceNodeDTO node) { public boolean validateNode(TestResourceNodeDTO node) {
try { try {
ResultHolder body = TaskRunnerClient.get(String.format(nodeControllerUrl, node.getIp(), node.getPort())); ResultHolder body = TaskRunnerClient.get(String.format(nodeControllerUrl, node.getIp(), node.getPort()));
if (body == null) { if (body == null) {

View File

@ -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_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_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_OPTIONS = "/system/task-center/resource-pool/options";
public static final String SYSTEM_RESOURCE_POOL_STATUS = "/system/task-center/resource-pool/status";
@Test @Test
@Order(1) @Order(1)
@ -98,7 +99,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
@Test @Test
@Order(3) @Order(3)
public void getStatistics() throws Exception { public void getStatistics() throws Exception {
List<String> ids = List.of("1", "2"); List<String> ids = List.of("1");
MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_STATISTICS, ids); MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_STATISTICS, ids);
// 获取返回值 // 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
@ -121,6 +122,21 @@ public class BaseTaskHubControllerTests extends BaseTest {
Assertions.assertNotNull(resultHolder); Assertions.assertNotNull(resultHolder);
} }
/**
* 校验资源池节点状态
*/
@Test
@Order(3)
public void getResourcePoolStatus() throws Exception {
List<String> 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);
}
/** /**
* 组织任务中心测试用例 * 组织任务中心测试用例