incubator-ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1084076 - in /incubator/ace/trunk/ace-nodelauncher-amazon: ./ src/main/java/org/apache/ace/nodelauncher/amazon/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/ace/ src/test/java/org/apache/ac...
Date Tue, 22 Mar 2011 06:20:38 GMT
Author: marrs
Date: Tue Mar 22 06:20:37 2011
New Revision: 1084076

URL: http://svn.apache.org/viewvc?rev=1084076&view=rev
Log:
Added support for opening up extra ports on cloud nodes via configuration.

Added:
    incubator/ace/trunk/ace-nodelauncher-amazon/src/test/
    incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/
    incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/org/
    incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/org/apache/
    incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/org/apache/ace/
    incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/org/apache/ace/nodelauncher/
    incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/org/apache/ace/nodelauncher/amazon/
    incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/org/apache/ace/nodelauncher/amazon/PortParseTest.java
Modified:
    incubator/ace/trunk/ace-nodelauncher-amazon/pom.xml
    incubator/ace/trunk/ace-nodelauncher-amazon/src/main/java/org/apache/ace/nodelauncher/amazon/AmazonNodeLauncher.java

Modified: incubator/ace/trunk/ace-nodelauncher-amazon/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-nodelauncher-amazon/pom.xml?rev=1084076&r1=1084075&r2=1084076&view=diff
==============================================================================
--- incubator/ace/trunk/ace-nodelauncher-amazon/pom.xml (original)
+++ incubator/ace/trunk/ace-nodelauncher-amazon/pom.xml Tue Mar 22 06:20:37 2011
@@ -125,6 +125,9 @@
             <version>0.1.44-1</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.util</artifactId>
+        </dependency>
     </dependencies>
-  
 </project>
\ No newline at end of file

Modified: incubator/ace/trunk/ace-nodelauncher-amazon/src/main/java/org/apache/ace/nodelauncher/amazon/AmazonNodeLauncher.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-nodelauncher-amazon/src/main/java/org/apache/ace/nodelauncher/amazon/AmazonNodeLauncher.java?rev=1084076&r1=1084075&r2=1084076&view=diff
==============================================================================
--- incubator/ace/trunk/ace-nodelauncher-amazon/src/main/java/org/apache/ace/nodelauncher/amazon/AmazonNodeLauncher.java
(original)
+++ incubator/ace/trunk/ace-nodelauncher-amazon/src/main/java/org/apache/ace/nodelauncher/amazon/AmazonNodeLauncher.java
Tue Mar 22 06:20:37 2011
@@ -104,6 +104,16 @@ public class AmazonNodeLauncher implemen
      */
     public static final String LAUNCHER_ARGUMENTS = "launcherArguments";
     
+    /**
+     * Configuration key: Extra ports to open on the nodes, besides the default ones (see
DEFAULT_PORTS).
+     */
+    public static final String EXTRA_PORTS = "extraPorts";
+    
+    /**
+     * Default set of ports to open on a node.
+     */
+    public static final int[] DEFAULT_PORTS = new int[] {22, 80, 8080};
+    
     private URL m_server;
     private String m_amiId; 
     private String m_location;
@@ -113,6 +123,7 @@ public class AmazonNodeLauncher implemen
     private String m_vmOptions;
     private String m_nodeBootstrap;
     private String m_launcherArguments;
+    private String m_extraPorts;
 
     private ComputeServiceContext m_computeServiceContext;
     
@@ -131,7 +142,9 @@ public class AmazonNodeLauncher implemen
                 .locationId(m_location)
                 .build();
         
-        template.getOptions().as(EC2TemplateOptions.class).inboundPorts(22, 80, 8080);
+        int[] extraPorts = parseExtraPorts(m_extraPorts);
+        int[] inboundPorts = mergePorts(DEFAULT_PORTS, extraPorts);
+        template.getOptions().as(EC2TemplateOptions.class).inboundPorts(inboundPorts);
         template.getOptions().blockOnComplete(false);
 
         Set<? extends NodeMetadata> tag = computeService.createNodesInGroup(m_tagPrefix
+ id, 1, template);
@@ -141,6 +154,27 @@ public class AmazonNodeLauncher implemen
                 Statements.exec(buildStartupScript(id)),
                 RunScriptOptions.Builder.blockOnComplete(false));
     }
