Example usage for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration

List of usage examples for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration.

Prototype

public CompositeConfiguration() 

Source Link

Document

Creates an empty CompositeConfiguration object which can then be added some other Configuration files

Usage

From source file:org.apache.log.extractor.App.java

private void initConfiguration() throws ConfigurationException {
    CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
    compositeConfiguration.addConfiguration(new SystemConfiguration());
    compositeConfiguration.addConfiguration(new PropertiesConfiguration("logExtractor.properties"));
    config = compositeConfiguration;//from   ww w . j a v  a2s  . c  o  m
}

From source file:org.apache.qpid.server.configuration.plugins.AbstractConfigurationTest.java

@Override
public void setUp() throws Exception {
    // Test does not directly use the AppRegistry but the configured broker
    // is required for the correct ConfigurationPlugin processing
    super.setUp();
    XMLConfiguration xmlconfig = new XMLConfiguration();
    xmlconfig.addProperty("base.element[@property]", "property");
    xmlconfig.addProperty("base.element.name", "name");
    // We make these strings as that is how they will be read from the file.
    xmlconfig.addProperty("base.element.positiveLong", String.valueOf(POSITIVE_LONG));
    xmlconfig.addProperty("base.element.negativeLong", String.valueOf(NEGATIVE_LONG));
    xmlconfig.addProperty("base.element.boolean", String.valueOf(true));
    xmlconfig.addProperty("base.element.double", String.valueOf(DOUBLE));
    for (int i = 0; i < LIST_SIZE; i++) {
        xmlconfig.addProperty("base.element.list", i);
    }/*from w w  w  . ja va2s  .co  m*/

    //Use a composite configuration as this is what our broker code uses.
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(xmlconfig);

    _plugin = new TestConfigPlugin();

    try {
        _plugin.setConfiguration("base.element", composite.subset("base.element"));
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail(e.toString());
    }

}

From source file:org.apache.qpid.server.configuration.QueueConfiguration.java

public QueueConfiguration(String name, VirtualHostConfiguration virtualHostConfiguration)
        throws ConfigurationException {
    _vHostConfig = virtualHostConfiguration;
    _name = name;/*from  w w  w. j a v  a  2 s. co m*/

    CompositeConfiguration mungedConf = new CompositeConfiguration();
    mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues.queue." + escapeTagName(name)));
    mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues"));

    setConfiguration("virtualhosts.virtualhost.queues.queue", mungedConf);
}

From source file:org.apache.qpid.server.configuration.QueueConfigurationTest.java

private VirtualHostConfiguration overrideConfiguration(String property, Object value)
        throws ConfigurationException {
    PropertiesConfiguration queueConfig = new PropertiesConfiguration();
    queueConfig.setProperty("queues.queue.test." + property, value);

    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(_fullHostConf.getConfig());
    config.addConfiguration(queueConfig);

    return new VirtualHostConfiguration("test", config, _broker);
}

From source file:org.apache.qpid.server.configuration.VirtualHostConfiguration.java

/**
 * Apply the given configuration to this VirtualHostConfiguration
 *
 * @param config the config to apply/*from ww  w . j  a v a 2 s .  com*/
 * @throws ConfigurationException if a problem occurs with configuration
 */
public void setConfiguration(Configuration config) throws ConfigurationException {
    setConfiguration("virtualhosts.virtualhost", config);

    Iterator i = getListValue("queues.queue.name").iterator();

    while (i.hasNext()) {
        String queueName = (String) i.next();
        _queues.put(queueName, new QueueConfiguration(queueName, this));
    }

    i = getListValue("exchanges.exchange.name").iterator();
    int count = 0;
    while (i.hasNext()) {
        CompositeConfiguration mungedConf = new CompositeConfiguration();
        mungedConf.addConfiguration(config.subset("exchanges.exchange(" + count++ + ")"));
        mungedConf.addConfiguration(getConfig().subset("exchanges"));
        String exchName = (String) i.next();
        _exchanges.put(exchName, new ExchangeConfiguration(exchName, mungedConf));
    }
}

From source file:org.apache.qpid.server.model.adapter.VirtualHostAdapter.java

private VirtualHostConfiguration createVirtualHostConfiguration(String virtualHostName)
        throws ConfigurationException {
    VirtualHostConfiguration configuration;
    String configurationFile = (String) getAttribute(CONFIG_PATH);
    if (configurationFile == null) {
        final MyConfiguration basicConfiguration = new MyConfiguration();
        PropertiesConfiguration config = new PropertiesConfiguration();
        config.addProperty("store.type", (String) getAttribute(STORE_TYPE));
        config.addProperty("store.environment-path", (String) getAttribute(STORE_PATH));
        basicConfiguration.addConfiguration(config);

        CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
        compositeConfiguration.addConfiguration(new SystemConfiguration());
        compositeConfiguration.addConfiguration(basicConfiguration);
        configuration = new VirtualHostConfiguration(virtualHostName, compositeConfiguration, _broker);
    } else {//from w ww  .j  a  v a2  s  .c om
        configuration = new VirtualHostConfiguration(virtualHostName, new File(configurationFile), _broker);
    }
    return configuration;
}

