use of com.typesafe.config.ConfigResolveOptions in project helios by spotify.
the class HeliosConfig method loadConfig.
/**
* @param component The name of the component we're loading config for
* (i.e. Temp jobs, Helios solo)
* @return The root configuration loaded from the helios configuration files.
*/
static Config loadConfig(final String component) {
final ConfigResolveOptions resolveOptions = ConfigResolveOptions.defaults().setAllowUnresolved(true);
final Config baseConfig = ConfigFactory.load(BASE_CONFIG_FILE, ConfigParseOptions.defaults(), resolveOptions);
final Config appConfig = ConfigFactory.load(APP_CONFIG_FILE, ConfigParseOptions.defaults(), resolveOptions);
return appConfig.withFallback(baseConfig);
}
use of com.typesafe.config.ConfigResolveOptions in project helios by spotify.
the class HeliosConfig method loadConfig.
/**
* Return the root configuration loaded from the helios configuration files.
*/
static Config loadConfig() {
final ConfigResolveOptions resolveOptions = ConfigResolveOptions.defaults().setAllowUnresolved(true);
final ConfigParseOptions parseOptions = ConfigParseOptions.defaults();
final Config baseConfig = ConfigFactory.load(BASE_CONFIG_FILE, parseOptions, resolveOptions);
final Config appConfig = ConfigFactory.load(APP_CONFIG_FILE, parseOptions, resolveOptions);
return appConfig.withFallback(baseConfig);
}
use of com.typesafe.config.ConfigResolveOptions in project incubator-gobblin by apache.
the class PullFileToConfigConverter method convert.
public void convert() throws IOException {
Config baseConfig = ConfigFactory.parseString(DO_NOT_OVERRIDE_KEY + ": []");
FileSystem pullFileFs = pullFileRootPath.getFileSystem(new Configuration());
FileSystem outputFs = this.outputPath.getFileSystem(new Configuration());
Config sysConfig = ConfigFactory.parseFile(this.sysConfigPath);
PullFileLoader pullFileLoader = new PullFileLoader(this.pullFileRootPath, pullFileFs, PullFileLoader.DEFAULT_JAVA_PROPS_PULL_FILE_EXTENSIONS, PullFileLoader.DEFAULT_HOCON_PULL_FILE_EXTENSIONS);
PackagedTemplatesJobCatalogDecorator catalog = new PackagedTemplatesJobCatalogDecorator();
ConfigResolveOptions configResolveOptions = ConfigResolveOptions.defaults();
configResolveOptions = configResolveOptions.setAllowUnresolved(true);
ResourceBasedJobTemplate template;
Config templateConfig;
try {
template = (ResourceBasedJobTemplate) catalog.getTemplate(templateURI.toUri());
templateConfig = sysConfig.withFallback(template.getRawTemplateConfig()).withFallback(baseConfig).resolve(configResolveOptions);
} catch (SpecNotFoundException | JobTemplate.TemplateException exc) {
throw new IOException(exc);
}
Set<String> doNotOverride = templateConfig.hasPath(DO_NOT_OVERRIDE_KEY) ? Sets.newHashSet(templateConfig.getStringList(DO_NOT_OVERRIDE_KEY)) : Sets.<String>newHashSet();
ConfigRenderOptions configRenderOptions = ConfigRenderOptions.defaults();
configRenderOptions = configRenderOptions.setComments(false);
configRenderOptions = configRenderOptions.setOriginComments(false);
configRenderOptions = configRenderOptions.setFormatted(true);
configRenderOptions = configRenderOptions.setJson(false);
for (FileStatus pullFile : pullFileFs.globStatus(this.fileGlobToConvert)) {
Config pullFileConfig = pullFileLoader.loadPullFile(pullFile.getPath(), ConfigFactory.empty(), true).resolve();
Map<String, String> outputConfigMap = Maps.newHashMap();
outputConfigMap.put(ConfigurationKeys.JOB_TEMPLATE_PATH, this.templateURI.toString());
boolean somethingChanged;
do {
somethingChanged = false;
Config currentOutputConfig = ConfigFactory.parseMap(outputConfigMap);
Config currentResolvedConfig = currentOutputConfig.withFallback(templateConfig).resolve(configResolveOptions);
for (Map.Entry<Object, Object> entry : ConfigUtils.configToProperties(pullFileConfig).entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
try {
if ((!currentResolvedConfig.hasPath(key)) || (!currentResolvedConfig.getString(key).equals(value) && !doNotOverride.contains(key))) {
if (!FILTER_KEYS.contains(key)) {
somethingChanged = true;
outputConfigMap.put(key, value);
}
}
} catch (ConfigException.NotResolved nre) {
// path is unresolved in config, will try again next iteration
}
}
} while (somethingChanged);
try {
Config outputConfig = ConfigFactory.parseMap(outputConfigMap);
Config currentResolvedConfig = outputConfig.withFallback(templateConfig).resolve();
String rendered = outputConfig.root().render(configRenderOptions);
Path newPath = PathUtils.removeExtension(pullFile.getPath(), PullFileLoader.DEFAULT_JAVA_PROPS_PULL_FILE_EXTENSIONS.toArray(new String[] {}));
newPath = PathUtils.addExtension(newPath, "conf");
newPath = new Path(this.outputPath, newPath.getName());
FSDataOutputStream os = outputFs.create(newPath);
os.write(rendered.getBytes(Charsets.UTF_8));
os.close();
} catch (ConfigException.NotResolved nre) {
throw new IOException("Not all configuration keys were resolved in pull file " + pullFile.getPath(), nre);
}
}
}
Aggregations