Search in sources :

Example 46 with RdosDefineException

use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.

the class TenantController method bindingTenant.

@PostMapping(value = "/bindingTenant")
public R<Void> bindingTenant(@RequestBody ComponentBindTenantVO vo) throws Exception {
    Cluster cluster = clusterService.getCluster(vo.getClusterId());
    if (cluster == null) {
        throw new RdosDefineException(ErrorCode.CANT_NOT_FIND_CLUSTER);
    }
    if (CollectionUtils.isNotEmpty(vo.getBindDBList())) {
        for (ComponentBindDBVO bindDBVO : vo.getBindDBList()) {
            if (Objects.isNull(bindDBVO.getComponentCode())) {
                throw new RdosDefineException(String.format(ErrorCode.META_COMPONENT_NOT_EXISTS.getMsg(), EComponentType.SPARK_THRIFT.getName()));
            }
        }
    }
    tenantService.bindingTenant(vo.getTenantId(), vo.getClusterId(), vo.getQueueId(), cluster.getClusterName(), vo.getBindDBList());
    return R.empty();
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Cluster(com.dtstack.taier.dao.domain.Cluster) ComponentBindDBVO(com.dtstack.taier.develop.vo.console.ComponentBindDBVO) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 47 with RdosDefineException

use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.

the class UploadController method addOrUpdateComponent.

@PostMapping(value = "/component/addOrUpdateComponent")
public R<ComponentVO> addOrUpdateComponent(@RequestParam("resources1") List<MultipartFile> files1, @RequestParam("resources2") List<MultipartFile> files2, @RequestParam("clusterId") Long clusterId, @RequestParam(value = "componentConfig") String componentConfig, @RequestParam("versionName") @NotNull String versionName, @RequestParam("kerberosFileName") String kerberosFileName, @RequestParam("componentTemplate") String componentTemplate, @RequestParam("componentCode") Integer componentCode, @RequestParam("storeType") Integer storeType, @RequestParam("principals") String principals, @RequestParam("principal") String principal, @RequestParam(value = "isMetadata", defaultValue = "false") Boolean isMetadata, @RequestParam(value = "isDefault", defaultValue = "false") Boolean isDefault, @RequestParam(value = "deployType") Integer deployType) {
    List<Resource> resources = getResourcesFromFiles(files1);
    List<Resource> resourcesAdd = getResourcesFromFiles(files2);
    resources.addAll(resourcesAdd);
    return new APITemplate<ComponentVO>() {

        @Override
        protected void checkParams() throws IllegalArgumentException {
            if (null == componentCode) {
                throw new RdosDefineException("Component type cannot be empty");
            }
            if (null == clusterId) {
                throw new RdosDefineException("Cluster Id cannot be empty");
            }
            if (CollectionUtils.isNotEmpty(resources) && resources.size() >= 2 && StringUtils.isBlank(kerberosFileName)) {
                // 上传二份文件 需要kerberosFileName文件名字段
                throw new RdosDefineException("kerberosFileName不能为空");
            }
            // 校验引擎是否添加
            if (EComponentType.deployTypeComponents.contains(componentCode) && null == deployType) {
                throw new RdosDefineException(ErrorCode.EMPTY_PARAMETERS.getMsg() + ":deployType");
            }
        }

        @Override
        protected ComponentVO process() throws RdosDefineException {
            // 校验引擎是否添加
            EComponentType componentType = EComponentType.getByCode(componentCode);
            if (EComponentType.deployTypeComponents.contains(componentType) && null == deployType) {
                throw new RdosDefineException("deploy type cannot be empty");
            }
            return consoleComponentService.addOrUpdateComponent(clusterId, componentConfig, resources, versionName, kerberosFileName, componentTemplate, componentType, storeType, principals, principal, isMetadata, isDefault, deployType);
        }
    }.execute();
}
Also used : ComponentVO(com.dtstack.taier.scheduler.vo.ComponentVO) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Resource(com.dtstack.taier.dao.dto.Resource) EComponentType(com.dtstack.taier.common.enums.EComponentType) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 48 with RdosDefineException

use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.

the class UploadController method getResourcesFromFiles.

private List<Resource> getResourcesFromFiles(List<MultipartFile> files) {
    List<Resource> resources = new ArrayList<>(files.size());
    for (MultipartFile file : files) {
        String fileOriginalName = file.getOriginalFilename();
        String path = uploadsDir + File.separator + fileOriginalName;
        File saveFile = new File(path);
        if (!saveFile.getParentFile().exists()) {
            saveFile.getParentFile().mkdirs();
        }
        try {
            file.transferTo(saveFile);
        } catch (Exception e) {
            LOGGER.error("", e);
            throw new RdosDefineException("An error occurred while storing the file");
        }
        resources.add(new Resource(fileOriginalName, path, (int) file.getSize(), file.getContentType(), file.getName()));
    }
    return resources;
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Resource(com.dtstack.taier.dao.dto.Resource) ArrayList(java.util.ArrayList) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 49 with RdosDefineException

use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.

the class StoragePart method getPluginName.

@Override
public String getPluginName() {
    List<Component> components = componentScheduleGroup.get(EComponentScheduleType.RESOURCE);
    if (CollectionUtils.isEmpty(components)) {
        throw new RdosDefineException(ErrorCode.RESOURCE_COMPONENT_NOT_CONFIG);
    }
    Component resourceComponent = components.get(0);
    String resourceVersion = resourceComponent.getVersionName();
    EComponentType resourceType = EComponentType.getByCode(resourceComponent.getComponentTypeCode());
    Optional<JSONObject> resourceModelConfig = context.getModelConfig(resourceType, resourceVersion);
    JSONObject storageModelConfig = resourceModelConfig.map(res -> res.getJSONObject(type.name())).orElseThrow(() -> new RdosDefineException(Strings.format(ErrorCode.RESOURCE_NOT_SUPPORT_COMPONENT_VERSION.getMsg(), resourceComponent.getComponentName(), type.name(), versionName)));
    return storageModelConfig.getString(type.name());
}
Also used : Strings(com.dtstack.taier.common.util.Strings) DataSource(com.dtstack.taier.develop.model.DataSource) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) StringUtils(org.apache.commons.lang3.StringUtils) EComponentType(com.dtstack.taier.common.enums.EComponentType) List(java.util.List) CollectionUtils(org.apache.commons.collections.CollectionUtils) Component(com.dtstack.taier.dao.domain.Component) Map(java.util.Map) Context(com.dtstack.taier.develop.model.system.Context) Optional(java.util.Optional) JSONObject(com.alibaba.fastjson.JSONObject) EComponentScheduleType(com.dtstack.taier.common.enums.EComponentScheduleType) ErrorCode(com.dtstack.taier.common.exception.ErrorCode) JSONObject(com.alibaba.fastjson.JSONObject) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) Component(com.dtstack.taier.dao.domain.Component) EComponentType(com.dtstack.taier.common.enums.EComponentType)

Example 50 with RdosDefineException

use of com.dtstack.taier.common.exception.RdosDefineException 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)176 JSONObject (com.alibaba.fastjson.JSONObject)80 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)20 EComponentType (com.dtstack.taier.common.enums.EComponentType)18 List (java.util.List)18 JSONArray (com.alibaba.fastjson.JSONArray)17 File (java.io.File)16 DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)15 Transactional (org.springframework.transaction.annotation.Transactional)15 BatchTask (com.dtstack.taier.dao.domain.BatchTask)14 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)13 Map (java.util.Map)13 ISourceDTO (com.dtstack.dtcenter.loader.dto.source.ISourceDTO)10 Component (com.dtstack.taier.dao.domain.Component)10 Resource (com.dtstack.taier.dao.dto.Resource)10 HashMap (java.util.HashMap)10 CollectionUtils (org.apache.commons.collections.CollectionUtils)10 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)9 BatchCatalogue (com.dtstack.taier.dao.domain.BatchCatalogue)9