use of org.apache.commons.configuration2.ex.ConfigurationException in project hadoop by apache.
the class MetricsConfig method loadFirst.
/**
* Load configuration from a list of files until the first successful load
* @param conf the configuration object
* @param files the list of filenames to try
* @return the configuration object
*/
static MetricsConfig loadFirst(String prefix, String... fileNames) {
for (String fname : fileNames) {
try {
Configuration cf = new Configurations().propertiesBuilder(fname).configure(new Parameters().properties().setFileName(fname).setListDelimiterHandler(new DefaultListDelimiterHandler(','))).getConfiguration().interpolatedConfiguration();
LOG.info("loaded properties from " + fname);
LOG.debug(toString(cf));
MetricsConfig mc = new MetricsConfig(cf, prefix);
LOG.debug(mc);
return mc;
} catch (ConfigurationException e) {
// Commons Configuration defines the message text when file not found
if (e.getMessage().startsWith("Could not locate")) {
continue;
}
throw new MetricsConfigException(e);
}
}
LOG.warn("Cannot locate configuration: tried " + Joiner.on(",").join(fileNames));
// default to an empty configuration
return new MetricsConfig(new PropertiesConfiguration(), prefix);
}
Aggregations