use of com.dtstack.taier.dao.domain.ScheduleJobJob in project Taier by DTStack.
the class UpstreamNextJobDependencyHandler method generationJobJobForTask.
@Override
public List<ScheduleJobJob> generationJobJobForTask(ScheduleCorn corn, Date currentDate, String currentJobKey) {
List<ScheduleJobJob> jobJobList = Lists.newArrayList();
for (ScheduleTaskShade taskShade : taskShadeList) {
try {
String jobKey = getJobKey(taskShade, currentDate);
// 如果获取不到key,说明是第一天生成实例,则不生成这条边
if (StringUtils.isBlank(jobKey)) {
continue;
}
ScheduleJobJob scheduleJobJob = new ScheduleJobJob();
scheduleJobJob.setTenantId(currentTaskShade.getTenantId());
scheduleJobJob.setJobKey(currentJobKey);
scheduleJobJob.setParentJobKey(jobKey);
scheduleJobJob.setJobKeyType(RelyType.UPSTREAM_NEXT_JOB.getType());
scheduleJobJob.setRule(getRule(corn.getScheduleConf()));
scheduleJobJob.setIsDeleted(Deleted.NORMAL.getStatus());
jobJobList.add(scheduleJobJob);
} catch (Exception e) {
LOGGER.error("", e);
}
}
return jobJobList;
}
use of com.dtstack.taier.dao.domain.ScheduleJobJob in project Taier by DTStack.
the class ForkJoinJobTask method filterJobKeyList.
private Set<String> filterJobKeyList(ScheduleJob scheduleJob, List<ScheduleJobJob> scheduleJobJobList, String parentJobDayStr, List<ScheduleJob> subJobsAndStatusByFlowId) {
Long jobTaskShadeId = JobKeyUtils.getTaskShadeIdFromJobKey(scheduleJob.getJobKey());
Set<String> jobKeyList = new HashSet<>();
if (null == jobTaskShadeId) {
return jobKeyList;
}
if (CollectionUtils.isNotEmpty(subJobsAndStatusByFlowId)) {
List<String> flowJobKeys = subJobsAndStatusByFlowId.stream().map(ScheduleJob::getJobKey).collect(Collectors.toList());
jobKeyList.addAll(flowJobKeys);
}
for (ScheduleJobJob scheduleJobJob : scheduleJobJobList) {
String childJobKey = scheduleJobJob.getJobKey();
Long childJobShadeId = JobKeyUtils.getTaskShadeIdFromJobKey(childJobKey);
// 排除自依赖
if (null != childJobShadeId && childJobShadeId.equals(jobTaskShadeId)) {
continue;
}
String childJobDayStr = JobKeyUtils.getJobTriggerTimeFromJobKey(childJobKey);
// 排除不是同一天执行的
if (!parentJobDayStr.equals(childJobDayStr)) {
continue;
}
// 添加除工作流内部子任务之外的下游任务依赖
if (CollectionUtils.isNotEmpty(subJobsAndStatusByFlowId) && subJobsAndStatusByFlowId.stream().anyMatch(s -> s.getJobKey().equalsIgnoreCase(childJobKey))) {
continue;
}
jobKeyList.add(scheduleJobJob.getJobKey());
}
return jobKeyList;
}
use of com.dtstack.taier.dao.domain.ScheduleJobJob in project Taier by DTStack.
the class JobUpStreamJudgeJobExecOperator method isExec.
@Override
public JobCheckRunInfo isExec(ScheduleJobDetails scheduleJobDetails) {
List<ScheduleJobJob> jobJobList = scheduleJobDetails.getJobJobList();
ScheduleJob scheduleJob = scheduleJobDetails.getScheduleJob();
JobCheckRunInfo checkRunInfo = new JobCheckRunInfo();
if (CollectionUtils.isNotEmpty(jobJobList)) {
List<String> parentJobKeys = jobJobList.stream().map(ScheduleJobJob::getParentJobKey).collect(Collectors.toList());
Map<String, ScheduleJob> scheduleJobMap = scheduleJobService.lambdaQuery().select(ScheduleJob::getStatus, ScheduleJob::getJobId, ScheduleJob::getJobKey, ScheduleJob::getJobName).in(ScheduleJob::getJobKey, parentJobKeys).eq(ScheduleJob::getIsDeleted, Deleted.NORMAL.getStatus()).list().stream().collect(Collectors.toMap(ScheduleJob::getJobKey, g -> (g)));
for (ScheduleJobJob scheduleJobJob : jobJobList) {
ScheduleJob parentScheduleJob = scheduleJobMap.get(scheduleJobJob.getParentJobKey());
// 1. 补数据实例父实例没有生成,就不去判断父实例状态 2. 周期实例父实例没有生成,就直接设置成实例失败,原因是父实例没有生成
if (parentScheduleJob == null) {
if (EScheduleType.NORMAL_SCHEDULE.getType().equals(scheduleJob.getType())) {
checkRunInfo.setPass(Boolean.FALSE);
checkRunInfo.setStatus(JobCheckStatus.FATHER_NO_CREATED);
checkRunInfo.setLogInfo(String.format(JobCheckStatus.FATHER_NO_CREATED.getMsg(), scheduleJob.getJobName(), scheduleJob.getJobId(), scheduleJobJob.getParentJobKey()));
return checkRunInfo;
} else {
continue;
}
}
// 判断上游依赖规则
// 1. 父实例运行完成,可以运行,也就是说父实例状态不影响子任务状态
// 2. 父实例运行成功,可以运行,也就是说父实例影响子任务状态
Integer rule = scheduleJobJob.getRule();
Integer status = parentScheduleJob.getStatus();
if (RelyRule.RUN_SUCCESS.getType().equals(rule)) {
Integer jobKeyType = scheduleJobJob.getJobKeyType();
// 父任务有运行失败的
if (TaskStatus.FAILED.getStatus().equals(status) || TaskStatus.SUBMITFAILD.getStatus().equals(status) || TaskStatus.PARENTFAILED.getStatus().equals(status)) {
checkRunInfo.setPass(Boolean.FALSE);
checkRunInfo.setStatus(JobCheckStatus.FATHER_JOB_EXCEPTION);
checkRunInfo.setLogInfo(String.format(JobCheckStatus.FATHER_JOB_EXCEPTION.getMsg(), parentScheduleJob.getJobName(), parentScheduleJob.getJobId()));
return checkRunInfo;
}
// 父实例是冻结(但是这些实例不能是自依赖,自依赖实例是用自己任务的状态判断是否冻结)
if (TaskStatus.FROZEN.getStatus().equals(status) && !RelyType.SELF_RELIANCE.getType().equals(jobKeyType)) {
checkRunInfo.setPass(Boolean.FALSE);
checkRunInfo.setStatus(JobCheckStatus.FATHER_JOB_FROZEN);
checkRunInfo.setLogInfo(String.format(JobCheckStatus.FATHER_JOB_FROZEN.getMsg(), parentScheduleJob.getJobName(), parentScheduleJob.getJobId()));
return checkRunInfo;
}
// 父实例是取消
if (TaskStatus.CANCELED.getStatus().equals(status) || TaskStatus.KILLED.getStatus().equals(status) || TaskStatus.AUTOCANCELED.getStatus().equals(status)) {
checkRunInfo.setPass(Boolean.FALSE);
checkRunInfo.setStatus(JobCheckStatus.DEPENDENCY_JOB_CANCELED);
checkRunInfo.setLogInfo(String.format(JobCheckStatus.DEPENDENCY_JOB_CANCELED.getMsg(), scheduleJob.getJobName(), scheduleJob.getJobId(), parentScheduleJob.getJobName(), parentScheduleJob.getJobId()));
return checkRunInfo;
}
}
if (!TaskStatus.FINISHED.getStatus().equals(status) && !TaskStatus.MANUALSUCCESS.getStatus().equals(status)) {
checkRunInfo.setPass(Boolean.FALSE);
checkRunInfo.setStatus(JobCheckStatus.FATHER_JOB_NOT_FINISHED);
checkRunInfo.setLogInfo(JobCheckStatus.FATHER_JOB_NOT_FINISHED.getMsg());
return checkRunInfo;
}
}
}
checkRunInfo.setPass(Boolean.TRUE);
return checkRunInfo;
}
use of com.dtstack.taier.dao.domain.ScheduleJobJob in project Taier by DTStack.
the class CycleJobScheduler method listExecJob.
@Override
protected List<ScheduleJobDetails> listExecJob(Long startSort, String nodeAddress, Boolean isEq) {
List<ScheduleJob> scheduleJobList = scheduleJobService.listCycleJob(startSort, nodeAddress, getScheduleType().getType(), isEq, JobPhaseStatus.CREATE.getCode());
List<String> jobKeys = scheduleJobList.stream().map(ScheduleJob::getJobKey).collect(Collectors.toList());
List<ScheduleJobJob> scheduleJobJobList = scheduleJobJobService.listByJobKeys(jobKeys);
Map<String, List<ScheduleJobJob>> jobJobMap = scheduleJobJobList.stream().collect(Collectors.groupingBy(ScheduleJobJob::getJobKey));
List<ScheduleJobDetails> scheduleJobDetailsList = new ArrayList<>(scheduleJobList.size());
for (ScheduleJob scheduleJob : scheduleJobList) {
ScheduleJobDetails scheduleJobDetails = new ScheduleJobDetails();
scheduleJobDetails.setScheduleJob(scheduleJob);
scheduleJobDetails.setJobJobList(jobJobMap.get(scheduleJob.getJobKey()));
scheduleJobDetailsList.add(scheduleJobDetails);
}
return scheduleJobDetailsList;
}
use of com.dtstack.taier.dao.domain.ScheduleJobJob in project Taier by DTStack.
the class OperatorRecordJobScheduler method listExecJob.
@Override
protected List<ScheduleJobDetails> listExecJob(Long startSort, String nodeAddress, Boolean isEq) {
List<ScheduleJobOperatorRecord> records = scheduleJobOperatorRecordService.listOperatorRecord(startSort, nodeAddress, getOperatorType().getType(), isEq);
if (CollectionUtils.isNotEmpty(records)) {
Set<String> jobIds = records.stream().map(ScheduleJobOperatorRecord::getJobId).collect(Collectors.toSet());
List<ScheduleJob> scheduleJobList = getScheduleJob(jobIds);
if (CollectionUtils.isNotEmpty(scheduleJobList)) {
List<String> jodExecIds = scheduleJobList.stream().map(ScheduleJob::getJobId).collect(Collectors.toList());
if (jobIds.size() != scheduleJobList.size()) {
// 过滤出来已经提交运行的实例,删除操作记录
List<String> deleteJobIdList = jobIds.stream().filter(jobId -> !jodExecIds.contains(jobId)).collect(Collectors.toList());
removeOperatorRecord(deleteJobIdList);
}
List<String> jobKeys = scheduleJobList.stream().map(ScheduleJob::getJobKey).collect(Collectors.toList());
List<ScheduleJobJob> scheduleJobJobList = scheduleJobJobService.listByJobKeys(jobKeys);
Map<String, List<ScheduleJobJob>> jobJobMap = scheduleJobJobList.stream().collect(Collectors.groupingBy(ScheduleJobJob::getJobKey));
List<ScheduleJobDetails> scheduleJobDetailsList = new ArrayList<>(scheduleJobList.size());
for (ScheduleJob scheduleJob : scheduleJobList) {
ScheduleJobDetails scheduleJobDetails = new ScheduleJobDetails();
scheduleJobDetails.setScheduleJob(scheduleJob);
scheduleJobDetails.setJobJobList(jobJobMap.get(scheduleJob.getJobKey()));
scheduleJobDetailsList.add(scheduleJobDetails);
}
return scheduleJobDetailsList;
} else {
removeOperatorRecord(Lists.newArrayList(jobIds));
}
}
return Lists.newArrayList();
}
Aggregations