Search in sources :

Example 1 with Configuration

use of org.apache.commons.configuration.Configuration in project whirr by apache.

the class ClusterSpecCommand method getClusterSpec.

protected ClusterSpec getClusterSpec(OptionSet optionSet) throws ConfigurationException {
    Configuration optionsConfig = new PropertiesConfiguration();
    for (Map.Entry<Property, OptionSpec> entry : optionSpecs.entrySet()) {
        Property property = entry.getKey();
        OptionSpec option = entry.getValue();
        if (property.hasMultipleArguments()) {
            optionsConfig.setProperty(property.getConfigName(), optionSet.valuesOf(option));
        } else {
            optionsConfig.setProperty(property.getConfigName(), optionSet.valueOf(option));
        }
    }
    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(optionsConfig);
    if (optionSet.has(configOption)) {
        Configuration defaults = new PropertiesConfiguration(optionSet.valueOf(configOption));
        config.addConfiguration(defaults);
    }
    for (Property required : EnumSet.of(SERVICE_NAME, CLUSTER_NAME, IDENTITY)) {
        if (config.getString(required.getConfigName()) == null) {
            throw new IllegalArgumentException(String.format("Option '%s' not set.", required.getSimpleName()));
        }
    }
    return ClusterSpec.fromConfiguration(config);
}
Also used : OptionSpec(joptsimple.OptionSpec) ArgumentAcceptingOptionSpec(joptsimple.ArgumentAcceptingOptionSpec) Configuration(org.apache.commons.configuration.Configuration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Map(java.util.Map) Property(org.apache.whirr.service.ClusterSpec.Property)

Example 2 with Configuration

use of org.apache.commons.configuration.Configuration in project archaius by Netflix.

the class OverridingPropertiesConfiguration method convertToConcurrentCompositeConfiguration.

/**
     * Convert CombinedConfiguration into {@link ConcurrentCompositeConfiguration} as the later has better performance
     * and thread safety. 
     * 
     * @param config Configuration to be converted
     */
public static ConcurrentCompositeConfiguration convertToConcurrentCompositeConfiguration(CombinedConfiguration config) {
    ConcurrentCompositeConfiguration root = new ConcurrentCompositeConfiguration();
    IdentityHashMap<Configuration, String> reverseMap = new IdentityHashMap<Configuration, String>();
    for (String name : (Set<String>) config.getConfigurationNames()) {
        Configuration child = config.getConfiguration(name);
        reverseMap.put(child, name);
    }
    for (int i = 0; i < config.getNumberOfConfigurations(); i++) {
        Configuration child = config.getConfiguration(i);
        String name = reverseMap.get(child);
        if (child instanceof CombinedConfiguration) {
            CombinedConfiguration combinedConf = (CombinedConfiguration) child;
            ConcurrentCompositeConfiguration newConf = convertToConcurrentCompositeConfiguration(combinedConf);
            root.addConfiguration(newConf, name);
        } else {
            Configuration conf = new ConcurrentMapConfiguration(child);
            root.addConfiguration((AbstractConfiguration) conf, name);
        }
    }
    return root;
}
Also used : Set(java.util.Set) Configuration(org.apache.commons.configuration.Configuration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) IdentityHashMap(java.util.IdentityHashMap) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Example 3 with Configuration

use of org.apache.commons.configuration.Configuration in project archaius by Netflix.

the class OverridingPropertiesConfiguration method getAllNamedConfiguration.

/**
     * Gets all named sub-configuration from a configuration in a map. This method examines each sub-configuration
     * which is an instance of {@link ConcurrentCompositeConfiguration} or CombinedConfiguration and extract the 
     * named configurations out of them.
     *  
     * @param conf Configuration to get all the named sub-configurations
     * @return map where key is the name of the sub-configuration and value is the sub-configuration
     */
public static Map<String, Configuration> getAllNamedConfiguration(Configuration conf) {
    List<Configuration> toProcess = new ArrayList<Configuration>();
    Map<String, Configuration> map = new HashMap<String, Configuration>();
    toProcess.add(conf);
    while (!toProcess.isEmpty()) {
        Configuration current = toProcess.remove(0);
        if (current instanceof ConcurrentCompositeConfiguration) {
            ConcurrentCompositeConfiguration composite = (ConcurrentCompositeConfiguration) current;
            for (String name : composite.getConfigurationNames()) {
                map.put(name, composite.getConfiguration(name));
            }
            for (Configuration c : composite.getConfigurations()) {
                toProcess.add(c);
            }
        } else if (current instanceof CombinedConfiguration) {
            CombinedConfiguration combined = (CombinedConfiguration) current;
            for (String name : (Set<String>) combined.getConfigurationNames()) {
                map.put(name, combined.getConfiguration(name));
            }
            for (int i = 0; i < combined.getNumberOfConfigurations(); i++) {
                toProcess.add(combined.getConfiguration(i));
            }
        }
    }
    return map;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ConcurrentMapConfiguration(com.netflix.config.ConcurrentMapConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Example 4 with Configuration

use of org.apache.commons.configuration.Configuration in project archaius by Netflix.

the class ConcurrentCompositeConfiguration method removeConfiguration.

/**
     * Removes the configuration with the specified name.
     *
     * @param name the name of the configuration to be removed
     * @return the removed configuration (<b>null</b> if this configuration
     * was not found)
     */
public Configuration removeConfiguration(String name) {
    Configuration conf = getConfiguration(name);
    if (conf != null && !conf.equals(containerConfiguration)) {
        configList.remove(conf);
        namedConfigurations.remove(name);
    } else if (conf != null && conf.equals(containerConfiguration)) {
        throw new IllegalArgumentException("Can't remove container configuration");
    }
    return conf;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration)

Example 5 with Configuration

use of org.apache.commons.configuration.Configuration in project archaius by Netflix.

the class ConcurrentCompositeConfiguration method getList.

/**
     * Get a List of objects associated with the given configuration key.
     * If the key doesn't map to an existing object, the default value
     * is returned.
     *
     * @param key The configuration key.
     * @param defaultValue The default value.
     * @return The associated List of value.
     * 
     */
@Override
public List getList(String key, List defaultValue) {
    List<Object> list = new ArrayList<Object>();
    // add all elements from the first configuration containing the requested key
    Iterator<AbstractConfiguration> it = configList.iterator();
    if (overrideProperties.containsKey(key)) {
        appendListProperty(list, overrideProperties, key);
    }
    while (it.hasNext() && list.isEmpty()) {
        Configuration config = it.next();
        if ((config != containerConfiguration || containerConfigurationChanged) && config.containsKey(key)) {
            appendListProperty(list, config, key);
        }
    }
    // add all elements from the in memory configuration
    if (list.isEmpty()) {
        appendListProperty(list, containerConfiguration, key);
    }
    if (list.isEmpty()) {
        return defaultValue;
    }
    ListIterator<Object> lit = list.listIterator();
    while (lit.hasNext()) {
        lit.set(interpolate(lit.next()));
    }
    return list;
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Configuration(org.apache.commons.configuration.Configuration) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

Configuration (org.apache.commons.configuration.Configuration)169 Test (org.junit.Test)42 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)39 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)23 Test (org.testng.annotations.Test)22 File (java.io.File)13 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)13 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)11 Properties (java.util.Properties)10 AtlasException (org.apache.atlas.AtlasException)9 ZkUtils (kafka.utils.ZkUtils)8 IndexLoadingConfigMetadata (com.linkedin.pinot.common.metadata.segment.IndexLoadingConfigMetadata)7 HashMap (java.util.HashMap)7 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 ArrayList (java.util.ArrayList)6 AtlasClient (org.apache.atlas.AtlasClient)6 BeforeClass (org.testng.annotations.BeforeClass)6 IOException (java.io.IOException)5 SimpleEntry (java.util.AbstractMap.SimpleEntry)5 ConfigurationException (org.apache.commons.configuration.ConfigurationException)5