List of usage examples for org.apache.commons.configuration CompositeConfiguration addConfiguration
public void addConfiguration(Configuration config)
From source file:org.apache.juddi.v3.client.config.ClientConfig.java
/** * Does the actual work of reading the configuration from System * Properties and/or uddi.xml file. When the uddi.xml * file is updated the file will be reloaded. By default the reloadDelay is * set to 1 second to prevent excessive date stamp checking. *///from w w w . j a v a 2 s. c o m private void loadConfiguration(String configurationFile, Properties properties) throws ConfigurationException { //Properties from system properties CompositeConfiguration compositeConfig = new CompositeConfiguration(); compositeConfig.addConfiguration(new SystemConfiguration()); //Properties from XML file if (System.getProperty(UDDI_CONFIG_FILENAME_PROPERTY) != null) { log.info("Using system property config override"); configurationFile = System.getProperty(UDDI_CONFIG_FILENAME_PROPERTY); } XMLConfiguration xmlConfig = null; if (configurationFile != null) { xmlConfig = new XMLConfiguration(configurationFile); } else { final String filename = System.getProperty(UDDI_CONFIG_FILENAME_PROPERTY); if (filename != null) { xmlConfig = new XMLConfiguration(filename); } else { xmlConfig = new XMLConfiguration(DEFAULT_UDDI_CONFIG); } } log.info("Reading UDDI Client properties file " + xmlConfig.getBasePath() + " use -D" + UDDI_CONFIG_FILENAME_PROPERTY + " to override"); this.configurationFile = xmlConfig.getBasePath(); long refreshDelay = xmlConfig.getLong(Property.UDDI_RELOAD_DELAY, 1000l); log.debug("Setting refreshDelay to " + refreshDelay); FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy(); fileChangedReloadingStrategy.setRefreshDelay(refreshDelay); xmlConfig.setReloadingStrategy(fileChangedReloadingStrategy); compositeConfig.addConfiguration(xmlConfig); //Making the new configuration globally accessible. config = compositeConfig; readConfig(properties); }
From source file:org.apache.log.extractor.App.java
private void initConfiguration() throws ConfigurationException { CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); compositeConfiguration.addConfiguration(new SystemConfiguration()); compositeConfiguration.addConfiguration(new PropertiesConfiguration("logExtractor.properties")); config = compositeConfiguration;/*from w ww . ja v a2 s. com*/ }
From source file:org.apache.qpid.server.configuration.plugins.AbstractConfigurationTest.java
@Override public void setUp() throws Exception { // Test does not directly use the AppRegistry but the configured broker // is required for the correct ConfigurationPlugin processing super.setUp(); XMLConfiguration xmlconfig = new XMLConfiguration(); xmlconfig.addProperty("base.element[@property]", "property"); xmlconfig.addProperty("base.element.name", "name"); // We make these strings as that is how they will be read from the file. xmlconfig.addProperty("base.element.positiveLong", String.valueOf(POSITIVE_LONG)); xmlconfig.addProperty("base.element.negativeLong", String.valueOf(NEGATIVE_LONG)); xmlconfig.addProperty("base.element.boolean", String.valueOf(true)); xmlconfig.addProperty("base.element.double", String.valueOf(DOUBLE)); for (int i = 0; i < LIST_SIZE; i++) { xmlconfig.addProperty("base.element.list", i); }//from ww w .ja v a2 s. c o m //Use a composite configuration as this is what our broker code uses. CompositeConfiguration composite = new CompositeConfiguration(); composite.addConfiguration(xmlconfig); _plugin = new TestConfigPlugin(); try { _plugin.setConfiguration("base.element", composite.subset("base.element")); } catch (ConfigurationException e) { e.printStackTrace(); fail(e.toString()); } }
From source file:org.apache.qpid.server.configuration.QueueConfiguration.java
public QueueConfiguration(String name, VirtualHostConfiguration virtualHostConfiguration) throws ConfigurationException { _vHostConfig = virtualHostConfiguration; _name = name;//from www . j a v a 2s. com CompositeConfiguration mungedConf = new CompositeConfiguration(); mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues.queue." + escapeTagName(name))); mungedConf.addConfiguration(_vHostConfig.getConfig().subset("queues")); setConfiguration("virtualhosts.virtualhost.queues.queue", mungedConf); }
From source file:org.apache.qpid.server.configuration.QueueConfigurationTest.java
private VirtualHostConfiguration overrideConfiguration(String property, Object value) throws ConfigurationException { PropertiesConfiguration queueConfig = new PropertiesConfiguration(); queueConfig.setProperty("queues.queue.test." + property, value); CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(_fullHostConf.getConfig()); config.addConfiguration(queueConfig); return new VirtualHostConfiguration("test", config, _broker); }
From source file:org.apache.qpid.server.configuration.VirtualHostConfiguration.java
/** * Apply the given configuration to this VirtualHostConfiguration * * @param config the config to apply//from w w w . j a va 2 s . co m * @throws ConfigurationException if a problem occurs with configuration */ public void setConfiguration(Configuration config) throws ConfigurationException { setConfiguration("virtualhosts.virtualhost", config); Iterator i = getListValue("queues.queue.name").iterator(); while (i.hasNext()) { String queueName = (String) i.next(); _queues.put(queueName, new QueueConfiguration(queueName, this)); } i = getListValue("exchanges.exchange.name").iterator(); int count = 0; while (i.hasNext()) { CompositeConfiguration mungedConf = new CompositeConfiguration(); mungedConf.addConfiguration(config.subset("exchanges.exchange(" + count++ + ")")); mungedConf.addConfiguration(getConfig().subset("exchanges")); String exchName = (String) i.next(); _exchanges.put(exchName, new ExchangeConfiguration(exchName, mungedConf)); } }
From source file:org.apache.qpid.server.model.adapter.VirtualHostAdapter.java
private VirtualHostConfiguration createVirtualHostConfiguration(String virtualHostName) throws ConfigurationException { VirtualHostConfiguration configuration; String configurationFile = (String) getAttribute(CONFIG_PATH); if (configurationFile == null) { final MyConfiguration basicConfiguration = new MyConfiguration(); PropertiesConfiguration config = new PropertiesConfiguration(); config.addProperty("store.type", (String) getAttribute(STORE_TYPE)); config.addProperty("store.environment-path", (String) getAttribute(STORE_PATH)); basicConfiguration.addConfiguration(config); CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); compositeConfiguration.addConfiguration(new SystemConfiguration()); compositeConfiguration.addConfiguration(basicConfiguration); configuration = new VirtualHostConfiguration(virtualHostName, compositeConfiguration, _broker); } else {//ww w.j a va 2 s . c o m configuration = new VirtualHostConfiguration(virtualHostName, new File(configurationFile), _broker); } return configuration; }
From source file:org.apache.whirr.actions.BootstrapClusterActionTest.java
@SuppressWarnings("unchecked") @Test//w w w.j a v a 2 s. c o m public void testDoActionRetriesSucceed() 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 hadoop-namenode+hadoop-jobtracker,4 hadoop-datanode+hadoop-tasktracker"); conf.addProperty("whirr.instance-templates-max-percent-failures", "60 hadoop-datanode+hadoop-tasktracker"); conf.addProperty("whirr.provider", "ec2"); config.addConfiguration(conf); ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf); Set<String> jtnn = new HashSet<String>(); jtnn.add("hadoop-jobtracker"); jtnn.add("hadoop-namenode"); Set<String> dntt = new HashSet<String>(); dntt.add("hadoop-datanode"); dntt.add("hadoop-tasktracker"); TestNodeStarterFactory nodeStarterFactory = null; ClusterActionHandler handler = mock(ClusterActionHandler.class); LoadingCache<String, ClusterActionHandler> handlerMap = convertMapToLoadingCache( ImmutableMap.<String, ClusterActionHandler>builder().put("hadoop-jobtracker", handler) .put("hadoop-namenode", handler).put("hadoop-datanode", handler) .put("hadoop-tasktracker", handler).build()); 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); // here is a scenario when jt+nn fails once, then the retry is successful // and from the dn+tt one node fails, then the retry is successful Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap(); Stack<Integer> jtnnStack = new Stack<Integer>(); jtnnStack.push(1); // then ok jtnnStack.push(0); // initially fail reaction.put(jtnn, jtnnStack); Stack<Integer> ddttStack = new Stack<Integer>(); ddttStack.push(3); // 3 from 4, just enough reaction.put(dntt, ddttStack); 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.actions.BootstrapClusterActionTest.java
@SuppressWarnings("unchecked") @Test(expected = IOException.class) public void testDoActionRetriesExceeds() throws Exception { CompositeConfiguration config = new CompositeConfiguration(); if (System.getProperty("config") != null) { config.addConfiguration(new PropertiesConfiguration(System.getProperty("config"))); }/*from www. ja v a 2 s . com*/ Configuration conf = new PropertiesConfiguration(); conf.addProperty("whirr.service-name", "test-service"); conf.addProperty("whirr.cluster-name", "test-cluster"); conf.addProperty("whirr.instance-templates", "1 hadoop-namenode+hadoop-jobtracker,4 hadoop-datanode+hadoop-tasktracker"); conf.addProperty("whirr.instance-templates-max-percent-failures", "60 hadoop-datanode+hadoop-tasktracker"); conf.addProperty("whirr.provider", "ec2"); config.addConfiguration(conf); ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf); Set<String> jtnn = new HashSet<String>(); jtnn.add("hadoop-jobtracker"); jtnn.add("hadoop-namenode"); Set<String> dntt = new HashSet<String>(); dntt.add("hadoop-datanode"); dntt.add("hadoop-tasktracker"); TestNodeStarterFactory nodeStarterFactory = null; ClusterActionHandler handler = mock(ClusterActionHandler.class); LoadingCache<String, ClusterActionHandler> handlerMap = convertMapToLoadingCache( ImmutableMap.<String, ClusterActionHandler>builder().put("hadoop-jobtracker", handler) .put("hadoop-namenode", handler).put("hadoop-datanode", handler) .put("hadoop-tasktracker", handler).build()); 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); // here is a scenario when jt+nn does not fail // but the dn+tt one node fails 3, then in the retry fails 2 // at the end result, the cluster will fail, throwing IOException Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap(); Stack<Integer> jtnnStack = new Stack<Integer>(); jtnnStack.push(new Integer(1)); reaction.put(jtnn, jtnnStack); Stack<Integer> ddttStack = new Stack<Integer>(); ddttStack.push(new Integer(1)); // 1 from 4, retryRequired ddttStack.push(new Integer(1)); // 1 from 4, still retryRequired reaction.put(dntt, ddttStack); nodeStarterFactory = new TestNodeStarterFactory(reaction); BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap, nodeStarterFactory); bootstrapper.execute(clusterSpec, null); // this should file with too many retries if (nodeStarterFactory != null) { nodeStarterFactory.validateCompletion(); } }
From source file:org.apache.whirr.actions.BootstrapClusterActionTest.java
@Test @SuppressWarnings("unchecked") public void testSubroleInvoked() throws Exception { CompositeConfiguration config = new CompositeConfiguration(); if (System.getProperty("config") != null) { config.addConfiguration(new PropertiesConfiguration(System.getProperty("config"))); }//from ww w . java 2 s. c o m 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(puppetHandlerFactory.create("module::manifest")).thenReturn(handler); 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(new Integer(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(); } }