Search in sources :

Example 1 with TaskResourceParam

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;
}
Also used : HashMap(java.util.HashMap) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) TemplateCatalogue(com.dtstack.taier.develop.enums.develop.TemplateCatalogue) ArrayList(java.util.ArrayList) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) TaskResourceParam(com.dtstack.taier.develop.dto.devlop.TaskResourceParam) BatchTaskGetComponentVersionResultVO(com.dtstack.taier.develop.vo.develop.result.BatchTaskGetComponentVersionResultVO) BatchCatalogue(com.dtstack.taier.dao.domain.BatchCatalogue) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)1 BatchCatalogue (com.dtstack.taier.dao.domain.BatchCatalogue)1 TaskResourceParam (com.dtstack.taier.develop.dto.devlop.TaskResourceParam)1 TemplateCatalogue (com.dtstack.taier.develop.enums.develop.TemplateCatalogue)1 BatchTaskGetComponentVersionResultVO (com.dtstack.taier.develop.vo.develop.result.BatchTaskGetComponentVersionResultVO)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1