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);
}
}
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;
}
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);
}
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;
}
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);
}
}
Aggregations