Search in sources :

Example 1 with ScheduleJobJob

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;
}
Also used : ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob) ScheduleTaskShade(com.dtstack.taier.dao.domain.ScheduleTaskShade) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 2 with ScheduleJobJob

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;
}
Also used : java.util(java.util) ForkJoinTask(java.util.concurrent.ForkJoinTask) ScheduleJobJobService(com.dtstack.taier.scheduler.service.ScheduleJobJobService) Logger(org.slf4j.Logger) ScheduleJobService(com.dtstack.taier.scheduler.service.ScheduleJobService) MapUtils(org.apache.commons.collections.MapUtils) RecursiveTask(java.util.concurrent.RecursiveTask) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) JobKeyUtils(com.dtstack.taier.scheduler.utils.JobKeyUtils) CollectionUtils(org.apache.commons.collections.CollectionUtils) EScheduleJobType(com.dtstack.taier.common.enums.EScheduleJobType) ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob) Deleted(com.dtstack.taier.common.enums.Deleted) ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob)

Example 3 with ScheduleJobJob

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;
}
Also used : Logger(org.slf4j.Logger) ScheduleJobService(com.dtstack.taier.scheduler.service.ScheduleJobService) JobCheckStatus(com.dtstack.taier.common.enums.JobCheckStatus) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) LoggerFactory(org.slf4j.LoggerFactory) EScheduleType(com.dtstack.taier.common.enums.EScheduleType) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) List(java.util.List) CollectionUtils(org.apache.commons.collections.CollectionUtils) RelyRule(com.dtstack.taier.scheduler.enums.RelyRule) RelyType(com.dtstack.taier.scheduler.enums.RelyType) Map(java.util.Map) ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob) ScheduleJobDetails(com.dtstack.taier.scheduler.server.ScheduleJobDetails) Deleted(com.dtstack.taier.common.enums.Deleted) TaskStatus(com.dtstack.taier.pluginapi.enums.TaskStatus) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob)

Example 4 with ScheduleJobJob

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;
}
Also used : ScheduleJobDetails(com.dtstack.taier.scheduler.server.ScheduleJobDetails) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ScheduleJobJob

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();
}
Also used : java.util(java.util) ScheduleJobJobService(com.dtstack.taier.scheduler.service.ScheduleJobJobService) Logger(org.slf4j.Logger) ScheduleJobOperatorRecord(com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord) ScheduleJobService(com.dtstack.taier.scheduler.service.ScheduleJobService) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) JudgeJobExecOperator(com.dtstack.taier.scheduler.server.scheduler.exec.JudgeJobExecOperator) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ScheduleJobOperatorRecordService(com.dtstack.taier.scheduler.service.ScheduleJobOperatorRecordService) Collectors(java.util.stream.Collectors) Lists(com.google.common.collect.Lists) ScheduleJobCacheService(com.dtstack.taier.scheduler.service.ScheduleJobCacheService) CollectionUtils(org.apache.commons.collections.CollectionUtils) ScheduleEngineJobCache(com.dtstack.taier.dao.domain.ScheduleEngineJobCache) ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob) ScheduleJobDetails(com.dtstack.taier.scheduler.server.ScheduleJobDetails) Deleted(com.dtstack.taier.common.enums.Deleted) OperatorType(com.dtstack.taier.common.enums.OperatorType) TaskStatus(com.dtstack.taier.pluginapi.enums.TaskStatus) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob) ScheduleJobDetails(com.dtstack.taier.scheduler.server.ScheduleJobDetails) ScheduleJobOperatorRecord(com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord)

Aggregations

ScheduleJobJob (com.dtstack.taier.dao.domain.ScheduleJobJob)11 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)7 Deleted (com.dtstack.taier.common.enums.Deleted)4 ScheduleJobDetails (com.dtstack.taier.scheduler.server.ScheduleJobDetails)4 Collectors (java.util.stream.Collectors)4 CollectionUtils (org.apache.commons.collections.CollectionUtils)4 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 ScheduleTaskShade (com.dtstack.taier.dao.domain.ScheduleTaskShade)3 ScheduleJobService (com.dtstack.taier.scheduler.service.ScheduleJobService)3 Lists (com.google.common.collect.Lists)3 List (java.util.List)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 EScheduleJobType (com.dtstack.taier.common.enums.EScheduleJobType)2 TaskStatus (com.dtstack.taier.pluginapi.enums.TaskStatus)2 RelyType (com.dtstack.taier.scheduler.enums.RelyType)2 ScheduleJobJobService (com.dtstack.taier.scheduler.service.ScheduleJobJobService)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Logger (org.slf4j.Logger)2