Search in sources :

Example 1 with IBatchJobExeService

use of com.dtstack.taier.develop.service.develop.IBatchJobExeService in project Taier by DTStack.

the class BatchJobService method startSyncImmediately.

/**
 * 运行同步任务
 *
 * @return
 */
public BatchStartSyncResultVO startSyncImmediately(Long taskId, Long userId, Boolean isRoot, Long tenantId) {
    BatchStartSyncResultVO batchStartSyncResultVO = new BatchStartSyncResultVO();
    batchStartSyncResultVO.setMsg(null);
    batchStartSyncResultVO.setJobId(null);
    batchStartSyncResultVO.setStatus(TaskStatus.SUBMITTING.getStatus());
    BatchTask batchTask = batchTaskService.getOneWithError(taskId);
    if (!batchTask.getTaskType().equals(EScheduleJobType.SYNC.getVal())) {
        throw new RdosDefineException("只支持同步任务直接运行");
    }
    try {
        IBatchJobExeService batchJobExeService = this.multiEngineServiceFactory.getBatchJobExeService(EScheduleJobType.SYNC.getType());
        Map<String, Object> actionParam = batchJobExeService.readyForSyncImmediatelyJob(batchTask, tenantId, isRoot);
        String extraInfo = JSON.toJSONString(actionParam);
        ParamTaskAction paramTaskAction = new ParamTaskAction();
        ScheduleTaskShade scheduleTaskShade = JSON.parseObject(extraInfo, ScheduleTaskShade.class);
        scheduleTaskShade.setExtraInfo(extraInfo);
        scheduleTaskShade.setTaskId(batchTask.getId());
        scheduleTaskShade.setScheduleConf(batchTask.getScheduleConf());
        scheduleTaskShade.setComponentVersion(batchTask.getComponentVersion());
        paramTaskAction.setBatchTask(scheduleTaskShade);
        ParamActionExt paramActionExt = actionService.paramActionExt(paramTaskAction.getBatchTask(), paramTaskAction.getJobId(), paramTaskAction.getFlowJobId());
        String jobId = paramActionExt.getJobId();
        actionService.start(paramActionExt);
        String name = MathUtil.getString(actionParam.get("name"));
        String job = MathUtil.getString(actionParam.get("job"));
        batchSelectSqlService.addSelectSql(jobId, name, TempJobType.SYNC_TASK.getType(), batchTask.getTenantId(), job, userId, EScheduleJobType.SPARK_SQL.getType());
        batchStartSyncResultVO.setMsg(String.format("任务提交成功,名称为: %s", name));
        batchStartSyncResultVO.setJobId(jobId);
        batchStartSyncResultVO.setStatus(TaskStatus.SUBMITTING.getStatus());
    } catch (Exception e) {
        LOGGER.warn("startSyncImmediately-->", e);
        batchStartSyncResultVO.setMsg(e.getMessage());
        batchStartSyncResultVO.setStatus(TaskStatus.SUBMITFAILD.getStatus());
    }
    return batchStartSyncResultVO;
}
Also used : BatchStartSyncResultVO(com.dtstack.taier.develop.vo.develop.result.BatchStartSyncResultVO) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ParamTaskAction(com.dtstack.taier.scheduler.impl.pojo.ParamTaskAction) JSONObject(com.alibaba.fastjson.JSONObject) IBatchJobExeService(com.dtstack.taier.develop.service.develop.IBatchJobExeService) ParamActionExt(com.dtstack.taier.scheduler.impl.pojo.ParamActionExt) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 2 with IBatchJobExeService

use of com.dtstack.taier.develop.service.develop.IBatchJobExeService in project Taier by DTStack.

the class BatchJobService method startSqlImmediately.

/**
 * 运行SQL任务
 * @param userId
 * @param tenantId
 * @param taskId
 * @param uniqueKey
 * @param sql
 * @param taskVariables
 * @param dtToken
 * @param isCheckDDL
 * @param isRoot
 * @param isEnd         是否是当前session最后一条sql
 * @return
 */
