Author: asavu
Date: Thu Dec 29 21:50:15 2011
New Revision: 1225666
URL: http://svn.apache.org/viewvc?rev=1225666&view=rev
Log:
WHIRR-458. Remove deprecated code and aliasing mechanism (asavu)
Added:
whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallManagerTest.java
Removed:
whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/FirewallSettings.java
whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallSettingsTest.java
Modified:
whirr/trunk/CHANGES.txt
whirr/trunk/core/src/main/java/org/apache/whirr/InstanceTemplate.java
whirr/trunk/core/src/main/java/org/apache/whirr/service/FirewallManager.java
whirr/trunk/core/src/test/java/org/apache/whirr/ClusterSpecTest.java
whirr/trunk/core/src/test/java/org/apache/whirr/actions/BootstrapClusterActionTest.java
Modified: whirr/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/whirr/trunk/CHANGES.txt?rev=1225666&r1=1225665&r2=1225666&view=diff
==============================================================================
--- whirr/trunk/CHANGES.txt (original)
+++ whirr/trunk/CHANGES.txt Thu Dec 29 21:50:15 2011
@@ -9,6 +9,8 @@ Trunk (unreleased changes)
WHIRR-457. Upgrade to jclouds 1.2.2 (asavu)
+ WHIRR-458. Remove deprecated code and aliasing mechanism (asavu)
+
Release 0.7.0 - 2011-12-11
NEW FEATURES
Modified: whirr/trunk/core/src/main/java/org/apache/whirr/InstanceTemplate.java
URL:
http://svn.apache.org/viewvc/whirr/trunk/core/src/main/java/org/apache/whirr/InstanceTemplate.java?rev=1225666&r1=1225665&r2=1225666&view=diff
==============================================================================
--- whirr/trunk/core/src/main/java/org/apache/whirr/InstanceTemplate.java
(original)
+++ whirr/trunk/core/src/main/java/org/apache/whirr/InstanceTemplate.java Thu
Dec 29 21:50:15 2011
@@ -24,7 +24,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -39,22 +38,8 @@ import org.slf4j.LoggerFactory;
* This is done by specifying the number of instances in each role.
*/
public class InstanceTemplate {
- private static Map<String, String> aliases = new HashMap<String, String>();
private static final Logger LOG =
LoggerFactory.getLogger(InstanceTemplate.class);
- static {
- /*
- * WARNING: this is not a generic aliasing mechanism. This code
- * should be removed in the following releases and it's
- * used only temporary to deprecate short legacy role names.
- */
- aliases.put("nn", "hadoop-namenode");
- aliases.put("jt", "hadoop-jobtracker");
- aliases.put("dn", "hadoop-datanode");
- aliases.put("tt", "hadoop-tasktracker");
- aliases.put("zk", "zookeeper");
- }
-
private Set<String> roles;
private int numberOfInstances;
private int minNumberOfInstances; // some instances may fail, at least a
minimum number is required
@@ -77,25 +62,11 @@ public class InstanceTemplate {
"Role '%s' may not contain space characters.", role);
}
- this.roles = replaceAliases(roles);
+ this.roles = roles;
this.numberOfInstances = numberOfInstances;
this.minNumberOfInstances = minNumberOfInstances;
}
- private static Set<String> replaceAliases(Set<String> roles) {
- Set<String> newRoles = Sets.newLinkedHashSet();
- for(String role : roles) {
- if (aliases.containsKey(role)) {
- LOG.warn("Role name '{}' is deprecated, use '{}'",
- role, aliases.get(role));
- newRoles.add(aliases.get(role));
- } else {
- newRoles.add(role);
- }
- }
- return newRoles;
- }
-
public Set<String> getRoles() {
return roles;
}
@@ -132,7 +103,6 @@ public class InstanceTemplate {
public static Map<String, String> parse(String... strings) {
Set<String> roles = Sets.newLinkedHashSet(Lists.newArrayList(strings));
- roles = replaceAliases(roles);
Map<String, String> templates = Maps.newHashMap();
for (String s : roles) {
String[] parts = s.split(" ");
Modified:
whirr/trunk/core/src/main/java/org/apache/whirr/service/FirewallManager.java
URL:
http://svn.apache.org/viewvc/whirr/trunk/core/src/main/java/org/apache/whirr/service/FirewallManager.java?rev=1225666&r1=1225665&r2=1225666&view=diff
==============================================================================
---
whirr/trunk/core/src/main/java/org/apache/whirr/service/FirewallManager.java
(original)
+++
whirr/trunk/core/src/main/java/org/apache/whirr/service/FirewallManager.java
Thu Dec 29 21:50:15 2011
@@ -19,15 +19,20 @@
package org.apache.whirr.service;
import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
import java.util.Collections;
import java.util.List;
import java.util.Set;
+import org.apache.commons.io.IOUtils;
import org.apache.whirr.Cluster;
import org.apache.whirr.ClusterSpec;
import org.apache.whirr.Cluster.Instance;
-import org.apache.whirr.service.jclouds.FirewallSettings;
+import org.jclouds.aws.util.AWSUtils;
import org.jclouds.compute.ComputeServiceContext;
+import org.jclouds.ec2.EC2Client;
+import org.jclouds.ec2.domain.IpProtocol;
import org.jclouds.javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -156,7 +161,7 @@ public class FirewallManager {
if (rule.source == null) {
cidrs = clusterSpec.getClientCidrs();
if (cidrs == null || cidrs.isEmpty()) {
- cidrs = Lists.newArrayList(FirewallSettings.getOriginatingIp());
+ cidrs = Lists.newArrayList(getOriginatingIp());
}
} else {
cidrs = Lists.newArrayList(rule.source + "/32");
@@ -173,8 +178,45 @@ public class FirewallManager {
LOG.info("Authorizing firewall ingress to {} on ports {} for {}",
new Object[] { instanceIds, rule.ports, cidrs });
- FirewallSettings.authorizeIngress(computeServiceContext, instances,
+ authorizeIngress(computeServiceContext, instances,
clusterSpec, cidrs, rule.ports);
}
+ /**
+ * @return the IP address of the client on which this code is running.
+ * @throws IOException
+ */
+ private String getOriginatingIp() throws IOException {
+ URL url = new URL("http://checkip.amazonaws.com/");
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.connect();
+ return IOUtils.toString(connection.getInputStream()).trim() + "/32";
+ }
+
+ public static void authorizeIngress(ComputeServiceContext
computeServiceContext,
+ Set<Instance> instances, ClusterSpec clusterSpec, List<String> cidrs,
int... ports) {
+
+ if (computeServiceContext.getProviderSpecificContext().getApi() instanceof
+ EC2Client) {
+ // This code (or something like it) may be added to jclouds (see
+ // http://code.google.com/p/jclouds/issues/detail?id=336).
+ // Until then we need this temporary workaround.
+ String region = AWSUtils.parseHandle(Iterables.get(instances,
0).getId())[0];
+ EC2Client ec2Client = EC2Client.class.cast(
+ computeServiceContext.getProviderSpecificContext().getApi());
+ String groupName = "jclouds#" + clusterSpec.getClusterName() + "#" +
region;
+ for (String cidr : cidrs) {
+ for (int port : ports) {
+ try {
+ ec2Client.getSecurityGroupServices()
+ .authorizeSecurityGroupIngressInRegion(region, groupName,
+ IpProtocol.TCP, port, port, cidr);
+ } catch(IllegalStateException e) {
+ LOG.warn(e.getMessage());
+ /* ignore, it means that this permission was already granted */
+ }
+ }
+ }
+ }
+ }
}
Modified: whirr/trunk/core/src/test/java/org/apache/whirr/ClusterSpecTest.java
URL:
http://svn.apache.org/viewvc/whirr/trunk/core/src/test/java/org/apache/whirr/ClusterSpecTest.java?rev=1225666&r1=1225665&r2=1225666&view=diff
==============================================================================
--- whirr/trunk/core/src/test/java/org/apache/whirr/ClusterSpecTest.java
(original)
+++ whirr/trunk/core/src/test/java/org/apache/whirr/ClusterSpecTest.java Thu
Dec 29 21:50:15 2011
@@ -213,19 +213,6 @@ public class ClusterSpecTest {
new InstanceTemplate(1, "a b");
}
- @Test
- public void testApplyRoleAliases() {
- CompositeConfiguration c = new CompositeConfiguration();
- Configuration config = new PropertiesConfiguration();
- config.addProperty("whirr.instance-templates", "1 nn+jt+tt+dn+zk");
- c.addConfiguration(config);
- InstanceTemplate template = InstanceTemplate.parse(c).get(0);
- Set<String> expected = Sets.newLinkedHashSet(Arrays.asList(new String[]{
- "hadoop-namenode", "hadoop-jobtracker", "hadoop-tasktracker",
- "hadoop-datanode", "zookeeper"}));
- assertThat(template.getRoles(), is(expected));
- }
-
@Test(expected = IllegalArgumentException.class)
public void testIllegalArgumentExceptionOnInstancesTemplates() throws
Exception {
Configuration conf = new PropertiesConfiguration();
Modified:
whirr/trunk/core/src/test/java/org/apache/whirr/actions/BootstrapClusterActionTest.java
URL:
http://svn.apache.org/viewvc/whirr/trunk/core/src/test/java/org/apache/whirr/actions/BootstrapClusterActionTest.java?rev=1225666&r1=1225665&r2=1225666&view=diff
==============================================================================
---
whirr/trunk/core/src/test/java/org/apache/whirr/actions/BootstrapClusterActionTest.java
(original)
+++
whirr/trunk/core/src/test/java/org/apache/whirr/actions/BootstrapClusterActionTest.java
Thu Dec 29 21:50:15 2011
@@ -87,8 +87,8 @@ public class BootstrapClusterActionTest
Configuration conf = new PropertiesConfiguration();
conf.addProperty("whirr.service-name", "test-service");
conf.addProperty("whirr.cluster-name", "test-cluster");
- conf.addProperty("whirr.instance-templates", "1 jt+nn,4 dn+tt");
- conf.addProperty("whirr.instance-templates-max-percent-failures", "60
dn+tt");
+ 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);
@@ -125,11 +125,11 @@ public class BootstrapClusterActionTest
// 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(new Integer(1)); // then ok
- jtnnStack.push(new Integer(0)); // initially fail
+ jtnnStack.push(1); // then ok
+ jtnnStack.push(0); // initially fail
reaction.put(jtnn, jtnnStack);
Stack<Integer> ddttStack = new Stack<Integer>();
- ddttStack.push(new Integer(3)); // 3 from 4, just enough
+ ddttStack.push(3); // 3 from 4, just enough
reaction.put(dntt, ddttStack);
nodeStarterFactory = new TestNodeStarterFactory(reaction);
@@ -152,8 +152,8 @@ public class BootstrapClusterActionTest
Configuration conf = new PropertiesConfiguration();
conf.addProperty("whirr.service-name", "test-service");
conf.addProperty("whirr.cluster-name", "test-cluster");
- conf.addProperty("whirr.instance-templates", "1 jt+nn,4 dn+tt");
- conf.addProperty("whirr.instance-templates-max-percent-failures", "60
dn+tt");
+ 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);
Added:
whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallManagerTest.java
URL:
http://svn.apache.org/viewvc/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallManagerTest.java?rev=1225666&view=auto
==============================================================================
---
whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallManagerTest.java
(added)
+++
whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallManagerTest.java
Thu Dec 29 21:50:15 2011
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.whirr.service.jclouds.integration;
+
+import com.google.common.collect.Sets;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.whirr.Cluster;
+import org.apache.whirr.ClusterSpec;
+import org.apache.whirr.service.ComputeCache;
+import org.apache.whirr.service.FirewallManager;
+import org.jclouds.compute.ComputeServiceContext;
+import org.jclouds.domain.Credentials;
+import org.jclouds.ec2.EC2Client;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Set;
+
+import static org.apache.whirr.service.FirewallManager.Rule;
+
+public class FirewallManagerTest {
+
+ private final String region = "us-east-1";
+
+ private ClusterSpec clusterSpec;
+ private Set<Cluster.Instance> instances;
+
+ private ComputeServiceContext context;
+ private FirewallManager manager;
+
+ private ClusterSpec getTestClusterSpec() throws Exception {
+ return ClusterSpec.withTemporaryKeys(
+ new PropertiesConfiguration("whirr-core-test.properties"));
+ }
+
+ @Before
+ public void setUpClass() throws Exception {
+ clusterSpec = getTestClusterSpec();
+ context = ComputeCache.INSTANCE.apply(clusterSpec);
+
+ /* create a dummy instance for testing */
+ instances = Sets.newHashSet(new Cluster.Instance(
+ new Credentials("dummy", "dummy"),
+ Sets.newHashSet("dummy-role"),
+ "50.0.0.1",
+ "10.0.0.1",
+ region + "/i-dummy",
+ null
+ ));
+
+ manager = new FirewallManager(context, clusterSpec, new
Cluster(instances));
+ }
+
+ @Test
+ public void testFirewallAuthorizationIsIdempotent() throws IOException {
+ if (context.getProviderSpecificContext().getApi() instanceof EC2Client) {
+ EC2Client ec2Client = EC2Client.class.cast(
+ context.getProviderSpecificContext().getApi());
+ String groupName = "jclouds#" + clusterSpec.getClusterName() + "#" +
region;
+
+ ec2Client.getSecurityGroupServices()
+ .createSecurityGroupInRegion(region, groupName, "group description");
+ try {
+ manager.addRule(
+ Rule.create().destination(instances).port(23344)
+ );
+
+ /* The second call should not throw an exception. */
+ manager.addRule(
+ Rule.create().destination(instances).port(23344)
+ );
+
+ } finally {
+ ec2Client.getSecurityGroupServices()
+ .deleteSecurityGroupInRegion(region, groupName);
+ }
+ }
+ }
+
+}