From source file:org.apache.whirr.actions.BootstrapClusterActionTest.java

@SuppressWarnings("unchecked")
@Test//from w  w w .j  a  v a 2  s. c o m
public void testDoActionRetriesSucceed() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.service-name", "test-service");
    conf.addProperty("whirr.cluster-name", "test-cluster");
    conf.addProperty("whirr.instance-templates",
            "1 hadoop-namenode+hadoop-jobtracker,4 hadoop-datanode+hadoop-tasktracker");
    conf.addProperty("whirr.instance-templates-max-percent-failures", "60 hadoop-datanode+hadoop-tasktracker");
    conf.addProperty("whirr.provider", "ec2");
    config.addConfiguration(conf);
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);

    Set<String> jtnn = new HashSet<String>();
    jtnn.add("hadoop-jobtracker");
    jtnn.add("hadoop-namenode");
    Set<String> dntt = new HashSet<String>();
    dntt.add("hadoop-datanode");
    dntt.add("hadoop-tasktracker");

    TestNodeStarterFactory nodeStarterFactory = null;

    ClusterActionHandler handler = mock(ClusterActionHandler.class);
    LoadingCache<String, ClusterActionHandler> handlerMap = convertMapToLoadingCache(
            ImmutableMap.<String, ClusterActionHandler>builder().put("hadoop-jobtracker", handler)
                    .put("hadoop-namenode", handler).put("hadoop-datanode", handler)
                    .put("hadoop-tasktracker", handler).build());

    Function<ClusterSpec, ComputeServiceContext> getCompute = mock(Function.class);
    ComputeServiceContext serviceContext = mock(ComputeServiceContext.class);
    ComputeService computeService = mock(ComputeService.class);
    TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
    Template template = mock(Template.class);

    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);

    // here is a scenario when jt+nn fails once, then the retry is successful
    // and from the dn+tt one node fails, then the retry is successful
    Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
    Stack<Integer> jtnnStack = new Stack<Integer>();
    jtnnStack.push(1); // then ok
    jtnnStack.push(0); // initially fail
    reaction.put(jtnn, jtnnStack);
    Stack<Integer> ddttStack = new Stack<Integer>();
    ddttStack.push(3); // 3 from 4, just enough
    reaction.put(dntt, ddttStack);

    nodeStarterFactory = new TestNodeStarterFactory(reaction);
    BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap,
            nodeStarterFactory);

    bootstrapper.execute(clusterSpec, null);
    if (nodeStarterFactory != null) {
        nodeStarterFactory.validateCompletion();
    }
}

From source file:org.apache.whirr.actions.BootstrapClusterActionTest.java

@SuppressWarnings("unchecked")
@Test(expected = IOException.class)
public void testDoActionRetriesExceeds() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }//w  ww .jav a2 s .c om
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.service-name", "test-service");
    conf.addProperty("whirr.cluster-name", "test-cluster");
    conf.addProperty("whirr.instance-templates",
            "1 hadoop-namenode+hadoop-jobtracker,4 hadoop-datanode+hadoop-tasktracker");
    conf.addProperty("whirr.instance-templates-max-percent-failures", "60 hadoop-datanode+hadoop-tasktracker");
    conf.addProperty("whirr.provider", "ec2");
    config.addConfiguration(conf);
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);

    Set<String> jtnn = new HashSet<String>();
    jtnn.add("hadoop-jobtracker");
    jtnn.add("hadoop-namenode");
    Set<String> dntt = new HashSet<String>();
    dntt.add("hadoop-datanode");
    dntt.add("hadoop-tasktracker");

    TestNodeStarterFactory nodeStarterFactory = null;

    ClusterActionHandler handler = mock(ClusterActionHandler.class);
    LoadingCache<String, ClusterActionHandler> handlerMap = convertMapToLoadingCache(
            ImmutableMap.<String, ClusterActionHandler>builder().put("hadoop-jobtracker", handler)
                    .put("hadoop-namenode", handler).put("hadoop-datanode", handler)
                    .put("hadoop-tasktracker", handler).build());

    Function<ClusterSpec, ComputeServiceContext> getCompute = mock(Function.class);
    ComputeServiceContext serviceContext = mock(ComputeServiceContext.class);
    ComputeService computeService = mock(ComputeService.class);
    TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
    Template template = mock(Template.class);

    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);

    // here is a scenario when jt+nn does not fail
    // but the dn+tt one node fails 3, then in the retry fails 2
    // at the end result, the cluster will fail, throwing IOException
    Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
    Stack<Integer> jtnnStack = new Stack<Integer>();
    jtnnStack.push(new Integer(1));
    reaction.put(jtnn, jtnnStack);
    Stack<Integer> ddttStack = new Stack<Integer>();
    ddttStack.push(new Integer(1)); // 1 from 4, retryRequired
    ddttStack.push(new Integer(1)); // 1 from 4, still retryRequired
    reaction.put(dntt, ddttStack);

    nodeStarterFactory = new TestNodeStarterFactory(reaction);
    BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap,
            nodeStarterFactory);

    bootstrapper.execute(clusterSpec, null); // this should file with too many retries
    if (nodeStarterFactory != null) {
        nodeStarterFactory.validateCompletion();
    }
}

