feat(任务中心): 系统&组织&项目任务中心-执行任务停止操作

This commit is contained in:
WangXu10 2024-10-14 16:28:00 +08:00 committed by Craftsman
parent 4db5958a48
commit 0fa54338dd
9 changed files with 234 additions and 2 deletions

View File

@ -8,6 +8,9 @@ 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.response.TaskStatisticsResponse;
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.utils.Pager;
import io.metersphere.system.utils.SessionUtils;
@ -68,4 +71,13 @@ public class ProjectTaskHubController {
public List<ResourcePoolOptionsDTO> getUserProject() {
return baseTaskHubService.getProjectResourcePoolOptions(SessionUtils.getCurrentProjectId());
}
@GetMapping("/exec-task/stop/{id}")
@Operation(summary = "项目-任务中心-用例执行任务-停止任务")
@Log(type = OperationLogType.UPDATE, expression = "#msClass.projectStopLog(#id)", msClass = BaseTaskHubLogService.class)
@RequiresPermissions(PermissionConstants.PROJECT_CASE_TASK_CENTER_EXEC_STOP)
public void stopTask(@PathVariable String id) {
baseTaskHubService.stopTask(id, SessionUtils.getUserId(), null, SessionUtils.getCurrentProjectId());
}
}

View File

@ -24,6 +24,7 @@ public class ProjectTaskHubControllerTests extends BaseTest {
public static final String PROJECT_TASK_ITEM_PAGE = "/project/task-center/exec-task/item/page";
public static final String PROJECT_STATISTICS = "/project/task-center/exec-task/statistics";
public static final String PROJECT_RESOURCE_POOL_OPTIONS = "/project/task-center/resource-pool/options";
public static final String PROJECT_TASK_STOP = "/project/task-center/exec-task/stop/";
@Test
@Order(1)
@ -84,7 +85,7 @@ public class ProjectTaskHubControllerTests extends BaseTest {
@Test
@Order(4)
public void getProStatistics() throws Exception {
List<String> ids = List.of("pro_1","pro_2");
List<String> ids = List.of("pro_1", "pro_2");
MvcResult mvcResult = this.requestPostWithOkAndReturn(PROJECT_STATISTICS, ids);
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
@ -106,4 +107,18 @@ public class ProjectTaskHubControllerTests extends BaseTest {
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
/**
* 项目执行任务停止
*/
@Test
@Order(6)
public void projectTaskStop() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(PROJECT_TASK_STOP + "1");
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
}

View File

@ -9,7 +9,10 @@ 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.response.TaskStatisticsResponse;
import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.BaseProjectMapper;
import io.metersphere.system.service.BaseTaskHubLogService;
import io.metersphere.system.service.BaseTaskHubService;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.utils.SessionUtils;
@ -75,4 +78,13 @@ public class OrganizationTaskHubController {
public List<ResourcePoolOptionsDTO> getUserProject() {
return baseTaskHubService.getOrgResourcePoolOptions(SessionUtils.getCurrentOrganizationId());
}
@GetMapping("/exec-task/stop/{id}")
@Operation(summary = "组织-任务中心-用例执行任务-停止任务")
@Log(type = OperationLogType.UPDATE, expression = "#msClass.orgStopLog(#id)", msClass = BaseTaskHubLogService.class)
@RequiresPermissions(PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_EXEC_STOP)
public void stopTask(@PathVariable String id) {
baseTaskHubService.stopTask(id, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), null);
}
}

View File

@ -2,11 +2,17 @@ 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.taskhub.*;
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse;
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;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
@ -73,7 +79,15 @@ public class SystemTaskHubController {
public List<ResourcePoolStatusDTO> resourcePoolStatus(@RequestBody List<String> ids) {
return baseTaskHubService.getResourcePoolStatus(ids);
}
//TODO 检查节点状态
@GetMapping("/exec-task/stop/{id}")
@Operation(summary = "系统-任务中心-用例执行任务-停止任务")
@Log(type = OperationLogType.UPDATE, 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);
}
//TODO 系统&组织&项目 任务按钮操作删除 停止 失败重跑 查看报告 批量删除 批量停止 批量失败重跑

View File

@ -1,5 +1,6 @@
package io.metersphere.system.mapper;
import io.metersphere.system.domain.ExecTask;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.taskhub.TaskHubDTO;
import org.apache.ibatis.annotations.Param;
@ -11,4 +12,6 @@ import java.util.List;
*/
public interface ExtExecTaskMapper {
List<TaskHubDTO> selectList(@Param("request") BasePageRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId);
void updateTaskStatus(@Param("execTask") ExecTask execTask);
}

View File

@ -20,4 +20,17 @@
</where>
</select>
<update id="updateTaskStatus">
UPDATE exec_task
SET `status` = #{execTask.status},
create_user = #{execTask.createUser}
WHERE
id = #{execTask.id}
<if test="execTask.projectId != null and execTask.projectId != ''">
and project_id = #{execTask.projectId}
</if>
<if test="execTask.organizationId != null and execTask.organizationId != ''">
and organization_id = #{execTask.organizationId}
</if>
</update>
</mapper>

View File

@ -0,0 +1,92 @@
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.UserRole;
import io.metersphere.system.dto.sdk.request.UserRoleUpdateRequest;
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.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author wx
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class BaseTaskHubLogService {
@Resource
private ExecTaskMapper execTaskMapper;
/**
* 系统停止任务日志
* @param id
* @return
*/
public LogDTO systemStopLog(String id) {
ExecTask execTask = execTaskMapper.selectByPrimaryKey(id);
LogDTO dto = null;
if (execTask != null) {
dto = new LogDTO(
OperationLogConstants.SYSTEM,
OperationLogConstants.SYSTEM,
execTask.getId(),
null,
OperationLogType.STOP.name(),
OperationLogModule.SETTING_SYSTEM_TASK_CENTER,
execTask.getTaskName());
}
return dto;
}
/**
* 组织停止任务日志
* @param id
* @return
*/
public LogDTO orgStopLog(String id) {
ExecTask execTask = execTaskMapper.selectByPrimaryKey(id);
LogDTO dto = null;
if (execTask != null) {
dto = new LogDTO(
OperationLogConstants.ORGANIZATION,
null,
execTask.getId(),
null,
OperationLogType.STOP.name(),
OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER,
execTask.getTaskName());
}
return dto;
}
/**
* 项目停止任务日志
* @param id
* @return
*/
public LogDTO projectStopLog(String id) {
ExecTask execTask = execTaskMapper.selectByPrimaryKey(id);
LogDTO dto = null;
if (execTask != null) {
dto = new LogDTO(
null,
null,
execTask.getId(),
null,
OperationLogType.STOP.name(),
OperationLogModule.PROJECT_MANAGEMENT_TASK_CENTER,
execTask.getTaskName());
}
return dto;
}
}

View File

@ -68,6 +68,10 @@ public class BaseTaskHubService {
private ProjectTestResourcePoolMapper projectTestResourcePoolMapper;
@Resource
private NodeResourcePoolService nodeResourcePoolService;
@Resource
private ExecTaskMapper execTaskMapper;
@Resource
private ExecTaskItemMapper execTaskItemMapper;
/**
* 系统-获取执行任务列表
@ -317,6 +321,12 @@ public class BaseTaskHubService {
return null;
}
/**
* 获取任务详情列表资源节点状态
*
* @param ids
* @return
*/
public List<ResourcePoolStatusDTO> getResourcePoolStatus(List<String> ids) {
List<ResourcePoolStatusDTO> statusDTOS = new ArrayList<>();
List<ExecTaskItem> itemList = extExecTaskItemMapper.selectPoolNodeByIds(ids);
@ -342,4 +352,34 @@ public class BaseTaskHubService {
});
return statusDTOS;
}
/**
* 停止任务
*
* @param id
* @param userId
* @param orgId
* @param projectId
*/
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);
//2.更新任务明细状态
ExecTaskItemExample itemExample = new ExecTaskItemExample();
itemExample.createCriteria().andTaskIdEqualTo(id);
ExecTaskItem execTaskItem = new ExecTaskItem();
execTaskItem.setStatus(ExecStatus.STOPPED.name());
execTaskItem.setExecutor(userId);
execTaskItemMapper.updateByExampleSelective(execTaskItem, itemExample);
//TODO 3.调用jmeter触发停止
}
}

View File

@ -37,6 +37,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
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";
public static final String SYSTEM_TASK_STOP = "/system/task-center/exec-task/stop/";
@Test
@Order(1)
@ -138,6 +139,21 @@ public class BaseTaskHubControllerTests extends BaseTest {
}
/**
* 系统执行任务停止
*/
@Test
@Order(4)
public void systemTaskStop() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(SYSTEM_TASK_STOP + "1");
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
/**
* 组织任务中心测试用例
*/
@ -146,6 +162,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
public static final String ORG_TASK_ITEM_PAGE = "/organization/task-center/exec-task/item/page";
public static final String ORG_STATISTICS = "/organization/task-center/exec-task/statistics";
public static final String ORG_RESOURCE_POOL_OPTIONS = "/organization/task-center/resource-pool/options";
public static final String ORG_TASK_STOP = "/organization/task-center/exec-task/stop/";
@Test
@Order(20)
@ -229,6 +246,20 @@ public class BaseTaskHubControllerTests extends BaseTest {
Assertions.assertNotNull(resultHolder);
}
/**
* 组织执行任务停止
*/
@Test
@Order(4)
public void orgTaskStop() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(ORG_TASK_STOP + "1");
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
@Test
@Order(21)