Search in sources :

Example 1 with ScheduleJobOperatorRecord

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

the class JobStopDealer method checkExpired.

private boolean checkExpired(JobElement jobElement) {
    ScheduleEngineJobCache jobCache = engineJobCacheService.getByJobId(jobElement.jobId);
    ScheduleJobOperatorRecord scheduleJobOperatorRecord = scheduleJobOperatorRecordService.getById(jobElement.stopJobId);
    if (jobCache != null && scheduleJobOperatorRecord != null && scheduleJobOperatorRecord.getGmtCreate() != null) {
        return jobCache.getGmtCreate().after(scheduleJobOperatorRecord.getGmtCreate());
    } else {
        return true;
    }
}
Also used : ScheduleJobOperatorRecord(com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord) ScheduleEngineJobCache(com.dtstack.taier.dao.domain.ScheduleEngineJobCache)

Example 2 with ScheduleJobOperatorRecord

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

the class JobStopDealer method buildScheduleJobOperatorRecord.

/**
 * 构建OperatorRecord
 *
 * @param finalIsForce 是否强制
 * @param scheduleJob 周期实例
 * @return ScheduleJobOperatorRecord
 */
private ScheduleJobOperatorRecord buildScheduleJobOperatorRecord(Integer finalIsForce, ScheduleJob scheduleJob) {
    ScheduleJobOperatorRecord jobStopRecord = new ScheduleJobOperatorRecord();
    jobStopRecord.setJobId(scheduleJob.getJobId());
    jobStopRecord.setOperatorType(OperatorType.STOP.getType());
    jobStopRecord.setForceCancelFlag(finalIsForce);
    jobStopRecord.setNodeAddress(environmentContext.getLocalAddress());
    return jobStopRecord;
}
Also used : ScheduleJobOperatorRecord(com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord)

Example 3 with ScheduleJobOperatorRecord

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

the class FillDataJobBuilder method savaFillJob.

/**
 * 持久化时间
 *
 * @param allJobList 所有集合
 */
private void savaFillJob(List<ScheduleJobDetails> allJobList) {
    scheduleJobService.insertJobList(allJobList, EScheduleType.FILL_DATA.getType());
    List<ScheduleJobOperatorRecord> operatorJobIds = allJobList.stream().map(jobBuilderBean -> {
        ScheduleJobOperatorRecord record = new ScheduleJobOperatorRecord();
        record.setJobId(jobBuilderBean.getScheduleJob().getJobId());
        record.setForceCancelFlag(ForceCancelFlag.NO.getFlag());
        record.setOperatorType(OperatorType.FILL_DATA.getType());
        record.setNodeAddress(jobBuilderBean.getScheduleJob().getNodeAddress());
        return record;
    }).collect(Collectors.toList());
    scheduleJobOperatorRecordService.saveBatch(operatorJobIds);
}
Also used : ForceCancelFlag(com.dtstack.taier.common.enums.ForceCancelFlag) java.util(java.util) ScheduleTaskShade(com.dtstack.taier.dao.domain.ScheduleTaskShade) Logger(org.slf4j.Logger) ScheduleJobOperatorRecord(com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) DateTime(org.joda.time.DateTime) LoggerFactory(org.slf4j.LoggerFactory) EScheduleType(com.dtstack.taier.common.enums.EScheduleType) Autowired(org.springframework.beans.factory.annotation.Autowired) ScheduleJobOperatorRecordService(com.dtstack.taier.scheduler.service.ScheduleJobOperatorRecordService) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) RetryUtil(com.dtstack.taier.pluginapi.util.RetryUtil) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) CollectionUtils(org.apache.commons.collections.CollectionUtils) FillJobTypeEnum(com.dtstack.taier.scheduler.enums.FillJobTypeEnum) DateUtil(com.dtstack.taier.pluginapi.util.DateUtil) ScheduleJobDetails(com.dtstack.taier.scheduler.server.ScheduleJobDetails) Deleted(com.dtstack.taier.common.enums.Deleted) OperatorType(com.dtstack.taier.common.enums.OperatorType) Transactional(org.springframework.transaction.annotation.Transactional) ScheduleJobOperatorRecord(com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord)

Example 4 with ScheduleJobOperatorRecord

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