From source file:org.apache.whirr.actions.BootstrapClusterActionTest.java

@Test
@SuppressWarnings("unchecked")
public void testSubroleInvoked() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }//from w  w  w .jav a 2s.  co  m
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.service-name", "test-service");
    conf.addProperty("whirr.cluster-name", "test-cluster");
    conf.addProperty("whirr.instance-templates", "1 puppet:module::manifest+something-else");
    conf.addProperty("whirr.provider", "ec2");
    config.addConfiguration(conf);
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);

    Set<String> nn = new HashSet<String>();
    nn.add("puppet:module::manifest");
    nn.add("something-else");

    TestNodeStarterFactory nodeStarterFactory = null;

    ClusterActionHandlerFactory puppetHandlerFactory = mock(ClusterActionHandlerFactory.class);
    ClusterActionHandler handler = mock(ClusterActionHandler.class);
    when(puppetHandlerFactory.getRolePrefix()).thenReturn("puppet:");
    when(puppetHandlerFactory.create("module::manifest")).thenReturn(handler);
    when(handler.getRole()).thenReturn("something-else");

    LoadingCache<String, ClusterActionHandler> handlerMap = new HandlerMapFactory()
            .create(ImmutableSet.of(puppetHandlerFactory), ImmutableSet.of(handler));

    Function<ClusterSpec, ComputeServiceContext> getCompute = mock(Function.class);
    ComputeServiceContext serviceContext = mock(ComputeServiceContext.class);
    ComputeService computeService = mock(ComputeService.class);
    TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
    Template template = mock(Template.class);

    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);

    Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
    Stack<Integer> nnStack = new Stack<Integer>();
    nnStack.push(new Integer(1));
    reaction.put(nn, nnStack);

    nodeStarterFactory = new TestNodeStarterFactory(reaction);
    BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap,
            nodeStarterFactory);

    bootstrapper.execute(clusterSpec, null);

    if (nodeStarterFactory != null) {
        nodeStarterFactory.validateCompletion();
    }
}

From source file:org.apache.whirr.actions.BootstrapClusterActionTest.java

@SuppressWarnings("unchecked")
@Test(expected = IllegalArgumentException.class)
/** test is the same as previous (SubroleInvoked) except it knows puppet, not puppet:, as the role;
 * the colon in the role def'n is the indication it accepts subroles,
 * so this should throw IllegalArgument when we refer to puppet:module...
 *//*from  w ww  . j a  v  a 2 s .  c  o m*/
public void testSubroleNotSupported() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.service-name", "test-service");
    conf.addProperty("whirr.cluster-name", "test-cluster");
    conf.addProperty("whirr.instance-templates", "1 puppet:module::manifest+something-else");
    conf.addProperty("whirr.provider", "ec2");
    config.addConfiguration(conf);
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);

    Set<String> nn = new HashSet<String>();
    nn.add("puppet:module::manifest");
    nn.add("something-else");

    TestNodeStarterFactory nodeStarterFactory = null;

    ClusterActionHandlerFactory puppetHandlerFactory = mock(ClusterActionHandlerFactory.class);
    ClusterActionHandler handler = mock(ClusterActionHandler.class);
    when(puppetHandlerFactory.getRolePrefix()).thenReturn("puppet");
    when(handler.getRole()).thenReturn("something-else");

    LoadingCache<String, ClusterActionHandler> handlerMap = new HandlerMapFactory()
            .create(ImmutableSet.of(puppetHandlerFactory), ImmutableSet.of(handler));

    Function<ClusterSpec, ComputeServiceContext> getCompute = mock(Function.class);
    ComputeServiceContext serviceContext = mock(ComputeServiceContext.class);
    ComputeService computeService = mock(ComputeService.class);
    TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
    Template template = mock(Template.class);

    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);

    Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
    Stack<Integer> nnStack = new Stack<Integer>();
    nnStack.push(1);
    reaction.put(nn, nnStack);

    nodeStarterFactory = new TestNodeStarterFactory(reaction);
    BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap,
            nodeStarterFactory);

    bootstrapper.execute(clusterSpec, null);

    if (nodeStarterFactory != null) {
        nodeStarterFactory.validateCompletion();
    }
}