Search in sources :

Example 1 with Configurations

use of org.apache.commons.configuration2.builder.fluent.Configurations 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);
}
Also used : DefaultListDelimiterHandler(org.apache.commons.configuration2.convert.DefaultListDelimiterHandler) Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) Configurations(org.apache.commons.configuration2.builder.fluent.Configurations) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Aggregations

Configuration (org.apache.commons.configuration2.Configuration)1 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)1 SubsetConfiguration (org.apache.commons.configuration2.SubsetConfiguration)1 Configurations (org.apache.commons.configuration2.builder.fluent.Configurations)1 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)1 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1