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.GetRunScriptRequest;
|
||||||
import io.metersphere.sdk.dto.api.task.TaskBatchRequestDTO;
|
import io.metersphere.sdk.dto.api.task.TaskBatchRequestDTO;
|
||||||
import io.metersphere.sdk.dto.api.task.TaskItem;
|
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.exception.MSException;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
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)
|
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
||||||
public void updateTaskItemErrorMassage(String taskItemId, TaskItemErrorMessage errorMessage) {
|
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.project.service.*;
|
||||||
import io.metersphere.sdk.constants.*;
|
import io.metersphere.sdk.constants.*;
|
||||||
import io.metersphere.sdk.dto.api.task.*;
|
import io.metersphere.sdk.dto.api.task.*;
|
||||||
|
import io.metersphere.sdk.exception.IResultCode;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.exception.TaskRunnerResultCode;
|
import io.metersphere.sdk.exception.TaskRunnerResultCode;
|
||||||
import io.metersphere.sdk.file.FileCenter;
|
import io.metersphere.sdk.file.FileCenter;
|
||||||
|
@ -264,6 +265,10 @@ public class ApiExecuteService {
|
||||||
throw new MSException(RESOURCE_POOL_EXECUTE_ERROR, e.getMessage());
|
throw new MSException(RESOURCE_POOL_EXECUTE_ERROR, e.getMessage());
|
||||||
} catch (MSException e) {
|
} catch (MSException e) {
|
||||||
LogUtils.error(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;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.error(e);
|
LogUtils.error(e);
|
||||||
|
@ -373,29 +378,41 @@ public class ApiExecuteService {
|
||||||
*/
|
*/
|
||||||
public void batchExecute(TaskBatchRequestDTO taskRequest) {
|
public void batchExecute(TaskBatchRequestDTO taskRequest) {
|
||||||
setTaskRequestParams(taskRequest.getTaskInfo());
|
setTaskRequestParams(taskRequest.getTaskInfo());
|
||||||
|
|
||||||
TaskInfo taskInfo = taskRequest.getTaskInfo();
|
TaskInfo taskInfo = taskRequest.getTaskInfo();
|
||||||
// 获取资源池
|
|
||||||
TestResourcePoolReturnDTO testResourcePool = getGetResourcePoolNodeDTO(taskInfo.getRunModeConfig(), taskInfo.getProjectId());
|
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(testResourcePool.getServerUrl())) {
|
try {
|
||||||
// 如果资源池配置了当前站点,则使用资源池的
|
// 获取资源池
|
||||||
taskInfo.setMsUrl(testResourcePool.getServerUrl());
|
TestResourcePoolReturnDTO testResourcePool = getGetResourcePoolNodeDTO(taskInfo.getRunModeConfig(), taskInfo.getProjectId());
|
||||||
}
|
|
||||||
taskInfo.setPoolId(testResourcePool.getId());
|
if (StringUtils.isNotBlank(testResourcePool.getServerUrl())) {
|
||||||
taskRequest.getTaskItems().forEach(taskItem -> {
|
// 如果资源池配置了当前站点,则使用资源池的
|
||||||
if (StringUtils.isBlank(taskItem.getReportId())) {
|
taskInfo.setMsUrl(testResourcePool.getServerUrl());
|
||||||
// 预先生成报告ID,避免资源池获取执行脚本时,超时重试,导致数据重复创建
|
|
||||||
taskItem.setReportId(IDGenerator.nextStr());
|
|
||||||
}
|
}
|
||||||
});
|
taskInfo.setPoolId(testResourcePool.getId());
|
||||||
|
taskRequest.getTaskItems().forEach(taskItem -> {
|
||||||
|
if (StringUtils.isBlank(taskItem.getReportId())) {
|
||||||
|
// 预先生成报告ID,避免资源池获取执行脚本时,超时重试,导致数据重复创建
|
||||||
|
taskItem.setReportId(IDGenerator.nextStr());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 判断是否为 K8S 资源池
|
// 判断是否为 K8S 资源池
|
||||||
boolean isK8SResourcePool = StringUtils.equals(testResourcePool.getType(), ResourcePoolTypeEnum.K8S.getName());
|
boolean isK8SResourcePool = StringUtils.equals(testResourcePool.getType(), ResourcePoolTypeEnum.K8S.getName());
|
||||||
if (isK8SResourcePool) {
|
if (isK8SResourcePool) {
|
||||||
k8sBatchExecute(taskRequest, taskInfo, testResourcePool);
|
k8sBatchExecute(taskRequest, taskInfo, testResourcePool);
|
||||||
} else {
|
} else {
|
||||||
nodeBatchExecute(taskRequest, taskInfo, testResourcePool);
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
TestResourceDTO testResourceDTO = new TestResourceDTO();
|
||||||
BeanUtils.copyBean(testResourceDTO, testResourcePool.getTestResourceReturnDTO());
|
BeanUtils.copyBean(testResourceDTO, testResourcePool.getTestResourceReturnDTO());
|
||||||
testResourceDTO.setId(testResourcePool.getId());
|
testResourceDTO.setId(testResourcePool.getId());
|
||||||
|
|
||||||
taskInfo.setPoolSize(testResourceDTO.getConcurrentNumber());
|
taskInfo.setPoolSize(testResourceDTO.getConcurrentNumber());
|
||||||
taskInfo.setPerTaskSize(testResourceDTO.getPodThreads());
|
taskInfo.setPerTaskSize(testResourceDTO.getPodThreads());
|
||||||
try {
|
EngineFactory.batchRunApi(taskRequest, testResourceDTO);
|
||||||
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) {
|
private List<TaskBatchRequestDTO> getDistributeTaskBatchRequest(TaskBatchRequestDTO taskRequest, int distributeSize) {
|
||||||
|
|
Loading…
Reference in New Issue