+    
+    int[] mergePorts(int[] first, int[] last) {
+        int[] result = new int[first.length + last.length];
+        for (int i = 0; i < result.length; i++) {
+            result[i] = (i < first.length) ? first[i] : last[i - first.length];
+        }
+        return result;
+    }
+    
+    int[] parseExtraPorts(String extraPorts) {
+        extraPorts = extraPorts.trim();
+        if (extraPorts.isEmpty()) {
+            return new int[] {};
+        }
+        String[] ports = extraPorts.split(",");
+        int[] result = new int[ports.length];
+        for (int i = 0; i < ports.length; i++) {
+            result[i] = Integer.parseInt(ports[i].trim());
+        }
+        return result;
+    }
 
     private String buildStartupScript(String id) throws MalformedURLException {
         StringBuilder script = new StringBuilder();
@@ -203,6 +237,7 @@ public class AmazonNodeLauncher implemen
             String nodeBootstrap = getConfigProperty(properties, NODE_BOOTSTRAP, "");
             String tagPrefix = getConfigProperty(properties, TAG_PREFIX, "");
             String launcherArguments = getConfigProperty(properties, LAUNCHER_ARGUMENTS,
"");
+            String extraPorts = getConfigProperty(properties, EXTRA_PORTS, "");
 
             m_server = server;
             m_amiId = amiId;
@@ -213,6 +248,7 @@ public class AmazonNodeLauncher implemen
             m_vmOptions = vmOptions;
             m_nodeBootstrap = nodeBootstrap;
             m_launcherArguments = launcherArguments;
+            m_extraPorts = extraPorts;
         }
     }
 

Added: incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/org/apache/ace/nodelauncher/amazon/PortParseTest.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/org/apache/ace/nodelauncher/amazon/PortParseTest.java?rev=1084076&view=auto
==============================================================================
--- incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/org/apache/ace/nodelauncher/amazon/PortParseTest.java
(added)
+++ incubator/ace/trunk/ace-nodelauncher-amazon/src/test/java/org/apache/ace/nodelauncher/amazon/PortParseTest.java
Tue Mar 22 06:20:37 2011
@@ -0,0 +1,25 @@
+package org.apache.ace.nodelauncher.amazon;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+import static org.apache.ace.test.utils.TestUtils.UNIT;
+
+public class PortParseTest {
+    @Test(groups = { UNIT })
+    public void testParsePortsFromString() throws Exception {
+        AmazonNodeLauncher instance = new AmazonNodeLauncher();
+        Assert.assertEquals(instance.parseExtraPorts("1,2,3"), new int[] {1, 2, 3});
+        Assert.assertEquals(instance.parseExtraPorts(""), new int[] {});
+        Assert.assertEquals(instance.parseExtraPorts("1 ,2 , 3 "), new int[] {1, 2, 3});
+        Assert.assertEquals(instance.parseExtraPorts("800,900"), new int[] {800, 900});
+    }
+    
+    @Test(groups = { UNIT })
+    public void testMergePorts() throws Exception {
+        AmazonNodeLauncher instance = new AmazonNodeLauncher();
+        Assert.assertEquals(instance.mergePorts(new int[] {1, 2}, new int[] {3, 4, 5}), new
int[] {1, 2, 3, 4, 5});
+        Assert.assertEquals(instance.mergePorts(new int[] {1}, new int[] {}), new int[] {1});
+        Assert.assertEquals(instance.mergePorts(new int[] {}, new int[] {}), new int[] {});
+        Assert.assertEquals(instance.mergePorts(new int[] {}, new int[] {1, 2, 3}), new int[]
{1, 2, 3});
+    }
+}



Mime
View raw message