use of com.dtstack.taier.develop.dto.devlop.TaskCheckResultVO in project Taier by DTStack.
the class BatchTaskService method checkTaskAndSaveVersion.
/**
* 检查要发布的任务并保存版本信息
*
* @param task 任务信息
* @param tenantId 项目id
* @param userId 用户id
* @param publishDesc 发布描述
* @param isRoot 是否是管理员
* @param ignoreCheck 是否忽略检查
* @return 检查结果
*/
private TaskCheckResultVO checkTaskAndSaveVersion(BatchTask task, Long tenantId, Long userId, String publishDesc, Boolean isRoot, Boolean ignoreCheck) {
TaskCheckResultVO checkVo = new TaskCheckResultVO();
checkVo.setErrorSign(PublishTaskStatusEnum.NOMAL.getType());
checkTaskCanSubmit(task);
task.setSubmitStatus(ESubmitStatus.SUBMIT.getStatus());
task.setGmtModified(Timestamp.valueOf(LocalDateTime.now()));
final BatchTaskVersion version = new BatchTaskVersion();
version.setCreateUserId(userId);
String versionSqlText = StringUtils.EMPTY;
if (EScheduleJobType.SPARK_SQL.getVal().intValue() == task.getTaskType().intValue()) {
// 语法检测
List<BatchTaskParam> taskParamsToReplace = batchTaskParamService.getTaskParam(task.getId());
versionSqlText = this.jobParamReplace.paramReplace(task.getSqlText(), taskParamsToReplace, this.sdf.format(new Date()));
// 避免重复校验
CheckSyntaxResult syntaxResult = batchSqlExeService.processSqlText(task.getTenantId(), task.getTaskType(), versionSqlText);
if (!syntaxResult.getCheckResult()) {
checkVo.setErrorSign(PublishTaskStatusEnum.CHECKSYNTAXERROR.getType());
checkVo.setErrorMessage(syntaxResult.getMessage());
return checkVo;
}
} else if (EScheduleJobType.SYNC.getVal().intValue() == task.getTaskType().intValue()) {
if (StringUtils.isNotEmpty(task.getSqlText())) {
final JSONObject jsonTask = JSON.parseObject(Base64Util.baseDecode(task.getSqlText()));
Integer createModelType = Integer.valueOf(jsonTask.getString("createModel"));
JSONObject job = jsonTask.getJSONObject("job");
if (Objects.isNull(job)) {
throw new RdosDefineException(String.format("数据同步任务:%s 未配置", task.getName()));
}
// 检测job格式
SyncJobCheck.checkJobFormat(job.toJSONString(), createModelType);
versionSqlText = jsonTask.getString("job");
}
}
version.setSqlText(versionSqlText);
version.setOriginSql(task.getSqlText());
version.setTenantId(task.getTenantId());
version.setTaskId(task.getId());
// 任务的版本号
version.setVersion(task.getVersion());
version.setTaskParams(task.getTaskParams());
version.setScheduleConf(task.getScheduleConf());
version.setScheduleStatus(task.getScheduleStatus());
version.setGmtModified(task.getGmtModified());
String dependencyTaskIds = StringUtils.EMPTY;
final List<BatchTaskTask> taskTasks = this.batchTaskTaskService.getAllParentTask(task.getId());
if (CollectionUtils.isNotEmpty(taskTasks)) {
List<Map<String, Object>> parentTasks = taskTasks.stream().map(taskTask -> {
Map<String, Object> map = Maps.newHashMap();
map.put("parentTaskId", taskTask.getParentTaskId());
return map;
}).collect(Collectors.toList());
dependencyTaskIds = JSON.toJSONString(parentTasks);
}
version.setDependencyTaskIds(dependencyTaskIds);
version.setPublishDesc(null == publishDesc ? "" : publishDesc);
// 插入一条记录信息
batchTaskVersionService.insert(version);
task.setVersion(version.getId().intValue());
return checkVo;
}
use of com.dtstack.taier.develop.dto.devlop.TaskCheckResultVO 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;
}
Aggregations