Search in sources :

Example 6 with ScheduleJobJob

use of com.dtstack.taier.dao.domain.ScheduleJobJob in project Taier by DTStack.

the class SelfRelianceDependencyHandler method generationJobJobForTask.

@Override
public List<ScheduleJobJob> generationJobJobForTask(ScheduleCorn corn, Date currentDate, String currentJobKey) {
    // 获得上一次执行的时间
    Date last = corn.last(currentDate);
    String lastDate = DateUtil.getDate(last, DateUtil.STANDARD_DATETIME_FORMAT);
    String lastJobKey = JobKeyUtils.generateJobKey(keyPreStr, currentTaskShade.getTaskId(), lastDate);
    // 判断是否上一次执行的时间和当前时间是否是同一天,如果是的话插入,不是的话,去查询一下数据库是否有实例生成。
    lastJobKey = needCreateKey(last, currentDate, lastJobKey);
    if (StringUtils.isBlank(lastJobKey)) {
        return Lists.newArrayList();
    }
    List<ScheduleJobJob> jobJobList = Lists.newArrayList();
    ScheduleJobJob scheduleJobJob = new ScheduleJobJob();
    scheduleJobJob.setTenantId(currentTaskShade.getTenantId());
    scheduleJobJob.setJobKey(currentJobKey);
    scheduleJobJob.setParentJobKey(lastJobKey);
    scheduleJobJob.setJobKeyType(RelyType.SELF_RELIANCE.getType());
    scheduleJobJob.setRule(getRule(corn.getScheduleConf()));
    scheduleJobJob.setIsDeleted(Deleted.NORMAL.getStatus());
    jobJobList.add(scheduleJobJob);
    return jobJobList;
}
Also used : ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob) Date(java.util.Date)

Example 7 with ScheduleJobJob

use of com.dtstack.taier.dao.domain.ScheduleJobJob in project Taier by DTStack.

the class UpstreamDependencyHandler 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.getType());
            scheduleJobJob.setRule(RelyRule.RUN_SUCCESS.getType());
            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 8 with ScheduleJobJob

use of com.dtstack.taier.dao.domain.ScheduleJobJob in project Taier by DTStack.

the class ScheduleJobJobTaskDTO method toJobJob.

public ScheduleJobJob toJobJob() {
    ScheduleJobJob scheduleJobJob = new ScheduleJobJob();
    BeanUtils.copyProperties(this, scheduleJobJob);
    return scheduleJobJob;
}
Also used : ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob)

Example 9 with ScheduleJobJob

use of com.dtstack.taier.dao.domain.ScheduleJobJob in project Taier by DTStack.

the class ForkJoinJobTask method compute.

@Override
protected ConcurrentHashMap<String, String> compute() {
    ScheduleJob scheduleJob = scheduleJobService.lambdaQuery().eq(ScheduleJob::getJobId, jobId).eq(ScheduleJob::getIsDeleted, Deleted.NORMAL.getStatus()).one();
    if (null == scheduleJob) {
        return null;
    }
    String jobKey = scheduleJob.getJobKey();
    // 从jobKey获取父任务的触发时间
    String parentJobDayStr = JobKeyUtils.getJobTriggerTimeFromJobKey(jobKey);
    if (Strings.isNullOrEmpty(parentJobDayStr)) {
        return null;
    }
    // 查询子工作任务
    List<ScheduleJobJob> scheduleJobJobList = scheduleJobJobService.lambdaQuery().eq(ScheduleJobJob::getParentJobKey, jobKey).eq(ScheduleJobJob::getIsDeleted, Deleted.NORMAL.getStatus()).list();
    if (CollectionUtils.isEmpty(scheduleJobJobList)) {
        return null;
    }
    List<ScheduleJob> flowJobList = null;
    // 如果工作流 和 实验任务 把子节点全部添加进来
    if (SPECIAL_TASK_TYPES.contains(scheduleJob.getTaskType())) {
        flowJobList = scheduleJobService.lambdaQuery().eq(ScheduleJob::getFlowJobId, scheduleJob.getJobId()).eq(ScheduleJob::getIsDeleted, Deleted.NORMAL.getStatus()).list();
    }
    Set<String> jobKeyList = this.filterJobKeyList(scheduleJob, scheduleJobJobList, parentJobDayStr, flowJobList);
    if (CollectionUtils.isEmpty(jobKeyList)) {
        return null;
    }
    List<ScheduleJob> childJobList = scheduleJobService.lambdaQuery().eq(ScheduleJob::getJobKey, jobKeyList).eq(ScheduleJob::getIsDeleted, Deleted.NORMAL.getStatus()).list();
    List<ForkJoinJobTask> tasks = new ArrayList<>();
    for (ScheduleJob childScheduleJob : childJobList) {
        if (results.containsKey(childScheduleJob.getJobId())) {
            continue;
        }
        results.put(childScheduleJob.getJobId(), childScheduleJob.getCycTime());
        if (isOnlyNextChild) {
            continue;
        }
        ForkJoinJobTask subTask = new ForkJoinJobTask(childScheduleJob.getJobId(), results, scheduleJobService, scheduleJobJobService, isOnlyNextChild);
        logger.info("forkJoinJobTask subTask jobId {} result {} isOnlyNextChild {} ", childScheduleJob.getJobId(), results.size(), isOnlyNextChild);
        tasks.add(subTask);
    }
    Collection<ForkJoinJobTask> forkJoinJobTasks = ForkJoinTask.invokeAll(tasks);
    for (ForkJoinJobTask forkJoinJobTask : forkJoinJobTasks) {
        Map<String, String> scheduleJobs = forkJoinJobTask.join();
        if (MapUtils.isNotEmpty(scheduleJobs)) {
            results.putAll(scheduleJobs);
        }
    }
    return results;
}
Also used : ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob)

