Search in sources :

Example 21 with JobClient

use of com.dtstack.taier.pluginapi.JobClient in project Taier by DTStack.

the class JobDealer method addSubmitJobVast.

/**
 * job cache 表已经存在
 * @param jobClients
 */
private void addSubmitJobVast(List<JobClient> jobClients) {
    List<String> jobIds = jobClients.stream().map(JobClient::getJobId).collect(Collectors.toList());
    updateCacheBatch(jobIds, EJobCacheStage.DB.getStage());
    scheduleJobService.updateJobStatusByJobIds(jobIds, TaskStatus.WAITENGINE.getStatus(), null);
    LOGGER.info(" addSubmitJobBatch jobId:{} update", JSONObject.toJSONString(jobIds));
    for (JobClient jobClient : jobClients) {
        jobClient.setCallBack((jobStatus) -> {
            updateJobStatus(jobClient.getJobId(), jobStatus);
        });
        // 加入节点的优先级队列
        this.addGroupPriorityQueue(jobComputeResourcePlain.getJobResource(jobClient), jobClient, true, false);
    }
}
Also used : JobClient(com.dtstack.taier.pluginapi.JobClient)

Example 22 with JobClient

use of com.dtstack.taier.pluginapi.JobClient in project Taier by DTStack.

the class JobStopDealer method stopJob.

private StoppedStatus stopJob(JobElement jobElement) throws Exception {
    ScheduleEngineJobCache jobCache = engineJobCacheService.getByJobId(jobElement.jobId);
    ScheduleJob scheduleJob = scheduleJobService.lambdaQuery().eq(ScheduleJob::getJobId, jobElement.jobId).eq(ScheduleJob::getIsDeleted, Deleted.NORMAL.getStatus()).one();
    if (jobCache == null) {
        if (scheduleJob != null && TaskStatus.isStopped(scheduleJob.getStatus())) {
            LOGGER.info("jobId:{} stopped success, set job is STOPPED.", jobElement.jobId);
            return StoppedStatus.STOPPED;
        } else {
            this.removeMemStatusAndJobCache(jobElement.jobId);
            LOGGER.info("jobId:{} jobCache is null, set job is MISSED.", jobElement.jobId);
            return StoppedStatus.MISSED;
        }
    } else if (null != scheduleJob && EJobCacheStage.unSubmitted().contains(jobCache.getStage())) {
        if (!TaskStatus.getWaitStatus().contains(scheduleJob.getStatus()) || EJobCacheStage.PRIORITY.getStage() != jobCache.getStage()) {
            this.removeMemStatusAndJobCache(jobCache.getJobId());
            LOGGER.info("jobId:{} is unsubmitted, set job is STOPPED.", jobElement.jobId);
            return StoppedStatus.STOPPED;
        } else {
            // 任务如果处于提交的状态过程中 但是stage由PRIORITY变更为SUBMITTED  直接删除会导致还是会提交到yarn上 占用资源
            LOGGER.info("jobId:{} is stopping.", jobCache.getJobId());
            return StoppedStatus.STOPPING;
        }
    } else {
        if (scheduleJob == null) {
            this.removeMemStatusAndJobCache(jobElement.jobId);
            LOGGER.info("jobId:{} scheduleJob is null, set job is MISSED.", jobElement.jobId);
            return StoppedStatus.MISSED;
        } else if (TaskStatus.getStoppedAndNotFound().contains(scheduleJob.getStatus())) {
            this.removeMemStatusAndJobCache(jobElement.jobId);
            LOGGER.info("jobId:{} and status:{} is StoppedAndNotFound, set job is STOPPED.", jobElement.jobId, scheduleJob.getStatus());
            return StoppedStatus.STOPPED;
        }
        ParamAction paramAction = PublicUtil.jsonStrToObject(jobCache.getJobInfo(), ParamAction.class);
        paramAction.setEngineTaskId(scheduleJob.getEngineJobId());
        paramAction.setApplicationId(scheduleJob.getApplicationId());
        JobClient jobClient = new JobClient(paramAction);
        jobClient.setForceCancel(jobElement.isForceCancel);
        if (StringUtils.isNotBlank(scheduleJob.getEngineJobId()) && !jobClient.getEngineTaskId().equals(scheduleJob.getEngineJobId())) {
            this.removeMemStatusAndJobCache(jobElement.jobId);
            LOGGER.info("jobId:{} stopped success, because of [difference engineJobId].", paramAction.getJobId());
            return StoppedStatus.STOPPED;
        }
        JobResult jobResult = workerOperator.stopJob(jobClient);
        if (jobResult.getCheckRetry()) {
            LOGGER.info("jobId:{} is retry.", paramAction.getJobId());
            return StoppedStatus.RETRY;
        } else {
            LOGGER.info("jobId:{} is stopping.", paramAction.getJobId());
            return StoppedStatus.STOPPING;
        }
    }
}
Also used : ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) ParamAction(com.dtstack.taier.pluginapi.pojo.ParamAction) JobResult(com.dtstack.taier.pluginapi.pojo.JobResult) JobClient(com.dtstack.taier.pluginapi.JobClient) ScheduleEngineJobCache(com.dtstack.taier.dao.domain.ScheduleEngineJobCache)

