diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java index 2cd9dc7427..44c16c4676 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java @@ -115,7 +115,8 @@ public class ProjectTaskHubControllerTests extends BaseTest { @Test @Order(6) public void projectTaskStop() throws Exception { - MvcResult mvcResult = this.requestGetWithOkAndReturn(PROJECT_TASK_STOP + "1"); + this.requestGet(PROJECT_TASK_STOP + "pro_1"); + MvcResult mvcResult = this.requestGetWithOkAndReturn(PROJECT_TASK_STOP + "pro_2"); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); diff --git a/backend/services/project-management/src/test/resources/dml/init_project_exec_task_test.sql b/backend/services/project-management/src/test/resources/dml/init_project_exec_task_test.sql index 0cb8861498..c2d4c4242e 100644 --- a/backend/services/project-management/src/test/resources/dml/init_project_exec_task_test.sql +++ b/backend/services/project-management/src/test/resources/dml/init_project_exec_task_test.sql @@ -5,4 +5,11 @@ VALUES ('pro_3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639); INSERT INTO `exec_task_item`(`id`, `task_id`, `resource_id`, `resource_name`, `task_origin`, `status`, `result`, `resource_pool_id`, `resource_pool_node`, `resource_type`, `project_id`, `organization_id`, `thread_id`, `start_time`, `end_time`, `executor`) -VALUES ('pro_1', 'pro_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); +VALUES + ('pro_1', 'pro_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), + ('pro_2', 'pro_2', '1', '1', '1', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); + +INSERT INTO `test_resource_pool` (`id`, `name`, `type`, `description`, `enable`, `create_time`, `update_time`, `create_user`, `server_url`, `all_org`, `deleted`) +VALUES + ('1', 'LOCAL', 'Node', '测试资源池', b'1', 1705894549000, 1705894549000, 'admin', NULL, b'1', b'0'), + ('2', 'LOCAL', 'Kubernetes', 'Kubernetes测试资源池', b'1', 1705894549000, 1705894549000, 'admin', NULL, b'1', b'0'); 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 7fc8a8a304..be94dd9e73 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,7 +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.taskcenter.request.TaskCenterBatchRequest; +import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.taskhub.*; import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse; @@ -10,7 +10,6 @@ import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.service.BaseTaskHubLogService; import io.metersphere.system.service.BaseTaskHubService; -import io.metersphere.system.service.SystemOrganizationLogService; import io.metersphere.system.utils.Pager; import io.metersphere.system.utils.SessionUtils; import io.swagger.v3.oas.annotations.Operation; @@ -83,13 +82,22 @@ public class SystemTaskHubController { @GetMapping("/exec-task/stop/{id}") @Operation(summary = "系统-任务中心-用例执行任务-停止任务") - @Log(type = OperationLogType.UPDATE, expression = "#msClass.systemStopLog(#id)", msClass = BaseTaskHubLogService.class) + @Log(type = OperationLogType.STOP, expression = "#msClass.systemStopLog(#id)", msClass = BaseTaskHubLogService.class) @RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_EXEC_STOP) public void stopTask(@PathVariable String id) { baseTaskHubService.stopTask(id, SessionUtils.getUserId(), null, null); } + @PostMapping("/exec-task/batch-stop") + @Operation(summary = "系统-任务中心-用例执行任务-批量停止任务") + @Log(type = OperationLogType.STOP, expression = "#msClass.systemBatchStopLog(#request)", msClass = BaseTaskHubLogService.class) + @RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_EXEC_STOP) + public void batchStopTask(@Validated @RequestBody TableBatchProcessDTO request) { + baseTaskHubService.batchStopTask(request, SessionUtils.getUserId(), null, null); + } + + @GetMapping("/exec-task/delete/{id}") @Operation(summary = "系统-任务中心-用例执行任务-删除任务") @Log(type = OperationLogType.DELETE, expression = "#msClass.systemDeleteLog(#id)", msClass = BaseTaskHubLogService.class) 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 debf3e89af..be9b6bea5f 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 @@ -18,4 +18,8 @@ public interface ExtExecTaskItemMapper { List selectPoolNodeByIds(@Param("ids") List ids); List selectExecInfoByResourceIds(@Param("resourceIds") List resourceIds); + + List getResourcePoolsByTaskIds(@Param("taskIds") List taskIds); + + void batchUpdateTaskItemStatus(@Param("taskIds") List taskIds, @Param("userId") String userId, @Param("organizationId") String organizationId, @Param("projectId") String projectId, @Param("status") String status); } 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 1cec1c2f59..6181c151aa 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 @@ -92,4 +92,38 @@ + + + + + + UPDATE exec_task_item + SET `status` = #{status}, + executor = #{userId} + WHERE task_id in + + #{taskId} + + + and project_id = #{projectId} + + + and organization_id = #{organizationId} + + and `status` = 'RUNNING' + \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java index 98dfb15e6a..009b0811b2 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java @@ -2,6 +2,7 @@ package io.metersphere.system.mapper; import io.metersphere.system.domain.ExecTask; import io.metersphere.system.dto.sdk.BasePageRequest; +import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.taskhub.TaskHubDTO; import org.apache.ibatis.annotations.Param; @@ -13,7 +14,9 @@ import java.util.List; public interface ExtExecTaskMapper { List selectList(@Param("request") BasePageRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId); - void updateTaskStatus(@Param("execTask") ExecTask execTask); - void deleteTaskById(@Param("id") String id, @Param("orgId") String orgId, @Param("projectId") String projectId); + + List getIds(@Param("request") TableBatchProcessDTO request); + + void batchUpdateTaskStatus(@Param("ids") List ids, @Param("userId") String userId, @Param("organizationId") String organizationId, @Param("projectId") String projectId, @Param("status") String status); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml index 9d3c67e44f..11d57d4841 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml @@ -17,23 +17,15 @@ and exec_task.project_id = #{projectId} + + + + + + - - UPDATE exec_task - SET `status` = #{execTask.status}, - create_user = #{execTask.createUser} - WHERE - id = #{execTask.id} - - and project_id = #{execTask.projectId} - - - and organization_id = #{execTask.organizationId} - - and `status` = 'RUNNING' - DELETE @@ -47,4 +39,70 @@ and `status` in ('PENDING', 'STOPPED', 'COMPLETED') + + + + + + + and ( + exec_task.num like concat('%', #{request.keyword},'%') + or exec_task.task_name like concat('%', #{request.keyword},'%') + ) + + + + + + + + + + + + + + + and exec_task.status in + + + + + and exec_task.trigger_mode in + + + + + and exec_task.result in + + + + + + + + + + + + UPDATE exec_task + SET `status` = #{status}, + create_user = #{userId} + WHERE id in + + #{id} + + + and project_id = #{projectId} + + + and organization_id = #{organizationId} + + and `status` = 'RUNNING' + \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubLogService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubLogService.java index d65469fe1d..ed3c8f03e7 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubLogService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubLogService.java @@ -3,16 +3,22 @@ package io.metersphere.system.service; import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.util.JSON; import io.metersphere.system.domain.ExecTask; +import io.metersphere.system.domain.ExecTaskExample; import io.metersphere.system.domain.UserRole; import io.metersphere.system.dto.sdk.request.UserRoleUpdateRequest; +import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.mapper.ExecTaskMapper; import jakarta.annotation.Resource; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + /** * @author wx */ @@ -21,7 +27,8 @@ import org.springframework.transaction.annotation.Transactional; public class BaseTaskHubLogService { @Resource private ExecTaskMapper execTaskMapper; - + @Resource + private BaseTaskHubService baseTaskHubService; /** * 系统停止任务日志 @@ -44,6 +51,34 @@ public class BaseTaskHubLogService { return dto; } + /** + * 系统批量停止任务日志 + * + * @param request + * @return + */ + public List systemBatchStopLog(TableBatchProcessDTO request) { + List ids = baseTaskHubService.getTaskIds(request); + ExecTaskExample example = new ExecTaskExample(); + example.createCriteria().andIdIn(ids); + List execTasks = execTaskMapper.selectByExample(example); + List logDTOList = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(execTasks)) { + execTasks.forEach(item -> { + LogDTO dto = new LogDTO( + OperationLogConstants.SYSTEM, + OperationLogConstants.SYSTEM, + item.getId(), + null, + OperationLogType.STOP.name(), + OperationLogModule.SETTING_SYSTEM_TASK_CENTER, + item.getTaskName()); + logDTOList.add(dto); + }); + } + return logDTOList; + } + /** * 组织停止任务日志 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 1a25f68cb6..22dba7bc5f 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,6 +2,8 @@ package io.metersphere.system.service; import com.github.pagehelper.Page; import com.github.pagehelper.page.PageMethod; +import io.metersphere.engine.EngineFactory; +import io.metersphere.engine.MsHttpClient; import io.metersphere.project.domain.Project; import io.metersphere.project.domain.ProjectExample; import io.metersphere.project.domain.ProjectTestResourcePool; @@ -9,14 +11,19 @@ import io.metersphere.project.domain.ProjectTestResourcePoolExample; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectTestResourcePoolMapper; import io.metersphere.sdk.constants.ExecStatus; +import io.metersphere.sdk.constants.ResourcePoolTypeEnum; import io.metersphere.sdk.constants.ResultStatus; +import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.LogUtils; 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.pool.TestResourcePoolReturnDTO; import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.sdk.OptionDTO; +import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.taskhub.*; import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse; @@ -82,6 +89,8 @@ public class BaseTaskHubService { private OrganizationMapper organizationMapper; @Resource private UserMapper userMapper; + @Resource + private TestResourcePoolService testResourcePoolService; /** * 系统-获取执行任务列表 @@ -282,12 +291,23 @@ public class BaseTaskHubService { return; } List userIds = list.stream().map(TaskHubItemDTO::getExecutor).distinct().toList(); + List resourcePoolIds = list.stream().map(TaskHubItemDTO::getResourcePoolId).distinct().toList(); Map userMaps = getUserMaps(userIds); + Map resourcePoolMaps = getResourcePoolMaps(resourcePoolIds); list.forEach(item -> { item.setUserName(userMaps.getOrDefault(item.getExecutor(), StringUtils.EMPTY)); + item.setResourcePoolName(resourcePoolMaps.getOrDefault(item.getResourcePoolId(), StringUtils.EMPTY)); }); } + private Map getResourcePoolMaps(List resourcePoolIds) { + TestResourcePoolExample poolExample = new TestResourcePoolExample(); + poolExample.createCriteria().andIdIn(resourcePoolIds); + List poolList = testResourcePoolMapper.selectByExample(poolExample); + Map poolMaps = poolList.stream().collect(Collectors.toMap(TestResourcePool::getId, TestResourcePool::getName)); + return poolMaps; + } + /** * 计算任务通过率和执行进度 * @@ -455,23 +475,57 @@ public class BaseTaskHubService { */ public void stopTask(String id, String userId, String orgId, String projectId) { //1.更新任务状态 - ExecTask execTask = new ExecTask(); - execTask.setId(id); - execTask.setStatus(ExecStatus.STOPPED.name()); - execTask.setCreateUser(userId); - execTask.setProjectId(projectId); - execTask.setOrganizationId(orgId); - extExecTaskMapper.updateTaskStatus(execTask); + extExecTaskMapper.batchUpdateTaskStatus(List.of(id), userId, orgId, projectId, ExecStatus.STOPPED.name()); + //2.更新任务明细状态 - ExecTaskItemExample itemExample = new ExecTaskItemExample(); - itemExample.createCriteria().andTaskIdEqualTo(id).andStatusEqualTo(ExecStatus.RUNNING.name()); - ExecTaskItem execTaskItem = new ExecTaskItem(); - execTaskItem.setStatus(ExecStatus.STOPPED.name()); - execTaskItem.setExecutor(userId); - execTaskItemMapper.updateByExampleSelective(execTaskItem, itemExample); - //TODO 3.调用jmeter触发停止 + extExecTaskItemMapper.batchUpdateTaskItemStatus(List.of(id), userId, orgId, projectId, ExecStatus.STOPPED.name()); + handleStopTask(List.of(id)); + } + private void handleStopTask(List ids) { + //获取详情资源池 + List list = extExecTaskItemMapper.getResourcePoolsByTaskIds(ids); + Map> resourcePoolMaps = list.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolId)); + resourcePoolMaps.forEach((k, v) -> { + //判断资源池类型 + TestResourcePoolReturnDTO testResourcePoolDTO = testResourcePoolService.getTestResourcePoolDetail(k); + boolean isK8SResourcePool = StringUtils.equals(testResourcePoolDTO.getType(), ResourcePoolTypeEnum.K8S.getName()); + if (isK8SResourcePool) { + List taskIds = list.stream().map(ExecTaskItem::getTaskId).distinct().toList(); + //K8S + handleK8STask(taskIds, testResourcePoolDTO); + } else { + Map> nodeItem = list.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolNode)); + handleNodeTask(nodeItem); + } + }); + } + private void handleNodeTask(Map> nodeItem) { + //通过任务向节点发起停止 + nodeItem.forEach((node, items) -> { + String endpoint = "http://".concat(node); + List itemIds = items.stream().map(ExecTaskItem::getId).toList(); + SubListUtils.dealForSubList(itemIds, 100, subList -> { + try { + LogUtils.info(String.format("开始发送停止请求到 %s 节点执行", endpoint), subList.toString()); + MsHttpClient.stopApiTaskItem(endpoint, subList); + } catch (Exception e) { + } + }); + }); + } + + private void handleK8STask(List taskIds, TestResourcePoolReturnDTO testResourcePoolDTO) { + SubListUtils.dealForSubList(taskIds, 100, subList -> { + try { + TestResourceDTO testResourceDTO = new TestResourceDTO(); + BeanUtils.copyBean(testResourceDTO, testResourcePoolDTO.getTestResourceReturnDTO()); + EngineFactory.stopApiTask(subList, testResourceDTO); + } catch (Exception e) { + LogUtils.error(e); + } + }); } public void deleteTask(String id, String orgId, String projectId) { @@ -483,4 +537,28 @@ public class BaseTaskHubService { execTaskItemMapper.deleteByExample(itemExample); //TODO jmeter执行队列中移除 } + + public void batchStopTask(TableBatchProcessDTO request, String userId, String orgId, String projectId) { + List ids = getTaskIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + //1.更新任务状态 + extExecTaskMapper.batchUpdateTaskStatus(ids, userId, orgId, projectId, ExecStatus.STOPPED.name()); + //2.更新任务明细状态 + extExecTaskItemMapper.batchUpdateTaskItemStatus(ids, userId, orgId, projectId, ExecStatus.STOPPED.name()); + handleStopTask(ids); + } + + } + + public List getTaskIds(TableBatchProcessDTO request) { + if (request.isSelectAll()) { + List ids = extExecTaskMapper.getIds(request); + if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { + ids.removeAll(request.getExcludeIds()); + } + return ids; + } else { + return request.getSelectIds(); + } + } } 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 b45c7bbe6e..a62359e014 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 @@ -6,7 +6,9 @@ import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.dto.sdk.BasePageRequest; +import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; +import io.metersphere.system.mapper.TestResourcePoolMapper; import io.metersphere.system.service.BaseTaskHubService; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; @@ -27,6 +29,8 @@ public class BaseTaskHubControllerTests extends BaseTest { @Resource private BaseTaskHubService baseTaskHubService; + @Resource + private TestResourcePoolMapper testResourcePoolMapper; /** * 系统任务中心测试用例 @@ -39,6 +43,7 @@ public class BaseTaskHubControllerTests extends BaseTest { public static final String SYSTEM_RESOURCE_POOL_STATUS = "/system/task-center/resource-pool/status"; public static final String SYSTEM_TASK_STOP = "/system/task-center/exec-task/stop/"; public static final String SYSTEM_TASK_DELETE = "/system/task-center/exec-task/delete/"; + public static final String SYSTEM_TASK_BATCH_STOP = "/system/task-center/exec-task/batch-stop/"; @Test @Order(1) @@ -146,7 +151,8 @@ public class BaseTaskHubControllerTests extends BaseTest { @Test @Order(4) public void systemTaskStop() throws Exception { - MvcResult mvcResult = this.requestGetWithOkAndReturn(SYSTEM_TASK_STOP + "1"); + this.requestGet(SYSTEM_TASK_STOP + "1"); + MvcResult mvcResult = this.requestGetWithOkAndReturn(SYSTEM_TASK_STOP + "2"); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); @@ -159,7 +165,7 @@ public class BaseTaskHubControllerTests extends BaseTest { * 系统执行任务删除 */ @Test - @Order(4) + @Order(7) public void systemTaskDelete() throws Exception { MvcResult mvcResult = this.requestGetWithOkAndReturn(SYSTEM_TASK_DELETE + "4"); // 获取返回值 @@ -170,6 +176,21 @@ public class BaseTaskHubControllerTests extends BaseTest { } + /** + * 系统执行任务停止 + */ + @Test + @Order(5) + public void systemTaskBatchStop() throws Exception { + TableBatchProcessDTO request = new TableBatchProcessDTO(); + request.setSelectAll(true); + this.requestPost(SYSTEM_TASK_BATCH_STOP, request); + request.setSelectAll(false); + request.setSelectIds(List.of("1", "2")); + this.requestPost(SYSTEM_TASK_BATCH_STOP, request); + } + + /** * 组织任务中心测试用例 */ @@ -266,21 +287,24 @@ public class BaseTaskHubControllerTests extends BaseTest { * 组织执行任务停止 */ @Test - @Order(4) + @Order(24) public void orgTaskStop() throws Exception { - MvcResult mvcResult = this.requestGetWithOkAndReturn(ORG_TASK_STOP + "1"); + this.requestGet(SYSTEM_TASK_STOP + "1"); + MvcResult mvcResult = this.requestGetWithOkAndReturn(ORG_TASK_STOP + "2"); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); // 返回请求正常 Assertions.assertNotNull(resultHolder); + testResourcePoolMapper.deleteByPrimaryKey("1"); + testResourcePoolMapper.deleteByPrimaryKey("2"); } /** * 组织执行任务删除 */ @Test - @Order(5) + @Order(25) public void orgTaskDelete() throws Exception { MvcResult mvcResult = this.requestGetWithOkAndReturn(ORG_TASK_DELETE + "4"); // 获取返回值 @@ -291,7 +315,6 @@ public class BaseTaskHubControllerTests extends BaseTest { } - @Test @Order(21) public void testInsert() throws Exception { diff --git a/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql b/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql index e281df6211..c62290e91a 100644 --- a/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql +++ b/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql @@ -19,4 +19,12 @@ VALUES INSERT INTO `exec_task_item`(`id`, `task_id`, `resource_id`, `resource_name`, `task_origin`, `status`, `result`, `resource_pool_id`, `resource_pool_node`, `resource_type`, `project_id`, `organization_id`, `thread_id`, `start_time`, `end_time`, `executor`) -VALUES ('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); +VALUES + ('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), + ('2', '2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); + + +INSERT INTO `test_resource_pool` (`id`, `name`, `type`, `description`, `enable`, `create_time`, `update_time`, `create_user`, `server_url`, `all_org`, `deleted`) +VALUES + ('1', 'LOCAL', 'Node', '测试资源池', b'1', 1705894549000, 1705894549000, 'admin', NULL, b'1', b'0'), + ('2', 'LOCAL', 'Kubernetes', 'Kubernetes测试资源池', b'1', 1705894549000, 1705894549000, 'admin', NULL, b'1', b'0'); \ No newline at end of file