Author: abayer
Date: Wed Aug  8 18:44:08 2012
New Revision: 1370882

URL: http://svn.apache.org/viewvc?rev=1370882&view=rev
Log:
WHIRR-63. Support EC2 Cluster Compute groups for Hadoop etc.

Modified:
    whirr/trunk/core/src/main/java/org/apache/whirr/ClusterSpec.java
    
whirr/trunk/core/src/main/java/org/apache/whirr/compute/BootstrapTemplate.java
    
whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/TemplateBuilderStrategy.java

Modified: whirr/trunk/core/src/main/java/org/apache/whirr/ClusterSpec.java
URL: 
http://svn.apache.org/viewvc/whirr/trunk/core/src/main/java/org/apache/whirr/ClusterSpec.java?rev=1370882&r1=1370881&r2=1370882&view=diff
==============================================================================
--- whirr/trunk/core/src/main/java/org/apache/whirr/ClusterSpec.java (original)
+++ whirr/trunk/core/src/main/java/org/apache/whirr/ClusterSpec.java Wed Aug  8 
18:44:08 2012
@@ -161,7 +161,9 @@ public class ClusterSpec {
       "urls from. Change this to host your own set of launch scripts."),
       
     TERMINATE_ALL_ON_LAUNCH_FAILURE(Boolean.class, false, "Whether or not to " 
+
-      "automatically terminate all nodes when cluster launch fails for some 
reason.");
+                                    "automatically terminate all nodes when 
cluster launch fails for some reason."),
+
+    AWS_EC2_PLACEMENT_GROUP(String.class, false, "If given, use this existing 
EC2 placement group. (aws-ec2 specific option)");
     
     private Class<?> type;
     private boolean multipleArguments;
@@ -279,6 +281,8 @@ public class ClusterSpec {
   
   private boolean terminateAllOnLaunchFailure;
 
+  private String awsEc2PlacementGroup;
+
   private Configuration config;
   
   public ClusterSpec() throws ConfigurationException {
@@ -338,6 +342,8 @@ public class ClusterSpec {
     setTerminateAllOnLaunchFailure(config.getBoolean(
         Property.TERMINATE_ALL_ON_LAUNCH_FAILURE.getConfigName(), 
Boolean.TRUE));
     
+    setAwsEc2PlacementGroup(getString(Property.AWS_EC2_PLACEMENT_GROUP));
+
     Map<String, List<String>> fr = new HashMap<String, List<String>>();
     String firewallPrefix = Property.FIREWALL_RULES.getConfigName();
     Pattern firewallRuleKeyPattern = 
Pattern.compile("^".concat(Pattern.quote(firewallPrefix).concat("(?:\\.(.+))?$")));
@@ -411,6 +417,8 @@ public class ClusterSpec {
     
     r.setTerminateAllOnLaunchFailure(isTerminateAllOnLaunchFailure());
 
+    r.setAwsEc2PlacementGroup(getAwsEc2PlacementGroup());
+
     return r;
   }
 
@@ -740,6 +748,13 @@ public class ClusterSpec {
     this.terminateAllOnLaunchFailure = terminateAllOnLaunchFailure;
   }
 
+  public String getAwsEc2PlacementGroup() {
+    return awsEc2PlacementGroup;
+  }
+  public void setAwsEc2PlacementGroup(String awsEc2PlacementGroup) {
+    this.awsEc2PlacementGroup = awsEc2PlacementGroup;
+  }
+
   /**
    * The rsa public key which is authorized to login to your on the cloud 
nodes.
    * 
@@ -912,6 +927,7 @@ public class ClusterSpec {
         && Objects.equal(getStateStoreContainer(), 
that.getStateStoreContainer())
         && Objects.equal(getStateStoreBlob(), that.getStateStoreBlob())
         && Objects.equal(getAwsEc2SpotPrice(), that.getAwsEc2SpotPrice())
+        && Objects.equal(getAwsEc2PlacementGroup(), 
that.getAwsEc2PlacementGroup())
         ;
     }
     return false;
@@ -945,7 +961,8 @@ public class ClusterSpec {
         getStateStore(),
         getStateStoreBlob(),
         getStateStoreContainer(),
-        getAwsEc2SpotPrice()
+        getAwsEc2SpotPrice(),
+        getAwsEc2PlacementGroup()
     );
   }
   
@@ -979,6 +996,7 @@ public class ClusterSpec {
       .add("stateStoreBlob", getStateStoreBlob())
       .add("awsEc2SpotPrice", getAwsEc2SpotPrice())
       .add("terminateAllOnLauchFailure",isTerminateAllOnLaunchFailure())
+      .add("awsEc2PlacementGroup",getAwsEc2PlacementGroup())
       .toString();
   }
 }

Modified: 
whirr/trunk/core/src/main/java/org/apache/whirr/compute/BootstrapTemplate.java
URL: 
http://svn.apache.org/viewvc/whirr/trunk/core/src/main/java/org/apache/whirr/compute/BootstrapTemplate.java?rev=1370882&r1=1370881&r2=1370882&view=diff
==============================================================================
--- 
whirr/trunk/core/src/main/java/org/apache/whirr/compute/BootstrapTemplate.java 
(original)
+++ 
whirr/trunk/core/src/main/java/org/apache/whirr/compute/BootstrapTemplate.java 
Wed Aug  8 18:44:08 2012
@@ -73,7 +73,6 @@ public class BootstrapTemplate {
     TemplateBuilder templateBuilder = computeService.templateBuilder()
       .options(runScript(bootstrap));
     strategy.configureTemplateBuilder(clusterSpec, templateBuilder, 
instanceTemplate);
-
     return setSpotInstancePriceIfSpecified(
       computeService.getContext(), clusterSpec, templateBuilder.build(), 
instanceTemplate
     );
@@ -109,9 +108,23 @@ public class BootstrapTemplate {
       }
     }
 
-    return template;
+    return setPlacementGroup(context, spec, template, instanceTemplate);
   }
 
+    /**
+     * Set the placement group, if desired - if it doesn't already exist, 
create it.
+     */
+    private static Template setPlacementGroup(ComputeServiceContext context, 
ClusterSpec spec,
+                                              Template template, 
InstanceTemplate instanceTemplate) {
+        if 
(AWSEC2ApiMetadata.CONTEXT_TOKEN.isAssignableFrom(context.getBackendType())) {
+            if (spec.getAwsEc2PlacementGroup() != null) {
+                
template.getOptions().as(AWSEC2TemplateOptions.class).placementGroup(spec.getAwsEc2PlacementGroup());
+            }
+        }
+
+        return template;
+    }
+                                                                               
      
   private static float firstPositiveOrDefault(float defaultValue, float... 
listOfValues) {
     for(float value : listOfValues) {
       if (value > 0) return value;

Modified: 
whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/TemplateBuilderStrategy.java
URL: 
http://svn.apache.org/viewvc/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/TemplateBuilderStrategy.java?rev=1370882&r1=1370881&r2=1370882&view=diff
==============================================================================
--- 
whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/TemplateBuilderStrategy.java
 (original)
+++ 
whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/TemplateBuilderStrategy.java
 Wed Aug  8 18:44:08 2012
@@ -44,7 +44,7 @@ public class TemplateBuilderStrategy {
       if ("aws-ec2".equals(clusterSpec.getProvider()))
           
templateBuilder.imageDescriptionMatches("^(?!.*(daily|testing)).*ubuntu-images.*$");
     }
-    
+
     if (clusterSpec.getHardwareId() != null || 
instanceTemplate.getHardwareId() != null) {
       templateBuilder.hardwareId(
         or(instanceTemplate.getHardwareId(), clusterSpec.getHardwareId())


Reply via email to