Search in sources :

Example 1 with BatchParamDTO

use of com.dtstack.taier.develop.dto.devlop.BatchParamDTO 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 2 with BatchParamDTO

use of com.dtstack.taier.develop.dto.devlop.BatchParamDTO in project Taier by DTStack.

the class BatchTaskParamService method buildBatchTaskParams.

public List<BatchTaskParam> buildBatchTaskParams(final long taskId, final List<BatchParamDTO> batchParamDTOS) {
    final List<BatchTaskParam> saves = new ArrayList<>(batchParamDTOS.size());
    for (final BatchParamDTO tmp : batchParamDTOS) {
        if (StringUtils.isBlank(tmp.getParamCommand())) {
            throw new RdosDefineException("自定义参数赋值不能为空");
        }
        BatchTaskParam batchTaskParam = new BatchTaskParam();
        batchTaskParam.setTaskId(taskId);
        batchTaskParam.setType(tmp.getType());
        batchTaskParam.setParamName(tmp.getParamName());
        batchTaskParam.setParamCommand(tmp.getParamCommand());
        saves.add(this.addOrUpdate(batchTaskParam));
    }
    return saves;
}
Also used : BatchParamDTO(com.dtstack.taier.develop.dto.devlop.BatchParamDTO) BatchTaskParam(com.dtstack.taier.dao.domain.BatchTaskParam) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ArrayList(java.util.ArrayList)

Example 3 with BatchParamDTO

use of com.dtstack.taier.develop.dto.devlop.BatchParamDTO in project Taier by DTStack.

the class BatchTaskParamService method paramResolver.

/**
 * 转换SQL任务中的 自定义参数 和 系统参数 为参数对象
 * @param taskVariables
 * @return
 */
public List<BatchParamDTO> paramResolver(final List<Map> taskVariables) {
    if (CollectionUtils.isEmpty(taskVariables)) {
        return Collections.emptyList();
    }
    final List<BatchParamDTO> parameters = new ArrayList<>(taskVariables.size());
    for (Map<String, Object> var : taskVariables) {
        final BatchParamDTO batchParamDTO = new BatchParamDTO(MathUtil.getIntegerVal(var.get("type")), MathUtil.getString(var.get("paramName")), MathUtil.getString(var.get("paramCommand")));
        parameters.add(batchParamDTO);
    }
    return parameters;
}
Also used : BatchParamDTO(com.dtstack.taier.develop.dto.devlop.BatchParamDTO) ArrayList(java.util.ArrayList) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

BatchParamDTO (com.dtstack.taier.develop.dto.devlop.BatchParamDTO)3 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)2 ArrayList (java.util.ArrayList)2 JSONObject (com.alibaba.fastjson.JSONObject)1 BatchTaskParam (com.dtstack.taier.dao.domain.BatchTaskParam)1 ExecuteResultVO (com.dtstack.taier.develop.dto.devlop.ExecuteResultVO)1 IBatchJobExeService (com.dtstack.taier.develop.service.develop.IBatchJobExeService)1 ParamActionExt (com.dtstack.taier.scheduler.impl.pojo.ParamActionExt)1 ParamTaskAction (com.dtstack.taier.scheduler.impl.pojo.ParamTaskAction)1