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);
}
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;
}
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();
}
}
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);
}
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"));
}
Aggregations