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

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

Introduction

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

Prototype

void setProperty(String key, Object value);

Source Link

Document

Set a property, this will replace any previously set values.

Usage

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

@Test
public void testConversion() {
    Configuration conf = new PropertiesConfiguration();
    conf.setProperty("p1", "v1,v2");
    conf.setProperty("p2", "v3");
    List<String> lines = HadoopConfigurationConverter.asXmlConfigurationLines(conf);
    assertThat(lines,/*from   w  w  w.ja  v  a  2  s .  c o  m*/
            is((List<String>) Lists.newArrayList("<configuration>", "  <property>", "    <name>p1</name>",
                    "    <value>v1,v2</value>", "  </property>", "  <property>", "    <name>p2</name>",
                    "    <value>v3</value>", "  </property>", "</configuration>")));
}

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

@Test
public void testFinal() {
    Configuration conf = new PropertiesConfiguration();
    conf.setProperty("p1", "v1");
    conf.setProperty("p2", "v2");
    conf.setProperty("p2.final", "true");
    List<String> lines = HadoopConfigurationConverter.asXmlConfigurationLines(conf);
    assertThat(lines,/*from www.  j av a2 s  .  com*/
            is((List<String>) Lists.newArrayList("<configuration>", "  <property>", "    <name>p1</name>",
                    "    <value>v1</value>", "  </property>", "  <property>", "    <name>p2</name>",
                    "    <value>v2</value>", "    <final>true</final>", "  </property>", "</configuration>")));
}

From source file:org.apache.whirr.service.hbase.HBaseConfigurationBuilder.java

static Configuration buildHBaseSiteConfiguration(ClusterSpec clusterSpec, Cluster cluster,
        Configuration defaults) throws ConfigurationException, IOException {
    Configuration config = build(clusterSpec, cluster, defaults, "hbase-site");

    Cluster.Instance master = cluster.getInstanceMatching(role(HBaseMasterClusterActionHandler.ROLE));
    String masterHostName = master.getPublicHostName();

    config.setProperty("hbase.rootdir", String.format("hdfs://%s:8020/hbase", masterHostName));
    config.setProperty("hbase.zookeeper.quorum", ZooKeeperCluster.getHosts(cluster));

    return config;
}

From source file:org.apache.whirr.service.puppet.functions.ModulePropertiesFromConfigurationTest.java

@Test
public void testWhenMatches() {
    Configuration conf = new PropertiesConfiguration();
    conf.setProperty("puppet.nginx.module", "git://github.com/puppetlabs/puppetlabs-nginx.git");
    conf.setProperty("puppet.nginx.module.branch", "notmaster");
    conf.setProperty("puppet.foox.module", null);
    conf.setProperty("puppet.module", "foo");
    assertEquals(// w  ww  . j  a va  2s.  co  m
            ImmutableMap.of("puppet.nginx.module.branch", "notmaster", "puppet.nginx.module",
                    "git://github.com/puppetlabs/puppetlabs-nginx.git"),
            ModulePropertiesFromConfiguration.INSTANCE.apply(conf));
}

From source file:org.apache.whirr.service.puppet.statements.CreateSitePpAndApplyRoles.java

@Override
public String render(OsFamily arg0) {

    // when we get to the last role, let's cat all the manifests we made together inside a
    // node default site.pp
    Builder<Statement> statements = ImmutableList.<Statement>builder();

    statements.add(Statements.rm(SITE_PP_FILE_LOCATION));
    Builder<String> sitePp = ImmutableList.<String>builder();

    sitePp.add("node default {");
    for (String role : roles) {
        String manifestAttribPrefix = role.replaceAll(":+", ".");
        Configuration manifestProps = new PropertiesConfiguration();
        for (@SuppressWarnings("unchecked")
        Iterator<String> it = config.getKeys(manifestAttribPrefix); it.hasNext();) {
            String key = it.next();
            manifestProps.setProperty(key, config.getProperty(key));
        }/*  w w w  .  j  a  va  2s  .c  om*/
        sitePp.add(getManifestForClusterSpecAndRole(role, manifestProps).toString());
    }
    sitePp.add("}");

    statements.add(appendFile(SITE_PP_FILE_LOCATION, sitePp.build()));
    statements.add(exec("puppet apply " + SITE_PP_FILE_LOCATION));

    return new StatementList(statements.build()).render(arg0);
}

