Search in sources :

Example 1 with ClientTemplate

use of com.dtstack.taier.scheduler.impl.pojo.ClientTemplate in project Taier by DTStack.

the class ConsoleComponentService method downloadFile.

/**
 * 下载文件
 *
 * @param componentId
 * @param downloadType 0:kerberos配置文件 1:配置文件 2:模板文件
 * @return
 */
public File downloadFile(Long componentId, Integer downloadType, Integer componentType, String versionName, Long clusterId, Integer deployType) {
    String localDownLoadPath = "";
    String uploadFileName = "";
    if (null == componentId) {
        EComponentType type = EComponentType.getByCode(componentType);
        // 解析模版中的信息 作为默认值 返回json
        List<ClientTemplate> clientTemplates = this.loadTemplate(clusterId, type, versionName, null, deployType);
        if (CollectionUtils.isNotEmpty(clientTemplates)) {
            Map<String, Object> fileMap = ComponentConfigUtils.convertClientTemplateToMap(clientTemplates);
            uploadFileName = EComponentType.getByCode(componentType).name() + ".json";
            localDownLoadPath = USER_DIR_DOWNLOAD + File.separator + uploadFileName;
            try {
                FileUtils.write(new File(localDownLoadPath), JSONObject.toJSONString(fileMap));
            } catch (Exception e) {
                throw new RdosDefineException("file does not exist");
            }
        }
    } else {
        Component component = componentMapper.selectById(componentId);
        if (null == component) {
            throw new RdosDefineException("Component does not exist");
        }
        SftpConfig sftpConfig = componentService.getComponentByClusterId(clusterId, EComponentType.SFTP.getTypeCode(), false, SftpConfig.class, null);
        if (null == sftpConfig) {
            throw new RdosDefineException("sftp component does not exist");
        }
        localDownLoadPath = USER_DIR_DOWNLOAD + File.separator + component.getComponentName();
        String remoteDir = sftpConfig.getPath() + File.separator + this.buildSftpPath(clusterId, component.getComponentTypeCode());
        SftpFileManage sftpFileManage = null;
        if (DownloadType.Kerberos.getCode() == downloadType) {
            remoteDir = remoteDir + File.separator + KERBEROS;
            localDownLoadPath = localDownLoadPath + File.separator + KERBEROS;
            sftpFileManage = SftpFileManage.getSftpManager(sftpConfig);
            sftpFileManage.downloadDir(remoteDir, localDownLoadPath);
        } else {
            if (StringUtils.isBlank(component.getUploadFileName())) {
                // 一种是  全部手动填写的 如flink
                EComponentType type = EComponentType.getByCode(componentType);
                String componentConfig = componentService.getComponentByClusterId(clusterId, type.getTypeCode(), true, String.class, component.getVersionValue());
                try {
                    localDownLoadPath = localDownLoadPath + ".json";
                    FileUtils.write(new File(localDownLoadPath), filterConfigMessage(componentConfig));
                } catch (IOException e) {
                    LOGGER.error("write upload file {} error", componentConfig, e);
                }
            } else {
                sftpFileManage = SftpFileManage.getSftpManager(sftpConfig);
                // 一种是 上传配置文件的需要到sftp下载
                sftpFileManage.downloadDir(remoteDir + File.separator + component.getUploadFileName(), localDownLoadPath);
            }
        }
        uploadFileName = component.getUploadFileName();
    }
    File file = new File(localDownLoadPath);
    if (!file.exists()) {
        throw new RdosDefineException("file does not exist");
    }
    String zipFilename = StringUtils.isBlank(uploadFileName) ? "download.zip" : uploadFileName;
    if (file.isDirectory()) {
        // 将文件夹压缩成zip文件
        return zipFile(componentId, downloadType, componentType, file, zipFilename);
    } else {
        return new File(localDownLoadPath);
    }
}
Also used : SftpFileManage(com.dtstack.taier.pluginapi.sftp.SftpFileManage) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate) SftpConfig(com.dtstack.taier.pluginapi.sftp.SftpConfig) IOException(java.io.IOException) EComponentType(com.dtstack.taier.common.enums.EComponentType) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException) JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File)

Example 2 with ClientTemplate

use of com.dtstack.taier.scheduler.impl.pojo.ClientTemplate in project Taier by DTStack.

the class ScheduleDictService method getHadoopVersion.

