use of com.dtstack.taier.common.exception.RdosDefineException 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.common.exception.RdosDefineException in project Taier by DTStack.
the class ScheduleActionService method paramActionExt.
public ParamActionExt paramActionExt(ScheduleTaskShade batchTask, String jobId, String flowJobId) throws Exception {
if (StringUtils.isBlank(jobId)) {
jobId = this.generateUniqueSign();
}
LOGGER.info("startJob ScheduleTaskShade: {} jobId:{} flowJobId:{} ", JSONObject.toJSONString(batchTask), jobId, flowJobId);
ScheduleJob scheduleJob = buildScheduleJob(batchTask, jobId, flowJobId);
ParamActionExt paramActionExt = paramActionExt(batchTask, scheduleJob, JSONObject.parseObject(batchTask.getExtraInfo()));
if (paramActionExt == null) {
throw new RdosDefineException("extraInfo can't null or empty string");
}
paramActionExt.setCycTime(scheduleJob.getCycTime());
paramActionExt.setTaskId(batchTask.getTaskId());
paramActionExt.setComponentVersion(batchTask.getComponentVersion());
paramActionExt.setFlowJobId(flowJobId);
return paramActionExt;
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class FileUtil method parse2Map.
/**
* parse file to map
* @param files
* @return {fileName, Map<K,V>}
*/
public static Map<String, Map<String, Object>> parse2Map(List<File> files) {
if (CollectionUtils.isEmpty(files)) {
return Collections.emptyMap();
}
Map<String, Map<String, Object>> confMap = new HashMap<>(files.size());
Map<String, Object> fileMap;
for (File file : files) {
if (file.getName().startsWith(CommonConstant.DOT)) {
// .开头过滤
continue;
}
if (file.getName().endsWith(CommonConstant.XML_SUFFIX)) {
// xml文件
try {
fileMap = Xml2JsonUtil.xml2map(file);
} catch (Exception e) {
throw new RdosDefineException(CommonConstant.XML_SUFFIX + ErrorCode.FILE_PARSE_ERROR.getMsg(), e);
}
} else if (file.getName().endsWith(CommonConstant.JSON_SUFFIX)) {
// json文件
String jsonStr;
try {
jsonStr = Xml2JsonUtil.readFile(file);
} catch (IOException e) {
throw new RdosDefineException(CommonConstant.JSON_SUFFIX + ErrorCode.FILE_PARSE_ERROR.getMsg(), e);
}
if (StringUtils.isBlank(jsonStr)) {
continue;
}
fileMap = (Map<String, Object>) JSONObject.parseObject(jsonStr, Map.class);
} else {
throw new RdosDefineException(ErrorCode.FILE_TYPE_NOT_SUPPORTED);
}
if (null != fileMap) {
confMap.put(file.getName(), fileMap);
}
}
return confMap;
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class Krb5FileUtil method readKrb5ByPath.
public static Map<String, HashMap<String, String>> readKrb5ByPath(String krb5Path) {
List<String> lines = new ArrayList<>();
File krb5File = new File(krb5Path);
try (InputStreamReader inputReader = new InputStreamReader(new FileInputStream(krb5File));
BufferedReader br = new BufferedReader(inputReader)) {
for (; ; ) {
String line = br.readLine();
if (line == null) {
break;
}
lines.add(line);
}
} catch (Exception e) {
LOGGER.error("krb5.conf read error:", e);
throw new RdosDefineException("krb5.conf read error");
}
return convertKrb5ToMap(lines);
}
use of com.dtstack.taier.common.exception.RdosDefineException in project Taier by DTStack.
the class JobParamOperatorPipeline method pipeline.
@Override
public void pipeline(Map<String, Object> actionParam, Map<String, Object> pipelineParam) throws Exception {
String urlKey = (String) super.getExecuteValue(actionParam, pipelineParam);
if (StringUtils.isNotBlank(urlKey)) {
@SuppressWarnings("unchecked") List<ScheduleTaskParamShade> taskParamShades = (List) pipelineParam.get(taskParamsToReplaceKey);
ScheduleJob scheduleJob = (ScheduleJob) pipelineParam.get(scheduleJobKey);
if (null == scheduleJob) {
throw new RdosDefineException("upload param pipeline schedule job can not be null");
}
pipelineParam.put(pipelineKey, JobParamReplace.paramReplace(urlKey, taskParamShades, scheduleJob.getCycTime()));
}
}
Aggregations