Search in sources :

Example 1 with ScheduleEngineJobRetry

use of com.dtstack.taier.dao.domain.ScheduleEngineJobRetry in project Taier by DTStack.

the class ActionService method queryJobLog.

/**
 * 查看周期实例日志
 *
 * @param jobId    实例id
 * @param pageInfo 第几次重试日志
 * @return 日志信息
 */
public ReturnJobLogVO queryJobLog(String jobId, Integer pageInfo) {
    if (pageInfo == null) {
        pageInfo = 1;
    }
    // 查询周期实例
    ScheduleJob scheduleJob = jobService.lambdaQuery().eq(ScheduleJob::getJobId, jobId).eq(ScheduleJob::getIsDeleted, Deleted.NORMAL.getStatus()).one();
    if (scheduleJob == null) {
        throw new RdosDefineException("not find job,please contact the administrator");
    }
    // 取最新
    if (0 == pageInfo) {
        pageInfo = scheduleJob.getRetryNum();
    }
    ReturnJobLogVO jobLogVO = new ReturnJobLogVO();
    jobLogVO.setPageIndex(pageInfo);
    jobLogVO.setPageSize(scheduleJob.getRetryNum());
    // 如果RetryNum>1 说明实例已经进行了一次重试,所以取查询重试日志
    if (scheduleJob.getRetryNum() > 1) {
        // 查询重试日志
        ScheduleEngineJobRetry scheduleEngineJobRetry = jobRetryService.lambdaQuery().eq(ScheduleEngineJobRetry::getJobId, jobId).eq(ScheduleEngineJobRetry::getRetryNum, pageInfo).eq(ScheduleEngineJobRetry::getIsDeleted, Deleted.NORMAL.getStatus()).orderBy(true, false, ScheduleEngineJobRetry::getId).one();
        if (scheduleEngineJobRetry != null) {
            jobLogVO.setLogInfo(scheduleEngineJobRetry.getLogInfo());
            jobLogVO.setEngineLog(scheduleEngineJobRetry.getEngineLog());
        }
        jobLogVO.setPageIndex(pageInfo);
        jobLogVO.setPageSize(scheduleJob.getMaxRetryNum());
    } else {
        // 查询当前日志
        ScheduleJobExpand scheduleJobExpand = jobExpandService.lambdaQuery().eq(ScheduleJobExpand::getIsDeleted, Deleted.NORMAL.getStatus()).eq(ScheduleJobExpand::getJobId, jobId).one();
        if (scheduleJobExpand != null) {
            jobLogVO.setLogInfo(scheduleJobExpand.getLogInfo());
            jobLogVO.setEngineLog(scheduleJobExpand.getEngineLog());
        }
    }
    // 封装sql信息
    ScheduleTaskShade scheduleTaskShade = taskService.lambdaQuery().eq(ScheduleTaskShade::getTaskId, scheduleJob.getTaskId()).eq(ScheduleTaskShade::getIsDeleted, Deleted.NORMAL.getStatus()).one();
    if (null != scheduleTaskShade) {
        JSONObject shadeInfo = scheduleTaskShadeInfoService.getInfoJSON(scheduleTaskShade.getTaskId());
        String taskParams = shadeInfo.getString("taskParamsToReplace");
        List<ScheduleTaskParamShade> taskParamsToReplace = JSONObject.parseArray(taskParams, ScheduleTaskParamShade.class);
        String sqlText = scheduleTaskShade.getSqlText();
        if (EScheduleJobType.SYNC.getType().equals(scheduleTaskShade.getTaskType())) {
            sqlText = Base64Util.baseDecode(sqlText);
        }
        sqlText = JobParamReplace.paramReplace(sqlText, taskParamsToReplace, scheduleJob.getCycTime());
        jobLogVO.setSqlText(sqlText);
        Timestamp execStartTime = scheduleJob.getExecStartTime();
        Timestamp execEndTime = scheduleJob.getExecEndTime();
        if (EScheduleJobType.SYNC.getType().equals(scheduleTaskShade.getTaskType())) {
            String syncLog = null;
            try {
                syncLog = batchServerLogService.formatPerfLogInfo(scheduleJob.getEngineJobId(), scheduleJob.getJobId(), Optional.ofNullable(execStartTime).orElse(Timestamp.valueOf(LocalDateTime.now())).getTime(), Optional.ofNullable(execEndTime).orElse(Timestamp.valueOf(LocalDateTime.now())).getTime(), scheduleJob.getTenantId());
            } catch (Exception e) {
                LOGGER.error("queryJobLog {} sync log error", jobId, e);
            }
            jobLogVO.setSyncLog(syncLog);
        }
        if (EScheduleJobType.SPARK_SQL.getType().equals(scheduleTaskShade.getTaskType())) {
            jobLogVO.setDownLoadUrl(String.format(CommonConstant.DOWNLOAD_LOG, scheduleJob.getJobId(), scheduleJob.getTaskType(), scheduleJob.getTenantId()));
        }
    }
    return jobLogVO;
}
Also used : ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) ScheduleEngineJobRetry(com.dtstack.taier.dao.domain.ScheduleEngineJobRetry) JSONObject(com.alibaba.fastjson.JSONObject) ReturnJobLogVO(com.dtstack.taier.develop.vo.schedule.ReturnJobLogVO) ScheduleTaskParamShade(com.dtstack.taier.dao.dto.ScheduleTaskParamShade) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Timestamp(java.sql.Timestamp) ScheduleJobExpand(com.dtstack.taier.dao.domain.ScheduleJobExpand) ScheduleTaskShade(com.dtstack.taier.dao.domain.ScheduleTaskShade) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 2 with ScheduleEngineJobRetry

