use of com.dtstack.taier.scheduler.dto.schedule.ScheduleTaskShadeDTO in project Taier by DTStack.
the class BatchTaskService method buildScheduleTaskShadeDTO.
/**
* 构建一个要发布到engine的任务DTO {@link ScheduleTaskShadeDTO}
* @param batchTask 要发布的任务集合
* @param parentTaskIds 父任务的id
* @return 调度任务DTO
*/
private ScheduleTaskShadeDTO buildScheduleTaskShadeDTO(final BatchTask batchTask, List<Long> parentTaskIds) {
if (batchTask.getId() <= 0) {
// 只有异常情况才会走到该逻辑
throw new RdosDefineException("batchTask id can't be 0", ErrorCode.SERVER_EXCEPTION);
}
final long taskId = batchTask.getId();
// 清空任务关联的batch_task_param, task_resource, task_task 表信息
this.batchTaskParamShadeService.clearDataByTaskId(taskId);
this.batchTaskResourceShadeService.clearDataByTaskId(taskId);
final List<BatchTaskParam> batchTaskParamList = this.batchTaskParamService.getTaskParam(batchTask.getId());
// 查询出任务所有的关联的资源(运行主体资源和依赖引用资源)
final List<BatchTaskResource> batchTaskResourceList = this.batchTaskResourceService.getTaskResources(batchTask.getId(), null);
List<Long> parentTaskList = this.batchTaskTaskService.getAllParentTaskId(batchTask.getId());
parentTaskIds.addAll(parentTaskList);
if (!CollectionUtils.isEmpty(batchTaskResourceList)) {
this.batchTaskResourceShadeService.saveTaskResource(batchTaskResourceList);
}
// 保存batch_task_shade
final ScheduleTaskShadeDTO scheduleTaskShadeDTO = new ScheduleTaskShadeDTO();
BeanUtils.copyProperties(batchTask, scheduleTaskShadeDTO);
scheduleTaskShadeDTO.setTaskId(batchTask.getId());
scheduleTaskShadeDTO.setScheduleStatus(EScheduleStatus.NORMAL.getVal());
if (!CollectionUtils.isEmpty(batchTaskParamList)) {
this.batchTaskParamShadeService.saveTaskParam(batchTaskParamList);
} else {
scheduleTaskShadeDTO.setTaskParams("");
}
return scheduleTaskShadeDTO;
}
use of com.dtstack.taier.scheduler.dto.schedule.ScheduleTaskShadeDTO in project Taier by DTStack.
the class BatchTaskService method publishBatchTaskInfo.
/**
* 批量发布任务至engine
* @param publishTask 要发布的task集合
* @param tenantId 项目id
* @param userId 用户id
* @param publishDesc 发布描述
* @param isRoot 是否是管理员
* @param ignoreCheck 忽略检查
* @return 发布结果
*/
public TaskCheckResultVO publishBatchTaskInfo(BatchTask publishTask, Long tenantId, Long userId, String publishDesc, Boolean isRoot, Boolean ignoreCheck) {
// 判断任务责任人是否存在 如果任务责任人不存在或无权限 不允许提交
User user = userService.getById(publishTask.getCreateUserId());
if (user == null) {
throw new RdosDefineException(String.format("%s任务责任人在数栈中不存在", publishTask.getName()));
}
TaskCheckResultVO checkResultVO = new TaskCheckResultVO();
checkResultVO.setErrorSign(PublishTaskStatusEnum.NOMAL.getType());
// 检查任务是否可以发布并记录版本信息
TaskCheckResultVO resultVO = checkTaskAndSaveVersion(publishTask, tenantId, userId, publishDesc, isRoot, ignoreCheck);
if (!PublishTaskStatusEnum.NOMAL.getType().equals(resultVO.getErrorSign())) {
// 做一下优化 如果是工作流任务的话 把任务名称打印出来
if (publishTask.getFlowId() > 0) {
resultVO.setErrorMessage(String.format("任务:%s提交失败,原因是:%s", publishTask.getName(), resultVO.getErrorMessage()));
}
return resultVO;
}
// 发布任务中所有的依赖关系
List<Long> parentTaskIds = Lists.newArrayList();
ScheduleTaskShadeDTO scheduleTaskShadeDTO = buildScheduleTaskShadeDTO(publishTask, parentTaskIds);
// 提交任务参数信息并保存任务记录和更新任务状态
try {
BatchTask batchTask = getOneWithError(scheduleTaskShadeDTO.getTaskId());
String extraInfo = this.batchJobService.getExtraInfo(batchTask, userId, null);
scheduleTaskShadeDTO.setExtraInfo(extraInfo);
// 无异常保存一条任务记录并更新任务状态
saveRecordAndUpdateSubmitStatus(batchTask, tenantId, userId, TaskOperateType.COMMIT.getType(), ESubmitStatus.SUBMIT.getStatus());
} catch (Exception e) {
LOGGER.error("send task error {} ", scheduleTaskShadeDTO.getTaskId(), e);
throw new RdosDefineException(String.format("任务提交异常:%s", e.getMessage()), e);
}
SavaTaskDTO savaTaskDTO = new SavaTaskDTO();
savaTaskDTO.setScheduleTaskShadeDTO(scheduleTaskShadeDTO);
savaTaskDTO.setParentTaskIdList(parentTaskIds);
// 批量发布任务
this.taskService.saveTask(savaTaskDTO);
LOGGER.info("待发布任务参数提交完毕");
return checkResultVO;
}
use of com.dtstack.taier.scheduler.dto.schedule.ScheduleTaskShadeDTO in project Taier by DTStack.
the class TaskService method saveTask.
/**
* 提交单个任务 (不包括工作流)
* @param savaTaskDTO 任务
* @return 是否提交成功
*/
public Boolean saveTask(SavaTaskDTO savaTaskDTO) {
ScheduleTaskShadeDTO scheduleTaskShadeDTO = savaTaskDTO.getScheduleTaskShadeDTO();
ScheduleTaskShade scheduleTaskShade = ScheduleTaskMapstructTransfer.INSTANCE.dtoToBean(scheduleTaskShadeDTO);
ScheduleTaskShade dbTaskShade = this.lambdaQuery().eq(ScheduleTaskShade::getTaskId, scheduleTaskShade.getTaskId()).eq(ScheduleTaskShade::getIsDeleted, Deleted.NORMAL.getStatus()).one();
ScheduleTaskShadeInfo scheduleTaskShadeInfo = new ScheduleTaskShadeInfo();
scheduleTaskShadeInfo.setInfo(scheduleTaskShade.getExtraInfo());
scheduleTaskShadeInfo.setTaskId(scheduleTaskShade.getTaskId());
// 保存任务或者更新任务
if (dbTaskShade != null) {
scheduleTaskShade.setId(dbTaskShade.getId());
this.updateById(scheduleTaskShade);
scheduleTaskShadeInfoService.update(scheduleTaskShadeInfo, scheduleTaskShade.getTaskId());
} else {
this.save(scheduleTaskShade);
scheduleTaskShadeInfoService.insert(scheduleTaskShadeInfo);
}
// 保存关系
List<Long> parentTaskIdList = savaTaskDTO.getParentTaskIdList();
List<ScheduleTaskTaskShade> scheduleTaskTaskShadeList = Lists.newArrayList();
for (Long parentTaskId : parentTaskIdList) {
ScheduleTaskTaskShade scheduleTaskTaskShade = new ScheduleTaskTaskShade();
scheduleTaskTaskShade.setTenantId(scheduleTaskShade.getTenantId());
scheduleTaskTaskShade.setTaskId(scheduleTaskShade.getTaskId());
scheduleTaskTaskShade.setParentTaskId(parentTaskId);
scheduleTaskTaskShadeList.add(scheduleTaskTaskShade);
}
// TODO 这块后面还需要考虑成环判断
// 删除任务依赖
tasktaskService.lambdaUpdate().eq(ScheduleTaskTaskShade::getTaskId, scheduleTaskShade.getTaskId()).remove();
return tasktaskService.saveBatch(scheduleTaskTaskShadeList);
}
Aggregations