Search in sources :

Example 1 with Deleted

use of com.dtstack.taier.common.enums.Deleted in project Taier by DTStack.

the class AbstractJobScanningScheduler method scanningJob.

/**
 * 扫描实例
 */
private void scanningJob() {
    try {
        String nodeAddress = zkService.getLocalAddress();
        // 1. 获得节点信息
        if (StringUtils.isBlank(nodeAddress)) {
            return;
        }
        LOGGER.info("scanningJob start scheduleType : {} nodeAddress:{}", getSchedulerName(), nodeAddress);
        // 2. 获得排序最小序号
        Long minSort = getMinSort();
        LOGGER.info("scanning start param: scheduleType {} nodeAddress {} minSort {} ", getSchedulerName(), nodeAddress, minSort);
        // 3. 扫描实例
        List<ScheduleJobDetails> scheduleJobDetails = listExecJob(minSort, nodeAddress, Boolean.TRUE);
        while (CollectionUtils.isNotEmpty(scheduleJobDetails)) {
            // 查询任务
            List<Long> taskIds = scheduleJobDetails.stream().map(ScheduleJobDetails::getScheduleJob).map(ScheduleJob::getTaskId).collect(Collectors.toList());
            Map<Long, ScheduleTaskShade> scheduleTaskShadeMap = scheduleTaskService.lambdaQuery().in(ScheduleTaskShade::getTaskId, taskIds).eq(ScheduleTaskShade::getIsDeleted, Deleted.NORMAL.getStatus()).list().stream().collect(Collectors.toMap(ScheduleTaskShade::getTaskId, g -> (g)));
            for (ScheduleJobDetails scheduleJobDetail : scheduleJobDetails) {
                // 提交实例
                ScheduleJob scheduleJob = scheduleJobDetail.getScheduleJob();
                ScheduleTaskShade scheduleTaskShade = scheduleTaskShadeMap.get(scheduleJob.getTaskId());
                if (scheduleTaskShade == null) {
                    String errMsg = JobCheckStatus.NO_TASK.getMsg();
                    scheduleJobService.updateStatusAndLogInfoById(scheduleJob.getJobId(), TaskStatus.SUBMITFAILD.getStatus(), errMsg);
                    LOGGER.warn("jobId:{} scheduleType:{} submit failed for taskId:{} already deleted.", scheduleJob.getJobId(), getSchedulerName(), scheduleJob.getTaskId());
                    continue;
                }
                scheduleJobDetail.setScheduleTaskShade(scheduleTaskShade);
                if (isSubmitJob(scheduleJobDetail)) {
                    submitJob(scheduleJobDetail);
                }
                if (minSort < scheduleJob.getJobExecuteOrder()) {
                    minSort = scheduleJob.getJobExecuteOrder();
                }
            }
            scheduleJobDetails = listExecJob(minSort, nodeAddress, Boolean.FALSE);
        }
    } catch (Exception e) {
        LOGGER.error("scheduleType:{} emitJob2Queue error:", getSchedulerName(), e);
    }
}
Also used : ScheduleJobDetails(com.dtstack.taier.scheduler.server.ScheduleJobDetails) ScheduleJobService(com.dtstack.taier.scheduler.service.ScheduleJobService) JobCheckStatus(com.dtstack.taier.common.enums.JobCheckStatus) 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) StringUtils(org.apache.commons.lang3.StringUtils) JobCheckRunInfo(com.dtstack.taier.scheduler.server.scheduler.exec.JobCheckRunInfo) InitializingBean(org.springframework.beans.factory.InitializingBean) CustomThreadFactory(com.dtstack.taier.pluginapi.CustomThreadFactory) ZkService(com.dtstack.taier.scheduler.zookeeper.ZkService) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TaskStatus(com.dtstack.taier.pluginapi.enums.TaskStatus) ScheduleTaskShade(com.dtstack.taier.dao.domain.ScheduleTaskShade) Logger(org.slf4j.Logger) ScheduleTaskShadeService(com.dtstack.taier.scheduler.service.ScheduleTaskShadeService) JudgeJobExecOperator(com.dtstack.taier.scheduler.server.scheduler.exec.JudgeJobExecOperator) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) JudgeNoPassJobHandler(com.dtstack.taier.scheduler.server.scheduler.handler.JudgeNoPassJobHandler) List(java.util.List) ScheduleJobDetails(com.dtstack.taier.scheduler.server.ScheduleJobDetails) Deleted(com.dtstack.taier.common.enums.Deleted) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) ScheduleTaskShade(com.dtstack.taier.dao.domain.ScheduleTaskShade)

Aggregations

Deleted (com.dtstack.taier.common.enums.Deleted)1 JobCheckStatus (com.dtstack.taier.common.enums.JobCheckStatus)1 EnvironmentContext (com.dtstack.taier.common.env.EnvironmentContext)1 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)1 ScheduleTaskShade (com.dtstack.taier.dao.domain.ScheduleTaskShade)1 CustomThreadFactory (com.dtstack.taier.pluginapi.CustomThreadFactory)1 TaskStatus (com.dtstack.taier.pluginapi.enums.TaskStatus)1 ScheduleJobDetails (com.dtstack.taier.scheduler.server.ScheduleJobDetails)1 JobCheckRunInfo (com.dtstack.taier.scheduler.server.scheduler.exec.JobCheckRunInfo)1 JudgeJobExecOperator (com.dtstack.taier.scheduler.server.scheduler.exec.JudgeJobExecOperator)1 JudgeNoPassJobHandler (com.dtstack.taier.scheduler.server.scheduler.handler.JudgeNoPassJobHandler)1 ScheduleJobService (com.dtstack.taier.scheduler.service.ScheduleJobService)1 ScheduleTaskShadeService (com.dtstack.taier.scheduler.service.ScheduleTaskShadeService)1 ZkService (com.dtstack.taier.scheduler.zookeeper.ZkService)1 List (java.util.List)1 Map (java.util.Map)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1