private List<ClientTemplate> getHadoopVersion() {
    List<Dict> dicts = dictMapper.listDictByType(DictType.HADOOP_VERSION.type);
    Map<String, List<Dict>> versions = dicts.stream().collect(Collectors.groupingBy(Dict::getDependName));
    List<ClientTemplate> clientTemplates = new ArrayList<>(versions.size());
    for (String dependName : versions.keySet()) {
        List<Dict> keyDicts = versions.get(dependName);
        keyDicts = keyDicts.stream().sorted(Comparator.comparing(Dict::getSort)).collect(Collectors.toList());
        List<ClientTemplate> templates = keyDicts.stream().map(s -> new ClientTemplate(s.getDictName(), s.getDictValue())).collect(Collectors.toList());
        ClientTemplate vendorFolder = new ClientTemplate();
        vendorFolder.setKey(dependName);
        vendorFolder.setValues(templates);
        clientTemplates.add(vendorFolder);
    }
    clientTemplates.sort(Comparator.comparing(ClientTemplate::getKey));
    return clientTemplates;
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) DictType(com.dtstack.taier.common.enums.DictType) Predicate(java.util.function.Predicate) LoggerFactory(org.slf4j.LoggerFactory) EnvironmentContext(com.dtstack.taier.common.env.EnvironmentContext) Autowired(org.springframework.beans.factory.annotation.Autowired) ComponentConfigMapper(com.dtstack.taier.dao.mapper.ComponentConfigMapper) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) ComponentConfig(com.dtstack.taier.dao.domain.ComponentConfig) EComponentType(com.dtstack.taier.common.enums.EComponentType) Dict(com.dtstack.taier.dao.domain.Dict) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) CollectionUtils(org.springframework.util.CollectionUtils) EScheduleJobType(com.dtstack.taier.common.enums.EScheduleJobType) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate) DictMapper(com.dtstack.taier.dao.mapper.DictMapper) Dict(com.dtstack.taier.dao.domain.Dict) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate)

Example 3 with ClientTemplate

use of com.dtstack.taier.scheduler.impl.pojo.ClientTemplate in project Taier by DTStack.

the class ComponentConfigUtils method buildDBDataToClientTemplate.

/**
 * 将数据库数据转换为前端展示的树结构
 *
 * @param componentConfigs
 * @return
 */
public static List<ClientTemplate> buildDBDataToClientTemplate(List<ComponentConfig> componentConfigs) {
    if (CollectionUtils.isEmpty(componentConfigs)) {
        return new ArrayList<>(0);
    }
    Map<String, List<ComponentConfig>> dependencyMapping = componentConfigs.stream().filter(c -> StringUtils.isNotBlank(c.getDependencyKey())).collect(Collectors.groupingBy(ComponentConfig::getDependencyKey));
    List<ClientTemplate> reduceTemplate = new ArrayList<>();
    List<ComponentConfig> emptyDependencyValue = componentConfigs.stream().filter(c -> StringUtils.isBlank(c.getDependencyKey())).collect(Collectors.toList());
    for (ComponentConfig componentConfig : emptyDependencyValue) {
        ClientTemplate clientTemplate = componentConfigToTemplate(componentConfig);
        deepToBuildClientTemplate(dependencyMapping, dependencyMapping.size(), clientTemplate, clientTemplate.getKey());
        reduceTemplate.add(clientTemplate);
    }
    return sortByKey(reduceTemplate);
}
Also used : java.util(java.util) EFrontType(com.dtstack.taier.common.enums.EFrontType) MapUtils(org.apache.commons.collections.MapUtils) Predicate(java.util.function.Predicate) BooleanUtils(org.apache.commons.lang3.BooleanUtils) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) ComponentConfig(com.dtstack.taier.dao.domain.ComponentConfig) EComponentType(com.dtstack.taier.common.enums.EComponentType) JSONArray(com.alibaba.fastjson.JSONArray) CollectionUtils(org.springframework.util.CollectionUtils) JSONObject(com.alibaba.fastjson.JSONObject) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate) BeanUtils(org.springframework.beans.BeanUtils) ComponentConfig(com.dtstack.taier.dao.domain.ComponentConfig) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate)

Example 4 with ClientTemplate

use of com.dtstack.taier.scheduler.impl.pojo.ClientTemplate in project Taier by DTStack.

the class ComponentConfigUtils method convertOldClientTemplateToTree.

/**
 * 将数据库console_component的component_template调整为完全的树结构
 *
 * @param clientTemplates
 * @return
 */
