use of com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord in project Taier by DTStack.
the class JobStopDealer method addStopJobs.
/**
* 添加取消实例
*
* @param scheduleJobList 需要被取消的任务
* @param isForce 是否强制杀死
* @return 操作数(取消了任务数)
*/
public int addStopJobs(List<ScheduleJob> scheduleJobList, Integer isForce) {
if (CollectionUtils.isEmpty(scheduleJobList)) {
return 0;
}
if (scheduleJobList.size() > JOB_STOP_LIMIT) {
throw new RdosDefineException("please don't stop too many tasks at once, limit:" + JOB_STOP_LIMIT);
}
// 分离实例是否提交到yarn上,如果提交到yarn上,需要发送请求stop,如果未提交,直接更新db
List<ScheduleJob> needSendStopJobs = new ArrayList<>(scheduleJobList.size());
List<String> unSubmitJobList = new ArrayList<>(scheduleJobList.size());
for (ScheduleJob job : scheduleJobList) {
if (isSubmit(job)) {
unSubmitJobList.add(job.getJobId());
} else {
needSendStopJobs.add(job);
}
}
// 查询一遍Operator表,过滤数据
List<ScheduleJobOperatorRecord> scheduleJobOperatorRecordList = scheduleJobOperatorRecordService.lambdaQuery().in(ScheduleJobOperatorRecord::getJobId, scheduleJobList.stream().map(ScheduleJob::getJobId).collect(Collectors.toList())).eq(ScheduleJobOperatorRecord::getIsDeleted, Deleted.NORMAL.getStatus()).eq(ScheduleJobOperatorRecord::getOperatorType, OperatorType.STOP.getType()).list();
List<String> alreadyExistJobIds = scheduleJobOperatorRecordList.stream().map(ScheduleJobOperatorRecord::getJobId).collect(Collectors.toList());
// 处理已经提交到yarn的实例状态
if (CollectionUtils.isNotEmpty(needSendStopJobs)) {
isForce = Optional.ofNullable(isForce).orElse(ForceCancelFlag.NO.getFlag());
Integer finalIsForce = isForce;
List<ScheduleJobOperatorRecord> jobOperatorRecordList = needSendStopJobs.stream().filter(scheduleJob -> !alreadyExistJobIds.contains(scheduleJob.getJobId())).map(scheduleJob -> buildScheduleJobOperatorRecord(finalIsForce, scheduleJob)).collect(Collectors.toList());
scheduleJobOperatorRecordService.saveBatch(jobOperatorRecordList);
}
// 更新未提交到yarn实例状态
if (CollectionUtils.isNotEmpty(unSubmitJobList)) {
cancellingJob(scheduleJobService.lambdaUpdate().in(ScheduleJob::getJobId, unSubmitJobList));
}
return scheduleJobList.size();
}
use of com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord in project Taier by DTStack.
the class FailoverStrategy method updateBatchJobs.
private void updateBatchJobs(Map<String, List<String>> nodeJobs) {
for (Map.Entry<String, List<String>> nodeEntry : nodeJobs.entrySet()) {
if (nodeEntry.getValue().isEmpty()) {
continue;
}
// 更新实例
ScheduleJob scheduleJob = new ScheduleJob();
scheduleJob.setNodeAddress(nodeEntry.getKey());
scheduleJobService.lambdaUpdate().in(ScheduleJob::getJobId, nodeEntry.getValue()).update(scheduleJob);
// 更新jobOperatorRecord
ScheduleJobOperatorRecord scheduleJobOperatorRecord = new ScheduleJobOperatorRecord();
scheduleJobOperatorRecord.setNodeAddress(nodeEntry.getKey());
scheduleJobOperatorRecordService.lambdaUpdate().in(ScheduleJobOperatorRecord::getJobId, nodeEntry.getValue()).update(scheduleJobOperatorRecord);
LOGGER.info("jobIds:{} failover to address:{}", nodeEntry.getValue(), nodeEntry.getKey());
}
}
Aggregations