Example usage for org.apache.commons.configuration Configuration addProperty

List of usage examples for org.apache.commons.configuration Configuration addProperty

Introduction

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

Prototype

void addProperty(String key, Object value);

Source Link

Document

Add a property to the configuration.

Usage

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

@Test
public void testNumberOfInstancesPerTemplate() throws Exception {
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.instance-templates",
            "1 hadoop-namenode+hadoop-jobtracker,3 hadoop-datanode+hadoop-tasktracker");
    conf.addProperty("whirr.instance-templates-max-percent-failures",
            "100 hadoop-namenode+hadoop-jobtracker,60 hadoop-datanode+hadoop-tasktracker");
    ClusterSpec expectedClusterSpec = ClusterSpec.withNoDefaults(conf);
    List<InstanceTemplate> templates = expectedClusterSpec.getInstanceTemplates();
    InstanceTemplate t1 = templates.get(0);
    assertThat(t1.getMinNumberOfInstances(), is(1));
    InstanceTemplate t2 = templates.get(1);
    assertThat(t2.getMinNumberOfInstances(), is(2));

    conf.setProperty("whirr.instance-templates-max-percent-failures", "60 hadoop-datanode+hadoop-tasktracker");
    expectedClusterSpec = ClusterSpec.withNoDefaults(conf);
    templates = expectedClusterSpec.getInstanceTemplates();
    t1 = templates.get(0);/*from w w w.  j a  v a 2 s  . c  om*/
    assertThat(t1.getMinNumberOfInstances(), is(1));
    t2 = templates.get(1);
    assertThat(t2.getMinNumberOfInstances(), is(2));

    conf.addProperty("whirr.instance-templates-minumum-number-of-instances",
            "1 hadoop-datanode+hadoop-tasktracker");
    expectedClusterSpec = ClusterSpec.withNoDefaults(conf);
    templates = expectedClusterSpec.getInstanceTemplates();
    t1 = templates.get(0);
    assertThat(t1.getMinNumberOfInstances(), is(1));
    t2 = templates.get(1);
    assertThat(t2.getMinNumberOfInstances(), is(2));

    conf.setProperty("whirr.instance-templates-minimum-number-of-instances",
            "3 hadoop-datanode+hadoop-tasktracker");
    expectedClusterSpec = ClusterSpec.withNoDefaults(conf);
    templates = expectedClusterSpec.getInstanceTemplates();
    t1 = templates.get(0);
    assertThat(t1.getMinNumberOfInstances(), is(1));
    t2 = templates.get(1);
    assertThat(t2.getMinNumberOfInstances(), is(3));
}

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

@Test
public void testDefaultBlobStoreforComputeProvider() throws Exception {
    for (String pair : new String[] { "ec2:aws-s3", "aws-ec2:aws-s3", "cloudservers:cloudfiles-us",
            "cloudservers-us:cloudfiles-us", "cloudservers-uk:cloudfiles-uk" }) {
        String[] parts = pair.split(":");

        Configuration config = new PropertiesConfiguration();
        config.addProperty("whirr.provider", parts[0]);

        ClusterSpec spec = ClusterSpec.withTemporaryKeys(config);
        assertThat(spec.getBlobStoreProvider(), is(parts[1]));
    }/*from  www  .j ava 2s  .c o  m*/
}

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);/*  w ww .j  ava 2s.co m*/
    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.service.elasticsearch.ElasticSearchConfigurationBuilderTest.java

@Test
public void testGenerateYamlConfig() {
    Configuration defaults = new PropertiesConfiguration();

    defaults.addProperty("cloud.aws.id", "a");
    defaults.addProperty("cloud.aws.key", "b");
    defaults.addProperty("index.store.type", "memory");

    String content = StringUtils.join(ElasticSearchConfigurationBuilder.asYamlLines(defaults), "\n");

    assertThat(content, is("cloud:\n" + "  aws:\n" + "    id: a\n" + "    key: b\n" + "index:\n" + "  store:\n"
            + "    type: memory"));
}

From source file:org.apache.whirr.service.elasticsearch.ElasticSearchConfigurationBuilderTest.java

@Test
public void testDefaultConfigAwsEC2() throws Exception {
    Configuration baseConfig = new PropertiesConfiguration();
    baseConfig.addProperty("whirr.provider", "aws-ec2");
    baseConfig.addProperty("es.plugins", "lang-javascript, lang-python");

    ClusterSpec spec = ClusterSpec.withTemporaryKeys(baseConfig);
    Configuration config = ElasticSearchConfigurationBuilder.buildConfig(spec, null);

    assertThat(config.getStringArray("es.plugins"), is(
            new String[] { "lang-javascript", "lang-python", "elasticsearch/elasticsearch-cloud-aws/1.5.0" }));
    assertThat(config.getString("es.discovery.type"), is("ec2"));
}

