Search in sources :

Example 6 with ScheduleJobOperatorRecord

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();
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) ScheduleJobService(com.dtstack.taier.scheduler.service.ScheduleJobService) LambdaUpdateChainWrapper(com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper) ShardCache(com.dtstack.taier.scheduler.jobdealer.cache.ShardCache) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) LoggerFactory(org.slf4j.LoggerFactory) EnvironmentContext(com.dtstack.taier.common.env.EnvironmentContext) Autowired(org.springframework.beans.factory.annotation.Autowired) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) StoppedJob(com.dtstack.taier.scheduler.jobdealer.bo.StoppedJob) CustomThreadRunsPolicy(com.dtstack.taier.common.CustomThreadRunsPolicy) EngineJobCacheService(com.dtstack.taier.scheduler.service.EngineJobCacheService) InitializingBean(org.springframework.beans.factory.InitializingBean) CustomThreadFactory(com.dtstack.taier.pluginapi.CustomThreadFactory) ParamAction(com.dtstack.taier.pluginapi.pojo.ParamAction) com.dtstack.taier.common.enums(com.dtstack.taier.common.enums) Lists(com.google.common.collect.Lists) CollectionUtils(org.apache.commons.collections.CollectionUtils) ScheduleEngineJobCache(com.dtstack.taier.dao.domain.ScheduleEngineJobCache) TaskStatus(com.dtstack.taier.pluginapi.enums.TaskStatus) Logger(org.slf4j.Logger) ScheduleJobOperatorRecord(com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord) java.util.concurrent(java.util.concurrent) Timestamp(java.sql.Timestamp) ScheduleJobOperatorRecordService(com.dtstack.taier.scheduler.service.ScheduleJobOperatorRecordService) Collectors(java.util.stream.Collectors) JobClient(com.dtstack.taier.pluginapi.JobClient) PublicUtil(com.dtstack.taier.pluginapi.util.PublicUtil) Component(org.springframework.stereotype.Component) JobResult(com.dtstack.taier.pluginapi.pojo.JobResult) DisposableBean(org.springframework.beans.factory.DisposableBean) WorkerOperator(com.dtstack.taier.scheduler.WorkerOperator) DelayBlockingQueue(com.dtstack.taier.common.queue.DelayBlockingQueue) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ScheduleJobOperatorRecord(com.dtstack.taier.dao.domain.ScheduleJobOperatorRecord)

Example 7 with ScheduleJobOperatorRecord

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());
    }
}
Also used : ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) 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