Search in sources :

Example 1 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration 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 CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project OpenAttestation by OpenAttestation.

the class TAConfig method gatherConfiguration.

private Configuration gatherConfiguration(String propertiesFilename, Properties defaults) {
    CompositeConfiguration composite = new CompositeConfiguration();
    // first priority are properties defined on the current JVM (-D switch or through web container)
    SystemConfiguration system = new SystemConfiguration();
    dumpConfiguration(system, "system");
    composite.addConfiguration(system);
    // second priority are properties defined on the classpath (like user's home directory)        
    try {
        // user's home directory (assuming it's on the classpath!)
        readPropertiesFile("/" + propertiesFilename, composite);
    } catch (IOException ex) {
        log.info("Did not find " + propertiesFilename + " on classpath", ex);
    }
    // third priority are properties defined in standard install location
    System.out.println("TAConfig os.name=" + System.getProperty("os.name"));
    ArrayList<File> files = new ArrayList<File>();
    // windows-specific location
    if (System.getProperty("os.name", "").toLowerCase().equals("win")) {
        System.out.println("TAConfig user.home=" + System.getProperty("user.home"));
        files.add(new File("C:" + File.separator + "Intel" + File.separator + "CloudSecurity" + File.separator + propertiesFilename));
        files.add(new File(System.getProperty("user.home") + File.separator + propertiesFilename));
    }
    // linux-specific location
    if (System.getProperty("os.name", "").toLowerCase().equals("linux") || System.getProperty("os.name", "").toLowerCase().equals("unix")) {
        files.add(new File("./config/" + propertiesFilename));
        files.add(new File("/etc/oat-client/" + propertiesFilename));
    }
    // this line specific to TA for backwards compatibility, not needed in AS/AH
    files.add(new File(System.getProperty("app.path") + File.separator + propertiesFilename));
    // add all the files we found
    for (File f : files) {
        try {
            if (f.exists() && f.canRead()) {
                PropertiesConfiguration standard = new PropertiesConfiguration(f);
                dumpConfiguration(standard, "file:" + f.getAbsolutePath());
                composite.addConfiguration(standard);
            }
        } catch (ConfigurationException ex) {
            log.error(null, ex);
        }
    }
    // last priority are the defaults that were passed in, we use them if no better source was found
    if (defaults != null) {
        MapConfiguration defaultconfig = new MapConfiguration(defaults);
        dumpConfiguration(defaultconfig, "default");
        composite.addConfiguration(defaultconfig);
    }
    dumpConfiguration(composite, "composite");
    return composite;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) MapConfiguration(org.apache.commons.configuration.MapConfiguration) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 3 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.

the class TestHelixStorageContainerManager method testStorageContainerManager.

@Ignore
@Test
public void testStorageContainerManager() throws Exception {
    String clusterName = runtime.getMethodName();
    int numStorageContainers = 12;
    int numHosts = 3;
    controller.createCluster(clusterName, numStorageContainers, 3);
    StorageConfiguration conf = new StorageConfiguration(new CompositeConfiguration());
    Endpoint[] endpoints = new Endpoint[numHosts];
    StorageContainerRegistryImpl[] registries = new StorageContainerRegistryImpl[numHosts];
    HelixStorageContainerManager[] managers = new HelixStorageContainerManager[numHosts];
    int basePort = 80;
    for (int i = 0; i < numHosts; i++) {
        endpoints[i] = createEndpoint("127.0.0.1", basePort + i);
        registries[i] = createRegistry();
        managers[i] = createManager(clusterName, conf, registries[i], endpoints[i]);
    }
    managers[0].start();
    while (registries[0].getNumStorageContainers() < numStorageContainers) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    assertEquals(numStorageContainers, registries[0].getNumStorageContainers());
    assertEquals(0, registries[1].getNumStorageContainers());
    assertEquals(0, registries[2].getNumStorageContainers());
    // start the second node
    managers[1].start();
    while (registries[0].getNumStorageContainers() > numStorageContainers / 2) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[1].getNumStorageContainers() < numStorageContainers / 2) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    assertEquals(numStorageContainers / 2, registries[0].getNumStorageContainers());
    assertEquals(numStorageContainers / 2, registries[1].getNumStorageContainers());
    assertEquals(0, registries[2].getNumStorageContainers());
    // start the third node
    managers[2].start();
    while (registries[0].getNumStorageContainers() > numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[1].getNumStorageContainers() > numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    while (registries[2].getNumStorageContainers() < numStorageContainers / 3) {
        TimeUnit.MILLISECONDS.sleep(20);
    }
    int totalStorageContainers = registries[0].getNumStorageContainers() + registries[1].getNumStorageContainers() + registries[2].getNumStorageContainers();
    assertEquals("Expected " + numStorageContainers + "But " + totalStorageContainers + " found", numStorageContainers, totalStorageContainers);
    assertEquals(numStorageContainers / 3, registries[0].getNumStorageContainers());
    assertEquals(numStorageContainers / 3, registries[1].getNumStorageContainers());
    assertEquals(numStorageContainers / 3, registries[2].getNumStorageContainers());
    for (int i = 0; i < 10; i++) {
        int nid = ThreadLocalRandom.current().nextInt(numHosts);
        long scId = ThreadLocalRandom.current().nextLong(numStorageContainers);
        Endpoint endpoint = managers[nid].getStorageContainer(scId);
        if (null != endpoint) {
            assertTrue(endpoint.equals(endpoints[0]) || endpoint.equals(endpoints[1]) || endpoint.equals(endpoints[2]));
        }
    }
    for (HelixStorageContainerManager manager : managers) {
        manager.close();
    }
}
Also used : StorageContainerRegistryImpl(org.apache.bookkeeper.stream.storage.impl.sc.StorageContainerRegistryImpl) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) StorageConfiguration(org.apache.bookkeeper.stream.storage.conf.StorageConfiguration) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.