@Deprecated
public static List<ClientTemplate> convertOldClientTemplateToTree(List<ClientTemplate> clientTemplates) {
    if (CollectionUtils.isEmpty(clientTemplates)) {
        return new ArrayList<>(0);
    }
    // 子key
    Map<String, List<ClientTemplate>> dependMapping = clientTemplates.stream().filter(c -> StringUtils.isNotBlank(c.getDependencyKey())).collect(Collectors.groupingBy(ClientTemplate::getDependencyKey));
    List<ClientTemplate> reduceTemplate = new ArrayList<>();
    for (ClientTemplate clientTemplate : clientTemplates) {
        if (StringUtils.isBlank(clientTemplate.getDependencyKey())) {
            reduceTemplate.add(clientTemplate);
        }
    }
    for (ClientTemplate clientTemplate : reduceTemplate) {
        List<ClientTemplate> sonTemplate = dependMapping.get(clientTemplate.getKey());
        if (CollectionUtils.isEmpty(sonTemplate)) {
            continue;
        }
        for (ClientTemplate template : sonTemplate) {
            if (null != template) {
                List<ClientTemplate> values = clientTemplate.getValues();
                if (null == values) {
                    clientTemplate.setValues(new ArrayList<>());
                } else {
                    clientTemplate.getValues().removeIf(s -> s.getKey().equalsIgnoreCase(template.getKey()));
                }
                clientTemplate.getValues().add(template);
            }
        }
    }
    return reduceTemplate;
}
Also used : java.util(java.util) EFrontType(com.dtstack.taier.common.enums.EFrontType) MapUtils(org.apache.commons.collections.MapUtils) Predicate(java.util.function.Predicate) BooleanUtils(org.apache.commons.lang3.BooleanUtils) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) ComponentConfig(com.dtstack.taier.dao.domain.ComponentConfig) EComponentType(com.dtstack.taier.common.enums.EComponentType) JSONArray(com.alibaba.fastjson.JSONArray) CollectionUtils(org.springframework.util.CollectionUtils) JSONObject(com.alibaba.fastjson.JSONObject) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate) BeanUtils(org.springframework.beans.BeanUtils) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate)

Example 5 with ClientTemplate

use of com.dtstack.taier.scheduler.impl.pojo.ClientTemplate in project Taier by DTStack.

the class ComponentConfigUtils method deepToBuildClientTemplate.

/**
 * 解析config成clientTemplate树结构
 *
 * @param dependencyMapping
 * @param maxDeep
 * @param clientTemplate
 * @param dependencyKey
 */
private static void deepToBuildClientTemplate(Map<String, List<ComponentConfig>> dependencyMapping, Integer maxDeep, ClientTemplate clientTemplate, String dependencyKey) {
    if (maxDeep <= 0) {
        return;
    }
    List<ComponentConfig> dependValueConfig = dependencyMapping.get(dependencyKey);
    if (!CollectionUtils.isEmpty(dependValueConfig)) {
        maxDeep = --maxDeep;
        List<ClientTemplate> valuesTemplate = new ArrayList<>();
        for (ComponentConfig componentConfig : dependValueConfig) {
            ClientTemplate componentClientTemplate = componentConfigToTemplate(componentConfig);
            componentClientTemplate.setRequired(BooleanUtils.toBoolean(componentConfig.getRequired()));
            deepToBuildClientTemplate(dependencyMapping, maxDeep, componentClientTemplate, dependencyKey + dependencySeparator + componentClientTemplate.getKey());
            valuesTemplate.add(componentClientTemplate);
        }
        clientTemplate.setValues(valuesTemplate);
    }
}
Also used : ComponentConfig(com.dtstack.taier.dao.domain.ComponentConfig) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate)

Aggregations

ClientTemplate (com.dtstack.taier.scheduler.impl.pojo.ClientTemplate)12 JSONObject (com.alibaba.fastjson.JSONObject)6 EComponentType (com.dtstack.taier.common.enums.EComponentType)5 ComponentConfig (com.dtstack.taier.dao.domain.ComponentConfig)5 JSONArray (com.alibaba.fastjson.JSONArray)3 java.util (java.util)3 Predicate (java.util.function.Predicate)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3 CollectionUtils (org.springframework.util.CollectionUtils)3 EFrontType (com.dtstack.taier.common.enums.EFrontType)2 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)2 MapUtils (org.apache.commons.collections.MapUtils)2 BooleanUtils (org.apache.commons.lang3.BooleanUtils)2 BeanUtils (org.springframework.beans.BeanUtils)2 DictType (com.dtstack.taier.common.enums.DictType)1 EScheduleJobType (com.dtstack.taier.common.enums.EScheduleJobType)1 EnvironmentContext (com.dtstack.taier.common.env.EnvironmentContext)1 com.dtstack.taier.dao.domain (com.dtstack.taier.dao.domain)1 Dict (com.dtstack.taier.dao.domain.Dict)1