use of com.torodb.stampede.config.model.backend.Backend in project torodb by torodb.
the class CliConfigUtils method uncatchedReadConfig.
private static Config uncatchedReadConfig(final CliConfig cliConfig) throws Exception {
ObjectMapper objectMapper = ConfigUtils.mapper();
Config defaultConfig = new Config();
ObjectNode configNode = (ObjectNode) objectMapper.valueToTree(defaultConfig);
if (cliConfig.hasConfFile() || cliConfig.hasXmlConfFile()) {
ObjectMapper mapper = null;
InputStream inputStream = null;
if (cliConfig.hasConfFile()) {
mapper = ConfigUtils.yamlMapper();
inputStream = cliConfig.getConfInputStream();
} else if (cliConfig.hasXmlConfFile()) {
mapper = ConfigUtils.xmlMapper();
inputStream = cliConfig.getXmlConfInputStream();
}
if (inputStream != null) {
Config config = mapper.readValue(inputStream, Config.class);
configNode = mapper.valueToTree(config);
}
}
if (cliConfig.getBackend() != null) {
Backend backend = new Backend(CliConfig.getBackendClass(cliConfig.getBackend()).newInstance());
ObjectNode backendNode = (ObjectNode) objectMapper.valueToTree(backend);
configNode.set("backend", backendNode);
}
if (cliConfig.getParams() != null) {
YAMLMapper yamlMapper = ConfigUtils.yamlMapper();
for (String paramPathValue : cliConfig.getParams()) {
int paramPathValueSeparatorIndex = paramPathValue.indexOf('=');
String pathAndProp = paramPathValue.substring(0, paramPathValueSeparatorIndex);
if (pathAndProp.startsWith("/")) {
pathAndProp = pathAndProp.substring(1);
}
pathAndProp = "/" + pathAndProp;
String value = paramPathValue.substring(paramPathValueSeparatorIndex + 1);
configNode = ConfigUtils.mergeParam(yamlMapper, configNode, pathAndProp, value);
}
}
Config config = objectMapper.treeToValue(configNode, Config.class);
validateBean(config);
return config;
}
Aggregations