use of com.dtstack.taier.develop.dto.devlop.TaskResourceParam in project Taier by DTStack.
the class BatchCatalogueService method initTemplateCatalogue.
/**
* 初始化任务开发下的 模板目录 和 模板任务
* @param oneCatalogue
* @param tenantId
* @param userId
* @return
*/
private List<BatchCatalogue> initTemplateCatalogue(BatchCatalogue oneCatalogue, Long tenantId, Long userId) {
List<BatchCatalogue> templateCatalogueList = new ArrayList<>(TemplateCatalogue.getValues().size());
// 需要初始化的模板任务所在的目录
BatchCatalogue batchTempTaskCatalogue = new BatchCatalogue();
batchTempTaskCatalogue.setLevel(CatalogueLevel.OTHER.getLevel());
batchTempTaskCatalogue.setNodePid(oneCatalogue.getId());
batchTempTaskCatalogue.setTenantId(tenantId);
batchTempTaskCatalogue.setCreateUserId(userId);
List<TemplateCatalogue> templateTaskCatalogues = TemplateCatalogue.getValues();
HashMap<String, Long> idsMap = new HashMap<>();
for (TemplateCatalogue templateCatalogue : templateTaskCatalogues) {
// 相同目录只创建一次
if (!idsMap.containsKey(templateCatalogue.getValue())) {
batchTempTaskCatalogue.setNodeName(templateCatalogue.getValue());
batchTempTaskCatalogue.setId(0L);
batchTempTaskCatalogue.setCatalogueType(RdosBatchCatalogueTypeEnum.NORAML.getType());
addOrUpdate(batchTempTaskCatalogue);
idsMap.put(templateCatalogue.getValue(), batchTempTaskCatalogue.getId());
}
templateCatalogueList.add(batchTempTaskCatalogue);
try {
String content = batchTaskTemplateService.getContentByType(EScheduleJobType.SPARK_SQL.getVal(), templateCatalogue.getType());
// 初始化任务
TaskResourceParam batchTask = new TaskResourceParam();
batchTask.setName(templateCatalogue.getFileName());
batchTask.setTaskType(EScheduleJobType.SPARK_SQL.getVal());
batchTask.setNodePid(idsMap.get(templateCatalogue.getValue()));
batchTask.setComputeType(ComputeType.BATCH.getType());
batchTask.setLockVersion(0);
batchTask.setVersion(0);
batchTask.setTenantId(tenantId);
batchTask.setUserId(userId);
batchTask.setCreateUserId(userId);
batchTask.setModifyUserId(userId);
if (StringUtils.isEmpty(content)) {
throw new RdosDefineException(ErrorCode.TEMPLATE_TASK_CONTENT_NOT_NULL);
}
batchTask.setSqlText(content);
// 添加init脚本中带有的任务参数
List<Map> taskVariables = new ArrayList<>();
Map<String, String> variable = new HashMap<>(3);
variable.put("paramCommand", PARAM_COMMAND);
variable.put("paramName", PARAM_NAME);
variable.put("type", TYPE4SYSTEM);
taskVariables.add(variable);
batchTask.setTaskVariables(taskVariables);
// SparkSQL任务支持多版本运行,添加默认的组件版本
List<BatchTaskGetComponentVersionResultVO> hadoopVersions = batchTaskService.getComponentVersionByTaskType(tenantId, EScheduleJobType.SPARK_SQL.getVal());
if (CollectionUtils.isNotEmpty(hadoopVersions)) {
batchTask.setComponentVersion(hadoopVersions.get(0).getComponentVersion());
}
batchTaskService.addOrUpdateTask(batchTask);
} catch (Exception e) {
LOGGER.error(ErrorCode.CATALOGUE_INIT_FAILED.getDescription(), e);
throw new RdosDefineException(ErrorCode.CATALOGUE_INIT_FAILED);
}
}
return templateCatalogueList;
}
Aggregations