List of usage examples for org.apache.commons.configuration Configuration setProperty
void setProperty(String key, Object value);
From source file:org.apache.whirr.ClusterSpecTest.java
@Test(expected = ConfigurationException.class) public void testBrokenPublicKey() throws IOException, JSchException, ConfigurationException { File privateKey = KeyPair.generateTemporaryFiles().get("private"); File publicKey = File.createTempFile("public", "key"); publicKey.deleteOnExit();/* www.j a v a 2s . c o m*/ Files.write("ssh-rsa BROKEN PUBLIC KEY".getBytes(), publicKey); Configuration conf = new PropertiesConfiguration(); conf.setProperty("whirr.private-key-file", privateKey.getAbsolutePath()); conf.setProperty("whirr.public-key-file", publicKey.getAbsolutePath()); ClusterSpec.withNoDefaults(conf); }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test(expected = ConfigurationException.class) public void testNotSameKeyPair() throws JSchException, IOException, ConfigurationException { Map<String, File> first = KeyPair.generateTemporaryFiles(); Map<String, File> second = KeyPair.generateTemporaryFiles(); Configuration conf = new PropertiesConfiguration(); conf.setProperty("whirr.private-key-file", first.get("private").getAbsolutePath()); conf.setProperty("whirr.public-key-file", second.get("public").getAbsolutePath()); ClusterSpec.withNoDefaults(conf);// ww w.j a va 2 s.c o m }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test(expected = IllegalArgumentException.class) public void testMissingCommaInInstanceTemplates() throws Exception { Configuration conf = new PropertiesConfiguration(); conf.setProperty(ClusterSpec.Property.INSTANCE_TEMPLATES.getConfigName(), "1 a+b 2 c+d"); // missing comma ClusterSpec.withTemporaryKeys(conf); }
From source file:org.apache.whirr.ClusterSpecTest.java
@Test public void testNumberOfInstancesPerTemplate() throws Exception { Configuration conf = new PropertiesConfiguration(); conf.addProperty("whirr.instance-templates", "1 hadoop-namenode+hadoop-jobtracker,3 hadoop-datanode+hadoop-tasktracker"); conf.addProperty("whirr.instance-templates-max-percent-failures", "100 hadoop-namenode+hadoop-jobtracker,60 hadoop-datanode+hadoop-tasktracker"); ClusterSpec expectedClusterSpec = ClusterSpec.withNoDefaults(conf); List<InstanceTemplate> templates = expectedClusterSpec.getInstanceTemplates(); InstanceTemplate t1 = templates.get(0); assertThat(t1.getMinNumberOfInstances(), is(1)); InstanceTemplate t2 = templates.get(1); assertThat(t2.getMinNumberOfInstances(), is(2)); conf.setProperty("whirr.instance-templates-max-percent-failures", "60 hadoop-datanode+hadoop-tasktracker"); expectedClusterSpec = ClusterSpec.withNoDefaults(conf); templates = expectedClusterSpec.getInstanceTemplates(); t1 = templates.get(0);/*from w w w . j a v a 2 s . co m*/ assertThat(t1.getMinNumberOfInstances(), is(1)); t2 = templates.get(1); assertThat(t2.getMinNumberOfInstances(), is(2)); conf.addProperty("whirr.instance-templates-minumum-number-of-instances", "1 hadoop-datanode+hadoop-tasktracker"); expectedClusterSpec = ClusterSpec.withNoDefaults(conf); templates = expectedClusterSpec.getInstanceTemplates(); t1 = templates.get(0); assertThat(t1.getMinNumberOfInstances(), is(1)); t2 = templates.get(1); assertThat(t2.getMinNumberOfInstances(), is(2)); conf.setProperty("whirr.instance-templates-minimum-number-of-instances", "3 hadoop-datanode+hadoop-tasktracker"); expectedClusterSpec = ClusterSpec.withNoDefaults(conf); templates = expectedClusterSpec.getInstanceTemplates(); t1 = templates.get(0); assertThat(t1.getMinNumberOfInstances(), is(1)); t2 = templates.get(1); assertThat(t2.getMinNumberOfInstances(), is(3)); }
From source file:org.apache.whirr.command.AbstractClusterCommand.java
/** * Load the cluster spec by parsing the command line option set *//*from w ww . j a va2 s . co m*/ 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(); Object value; if (property.hasMultipleArguments()) { value = optionSet.valuesOf(option); } else { value = optionSet.valueOf(option); } if (value != null) { optionsConfig.setProperty(property.getConfigName(), value); } } CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(optionsConfig); if (optionSet.has(configOption)) { Configuration defaults = new PropertiesConfiguration(optionSet.valueOf(configOption)); config.addConfiguration(defaults); } ClusterSpec clusterSpec = new ClusterSpec(config); for (Property required : EnumSet.of(CLUSTER_NAME, PROVIDER, IDENTITY, CREDENTIAL, INSTANCE_TEMPLATES, PRIVATE_KEY_FILE)) { if (clusterSpec.getConfiguration().getString(required.getConfigName()) == null) { throw new IllegalArgumentException(String.format("Option '%s' not set.", required.getSimpleName())); } } return clusterSpec; }
From source file:org.apache.whirr.service.accumulo.AccumuloConfigurationBuilder.java
static Configuration buildAccumuloSiteConfiguration(ClusterSpec clusterSpec, Cluster cluster, Configuration defaults) throws ConfigurationException, IOException { Configuration config = build(clusterSpec, cluster, defaults, "accumulo-site"); config.setProperty("instance.zookeeper.host", ZooKeeperCluster.getHosts(cluster)); return config; }
From source file:org.apache.whirr.service.BaseServiceDryRunTest.java
protected ClusterSpec newClusterSpecForProperties(Map<String, String> properties) throws ConfigurationException, JSchException, IOException { Configuration config = new PropertiesConfiguration(); config.setProperty("whirr.provider", "stub"); config.setProperty("whirr.cluster-name", "stub-test"); config.setProperty("whirr.state-store", "memory"); for (Entry<String, String> entry : properties.entrySet()) config.setProperty(entry.getKey(), entry.getValue()); // we don't want to create files return new ClusterSpec(config) { @Override/*from w ww . j ava 2 s . com*/ protected void checkAndSetKeyPair() { setPrivateKey("-----BEGIN RSA PRIVATE KEY-----"); setPublicKey("ssh-rsa AAAAB3NzaC1yc2EA"); } }; }
From source file:org.apache.whirr.service.hadoop.HadoopConfigurationBuilder.java
@VisibleForTesting static Configuration buildCommonConfiguration(ClusterSpec clusterSpec, Cluster cluster, Configuration defaults) throws ConfigurationException, IOException { Configuration config = build(clusterSpec, cluster, defaults, "hadoop-common"); Instance namenode = cluster.getInstanceMatching(role(HadoopNameNodeClusterActionHandler.ROLE)); LOG.debug("hadoop building common configuration, with hostname " + namenode.getPublicHostName()); config.setProperty("fs.default.name", String.format("hdfs://%s:8020/", namenode.getPublicHostName())); return config; }
From source file:org.apache.whirr.service.hadoop.HadoopConfigurationBuilder.java
@VisibleForTesting static Configuration buildMapReduceConfiguration(ClusterSpec clusterSpec, Cluster cluster, Configuration defaults) throws ConfigurationException, IOException { Configuration config = build(clusterSpec, cluster, defaults, "hadoop-mapreduce"); Set<Instance> taskTrackers = cluster.getInstancesMatching(role(HadoopTaskTrackerClusterActionHandler.ROLE)); if (!taskTrackers.isEmpty()) { Hardware hardware = Iterables.getFirst(taskTrackers, null).getNodeMetadata().getHardware(); /* null when using the BYON jclouds compute provider */ if (hardware != null) { int coresPerNode = 0; for (Processor processor : hardware.getProcessors()) { coresPerNode += processor.getCores(); }//from w ww . j a va 2 s . co m int mapTasksPerNode = (int) Math.ceil(coresPerNode * 1.0); int reduceTasksPerNode = (int) Math.ceil(coresPerNode * 0.75); setIfAbsent(config, "mapred.tasktracker.map.tasks.maximum", mapTasksPerNode + ""); setIfAbsent(config, "mapred.tasktracker.reduce.tasks.maximum", reduceTasksPerNode + ""); int clusterReduceSlots = taskTrackers.size() * reduceTasksPerNode; setIfAbsent(config, "mapred.reduce.tasks", clusterReduceSlots + ""); } } Set<Instance> jobtracker = cluster.getInstancesMatching(role(HadoopJobTrackerClusterActionHandler.ROLE)); if (!jobtracker.isEmpty()) { config.setProperty("mapred.job.tracker", String.format("%s:8021", Iterables.getOnlyElement(jobtracker).getPublicHostName())); } return config; }
From source file:org.apache.whirr.service.hadoop.HadoopConfigurationBuilder.java
private static void setIfAbsent(Configuration config, String property, String value) { if (!config.containsKey(property)) { config.setProperty(property, value); }//from ww w . j av a 2 s . c o m }