Example 23 with JobClient

use of com.dtstack.taier.pluginapi.JobClient in project Taier by DTStack.

the class JobSubmitDealer method run.

@Override
public void run() {
    while (true) {
        try {
            JobClient jobClient = queue.take();
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("jobId:{} jobResource:{} queue size:{} take job from priorityQueue.", jobClient.getJobId(), jobResource, queue.size());
            }
            if (checkIsFinished(jobClient)) {
                continue;
            }
            if (checkJobSubmitExpired(jobClient)) {
                shardCache.updateLocalMemTaskStatus(jobClient.getJobId(), TaskStatus.AUTOCANCELED.getStatus());
                jobClient.doStatusCallBack(TaskStatus.AUTOCANCELED.getStatus());
                engineJobCacheService.deleteByJobId(jobClient.getJobId());
                LOGGER.info("jobId:{} checkJobSubmitExpired is true, job ignore to submit.", jobClient.getJobId());
                continue;
            }
            if (!checkMaxPriority(jobResource)) {
                LOGGER.info("jobId:{} checkMaxPriority is false, wait other node job which priority higher.", jobClient.getJobId());
                queue.put(jobClient);
                Thread.sleep(jobLackingInterval);
                continue;
            }
            // 提交任务
            jobSubmitConcurrentService.submit(() -> {
                submitJob(jobClient);
            });
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    }
}
Also used : JobClient(com.dtstack.taier.pluginapi.JobClient) WorkerAccessException(com.dtstack.taier.common.exception.WorkerAccessException) ClientArgumentException(com.dtstack.taier.pluginapi.exception.ClientArgumentException) ClientAccessException(com.dtstack.taier.common.exception.ClientAccessException) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 24 with JobClient

use of com.dtstack.taier.pluginapi.JobClient in project Taier by DTStack.

the class JobSubmittedDealer method run.