From source file:org.apache.whirr.service.elasticsearch.ElasticSearchConfigurationBuilderTest.java

@Test
public void testDefaultUnicastConfig() throws Exception {
    Configuration baseConfig = new PropertiesConfiguration();
    baseConfig.addProperty("whirr.provider", "cloudservers-us");

    ClusterSpec spec = ClusterSpec.withTemporaryKeys(baseConfig);
    Cluster cluster = mock(Cluster.class);

    Set<Cluster.Instance> instances = Sets.newLinkedHashSet();
    for (String host : Lists.newArrayList("10.0.0.1", "10.0.0.2")) {
        Cluster.Instance instance = mock(Cluster.Instance.class);
        when(instance.getPrivateIp()).thenReturn(host);
        instances.add(instance);/*from w w w.  ja  v  a  2 s .c  o  m*/
    }
    when(cluster.getInstancesMatching((Predicate<Cluster.Instance>) any())).thenReturn(instances);

    Configuration config = ElasticSearchConfigurationBuilder.buildConfig(spec, cluster);
    String content = StringUtils.join(ElasticSearchConfigurationBuilder
            .asYamlLines(config.subset(ElasticSearchConfigurationBuilder.ES_PREFIX)), "\n");

    assertThat(content, is("index:\n" + "  store:\n" + "    type: memory\n" + "gateway:\n" + "  type: none\n"
            + "discovery:\n" + "  zen:\n" + "    ping:\n" + "      multicast:\n" + "        enabled: false\n"
            + "      unicast:\n" + "        hosts: [\"10.0.0.1:9300\", \"10.0.0.2:9300\"]"));
}

From source file:org.apache.whirr.service.elasticsearch.ElasticSearchConfigurationBuilderTest.java

@Test
public void testOverrideDefaults() throws Exception {
    Configuration baseConfig = new PropertiesConfiguration();
    baseConfig.addProperty("whirr.provider", "aws-ec2");
    baseConfig.addProperty("es.index.store.type", "fs");

    ClusterSpec spec = ClusterSpec.withTemporaryKeys(baseConfig);
    Configuration config = ElasticSearchConfigurationBuilder.buildConfig(spec, null);

    assertThat(config.getString("es.index.store.type"), is("fs"));
}

From source file:org.apache.whirr.service.hadoop.HadoopConfigurationBuilderTest.java

@Test
public void testOverrides() throws Exception {
    Configuration overrides = new PropertiesConfiguration();
    overrides.addProperty("hadoop-common.p1", "overridden1");
    overrides.addProperty("hadoop-common.p2", "overridden2");
    overrides.addProperty("hadoop-common.fs.default.name", "not-overridden");
    clusterSpec = ClusterSpec.withNoDefaults(overrides);
    Configuration conf = HadoopConfigurationBuilder.buildCommonConfiguration(clusterSpec, cluster, defaults);
    assertThat(Iterators.size(conf.getKeys()), is(3));
    assertThat(conf.getString("p1"), is("overridden1"));
    assertThat(conf.getString("p2"), is("overridden2"));
    assertThat("Can't override dynamically set properties", conf.getString("fs.default.name"),
            matches("hdfs://.+:8020/"));
}

From source file:org.apache.whirr.service.hadoop.HadoopConfigurationBuilderTest.java

@Test
public void testOverridesNumberOfMappers() throws Exception {
    Configuration overrides = new PropertiesConfiguration();
    overrides.addProperty("hadoop-mapreduce.mapred.tasktracker.map.tasks.maximum", "70");
    clusterSpec = ClusterSpec.withNoDefaults(overrides);
    Configuration conf = HadoopConfigurationBuilder.buildMapReduceConfiguration(clusterSpec, cluster, defaults);
    assertThat(conf.getString("mapred.tasktracker.map.tasks.maximum"), is("70"));
}

From source file:org.apache.whirr.service.hadoop.HadoopConfigurationBuilderTest.java

@Test
public void testOverridesNumberOfReducers() throws Exception {
    Configuration overrides = new PropertiesConfiguration();
    overrides.addProperty("hadoop-mapreduce.mapred.reduce.tasks", "7");
    clusterSpec = ClusterSpec.withNoDefaults(overrides);
    Configuration conf = HadoopConfigurationBuilder.buildMapReduceConfiguration(clusterSpec, cluster, defaults);
    assertThat(conf.getString("mapred.reduce.tasks"), is("7"));
}