List of usage examples for org.apache.commons.configuration Configuration getStringArray
String[] getStringArray(String key);
From source file:org.apache.servicecomb.serviceregistry.api.registry.TestMicroserviceFactory.java
@Test public void testSetDescriptionOnNullDescription() { Microservice microservice = new Microservice(); MicroserviceFactory factory = new MicroserviceFactory(); Configuration configuration = Mockito.mock(Configuration.class); Mockito.when(configuration.getStringArray(CONFIG_QUALIFIED_MICROSERVICE_DESCRIPTION_KEY)).thenReturn(null); Deencapsulation.invoke(factory, "setDescription", configuration, microservice); Assert.assertNull(microservice.getDescription()); Mockito.when(configuration.getStringArray(CONFIG_QUALIFIED_MICROSERVICE_DESCRIPTION_KEY)) .thenReturn(new String[] {}); Deencapsulation.invoke(factory, "setDescription", configuration, microservice); Assert.assertNull(microservice.getDescription()); }
From source file:org.apache.servicecomb.serviceregistry.api.registry.TestMicroserviceFactory.java
@Test public void testSetDescriptionOnEmptyDescription() { Microservice microservice = new Microservice(); MicroserviceFactory factory = new MicroserviceFactory(); Configuration configuration = Mockito.mock(Configuration.class); Mockito.when(configuration.getStringArray(CONFIG_QUALIFIED_MICROSERVICE_DESCRIPTION_KEY)) .thenReturn(new String[] { "", "" }); Deencapsulation.invoke(factory, "setDescription", configuration, microservice); Assert.assertEquals(",", microservice.getDescription()); }
From source file:org.apache.servicecomb.serviceregistry.api.registry.TestMicroserviceFactory.java
@Test public void testSetDescriptionOnBlankDescription() { Microservice microservice = new Microservice(); MicroserviceFactory factory = new MicroserviceFactory(); Configuration configuration = Mockito.mock(Configuration.class); Mockito.when(configuration.getStringArray(CONFIG_QUALIFIED_MICROSERVICE_DESCRIPTION_KEY)) .thenReturn(new String[] { " ", " " }); Deencapsulation.invoke(factory, "setDescription", configuration, microservice); Assert.assertEquals(" , ", microservice.getDescription()); }
From source file:org.apache.whirr.InstanceTemplate.java
public static List<InstanceTemplate> parse(Configuration configuration) throws ConfigurationException { final String[] instanceTemplates = configuration .getStringArray(ClusterSpec.Property.INSTANCE_TEMPLATES.getConfigName()); List<InstanceTemplate> templates = newArrayList(); for (String s : instanceTemplates) { String[] parts = s.split(" "); checkArgument(parts.length == 2, "Invalid instance template syntax for '%s'. Does not match " + "'<number> <role1>+<role2>+<role3>...', e.g. '1 hadoop-namenode+hadoop-jobtracker'.", s);/*ww w . j a v a 2 s. c o m*/ int numberOfInstances = Integer.parseInt(parts[0]); String templateGroup = parts[1]; InstanceTemplate.Builder templateBuilder = InstanceTemplate.builder() .numberOfInstance(numberOfInstances).roles(templateGroup.split("\\+")).minNumberOfInstances( parseMinNumberOfInstances(configuration, templateGroup, numberOfInstances)); parseInstanceTemplateGroupOverrides(configuration, templateGroup, templateBuilder); templates.add(templateBuilder.build()); } validateThatWeHaveNoOtherOverrides(templates, configuration); return templates; }
From source file:org.apache.whirr.InstanceTemplate.java
private static int parseMinNumberOfInstances(Configuration configuration, String templateGroup, int numberOfInstances) { Map<String, String> maxPercentFailures = parse(configuration .getStringArray(ClusterSpec.Property.INSTANCE_TEMPLATES_MAX_PERCENT_FAILURES.getConfigName())); Map<String, String> minInstances = parse(configuration.getStringArray( ClusterSpec.Property.INSTANCE_TEMPLATES_MINIMUM_NUMBER_OF_INSTANCES.getConfigName())); int minNumberOfInstances = 0; String maxPercentFail = maxPercentFailures.get(templateGroup); if (maxPercentFail != null) { // round up integer division (a + b -1) / b minNumberOfInstances = (Integer.parseInt(maxPercentFail) * numberOfInstances + 99) / 100; }/*from w ww . j a v a 2 s . c o m*/ String minNumberOfInst = minInstances.get(templateGroup); if (minNumberOfInst != null) { int minExplicitlySet = Integer.parseInt(minNumberOfInst); if (minNumberOfInstances > 0) { // maximum between two minims minNumberOfInstances = Math.max(minNumberOfInstances, minExplicitlySet); } else { minNumberOfInstances = minExplicitlySet; } } if (minNumberOfInstances == 0 || minNumberOfInstances > numberOfInstances) { minNumberOfInstances = numberOfInstances; } return minNumberOfInstances; }
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.ElasticSearchHandler.java
@Override protected void beforeConfigure(ClusterActionEvent event) throws IOException { ClusterSpec spec = event.getClusterSpec(); Cluster cluster = event.getCluster(); event.getFirewallManager().addRule(/*from w ww. ja v a2 s. c o m*/ Rule.create().destination(cluster.getInstancesMatching(role(ROLE))).port(HTTP_CLIENT_PORT)); Configuration config = ElasticSearchConfigurationBuilder.buildConfig(spec, cluster); addStatement(event, ElasticSearchConfigurationBuilder.build("/tmp/elasticsearch.yml", config)); addStatement(event, call("configure_elasticsearch", config.getStringArray("es.plugins"))); }
From source file:org.apache.whirr.service.hadoop.HadoopConfigurationConverter.java
@VisibleForTesting static List<String> asXmlConfigurationLines(Configuration hadoopConfig) { List<String> lines = Lists.newArrayList(); lines.add("<configuration>"); for (@SuppressWarnings("unchecked") Iterator<String> it = hadoopConfig.getKeys(); it.hasNext();) { String key = it.next();//from ww w. j a v a2 s . c o m if (key.endsWith(FINAL_SUFFIX)) { continue; } // rebuild the original value by joining all of them with the default separator String value = StringUtils.join(hadoopConfig.getStringArray(key), AbstractConfiguration.getDefaultListDelimiter()); lines.add(" <property>"); lines.add(String.format(" <name>%s</name>", key)); lines.add(String.format(" <value>%s</value>", value)); String finalValue = hadoopConfig.getString(key + FINAL_SUFFIX); if (finalValue != null) { lines.add(String.format(" <final>%s</final>", finalValue)); } lines.add(" </property>"); } lines.add("</configuration>"); return lines; }
From source file:org.apache.wookie.ajaxmodel.impl.WidgetAPIImpl.java
public Map<String, Object> getCouplingWidgetAttributes(IWidgetInstance widgetInstance, HttpServletRequest request) {// www.jav a2 s . c o m Configuration properties = (Configuration) request.getSession().getServletContext() .getAttribute("properties"); String[] couplingAttributes = properties.getStringArray("widget.iwc.coupling"); Map<String, Object> couplingWidgetAttributes = new HashMap<String, Object>(); for (String attribute : couplingAttributes) { if (attribute.equals("sharedDataKey")) { couplingWidgetAttributes.put(attribute, widgetInstance.getSharedDataKey()); } else if (attribute.equals("apiKey")) { couplingWidgetAttributes.put(attribute, widgetInstance.getApiKey()); } else if (attribute.equals("idKey")) { couplingWidgetAttributes.put(attribute, widgetInstance.getIdKey()); } else if (attribute.equals("userId")) { couplingWidgetAttributes.put(attribute, widgetInstance.getUserId()); } // add more criteria if needed } return couplingWidgetAttributes; }
From source file:org.apache.wookie.server.ContextListener.java
/** * Starts a watcher thread for hot-deploy of new widgets dropped into the deploy folder * this is controlled using the <code>widget.hot_deploy=true|false</code> property * and configured to look in the folder specified by the <code>widget.deployfolder</code> property * @param context the current servlet context * @param configuration the configuration properties *///ww w . ja v a2s . c om private void startWatcher(ServletContext context, Configuration configuration, final Messages localizedMessages) { /* * Start watching for widget deployment */ final File deploy = new File(WidgetPackageUtils .convertPathToPlatform(context.getRealPath(configuration.getString("widget.deployfolder")))); final String UPLOADFOLDER = context.getRealPath(configuration.getString("widget.useruploadfolder")); final String WIDGETFOLDER = context.getRealPath(configuration.getString("widget.widgetfolder")); final String localWidgetFolderPath = configuration.getString("widget.widgetfolder"); final String[] locales = configuration.getStringArray("widget.locales"); final String contextPath = context.getContextPath(); Thread thr = new Thread() { public void run() { int interval = 5000; WgtWatcher watcher = new WgtWatcher(); watcher.setWatchDir(deploy); watcher.setListener(new WgtWatcher.FileChangeListener() { public void fileModified(File f) { // get persistence manager for this thread IPersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager(); try { persistenceManager.begin(); File upload = WidgetFileUtils.dealWithDroppedFile(UPLOADFOLDER, f); W3CWidgetFactory fac = new W3CWidgetFactory(); fac.setLocales(locales); fac.setLocalPath(contextPath + localWidgetFolderPath); fac.setOutputDirectory(WIDGETFOLDER); fac.setFeatures(persistenceManager.findServerFeatureNames()); fac.setStartPageProcessor(new StartPageProcessor()); W3CWidget model = fac.parse(upload); WidgetJavascriptSyntaxAnalyzer jsa = new WidgetJavascriptSyntaxAnalyzer( fac.getUnzippedWidgetDirectory()); if (persistenceManager.findWidgetByGuid(model.getIdentifier()) == null) { WidgetFactory.addNewWidget(model, true); String message = model.getLocalName("en") + "' - " + localizedMessages.getString("WidgetAdminServlet.19"); _logger.info(message); FlashMessage.getInstance().message(message); } else { String message = model.getLocalName("en") + "' - " + localizedMessages.getString("WidgetAdminServlet.20"); _logger.info(message); FlashMessage.getInstance().message(message); } persistenceManager.commit(); } catch (IOException e) { persistenceManager.rollback(); String error = f.getName() + ":" + localizedMessages.getString("WidgetHotDeploy.1"); FlashMessage.getInstance().error(error); _logger.error(error); } catch (BadWidgetZipFileException e) { persistenceManager.rollback(); String error = f.getName() + ":" + localizedMessages.getString("WidgetHotDeploy.2"); FlashMessage.getInstance().error(error); _logger.error(error); } catch (BadManifestException e) { persistenceManager.rollback(); String error = f.getName() + ":" + localizedMessages.getString("WidgetHotDeploy.3"); FlashMessage.getInstance().error(error); _logger.error(error); } catch (Exception e) { persistenceManager.rollback(); String error = f.getName() + ":" + e.getLocalizedMessage(); FlashMessage.getInstance().error(error); _logger.error(error); } finally { // close thread persistence manager PersistenceManagerFactory.closePersistenceManager(); } } public void fileRemoved(File f) { // Not implemented - the .wgt files are removed as part of the deployment process } }); try { while (true) { watcher.check(); Thread.sleep(interval); } } catch (InterruptedException iex) { } } }; thr.start(); }