use of com.dtstack.taier.scheduler.impl.pojo.ParamTaskAction in project Taier by DTStack.
the class BatchJobService method getParamTaskAction.
/**
* 初始化engine paramActionExt 入参
* @param batchTask
* @param userId
* @param taskParamsToReplace 需要替换的 系统参数和自定义参数
* @return
* @throws Exception
*/
private ParamTaskAction getParamTaskAction(BatchTask batchTask, Long userId, List<BatchTaskParamShade> taskParamsToReplace) throws Exception {
ParamTaskAction paramTaskAction = new ParamTaskAction();
// 将 BatchTask 对象转换为调度的 ScheduleTaskShade 对象
ScheduleTaskShade scheduleTaskShade = new ScheduleTaskShade();
BeanUtils.copyProperties(batchTask, scheduleTaskShade);
scheduleTaskShade.setTaskId(batchTask.getId());
scheduleTaskShade.setTaskType(batchTask.getTaskType());
// 构建运行任务的完整命令(包含真正执行的SQL内容)
String extraInfo = getExtraInfo(batchTask, userId, taskParamsToReplace);
JSONObject jsonObject = JSON.parseObject(extraInfo);
if (jsonObject.containsKey("sqlText")) {
jsonObject.put("sqlText", batchTask.getSqlText());
}
extraInfo = jsonObject.toJSONString();
scheduleTaskShade.setExtraInfo(extraInfo);
paramTaskAction.setBatchTask(scheduleTaskShade);
return paramTaskAction;
}
use of com.dtstack.taier.scheduler.impl.pojo.ParamTaskAction 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;
}
use of com.dtstack.taier.scheduler.impl.pojo.ParamTaskAction 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;
}
Aggregations