public ExecuteResultVO startSqlImmediately(Long userId, Long tenantId, Long taskId, String uniqueKey, String sql, List<Map> taskVariables, String dtToken, Integer isCheckDDL, Boolean isRoot, Boolean isEnd) {
    final User user = userService.getById(userId);
    dtToken = String.format("%s;dt_user_id=%s;dt_username=%s;", dtToken, user.getId(), user.getUserName());
    ExecuteResultVO result = new ExecuteResultVO();
    try {
        final BatchTask task = batchTaskService.getOneWithError(taskId);
        result.setTaskType(task.getTaskType());
        // 真正运行的SQL是页面传入的SQL
        task.setSqlText(sql);
        // 将SQL中的 系统参数和自定义参数 转换为DTO对象
        List<BatchParamDTO> batchParamDTOS = this.batchTaskParamService.paramResolver(taskVariables);
        final List<BatchTaskParam> params = this.batchTaskParamService.convertParam(batchParamDTOS);
        List<BatchTaskParamShade> taskParamsToReplace = this.batchTaskParamService.convertShade(params);
        ParamTaskAction paramTaskAction = getParamTaskAction(task, userId, taskParamsToReplace);
        ParamActionExt paramActionExt = actionService.paramActionExt(paramTaskAction.getBatchTask(), paramTaskAction.getJobId(), paramTaskAction.getFlowJobId());
        sql = paramActionExt.getSqlText();
        String jobId = paramActionExt.getJobId();
        task.setTaskParams(paramActionExt.getTaskParams());
        IBatchJobExeService batchJobService = this.multiEngineServiceFactory.getBatchJobExeService(task.getTaskType());
        result = batchJobService.startSqlImmediately(userId, tenantId, uniqueKey, taskId, sql, isRoot, task, dtToken, isEnd, jobId);
    } catch (Exception e) {
        LOGGER.warn("startSqlImmediately-->", e);
        result.setMsg(e.getMessage());
        result.setStatus(TaskStatus.FAILED.getStatus());
        result.setSqlText(sql);
        return result;
    }
    return result;
}
Also used : ParamTaskAction(com.dtstack.taier.scheduler.impl.pojo.ParamTaskAction) ExecuteResultVO(com.dtstack.taier.develop.dto.devlop.ExecuteResultVO) IBatchJobExeService(com.dtstack.taier.develop.service.develop.IBatchJobExeService) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) BatchParamDTO(com.dtstack.taier.develop.dto.devlop.BatchParamDTO) ParamActionExt(com.dtstack.taier.scheduler.impl.pojo.ParamActionExt)

Example 3 with IBatchJobExeService

use of com.dtstack.taier.develop.service.develop.IBatchJobExeService in project Taier by DTStack.

the class BatchJobService method getExtraInfo.

/**
 * 构建运行任务的完整命令(包含真正执行的SQL内容)
 * @param batchTask
 * @param userId
 * @param taskParamsToReplace SQL中需要匹配和替换的 系统参数与自定义参数
 * @return info信息
 * @throws Exception
 */
public String getExtraInfo(BatchTask batchTask, Long userId, List<BatchTaskParamShade> taskParamsToReplace) throws Exception {
    // 任务参数若为null,则表示是提交任务,否则就是临时运行任务
    if (taskParamsToReplace == null) {
        taskParamsToReplace = this.batchTaskParamShadeService.getTaskParam(batchTask.getId());
    }
    IBatchJobExeService jobExecuteService = this.multiEngineServiceFactory.getBatchJobExeService(batchTask.getTaskType());
    // 构建任务运行完整信息
    Map<String, Object> actionParam = Maps.newHashMap();
    // 构建 sqlText、taskParams,如果是数据同步任务,则根据id替换数据源
    jobExecuteService.readyForTaskStartTrigger(actionParam, batchTask.getTenantId(), batchTask, taskParamsToReplace);
    actionParam.put("taskId", batchTask.getId());
    actionParam.put("taskType", EScheduleJobType.getByTaskType(batchTask.getTaskType()).getEngineJobType());
    actionParam.put("name", batchTask.getName());
    actionParam.put("computeType", batchTask.getComputeType());
    actionParam.put("tenantId", batchTask.getTenantId());
    actionParam.put("isFailRetry", false);
    actionParam.put("maxRetryNum", 0);
    actionParam.put("taskParamsToReplace", JSON.toJSONString(taskParamsToReplace));
    User user;
    if (Objects.isNull(userId)) {
        user = userService.getById(batchTask.getCreateUserId());
    } else {
        user = userService.getById(userId);
    }
    if (Objects.isNull(user)) {
        throw new RdosDefineException(String.format("当前用户已被移除,userId:%d", userId == null ? batchTask.getCreateUserId() : userId));
    }
    actionParam.put("userId", user.getId());
    // 出错重试配置,兼容之前的任务,没有这个参数则默认重试
    JSONObject scheduleConf = JSON.parseObject(batchTask.getScheduleConf());
    if (scheduleConf.containsKey("isFailRetry")) {
        actionParam.put("isFailRetry", scheduleConf.getBooleanValue("isFailRetry"));
        if (scheduleConf.getBooleanValue("isFailRetry")) {
            int maxRetryNum = scheduleConf.getIntValue("maxRetryNum") == 0 ? 3 : scheduleConf.getIntValue("maxRetryNum");
            actionParam.put("maxRetryNum", maxRetryNum);
        } else {
            actionParam.put("maxRetryNum", 0);
        }
    }
    String extraInfo = objMapper.writeValueAsString(actionParam);
    extraInfo = extraInfo.replaceAll("\r\n", System.getProperty("line.separator"));
    return extraInfo;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) JSONObject(com.alibaba.fastjson.JSONObject) IBatchJobExeService(com.dtstack.taier.develop.service.develop.IBatchJobExeService)

Aggregations

RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 IBatchJobExeService (com.dtstack.taier.develop.service.develop.IBatchJobExeService)3 JSONObject (com.alibaba.fastjson.JSONObject)2 ParamActionExt (com.dtstack.taier.scheduler.impl.pojo.ParamActionExt)2 ParamTaskAction (com.dtstack.taier.scheduler.impl.pojo.ParamTaskAction)2 BatchParamDTO (com.dtstack.taier.develop.dto.devlop.BatchParamDTO)1 ExecuteResultVO (com.dtstack.taier.develop.dto.devlop.ExecuteResultVO)1 BatchStartSyncResultVO (com.dtstack.taier.develop.vo.develop.result.BatchStartSyncResultVO)1