use of com.dtstack.taier.dao.domain.ScheduleEngineJobRetry in project Taier by DTStack.

the class ScheduleActionService method retryLog.

/**
 * 根据jobid 和 计算类型,查询job的重试retry日志
 */
public List<ActionRetryLogVO> retryLog(String jobId) {
    if (StringUtils.isBlank(jobId)) {
        throw new RdosDefineException("jobId is not allow null", ErrorCode.INVALID_PARAMETERS);
    }
    List<ActionRetryLogVO> logs = new ArrayList<>(5);
    List<ScheduleEngineJobRetry> jobRetries = engineJobRetryMapper.selectList(Wrappers.lambdaQuery(ScheduleEngineJobRetry.class).eq(ScheduleEngineJobRetry::getJobId, jobId).last(" limit 5"));
    if (CollectionUtils.isNotEmpty(jobRetries)) {
        jobRetries.forEach(jobRetry -> {
            ActionRetryLogVO vo = new ActionRetryLogVO();
            vo.setRetryNum(jobRetry.getRetryNum());
            vo.setLogInfo(jobRetry.getLogInfo());
            vo.setRetryTaskParams(jobRetry.getRetryTaskParams());
            logs.add(vo);
        });
    }
    return logs;
}
Also used : ScheduleEngineJobRetry(com.dtstack.taier.dao.domain.ScheduleEngineJobRetry) ActionRetryLogVO(com.dtstack.taier.scheduler.vo.action.ActionRetryLogVO) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 3 with ScheduleEngineJobRetry

use of com.dtstack.taier.dao.domain.ScheduleEngineJobRetry in project Taier by DTStack.

the class ScheduleActionService method retryLogDetail.

/**
 * 根据jobid 和 计算类型,查询job的重试retry日志
 */
public ActionRetryLogVO retryLogDetail(String jobId, Integer retryNum) {
    if (StringUtils.isBlank(jobId)) {
        throw new RdosDefineException("jobId  is not allow null", ErrorCode.INVALID_PARAMETERS);
    }
    if (retryNum == null || retryNum <= 0) {
        retryNum = 1;
    }
    ScheduleJob scheduleJob = scheduleJobService.getByJobId(jobId);
    // 数组库中存储的retryNum为0开始的索引位置
    ScheduleEngineJobRetry jobRetry = engineJobRetryMapper.selectOne(Wrappers.lambdaQuery(ScheduleEngineJobRetry.class).eq(ScheduleEngineJobRetry::getJobId, jobId).eq(ScheduleEngineJobRetry::getRetryNum, retryNum - 1));
    ActionRetryLogVO vo = new ActionRetryLogVO();
    if (jobRetry != null) {
        vo.setRetryNum(jobRetry.getRetryNum());
        vo.setLogInfo(jobRetry.getLogInfo());
        String engineLog = jobRetry.getEngineLog();
        if (StringUtils.isBlank(jobRetry.getEngineLog())) {
            engineLog = jobDealer.getAndUpdateEngineLog(jobId, jobRetry.getEngineJobId(), jobRetry.getApplicationId(), scheduleJob.getTenantId());
            if (engineLog != null) {
                LOGGER.info("engineJobRetryDao.updateEngineLog id:{}, jobId:{}, engineLog:{}", jobRetry.getId(), jobRetry.getJobId(), engineLog);
                jobRetry.setEngineLog(engineLog);
                engineJobRetryMapper.updateById(jobRetry);
            } else {
                engineLog = "";
            }
        }
        vo.setEngineLog(engineLog);
        vo.setRetryTaskParams(jobRetry.getRetryTaskParams());
    }
    return vo;
}
Also used : ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) ScheduleEngineJobRetry(com.dtstack.taier.dao.domain.ScheduleEngineJobRetry) ActionRetryLogVO(com.dtstack.taier.scheduler.vo.action.ActionRetryLogVO) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Aggregations

RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 ScheduleEngineJobRetry (com.dtstack.taier.dao.domain.ScheduleEngineJobRetry)3 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)2 ActionRetryLogVO (com.dtstack.taier.scheduler.vo.action.ActionRetryLogVO)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ScheduleJobExpand (com.dtstack.taier.dao.domain.ScheduleJobExpand)1 ScheduleTaskShade (com.dtstack.taier.dao.domain.ScheduleTaskShade)1 ScheduleTaskParamShade (com.dtstack.taier.dao.dto.ScheduleTaskParamShade)1 ReturnJobLogVO (com.dtstack.taier.develop.vo.schedule.ReturnJobLogVO)1 Timestamp (java.sql.Timestamp)1