use of com.dtstack.taier.dao.domain.BatchTaskTask in project Taier by DTStack.
the class BatchTaskService method allProductGlobalSearch.
/**
* 查找所有产品提交的任务
*
* @param searchVO
* @return
*/
public List<BatchAllProductGlobalReturnVO> allProductGlobalSearch(AllProductGlobalSearchVO searchVO) {
BatchTask batchTask = developTaskDao.getOne(searchVO.getTaskId());
if (batchTask == null) {
throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_TASK);
}
if (batchTask.getTaskType().intValue() == EScheduleJobType.VIRTUAL.getVal().intValue()) {
throw new RdosDefineException(ErrorCode.VIRTUAL_TASK_UNSUPPORTED_OPERATION);
}
// 过滤掉已经依赖的任务
final List<BatchTaskTask> taskTasks = this.batchTaskTaskService.getByParentTaskId(searchVO.getTaskId());
final List<Long> excludeIds = new ArrayList<>(taskTasks.size());
excludeIds.add(searchVO.getTaskId());
taskTasks.forEach(taskTask -> excludeIds.add(taskTask.getTaskId()));
List<ScheduleTaskShade> scheduleTaskShadeList = taskService.findTaskByTaskName(searchVO.getTaskName(), searchVO.getSelectTenantId(), searchVO.getUserId());
List<ScheduleTaskShade> filterTask = scheduleTaskShadeList.stream().filter(scheduleTask -> !excludeIds.contains(scheduleTask.getTaskId())).collect(Collectors.toList());
Map<Long, Tenant> tenantMap = tenantService.listAllTenant().stream().collect(Collectors.toMap(Tenant::getId, g -> (g)));
List<BatchAllProductGlobalReturnVO> voList = Lists.newArrayList();
for (ScheduleTaskShade scheduleTaskShade : filterTask) {
BatchAllProductGlobalReturnVO vo = new BatchAllProductGlobalReturnVO();
vo.setTaskId(scheduleTaskShade.getTaskId());
vo.setTaskName(scheduleTaskShade.getName());
Tenant tenant = tenantMap.get(scheduleTaskShade.getTenantId());
if (tenant != null) {
vo.setTenantId(tenant.getId());
vo.setTenantName(tenant.getTenantName());
}
voList.add(vo);
}
return voList;
}
use of com.dtstack.taier.dao.domain.BatchTaskTask in project Taier by DTStack.
the class BatchTaskTaskService method getForefathers.
/**
* 展开上一个父节点
*
* @author toutian
*/
public ScheduleTaskVO getForefathers(BatchTask task) {
BatchTaskBatchVO vo = new BatchTaskBatchVO();
BeanUtils.copyProperties(task, vo);
vo.setVersion(task.getVersion());
vo.setCreateUser(userService.getUserByDTO(task.getCreateUserId()));
vo.setModifyUser(userService.getUserByDTO(task.getModifyUserId()));
vo.setTenantName(tenantService.getTenantById(task.getTenantId()).getTenantName());
List<BatchTaskTask> taskTasks = developTaskTaskDao.listByTaskId(task.getId());
if (CollectionUtils.isEmpty(taskTasks)) {
return vo;
}
List<ScheduleTaskVO> fatherTaskVOs = Lists.newArrayList();
for (BatchTaskTask taskTask : taskTasks) {
Long parentTaskId = taskTask.getParentTaskId();
ScheduleTaskShade taskShade = taskService.findTaskByTaskId(parentTaskId);
if (taskShade != null) {
ScheduleTaskVO scheduleTaskVO = new ScheduleTaskVO();
BeanUtils.copyProperties(taskShade, scheduleTaskVO);
scheduleTaskVO.setId(taskShade.getTaskId());
scheduleTaskVO.setTenantName(tenantService.getByDtTenantId(taskShade.getTenantId()).getTenantName());
fatherTaskVOs.add(scheduleTaskVO);
}
}
vo.setTaskVOS(fatherTaskVOs);
return vo;
}
use of com.dtstack.taier.dao.domain.BatchTaskTask 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.dao.domain.BatchTaskTask in project Taier by DTStack.
the class BatchTaskService method isHasLoop.
public Long isHasLoop(final Long parentTaskId, final HashSet<Long> node) {
HashSet<Long> loopNode = new HashSet<>(node.size() + 1);
loopNode.addAll(node);
loopNode.add(parentTaskId);
// 出现闭环则返回
if (loopNode.size() == node.size()) {
return parentTaskId;
}
List<BatchTaskTask> taskTasks = batchTaskTaskService.getAllParentTask(parentTaskId);
if (CollectionUtils.isEmpty(taskTasks)) {
return 0L;
}
for (BatchTaskTask subTask : taskTasks) {
Long loopTaskId = isHasLoop(subTask.getParentTaskId(), loopNode);
if (loopTaskId != 0L) {
return loopTaskId;
}
}
return 0L;
}
use of com.dtstack.taier.dao.domain.BatchTaskTask in project Taier by DTStack.
the class BatchTaskTaskService method addOrUpdateTaskTask.
@Transactional(rollbackFor = Exception.class)
public void addOrUpdateTaskTask(Long taskId, List<BatchTask> dependencyTasks) {
List<BatchTaskTask> taskTasks = developTaskTaskDao.listByTaskId(taskId);
List<BatchTaskTask> dependencyTaskTasks = getTaskTasksByTaskIdAndTasks(taskId, dependencyTasks);
List<BatchTaskTask> existDependencyTasks = Lists.newArrayList();
for (BatchTaskTask taskTask : taskTasks) {
BatchTaskTask existTaskTask = existTaskTask(dependencyTaskTasks, taskTask);
if (existTaskTask != null) {
existDependencyTasks.add(existTaskTask);
continue;
}
developTaskTaskDao.delete(taskTask.getId());
}
dependencyTaskTasks.removeAll(existDependencyTasks);
for (BatchTaskTask taskTask : dependencyTaskTasks) {
addOrUpdate(taskTask);
}
}
Aggregations