use of com.dtstack.taier.dao.domain.ComponentConfig in project Taier by DTStack.
the class ComponentConfigService method getComponentVoByComponent.
public List<IComponentVO> getComponentVoByComponent(List<Component> components, boolean isFilter, Long clusterId, boolean isConvertHadoopVersion, boolean multiVersion) {
if (null == clusterId) {
throw new RdosDefineException("集群id不能为空");
}
if (CollectionUtils.isEmpty(components)) {
return new ArrayList<>(0);
}
// 集群所关联的组件的配置
List<ComponentConfig> componentConfigs = componentConfigMapper.listByClusterId(clusterId, isFilter);
if (CollectionUtils.isEmpty(componentConfigs)) {
return new ArrayList<>(0);
}
// 组件按类型分组, 因为可能存在组件有多个版本, 此时需要兼容单版本和多版本格式问题
Map<Integer, IComponentVO> componentVoMap = new HashMap<>(components.size());
components.stream().collect(Collectors.groupingBy(Component::getComponentTypeCode, Collectors.toList())).forEach((k, v) -> componentVoMap.put(k, multiVersion ? ComponentMultiVersionVO.getInstanceWithCapacityAndType(k, v.size()) : ComponentVO.getInstance()));
// 配置按照组件进行分组, 存在组件有多个版本
Map<Long, List<ComponentConfig>> componentIdConfigs = componentConfigs.stream().collect(Collectors.groupingBy(ComponentConfig::getComponentId));
List<IComponentVO> componentVoList = new ArrayList<>(components.size());
for (Component component : components) {
IComponentVO customComponent = componentVoMap.get(component.getComponentTypeCode());
ComponentVO componentVO = IComponentVO.getComponentVo(customComponent, component);
;
// 当前组件的配置
List<ComponentConfig> configs = componentIdConfigs.get(component.getId());
// hdfs yarn 才将自定义参数移除 过滤返回给前端
boolean isHadoopControl = EComponentType.hadoopVersionComponents.contains(EComponentType.getByCode(component.getComponentTypeCode()));
if (isHadoopControl) {
// 配置按照编辑类型进行分组
Map<String, List<ComponentConfig>> configTypeMapping = configs.stream().collect(Collectors.groupingBy(ComponentConfig::getType));
// hdfs yarn 4.1 template只有自定义参数
componentVO.setComponentTemplate(JSONObject.toJSONString(ComponentConfigUtils.buildDBDataToClientTemplate(configTypeMapping.get(EFrontType.CUSTOM_CONTROL.name()))));
// hdfs yarn 4.1 config为xml配置参数
componentVO.setComponentConfig(JSONObject.toJSONString(ComponentConfigUtils.convertComponentConfigToMap(configTypeMapping.get(EFrontType.XML.name()))));
} else {
Map<String, Object> configToMap = ComponentConfigUtils.convertComponentConfigToMap(configs);
componentVO.setComponentTemplate(JSONObject.toJSONString(ComponentConfigUtils.buildDBDataToClientTemplate(configs)));
componentVO.setComponentConfig(JSONObject.toJSONString(configToMap));
componentVO.setDeployType(component.getDeployType());
}
if (isConvertHadoopVersion && isHadoopControl) {
// 设置hadoopVersion 的key 如cdh 5.1.x
ComponentConfig componentConfig = componentConfigMapper.listByKey(component.getId(), ConfigConstant.HADOOP_VERSION);
if (null != componentConfig) {
componentVO.setVersionValue(componentConfig.getValue());
} else if (StringUtils.isNotBlank(component.getVersionValue())) {
// 兼容老数据
String dependName = "hadoop3".equalsIgnoreCase(component.getVersionValue()) || component.getVersionValue().startsWith("3") ? "Hadoop3" : "Hadoop2";
List<Dict> hadoopVersion = dictMapper.getByDependName(DictType.HADOOP_VERSION.type, dependName);
if (!CollectionUtils.isEmpty(hadoopVersion)) {
componentVO.setVersionValue(hadoopVersion.get(0).getDictName());
}
}
}
// 多版本才需要调用
if (customComponent.multiVersion()) {
customComponent.addComponent(componentVO);
}
}
componentVoList.addAll(componentVoMap.values());
return componentVoList;
}
use of com.dtstack.taier.dao.domain.ComponentConfig 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.dao.domain.ComponentConfig 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);
}
}
use of com.dtstack.taier.dao.domain.ComponentConfig in project Taier by DTStack.
the class ComponentConfigUtils method saveTreeToList.
/**
* 将展示的树结构转换为List存入数据库中
*
* @param reduceTemplate
* @param clusterId
* @param componentId
* @param dependKey
* @param dependValue
*/
public static List<ComponentConfig> saveTreeToList(List<ClientTemplate> reduceTemplate, Long clusterId, Long componentId, String dependKey, String dependValue, Integer componentTypeCode) {
List<ComponentConfig> saveComponentConfigs = new ArrayList<>();
for (ClientTemplate clientTemplate : reduceTemplate) {
ComponentConfig componentConfig = ComponentConfigUtils.convertClientTemplateToConfig(clientTemplate);
componentConfig.setClusterId(clusterId);
componentConfig.setComponentId(componentId);
if (StringUtils.isNotBlank(dependKey)) {
componentConfig.setDependencyKey(dependKey);
}
if (StringUtils.isNotBlank(dependValue) && componentConfig.getType().equalsIgnoreCase(EFrontType.GROUP.name())) {
componentConfig.setDependencyValue(dependValue);
}
componentConfig.setRequired(BooleanUtils.toInteger(clientTemplate.isRequired(), 1, 0, 0));
componentConfig.setComponentTypeCode(componentTypeCode);
saveComponentConfigs.add(componentConfig);
if (!CollectionUtils.isEmpty(clientTemplate.getValues())) {
String dependKeys = "";
// deploymode$perjob$metrics.reporter.promgateway.deleteOnShutdown
if (StringUtils.isNotBlank(dependKey)) {
dependKeys = dependKey + dependencySeparator + clientTemplate.getKey();
} else {
dependKeys = clientTemplate.getKey();
}
List<ComponentConfig> componentConfigs = saveTreeToList(clientTemplate.getValues(), clusterId, componentId, dependKeys, clientTemplate.getDependencyValue(), componentTypeCode);
if (!CollectionUtils.isEmpty(componentConfigs)) {
saveComponentConfigs.addAll(componentConfigs);
}
}
}
return saveComponentConfigs;
}
use of com.dtstack.taier.dao.domain.ComponentConfig in project Taier by DTStack.
the class ComponentConfigUtils method convertComponentConfigToMap.
/**
* 将数据库数据转换为key-value形式 供插件使用
* @param configs
* @return
*/
@SuppressWarnings("unchecked")
public static Map<String, Object> convertComponentConfigToMap(List<ComponentConfig> configs) {
if (CollectionUtils.isEmpty(configs)) {
return new HashMap<>(0);
}
Map<String, List<ComponentConfig>> dependencyMapping = configs.stream().filter(c -> StringUtils.isNotBlank(c.getDependencyKey())).collect(Collectors.groupingBy(ComponentConfig::getDependencyKey));
List<ComponentConfig> emptyDependencyValue = configs.stream().filter(c -> StringUtils.isBlank(c.getDependencyKey())).collect(Collectors.toList());
Map<String, Object> configMaps = new HashMap<>(configs.size());
for (ComponentConfig componentConfig : emptyDependencyValue) {
Map<String, Object> deepToBuildConfigMap = ComponentConfigUtils.deepToBuildConfigMap(dependencyMapping, dependencyMapping.size(), componentConfig.getKey());
if (DEPLOY_MODE.equalsIgnoreCase(componentConfig.getKey()) || EFrontType.GROUP.name().equalsIgnoreCase(componentConfig.getType())) {
configMaps.put(componentConfig.getKey(), DEPLOY_MODE.equalsIgnoreCase(componentConfig.getKey()) ? JSONArray.parseArray(componentConfig.getValue()) : componentConfig.getValue());
Object specialDeepConfig = deepToBuildConfigMap.get(componentConfig.getKey());
if (specialDeepConfig instanceof Map) {
// }
if (DEPLOY_MODE.equalsIgnoreCase(componentConfig.getKey())) {
// 只设置对应的值
JSONArray deployValues = JSONArray.parseArray(componentConfig.getValue());
for (Object deployValue : deployValues) {
Map deployValueMap = new HashMap<>();
deployValueMap.put(deployValue, ((Map<?, ?>) specialDeepConfig).get(deployValue));
configMaps.putAll(deployValueMap);
}
}
} else if (EFrontType.GROUP.name().equalsIgnoreCase(componentConfig.getType())) {
// group正常处理
// {
// "pythonConf":{},
// "jupyterConf":{},
// "typeName":"yarn2-hdfs2-dtscript",
// "commonConf":{}
// }
configMaps.put(componentConfig.getKey(), deepToBuildConfigMap);
} else {
configMaps.putAll(deepToBuildConfigMap);
}
} else {
if (!CollectionUtils.isEmpty(deepToBuildConfigMap)) {
if (EFrontType.RADIO_LINKAGE.name().equalsIgnoreCase(componentConfig.getType())) {
parseRadioLinkage(dependencyMapping, configMaps, componentConfig, deepToBuildConfigMap);
} else if (EFrontType.SELECT.name().equalsIgnoreCase(componentConfig.getType())) {
configMaps.put(componentConfig.getKey(), componentConfig.getValue());
} else {
configMaps.putAll(deepToBuildConfigMap);
if (EFrontType.RADIO.name().equalsIgnoreCase(componentConfig.getType())) {
// radio 需要将子配置添加进去 自身也需要
configMaps.put(componentConfig.getKey(), componentConfig.getValue());
}
}
} else {
configMaps.put(componentConfig.getKey(), componentConfig.getValue());
}
}
}
return configMaps;
}
Aggregations