fix(接口测试): 资源池禁用,任务项没有错误提示
--bug=1049106 --user=陈建星 【任务中心】-禁用测试计划使用的资源池后,执行测试计划,执行完成后,任务详情的排队状态没有异常提示 https://www.tapd.cn/55049933/s/1616375
This commit is contained in:
parent
784f37d67f
commit
63189f3ca0
|
@ -35,6 +35,7 @@ import io.metersphere.sdk.constants.TaskItemErrorMessage;
|
|||
import io.metersphere.sdk.dto.api.task.GetRunScriptRequest;
|
||||
import io.metersphere.sdk.dto.api.task.TaskBatchRequestDTO;
|
||||
import io.metersphere.sdk.dto.api.task.TaskItem;
|
||||
import io.metersphere.sdk.dto.api.task.TaskRequestDTO;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
|
@ -552,6 +553,16 @@ public class ApiCommonService {
|
|||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||
public void batchUpdateTaskItemErrorMassage(TaskItemErrorMessage errorMessage, TaskRequestDTO taskRequestDTO) {
|
||||
// 更新任务项的异常信息
|
||||
ExecTaskItem execTaskItem = new ExecTaskItem();
|
||||
execTaskItem.setId(taskRequestDTO.getTaskItem().getId());
|
||||
execTaskItem.setErrorMessage(errorMessage.name());
|
||||
execTaskItemMapper.updateByPrimaryKeySelective(execTaskItem);
|
||||
}
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||
public void updateTaskItemErrorMassage(String taskItemId, TaskItemErrorMessage errorMessage) {
|
||||
// 更新任务项的异常信息
|
||||
|
|
|
@ -32,6 +32,7 @@ import io.metersphere.project.dto.environment.http.SelectModule;
|
|||
import io.metersphere.project.service.*;
|
||||
import io.metersphere.sdk.constants.*;
|
||||
import io.metersphere.sdk.dto.api.task.*;
|
||||
import io.metersphere.sdk.exception.IResultCode;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.exception.TaskRunnerResultCode;
|
||||
import io.metersphere.sdk.file.FileCenter;
|
||||
|
@ -264,6 +265,10 @@ public class ApiExecuteService {
|
|||
throw new MSException(RESOURCE_POOL_EXECUTE_ERROR, e.getMessage());
|
||||
} catch (MSException e) {
|
||||
LogUtils.error(e);
|
||||
IResultCode errorCode = e.getErrorCode();
|
||||
if (errorCode == ApiResultCode.EXECUTE_RESOURCE_POOL_NOT_CONFIG) {
|
||||
apiCommonService.batchUpdateTaskItemErrorMassage(TaskItemErrorMessage.INVALID_RESOURCE_POOL, taskRequest);
|
||||
}
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
LogUtils.error(e);
|
||||
|
@ -373,8 +378,9 @@ public class ApiExecuteService {
|
|||
*/
|
||||
public void batchExecute(TaskBatchRequestDTO taskRequest) {
|
||||
setTaskRequestParams(taskRequest.getTaskInfo());
|
||||
|
||||
TaskInfo taskInfo = taskRequest.getTaskInfo();
|
||||
|
||||
try {
|
||||
// 获取资源池
|
||||
TestResourcePoolReturnDTO testResourcePool = getGetResourcePoolNodeDTO(taskInfo.getRunModeConfig(), taskInfo.getProjectId());
|
||||
|
||||
|
@ -397,6 +403,17 @@ public class ApiExecuteService {
|
|||
} else {
|
||||
nodeBatchExecute(taskRequest, taskInfo, testResourcePool);
|
||||
}
|
||||
} catch (MSException e) {
|
||||
LogUtils.error(e);
|
||||
IResultCode errorCode = e.getErrorCode();
|
||||
if (errorCode == ApiResultCode.EXECUTE_RESOURCE_POOL_NOT_CONFIG) {
|
||||
apiCommonService.batchUpdateTaskItemErrorMassage(TaskItemErrorMessage.INVALID_RESOURCE_POOL, taskRequest);
|
||||
}
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
LogUtils.error(e);
|
||||
throw new MSException(RESOURCE_POOL_EXECUTE_ERROR, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void nodeBatchExecute(TaskBatchRequestDTO taskRequest, TaskInfo taskInfo, TestResourcePoolReturnDTO testResourcePool) {
|
||||
|
@ -463,19 +480,14 @@ public class ApiExecuteService {
|
|||
}
|
||||
}
|
||||
|
||||
private void k8sBatchExecute(TaskBatchRequestDTO taskRequest, TaskInfo taskInfo, TestResourcePoolReturnDTO testResourcePool) {
|
||||
private void k8sBatchExecute(TaskBatchRequestDTO taskRequest, TaskInfo taskInfo, TestResourcePoolReturnDTO testResourcePool) throws Exception {
|
||||
TestResourceDTO testResourceDTO = new TestResourceDTO();
|
||||
BeanUtils.copyBean(testResourceDTO, testResourcePool.getTestResourceReturnDTO());
|
||||
testResourceDTO.setId(testResourcePool.getId());
|
||||
|
||||
taskInfo.setPoolSize(testResourceDTO.getConcurrentNumber());
|
||||
taskInfo.setPerTaskSize(testResourceDTO.getPodThreads());
|
||||
try {
|
||||
EngineFactory.batchRunApi(taskRequest, testResourceDTO);
|
||||
} catch (Exception e) {
|
||||
LogUtils.error(e);
|
||||
apiCommonService.batchUpdateTaskItemErrorMassage(TaskItemErrorMessage.INVALID_RESOURCE_POOL, taskRequest);
|
||||
}
|
||||
}
|
||||
|
||||
private List<TaskBatchRequestDTO> getDistributeTaskBatchRequest(TaskBatchRequestDTO taskRequest, int distributeSize) {
|
||||
|
|
Loading…
Reference in New Issue