From source file:org.apache.whirr.service.puppet.statements.CreateSitePpAndApplyRolesTest.java

@Test
public void testWithAttribs() throws IOException {
    Configuration conf = new PropertiesConfiguration();
    conf.setProperty("puppet.nginx.module", "git://github.com/puppetlabs/puppetlabs-nginx.git");
    conf.setProperty("nginx.server.hostname", "foohost");

    CreateSitePpAndApplyRoles nginx = new CreateSitePpAndApplyRoles(ImmutableSet.of("nginx::server"), conf);

    assertEquals(CharStreams.toString(//from www .  jav  a  2 s .c o  m
            Resources.newReaderSupplier(Resources.getResource("nginx-with-attribs.txt"), Charsets.UTF_8)),
            nginx.render(OsFamily.UNIX));
}

From source file:org.apache.whirr.service.yarn.YarnConfigurationBuilder.java

@VisibleForTesting
static Configuration buildConfiguration(ClusterSpec clusterSpec, Cluster cluster, String role,
        Configuration defaults) throws ConfigurationException, IOException {
    Configuration config = build(clusterSpec, cluster, defaults, "hadoop-yarn");

    Instance resourceManager = cluster.getInstanceMatching(role(YarnResourceManagerHandler.ROLE));
    String resourceManagerPrivateAddress = resourceManager.getPrivateAddress().getHostName();
    config.setProperty("yarn.resourcemanager.address", String.format("%s:8040", resourceManagerPrivateAddress));
    config.setProperty("yarn.resourcemanager.scheduler.address",
            String.format("%s:8030", resourceManagerPrivateAddress));
    config.setProperty("yarn.resourcemanager.resource-tracker.address",
            String.format("%s:8025", resourceManagerPrivateAddress));
    return config;
}

From source file:org.apache.wookie.tests.beans.JCRPersistenceTest.java

/**
 * Set up JCR persistence runtime test environment.
 * /*from  w w  w .j  av  a2  s.  c  o m*/
 * @throws Exception
 */
@Before
public void setUpPerTest() throws Exception {
    logger.info("JCR set up test");

    // load repository configuration from environment
    String testRepositoryDir = System.getProperty("user.dir") + "/build/test-repository";
    repositoryDir = getSystemProperty(REPOSITORY_DIRECTORY_PROPERTY_NAME, testRepositoryDir);
    repositoryUser = getSystemProperty(REPOSITORY_USER_PROPERTY_NAME, "java");
    repositoryPassword = getSystemProperty(REPOSITORY_PASSWORD_PROPERTY_NAME, "java");
    repositoryRootPath = getSystemProperty(REPOSITORY_ROOT_PATH_PROPERTY_NAME, "/wookie");
    repositoryWorkspace = getSystemProperty(REPOSITORY_WORKSPACE_PROPERTY_NAME, "default");

    // construct JCR remote client repository instance
    File repositoryDirFile = new File(repositoryDir);
    if (!repositoryDirFile.exists()) {
        repositoryDirFile.mkdirs();
    }
    String derbyLog = repositoryDir + File.separator + "derby.log";
    System.setProperty("derby.stream.error.file", derbyLog);
    String repositoryConfig = repositoryDir + File.separator + "repository.xml";
    Repository repository = new TransientRepository(repositoryConfig, repositoryDir);

    // create JNDI context
    rootContext = new InitialContext();
    Context namingContext = lookupOrCreateNamingContext(rootContext, "java:comp");
    namingContext = lookupOrCreateNamingContext(namingContext, "env");
    lookupOrCreateNamingContext(namingContext, "jcr");

    // bind datasource to JNDI context
    rootContext.rebind(JCRPersistenceManager.WIDGET_REPOSITORY_JNDI_REPOSITORY_FULL_NAME, repository);

    // initialize persistence manager factory and persistence manager;
    // truncate and initialize persistent store
    Configuration configuration = new PropertiesConfiguration();
    configuration.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_CLASS_NAME_PROPERTY_NAME,
            JCRPersistenceManager.class.getName());
    configuration.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_INITIALIZE_STORE_PROPERTY_NAME,
            "true");
    configuration.setProperty(JCRPersistenceManager.PERSISTENCE_MANAGER_USER_PROPERTY_NAME, repositoryUser);
    configuration.setProperty(JCRPersistenceManager.PERSISTENCE_MANAGER_PASSWORD_PROPERTY_NAME,
            repositoryPassword);
    configuration.setProperty(JCRPersistenceManager.PERSISTENCE_MANAGER_ROOT_PATH_PROPERTY_NAME,
            repositoryRootPath);
    configuration.setProperty(JCRPersistenceManager.PERSISTENCE_MANAGER_WORKSPACE_PROPERTY_NAME,
            repositoryWorkspace);
    PersistenceManagerFactory.initialize(configuration);

    logger.info("JCR test set up");
    configured = true;
}