the class OperatorRecordJobScheduler method removeOperatorRecord.

/**
 * 删除没有用的操作记录
 *
 * @param deleteJobIdList 实例id
 */
private void removeOperatorRecord(List<String> deleteJobIdList) {
    // 删除OperatorRecord记录时,需要考虑的问题
    // 1. 因为入jobId已经对应的实例已经提交状态,未提交的id不会进入
    // 2. 就是cache是空的情况下,有两种可能性
    // 第一就是还没有创建cache,这个时候Operator不能删
    // 第二是job运行完成后,这个时候Operator需要删除
    // 查询cache表的数据
    Map<String, ScheduleEngineJobCache> scheduleEngineJobCacheMaps = scheduleJobCacheService.lambdaQuery().in(ScheduleEngineJobCache::getJobId, deleteJobIdList).eq(ScheduleEngineJobCache::getIsDeleted, Deleted.NORMAL.getStatus()).list().stream().collect(Collectors.toMap(ScheduleEngineJobCache::getJobId, g -> (g)));
    // 查询需要删除的OperatorRecord的实例信息
    Map<String, ScheduleJob> scheduleJobMap = scheduleJobService.lambdaQuery().in(ScheduleJob::getJobId, deleteJobIdList).eq(ScheduleJob::getIsDeleted, Deleted.NORMAL.getStatus()).list().stream().collect(Collectors.toMap(ScheduleJob::getJobId, g -> (g)));
    List<String> needDeleteJobIdList = Lists.newArrayList();
    for (String jobId : deleteJobIdList) {
        ScheduleEngineJobCache scheduleEngineJobCache = scheduleEngineJobCacheMaps.get(jobId);
        if (scheduleEngineJobCache != null) {
            // cache是空的 两种情况 就是上面2的两种情况,这时我们需要判断job的状态
            ScheduleJob scheduleJob = scheduleJobMap.get(jobId);
            // 如果周期实例是停止状态,那说明job运行完成后,这个时候Operator需要删除
            if (scheduleJob != null && TaskStatus.STOPPED_STATUS.contains(scheduleJob.getStatus())) {
                needDeleteJobIdList.add(jobId);
            }
            if (scheduleJob == null) {
                // 实例查询不到的情况,一般不会出现,但是出来的OperatorRecord也是没有存在的必要,所以需要直接删除
                needDeleteJobIdList.add(jobId);
            }
        } else {
            // cache信息不是空的,就可以直接删除,重启可以考cache重新拉起
            needDeleteJobIdList.add(jobId);
        }
    }
    // 删除OperatorRecord记录
    if (CollectionUtils.isNotEmpty(needDeleteJobIdList)) {
        scheduleJobOperatorRecordService.lambdaUpdate().in(ScheduleJobOperatorRecord::getJobId, needDeleteJobIdList).remove();
    }
}
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) ScheduleEngineJobCache(com.dtstack.taier.dao.domain.ScheduleEngineJobCache)

Example 5 with ScheduleJobOperatorRecord

use of com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord 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

ScheduleJobOperatorRecord (com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord)7 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)5 ScheduleEngineJobCache (com.dtstack.taier.dao.domain.ScheduleEngineJobCache)4 ScheduleJobOperatorRecordService (com.dtstack.taier.scheduler.service.ScheduleJobOperatorRecordService)4 Lists (com.google.common.collect.Lists)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 CollectionUtils (org.apache.commons.collections.CollectionUtils)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Deleted (com.dtstack.taier.common.enums.Deleted)3 OperatorType (com.dtstack.taier.common.enums.OperatorType)3 TaskStatus (com.dtstack.taier.pluginapi.enums.TaskStatus)3 ScheduleJobDetails (com.dtstack.taier.scheduler.server.ScheduleJobDetails)3 ScheduleJobService (com.dtstack.taier.scheduler.service.ScheduleJobService)3 ScheduleJobJob (com.dtstack.taier.dao.domain.ScheduleJobJob)2 JudgeJobExecOperator (com.dtstack.taier.scheduler.server.scheduler.exec.JudgeJobExecOperator)2 ScheduleJobCacheService (com.dtstack.taier.scheduler.service.ScheduleJobCacheService)2 ScheduleJobJobService (com.dtstack.taier.scheduler.service.ScheduleJobJobService)2