Example 10 with ScheduleJobJob

use of com.dtstack.taier.dao.domain.ScheduleJobJob in project Taier by DTStack.

the class AbstractJobBuilder method buildJobBuilderBean.

/**
 * 构建JobBuilderBean
 *
 * @param scheduleTaskShade 需要被构建的任务
 * @param name 实例名称
 * @param fillId 补数据id
 * @param jobSortWorker 排序器
 * @param corn 周期实例
 * @param scheduleConf 调度配置
 * @param currentData 当前时间
 * @return
 */
private ScheduleJobDetails buildJobBuilderBean(ScheduleTaskShade scheduleTaskShade, String name, Long fillId, JobSortWorker jobSortWorker, ScheduleCorn corn, ScheduleConf scheduleConf, Date currentData, String flowJobId) {
    String triggerTime = DateUtil.getDate(currentData, DateUtil.STANDARD_DATETIME_FORMAT);
    String cycTime = DateUtil.getTimeStrWithoutSymbol(triggerTime);
    String jobKey = JobKeyUtils.generateJobKey(getKeyPreStr(name), scheduleTaskShade.getTaskId(), cycTime);
    // 实例
    ScheduleJob scheduleJob = new ScheduleJob();
    scheduleJob.setTenantId(scheduleTaskShade.getTenantId());
    scheduleJob.setJobId(actionService.generateUniqueSign());
    scheduleJob.setJobKey(jobKey);
    scheduleJob.setJobName(getName(scheduleTaskShade, name, cycTime));
    scheduleJob.setTaskId(scheduleTaskShade.getTaskId());
    scheduleJob.setCreateUserId(scheduleTaskShade.getCreateUserId());
    scheduleJob.setIsDeleted(Deleted.NORMAL.getStatus());
    scheduleJob.setType(getType());
    scheduleJob.setIsRestart(Restarted.NORMAL.getStatus());
    scheduleJob.setCycTime(cycTime);
    scheduleJob.setDependencyType(scheduleConf.getSelfReliance());
    scheduleJob.setFlowJobId(flowJobId);
    scheduleJob.setPeriodType(scheduleConf.getPeriodType());
    scheduleJob.setStatus(TaskStatus.UNSUBMIT.getStatus());
    scheduleJob.setTaskType(scheduleTaskShade.getTaskType());
    scheduleJob.setFillId(fillId);
    scheduleJob.setMaxRetryNum(scheduleConf.getMaxRetryNum());
    scheduleJob.setVersionId(scheduleTaskShade.getVersionId());
    scheduleJob.setComputeType(scheduleTaskShade.getComputeType());
    scheduleJob.setNextCycTime(DateUtil.getDate(corn.next(currentData), DateUtil.STANDARD_DATETIME_FORMAT));
    scheduleJob.setJobExecuteOrder(JobExecuteOrderUtil.buildJobExecuteOrder(cycTime, jobSortWorker.getSort()));
    // 获得依赖
    List<ScheduleJobJob> jobJobList = Lists.newArrayList();
    DependencyHandler dependencyHandler = dependencyManager.getDependencyHandler(getKeyPreStr(name), scheduleTaskShade, corn);
    while (dependencyHandler != null) {
        jobJobList.addAll(dependencyHandler.generationJobJobForTask(corn, currentData, jobKey));
        dependencyHandler = dependencyHandler.next();
    }
    ScheduleJobDetails jobBuilderBean = new ScheduleJobDetails();
    jobBuilderBean.setJobJobList(jobJobList);
    jobBuilderBean.setScheduleJob(scheduleJob);
    return jobBuilderBean;
}
Also used : ScheduleJobDetails(com.dtstack.taier.scheduler.server.ScheduleJobDetails) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) DependencyHandler(com.dtstack.taier.scheduler.server.builder.dependency.DependencyHandler) ScheduleJobJob(com.dtstack.taier.dao.domain.ScheduleJobJob)

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