You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whirr.apache.org by as...@apache.org on 2011/06/03 00:13:47 UTC
svn commit: r1130851 - in /incubator/whirr/trunk: ./
core/src/main/java/org/apache/whirr/service/jclouds/
core/src/test/java/org/apache/whirr/service/jclouds/integration/
Author: asavu
Date: Thu Jun 2 22:13:46 2011
New Revision: 1130851
URL: http://svn.apache.org/viewvc?rev=1130851&view=rev
Log:
WHIRR-249. Firewall authorization should be idempotent (asavu)
Added:
incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/
incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallSettingsTest.java (with props)
Modified:
incubator/whirr/trunk/CHANGES.txt
incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/FirewallSettings.java
Modified: incubator/whirr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/CHANGES.txt?rev=1130851&r1=1130850&r2=1130851&view=diff
==============================================================================
--- incubator/whirr/trunk/CHANGES.txt (original)
+++ incubator/whirr/trunk/CHANGES.txt Thu Jun 2 22:13:46 2011
@@ -15,6 +15,8 @@ Trunk (unreleased changes)
WHIRR-315. Temporary override Providers#withIds until jclouds
beta-10 is out (asavu and Adrian Cole)
+ WHIRR-249. Firewall authorization should be idempotent (asavu)
+
Release 0.5.0 - 2011-05-16
INCOMPATIBLE CHANGES
Modified: incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/FirewallSettings.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/FirewallSettings.java?rev=1130851&r1=1130850&r2=1130851&view=diff
==============================================================================
--- incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/FirewallSettings.java (original)
+++ incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/FirewallSettings.java Thu Jun 2 22:13:46 2011
@@ -35,6 +35,8 @@ import org.jclouds.aws.util.AWSUtils;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.domain.IpProtocol;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utility functions for controlling firewall settings for a cluster.
@@ -42,6 +44,8 @@ import org.jclouds.ec2.domain.IpProtocol
*/
@Deprecated
public class FirewallSettings {
+
+ private static final Logger LOG = LoggerFactory.getLogger(FirewallSettings.class);
/**
* @return the IP address of the client on which this code is running.
@@ -91,9 +95,14 @@ public class FirewallSettings {
String groupName = "jclouds#" + clusterSpec.getClusterName() + "#" + region;
for (String cidr : cidrs) {
for (int port : ports) {
- ec2Client.getSecurityGroupServices()
- .authorizeSecurityGroupIngressInRegion(region, groupName,
+ 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 */
+ }
}
}
}
Added: incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallSettingsTest.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallSettingsTest.java?rev=1130851&view=auto
==============================================================================
--- incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallSettingsTest.java (added)
+++ incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallSettingsTest.java Thu Jun 2 22:13:46 2011
@@ -0,0 +1,88 @@
+/**
+ * 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.jclouds.FirewallSettings;
+import org.jclouds.compute.ComputeServiceContext;
+import org.jclouds.domain.Credentials;
+import org.jclouds.ec2.EC2Client;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Set;
+
+public class FirewallSettingsTest {
+
+ private static final String REGION = "us-east-1";
+
+ private static ClusterSpec spec;
+ private static Set<Cluster.Instance> instances;
+
+ private static ComputeServiceContext context;
+
+ private static ClusterSpec getTestClusterSpec() throws Exception {
+ return ClusterSpec.withTemporaryKeys(
+ new PropertiesConfiguration("whirr-core-test.properties"));
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ spec = getTestClusterSpec();
+ context = ComputeCache.INSTANCE.apply(spec);
+
+ /* 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
+ ));
+ }
+
+ @Test
+ public void testFirewallAuthorizationIsIdempotent() throws IOException {
+ if (context.getProviderSpecificContext().getApi() instanceof EC2Client) {
+ EC2Client ec2Client = EC2Client.class.cast(
+ context.getProviderSpecificContext().getApi());
+ String groupName = "jclouds#" + spec.getClusterName() + "#" + REGION;
+
+ ec2Client.getSecurityGroupServices()
+ .createSecurityGroupInRegion(REGION, groupName, "group description");
+ try {
+ FirewallSettings.authorizeIngress(context, instances, spec, 23344);
+
+ /* The second call should not throw an exception. */
+ FirewallSettings.authorizeIngress(context, instances, spec, 23344);
+
+ } finally {
+ ec2Client.getSecurityGroupServices()
+ .deleteSecurityGroupInRegion(REGION, groupName);
+ }
+ }
+ }
+
+}
Propchange: incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/integration/FirewallSettingsTest.java
------------------------------------------------------------------------------
svn:eol-style = native