feat(任务中心): 系统获取资源池下拉选项
This commit is contained in:
parent
3c33c48aa6
commit
250f7dd894
|
@ -2,6 +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.TaskHubDTO;
|
import io.metersphere.system.dto.taskhub.TaskHubDTO;
|
||||||
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
|
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
|
||||||
import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO;
|
import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO;
|
||||||
|
@ -16,10 +17,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
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.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -61,4 +59,23 @@ public class SystemTaskHubController {
|
||||||
public List<TaskStatisticsResponse> calculateRate(@RequestBody List<String> ids) {
|
public List<TaskStatisticsResponse> calculateRate(@RequestBody List<String> ids) {
|
||||||
return baseTaskHubService.calculateRate(ids, null, null);
|
return baseTaskHubService.calculateRate(ids, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/resource-pool/options")
|
||||||
|
@Operation(summary = "系统-任务中心-获取资源池下拉选项")
|
||||||
|
public List<ResourcePoolOptionsDTO> getUserProject() {
|
||||||
|
return baseTaskHubService.getResourcePoolOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO 检查节点状态
|
||||||
|
|
||||||
|
//TODO 组织&项目 获取资源池下拉选项
|
||||||
|
|
||||||
|
//TODO 系统&组织&项目 任务按钮操作:删除 停止 失败重跑 查看报告 批量删除 批量停止 批量失败重跑
|
||||||
|
|
||||||
|
|
||||||
|
//TODO 系统&组织&项目 任务详情按钮操作:查看 停止 批量停止
|
||||||
|
|
||||||
|
|
||||||
|
//TODO 系统&组织&项目 后台任务操作:删除 批量开启 批量关闭
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<OptionDTO> children = new ArrayList<>();
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wx
|
* @author wx
|
||||||
|
@ -20,5 +21,8 @@ public class TaskHubItemRequest extends BasePageRequest implements Serializable
|
||||||
private String taskId;
|
private String taskId;
|
||||||
|
|
||||||
@Schema(description = "资源池id")
|
@Schema(description = "资源池id")
|
||||||
private String resourcePoolId;
|
private List<String> resourcePoolIds;
|
||||||
|
|
||||||
|
@Schema(description = "资源池节点")
|
||||||
|
private List<String> resourcePoolNodes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,17 @@
|
||||||
<if test="projectId != null and projectId != ''">
|
<if test="projectId != null and projectId != ''">
|
||||||
and exec_task_item.project_id = #{projectId}
|
and exec_task_item.project_id = #{projectId}
|
||||||
</if>
|
</if>
|
||||||
<if test="request.resourcePoolId != null and request.resourcePoolId != ''">
|
<if test="request.resourcePoolIds != null and request.resourcePoolIds.size() > 0">
|
||||||
and exec_task_item.resource_pool_id = #{request.resourcePoolId}
|
and exec_task_item.resource_pool_id in
|
||||||
|
<foreach collection="request.resourcePoolIds" item="resourcePoolId" separator="," open="(" close=")">
|
||||||
|
#{request.resourcePoolId}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="request.resourcePoolNodes != null and request.resourcePoolNodes.size() > 0">
|
||||||
|
and exec_task_item.resource_pool_node in
|
||||||
|
<foreach collection="request.resourcePoolNodes" item="resourcePoolNode" separator="," open="(" close=")">
|
||||||
|
#{request.resourcePoolNode}
|
||||||
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -2,14 +2,15 @@ package io.metersphere.system.service;
|
||||||
|
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.page.PageMethod;
|
import com.github.pagehelper.page.PageMethod;
|
||||||
import io.metersphere.plan.mapper.TestPlanMapper;
|
|
||||||
import io.metersphere.sdk.constants.ExecStatus;
|
import io.metersphere.sdk.constants.ExecStatus;
|
||||||
import io.metersphere.sdk.constants.ResultStatus;
|
import io.metersphere.sdk.constants.ResultStatus;
|
||||||
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.SubListUtils;
|
import io.metersphere.sdk.util.SubListUtils;
|
||||||
import io.metersphere.system.domain.ExecTask;
|
import io.metersphere.system.domain.*;
|
||||||
import io.metersphere.system.domain.ExecTaskItem;
|
import io.metersphere.system.dto.pool.TestResourceDTO;
|
||||||
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.TaskHubDTO;
|
import io.metersphere.system.dto.taskhub.TaskHubDTO;
|
||||||
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
|
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
|
||||||
import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO;
|
import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO;
|
||||||
|
@ -55,7 +56,9 @@ public class BaseTaskHubService {
|
||||||
@Resource
|
@Resource
|
||||||
private ExtExecTaskItemMapper extExecTaskItemMapper;
|
private ExtExecTaskItemMapper extExecTaskItemMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private TestPlanMapper testPlanMapper;
|
private TestResourcePoolMapper testResourcePoolMapper;
|
||||||
|
@Resource
|
||||||
|
private TestResourcePoolBlobMapper testResourcePoolBlobMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统-获取执行任务列表
|
* 系统-获取执行任务列表
|
||||||
|
@ -216,4 +219,49 @@ public class BaseTaskHubService {
|
||||||
return responseList;
|
return responseList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有资源池及节点下拉选项
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<ResourcePoolOptionsDTO> getResourcePoolOptions() {
|
||||||
|
//获取全部资源池
|
||||||
|
TestResourcePoolExample example = new TestResourcePoolExample();
|
||||||
|
example.createCriteria().andDeletedEqualTo(false);
|
||||||
|
List<TestResourcePool> allResourcePools = testResourcePoolMapper.selectByExample(example);
|
||||||
|
List<String> ids = allResourcePools.stream().map(TestResourcePool::getId).toList();
|
||||||
|
//获取全部资源池节点
|
||||||
|
TestResourcePoolBlobExample blobExample = new TestResourcePoolBlobExample();
|
||||||
|
blobExample.createCriteria().andIdIn(ids);
|
||||||
|
List<TestResourcePoolBlob> testResourcePoolBlobs = testResourcePoolBlobMapper.selectByExampleWithBLOBs(blobExample);
|
||||||
|
Map<String, List<TestResourcePoolBlob>> poolMap = testResourcePoolBlobs.stream().collect(Collectors.groupingBy(TestResourcePoolBlob::getId));
|
||||||
|
|
||||||
|
return handleOptions(allResourcePools, poolMap);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ResourcePoolOptionsDTO> handleOptions(List<TestResourcePool> allResourcePools, Map<String, List<TestResourcePoolBlob>> poolMap) {
|
||||||
|
List<ResourcePoolOptionsDTO> 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<OptionDTO> 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_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_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";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
|
@ -97,7 +98,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", "2");
|
||||||
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);
|
||||||
|
@ -106,6 +107,20 @@ public class BaseTaskHubControllerTests extends BaseTest {
|
||||||
Assertions.assertNotNull(resultHolder);
|
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
|
@Test
|
||||||
@Order(4)
|
@Order(4)
|
||||||
public void getOrgStatistics() throws Exception {
|
public void getOrgStatistics() throws Exception {
|
||||||
List<String> ids = List.of("1","2");
|
List<String> ids = List.of("1", "2");
|
||||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(ORG_STATISTICS, ids);
|
MvcResult mvcResult = this.requestPostWithOkAndReturn(ORG_STATISTICS, ids);
|
||||||
// 获取返回值
|
// 获取返回值
|
||||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
|
@ -183,8 +198,6 @@ public class BaseTaskHubControllerTests extends BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(21)
|
@Order(21)
|
||||||
public void testInsert() throws Exception {
|
public void testInsert() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue