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

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

Introduction

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

Prototype

public void addConfiguration(Configuration config) 

Source Link

Document

Add a configuration.

Usage

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...
 *///w w w .  java  2s . 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();
    }
}

From source file:org.apache.whirr.ClusterSpec.java

private Configuration composeWithDefaults(Configuration userConfig) throws ConfigurationException {
    CompositeConfiguration composed = new CompositeConfiguration();
    composed.addConfiguration(userConfig);
    composed.addConfiguration(/*from  ww  w.  jav  a2 s .c  om*/
            new PropertiesConfiguration(getClass().getClassLoader().getResource(DEFAULT_PROPERTIES)));
    return composed;
}

From source file:org.apache.whirr.ClusterSpecTest.java

@Test
public void testApplySubroleAliases() throws ConfigurationException {
    CompositeConfiguration c = new CompositeConfiguration();
    Configuration config = new PropertiesConfiguration();
    config.addProperty("whirr.instance-templates",
            "1 puppet:somepup::pet+something-else, 1 something-else-only");
    c.addConfiguration(config);
    InstanceTemplate template = InstanceTemplate.parse(c).get(0);
    Set<String> expected = Sets
            .newLinkedHashSet(Arrays.asList(new String[] { "puppet:somepup::pet", "something-else" }));
    assertThat(template.getRoles(), is(expected));

    InstanceTemplate template2 = InstanceTemplate.parse(c).get(1);
    Set<String> expected2 = Sets.newLinkedHashSet(Arrays.asList(new String[] { "something-else-only" }));
    assertThat(template2.getRoles(), is(expected2));
}

From source file:org.apache.whirr.command.AbstractClusterCommand.java

/**
 * Load the cluster spec by parsing the command line option set
 *//* w w w  . j  ava  2 s .  c om*/
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();
        Object value;
        if (property.hasMultipleArguments()) {
            value = optionSet.valuesOf(option);
        } else {
            value = optionSet.valueOf(option);
        }
        if (value != null) {
            optionsConfig.setProperty(property.getConfigName(), value);
        }
    }
    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(optionsConfig);
    if (optionSet.has(configOption)) {
        Configuration defaults = new PropertiesConfiguration(optionSet.valueOf(configOption));
        config.addConfiguration(defaults);
    }
    ClusterSpec clusterSpec = new ClusterSpec(config);

    for (Property required : EnumSet.of(CLUSTER_NAME, PROVIDER, IDENTITY, CREDENTIAL, INSTANCE_TEMPLATES,
            PRIVATE_KEY_FILE)) {
        if (clusterSpec.getConfiguration().getString(required.getConfigName()) == null) {
            throw new IllegalArgumentException(String.format("Option '%s' not set.", required.getSimpleName()));
        }
    }

    return clusterSpec;
}

From source file:org.apache.whirr.service.accumulo.AccumuloConfigurationBuilder.java

private static Configuration build(ClusterSpec clusterSpec, Cluster cluster, Configuration defaults,
        String prefix) throws ConfigurationException {
    CompositeConfiguration config = new CompositeConfiguration();
    Configuration sub = clusterSpec.getConfigurationForKeysWithPrefix(prefix);
    config.addConfiguration(sub.subset(prefix)); // remove prefix
    config.addConfiguration(defaults.subset(prefix));
    return config;
}

From source file:org.apache.whirr.service.cassandra.integration.CassandraServiceTest.java

@Before
public void setUp() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }//from www  . ja  va2 s.  co m
    config.addConfiguration(new PropertiesConfiguration("whirr-cassandra-test.properties"));
    clusterSpec = ClusterSpec.withTemporaryKeys(config);

    controller = new ClusterController();
    cluster = controller.launchCluster(clusterSpec);

    waitForCassandra();
}

From source file:org.apache.whirr.service.cdh.integration.Cdh3HadoopServiceTest.java

@BeforeClass
public static void setUp() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }/*from  w w  w.  ja  v  a 2 s  . c  o m*/
    config.addConfiguration(new PropertiesConfiguration(getPropertiesFilename()));
    clusterSpec = ClusterSpec.withTemporaryKeys(config);
    controller = new ClusterController();

    cluster = controller.launchCluster(clusterSpec);
    proxy = new HadoopProxy(clusterSpec, cluster);
    proxy.start();
}

From source file:org.apache.whirr.service.cdh.integration.Cdh3ZooKeeperServiceTest.java

@Before
public void setUp() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }/*from   w w w .j av a  2 s .c  o  m*/
    config.addConfiguration(new PropertiesConfiguration("whirr-zookeeper-cdh3-test.properties"));
    clusterSpec = ClusterSpec.withTemporaryKeys(config);
    controller = new ClusterController();

    cluster = controller.launchCluster(clusterSpec);
    hosts = ZooKeeperCluster.getHosts(cluster);
}

From source file:org.apache.whirr.service.cdh.integration.CdhZooKeeperServiceTest.java

@Before
public void setUp() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }/*from   w  w w.j  a va2s .  c  o m*/
    config.addConfiguration(new PropertiesConfiguration("whirr-zookeeper-cdh-test.properties"));
    clusterSpec = ClusterSpec.withTemporaryKeys(config);
    controller = new ClusterController();

    cluster = controller.launchCluster(clusterSpec);
    hosts = ZooKeeperCluster.getHosts(cluster);
}

From source file:org.apache.whirr.service.chef.integration.ChefServiceTest.java

@BeforeClass
public static void setUp() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }/*from  www.java 2s  .  c  om*/
    config.addConfiguration(new PropertiesConfiguration("whirr-chef-test.properties"));
    clusterSpec = ClusterSpec.withTemporaryKeys(config);
    controller = new ClusterController();
    controller.launchCluster(clusterSpec);
}