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;
}
}
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;
}
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);
}
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();
}
}
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();
}
Aggregations