the class BookieShell method main.

public static void main(String[] argv) throws Exception {
    BookieShell shell = new BookieShell();
    // handle some common options for multiple cmds
    Options opts = new Options();
    opts.addOption(CONF_OPT, true, "configuration file");
    opts.addOption(LEDGERID_FORMATTER_OPT, true, "format of ledgerId");
    opts.addOption(ENTRY_FORMATTER_OPT, true, "format of entries");
    BasicParser parser = new BasicParser();
    CommandLine cmdLine = parser.parse(opts, argv, true);
    // load configuration
    CompositeConfiguration conf = new CompositeConfiguration();
    if (cmdLine.hasOption(CONF_OPT)) {
        String val = cmdLine.getOptionValue(CONF_OPT);
        conf.addConfiguration(new PropertiesConfiguration(new File(val).toURI().toURL()));
    }
    shell.setConf(conf);
    // ledgerid format
    if (cmdLine.hasOption(LEDGERID_FORMATTER_OPT)) {
        String val = cmdLine.getOptionValue(LEDGERID_FORMATTER_OPT);
        shell.ledgerIdFormatter = LedgerIdFormatter.newLedgerIdFormatter(val, shell.bkConf);
    } else {
        shell.ledgerIdFormatter = LedgerIdFormatter.newLedgerIdFormatter(shell.bkConf);
    }
    LOG.debug("Using ledgerIdFormatter {}", shell.ledgerIdFormatter.getClass());
    // entry format
    if (cmdLine.hasOption(ENTRY_FORMATTER_OPT)) {
        String val = cmdLine.getOptionValue(ENTRY_FORMATTER_OPT);
        shell.entryFormatter = EntryFormatter.newEntryFormatter(val, shell.bkConf);
    } else {
        shell.entryFormatter = EntryFormatter.newEntryFormatter(shell.bkConf);
    }
    LOG.debug("Using entry formatter {}", shell.entryFormatter.getClass());
    int res = shell.run(cmdLine.getArgs());
    System.exit(res);
}
Also used : Options(org.apache.commons.cli.Options) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) File(java.io.File) Checkpoint(org.apache.bookkeeper.bookie.CheckpointSource.Checkpoint)

Example 5 with CompositeConfiguration

use of org.apache.commons.configuration.CompositeConfiguration in project bookkeeper by apache.

the class TestConfigurationSubscription method testInitialConfigLoad.

@Test(timeout = 60000)
public void testInitialConfigLoad() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("prop1", "1");
    writer.setProperty("prop2", "abc");
    writer.setProperty("prop3", "123.0");
    writer.setProperty("prop4", "11132");
    writer.setProperty("prop5", "true");
    writer.save();
    ScheduledExecutorService mockScheduler = new DeterministicScheduler();
    FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
    ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration());
    List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
    ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
    assertEquals(1, conf.getInt("prop1"));
    assertEquals("abc", conf.getString("prop2"));
    assertEquals(123.0, conf.getFloat("prop3"), 0);
    assertEquals(11132, conf.getInt("prop4"));
    assertEquals(true, conf.getBoolean("prop5"));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) DeterministicScheduler(org.jmock.lib.concurrent.DeterministicScheduler) Test(org.junit.Test)

Aggregations

CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)89 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)46 Test (org.junit.Test)24 ClusterController (org.apache.whirr.ClusterController)22 Configuration (org.apache.commons.configuration.Configuration)21 File (java.io.File)17 Before (org.junit.Before)11 ForceField (ffx.potential.parameters.ForceField)10 ConfigurationException (org.apache.commons.configuration.ConfigurationException)9 HadoopProxy (org.apache.whirr.service.hadoop.HadoopProxy)9 BeforeClass (org.junit.BeforeClass)9 IOException (java.io.IOException)8 ClusterSpec (org.apache.whirr.ClusterSpec)8 MolecularAssembly (ffx.potential.MolecularAssembly)7 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)7 PDBFilter (ffx.potential.parsers.PDBFilter)7 MapConfiguration (org.apache.commons.configuration.MapConfiguration)6 Crystal (ffx.crystal.Crystal)5 ReflectionList (ffx.crystal.ReflectionList)5 ForceFieldEnergy (ffx.potential.ForceFieldEnergy)5