From source file:org.apache.wookie.tests.beans.JPAPersistenceTest.java

/**
 * Set up JPA persistence runtime test environment.
 * //from www  .  java  2  s  .co  m
 * @throws Exception
 */
@Before
public void setUpPerTest() throws Exception {
    logger.info("JPA set up test");

    // load database configuration from environment
    String testDatabaseDir = (System.getProperty("user.dir") + "/build/test-database")
            .replace(File.separatorChar, '/');
    dbUser = getSystemProperty(DB_USER_PROPERTY_NAME, "java");
    dbPassword = getSystemProperty(DB_PASSWORD_PROPERTY_NAME, "java");
    dbDriver = getSystemProperty(DB_DRIVER_CLASS_PROPERTY_NAME, "org.apache.derby.jdbc.EmbeddedDriver");
    dbUri = getSystemProperty(DB_URI_PROPERTY_NAME, "jdbc:derby:" + testDatabaseDir + "/widgetdb;create=true");
    dbType = getSystemProperty(DB_TYPE_PROPERTY_NAME, "derby");

    // load driver
    Class.forName(dbDriver);

    // test connection
    Connection conn = DriverManager.getConnection(dbUri, dbUser, dbPassword);
    conn.close();

    // construct pooling datasource
    connectionPool = new GenericObjectPool(null, 0, GenericObjectPool.WHEN_EXHAUSTED_GROW, 0, 5);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dbUri, dbUser, dbPassword);
    new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
    DataSource dataSource = new PoolingDataSource(connectionPool);

    // create JNDI context
    rootContext = new InitialContext();
    Context namingContext = lookupOrCreateNamingContext(rootContext, "java:comp");
    namingContext = lookupOrCreateNamingContext(namingContext, "env");
    lookupOrCreateNamingContext(namingContext, "jdbc");

    // bind datasource to JNDI context
    rootContext.rebind(JPAPersistenceManager.WIDGET_DATABASE_JNDI_DATASOURCE_FULL_NAME, dataSource);

    // initialize persistence manager factory and persistence manager;
    // truncate and initialize persistent store
    Configuration configuration = new PropertiesConfiguration();
    configuration.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_CLASS_NAME_PROPERTY_NAME,
            JPAPersistenceManager.class.getName());
    configuration.setProperty(PersistenceManagerFactory.PERSISTENCE_MANAGER_INITIALIZE_STORE_PROPERTY_NAME,
            "true");
    configuration.setProperty(JPAPersistenceManager.PERSISTENCE_MANAGER_CACHE_SIZE_PROPERTY_NAME, "1000");
    configuration.setProperty(JPAPersistenceManager.PERSISTENCE_MANAGER_DB_TYPE_PROPERTY_NAME, dbType);
    PersistenceManagerFactory.initialize(configuration);

    logger.info("JPA test set up");
    configured = true;
}

From source file:org.bhave.experiment.AbstractConfigurablePrototype.java

/**
 * Creates a deep copy for the supplied configuration object
 *
 * @param config a configuration object//from  www  . j  a  v  a  2s .c o m
 */
@Override
public void loadConfiguration(Configuration config) {
    Configuration newConfig = new PropertiesConfiguration();

    Iterator<String> keyIt = config.getKeys();

    while (keyIt.hasNext()) {
        String key = keyIt.next();
        newConfig.setProperty(key, config.getProperty(key));
    }
    this.config = newConfig;
}