@Override
public void run() {
    while (true) {
        JobClient jobClient = null;
        try {
            jobClient = queue.take();
            if (jobRestartDealer.checkAndRestartForSubmitResult(jobClient)) {
                LOGGER.warn("failed submit job restarting, jobId:{} jobResult:{} ...", jobClient.getJobId(), jobClient.getJobResult());
                continue;
            }
            LOGGER.info("success submit job to Engine, jobId:{} jobResult:{} ...", jobClient.getJobId(), jobClient.getJobResult());
            // 存储执行日志
            if (StringUtils.isNotBlank(jobClient.getEngineTaskId()) || StringUtils.isNotBlank(jobClient.getApplicationId())) {
                JobResult jobResult = jobClient.getJobResult();
                String appId = jobResult.getData(JobResult.JOB_ID_KEY);
                JSONObject jobExtraInfo = jobResult.getExtraInfoJson();
                jobExtraInfo.put(JobResultConstant.JOB_GRAPH, JobGraphUtil.formatJSON(appId, jobExtraInfo.getString(JobResultConstant.JOB_GRAPH), jobClient.getComputeType()));
                scheduleJobService.updateJobSubmitSuccess(jobClient.getJobId(), jobClient.getEngineTaskId(), appId);
                jobDealer.updateCache(jobClient, EJobCacheStage.SUBMITTED.getStage());
                jobClient.doStatusCallBack(TaskStatus.SUBMITTED.getStatus());
                JobClient finalJobClient = jobClient;
                shardCache.updateLocalMemTaskStatus(jobClient.getJobId(), TaskStatus.SUBMITTED.getStatus(), (jobId) -> {
                    LOGGER.warn("success submit job to Engine, jobId:{} jobResult:{} but shareManager is not found ...", jobId, finalJobClient.getJobResult());
                    finalJobClient.doStatusCallBack(TaskStatus.CANCELED.getStatus());
                });
            } else {
                jobClientFail(jobClient.getJobId(), jobClient.getJobResult().getJsonStr());
            }
        } catch (Throwable e) {
            LOGGER.error("jobId submitted {} jobStatus dealer run error", null == jobClient ? "" : jobClient.getJobId(), e);
            if (null != jobClient) {
                jobClientFail(jobClient.getJobId(), JobResult.createErrorResult(e).getJsonStr());
            }
        }
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JobResult(com.dtstack.taier.pluginapi.pojo.JobResult) JobClient(com.dtstack.taier.pluginapi.JobClient)

Example 25 with JobClient

use of com.dtstack.taier.pluginapi.JobClient in project Taier by DTStack.

the class LogAspect method afterReturningAdvice.

@AfterReturning(pointcut = "execution(public * com.dtstack.taier.scheduler.WorkerOperator.*(..))", returning = "ret")
public void afterReturningAdvice(JoinPoint joinPoint, Object ret) {
    try {
        String methodName = joinPoint.getSignature().getName();
        if (filterMethod.contains(methodName)) {
            return;
        }
        String argsString = null;
        Object[] args = joinPoint.getArgs();
        Optional<Object> jobClientOpt = Arrays.stream(args).filter(a -> a instanceof JobClient).findFirst();
        if (jobClientOpt.isPresent()) {
            if (logPluginInfoMethod.contains(methodName)) {
                argsString = JSONObject.toJSONString(jobClientOpt.get(), submitPropertyFilter);
            } else {
                // 忽略pluginInfo打印
                argsString = JSONObject.toJSONString(jobClientOpt.get(), propertyFilter);
            }
        } else {
            if (skipChangeMethod.contains(methodName)) {
                if (ret instanceof TaskStatus && (TaskStatus.RUNNING.equals(ret) || TaskStatus.SCHEDULED.equals(ret))) {
                    // 状态获取 多以running 为主 过滤频繁打印
                    return;
                }
            } else {
                argsString = JSONObject.toJSONString(args);
            }
        }
        if (LOGGER.isInfoEnabled()) {
            JSONObject logInfo = new JSONObject(3);
            logInfo.put("method", joinPoint.getSignature().getDeclaringTypeName() + "." + methodName);
            logInfo.put("args", argsString);
            logInfo.put("return", JSONObject.toJSONString(ret));
            LOGGER.info(logInfo.toJSONString());
        }
    } catch (Exception e) {
        LOGGER.error("logAspect error ", e);
    }
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) PropertyFilter(com.alibaba.fastjson.serializer.PropertyFilter) LoggerFactory(org.slf4j.LoggerFactory) AfterReturning(org.aspectj.lang.annotation.AfterReturning) ArrayList(java.util.ArrayList) JobClient(com.dtstack.taier.pluginapi.JobClient) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) Aspect(org.aspectj.lang.annotation.Aspect) Optional(java.util.Optional) JSONObject(com.alibaba.fastjson.JSONObject) JoinPoint(org.aspectj.lang.JoinPoint) TaskStatus(com.dtstack.taier.pluginapi.enums.TaskStatus) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) TaskStatus(com.dtstack.taier.pluginapi.enums.TaskStatus) JobClient(com.dtstack.taier.pluginapi.JobClient) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Aggregations

JobClient (com.dtstack.taier.pluginapi.JobClient)28 ParamAction (com.dtstack.taier.pluginapi.pojo.ParamAction)14 Test (org.junit.Test)6 PluginDefineException (com.dtstack.taier.pluginapi.exception.PluginDefineException)5 JobResult (com.dtstack.taier.pluginapi.pojo.JobResult)5 IOException (java.io.IOException)5 JarFileInfo (com.dtstack.taier.pluginapi.JarFileInfo)4 JobIdentifier (com.dtstack.taier.pluginapi.JobIdentifier)4 ClusterResource (com.dtstack.taier.pluginapi.pojo.ClusterResource)4 Properties (java.util.Properties)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 JSONObject (com.alibaba.fastjson.JSONObject)3 KerberosUtils (com.dtstack.taier.base.util.KerberosUtils)3 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 ScheduleEngineJobCache (com.dtstack.taier.dao.domain.ScheduleEngineJobCache)3 FlinkConfig (com.dtstack.taier.flink.FlinkConfig)3 EJobType (com.dtstack.taier.pluginapi.enums.EJobType)3 JudgeResult (com.dtstack.taier.pluginapi.pojo.JudgeResult)3 File (java.io.File)3