Updated Branches:
  refs/heads/trunk 2007d8133 -> d1ebe0ce3

WHIRR-660. Provide useful error message/exception if empty instance templates


Project: http://git-wip-us.apache.org/repos/asf/whirr/repo
Commit: http://git-wip-us.apache.org/repos/asf/whirr/commit/d1ebe0ce
Tree: http://git-wip-us.apache.org/repos/asf/whirr/tree/d1ebe0ce
Diff: http://git-wip-us.apache.org/repos/asf/whirr/diff/d1ebe0ce

Branch: refs/heads/trunk
Commit: d1ebe0ce380d47d4d460ca882fd4f886c7bb3a9f
Parents: 2007d81
Author: Andrew Bayer <andrew.ba...@gmail.com>
Authored: Mon Mar 11 10:48:03 2013 -0700
Committer: Andrew Bayer <andrew.ba...@gmail.com>
Committed: Mon Mar 11 10:48:03 2013 -0700

----------------------------------------------------------------------
 CHANGES.txt                                        |    3 ++
 .../whirr/actions/ScriptBasedClusterAction.java    |    4 +++
 .../actions/ScriptBasedClusterActionTest.java      |   21 +++++++++++++++
 3 files changed, 28 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/whirr/blob/d1ebe0ce/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 65dab4d..28c28fd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,9 @@ Release 0.8.2 (unreleased changes)
 
   IMPROVEMENTS
 
+    WHIRR-660. Provide useful message if whirr.instance-templates is
+    empty or not provided. (abayer)
+  
     WHIRR-672. Allow eager caching of instance hostname based on pre-provision
     instance metadata. (Graham Gear via tomwhite)
 

http://git-wip-us.apache.org/repos/asf/whirr/blob/d1ebe0ce/core/src/main/java/org/apache/whirr/actions/ScriptBasedClusterAction.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/whirr/actions/ScriptBasedClusterAction.java 
b/core/src/main/java/org/apache/whirr/actions/ScriptBasedClusterAction.java
index 5390fef..2c781af 100644
--- a/core/src/main/java/org/apache/whirr/actions/ScriptBasedClusterAction.java
+++ b/core/src/main/java/org/apache/whirr/actions/ScriptBasedClusterAction.java
@@ -95,6 +95,10 @@ public abstract class ScriptBasedClusterAction extends 
ClusterAction {
   public Cluster execute(ClusterSpec clusterSpec, Cluster cluster)
       throws IOException, InterruptedException {
 
+    if (clusterSpec.getInstanceTemplates().size() == 0) {
+        throw new IllegalArgumentException("No instance templates specified.");
+    }
+    
     Map<InstanceTemplate, ClusterActionEvent> eventMap = Maps.newHashMap();
     Cluster newCluster = cluster;
     for (InstanceTemplate instanceTemplate : 
clusterSpec.getInstanceTemplates()) {

http://git-wip-us.apache.org/repos/asf/whirr/blob/d1ebe0ce/core/src/test/java/org/apache/whirr/actions/ScriptBasedClusterActionTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/whirr/actions/ScriptBasedClusterActionTest.java 
b/core/src/test/java/org/apache/whirr/actions/ScriptBasedClusterActionTest.java
index f992dec..dc3ab79 100644
--- 
a/core/src/test/java/org/apache/whirr/actions/ScriptBasedClusterActionTest.java
+++ 
b/core/src/test/java/org/apache/whirr/actions/ScriptBasedClusterActionTest.java
@@ -117,6 +117,27 @@ public abstract class ScriptBasedClusterActionTest<T 
extends ScriptBasedClusterA
     return InstanceTemplate.builder().numberOfInstance(1).roles(roles).build();
   }
 
+  @Test(expected = IllegalArgumentException.class)
+  public void testEmptyInstanceTemplates() throws Exception {
+    T action = newClusterActionInstance(EMPTYSET, EMPTYSET);
+    DryRun dryRun = getDryRunForAction(action).reset();
+
+    ClusterSpec tempSpec = ClusterSpec.withTemporaryKeys();
+
+    tempSpec.setClusterName("test-cluster-for-script-exection");
+    tempSpec.setProvider("stub");
+    tempSpec.setIdentity("dummy");
+    tempSpec.setStateStore("none");
+
+    ClusterController controller = new ClusterController();
+    Cluster tempCluster = controller.launchCluster(tempSpec);
+
+    
+    action.execute(tempSpec, tempCluster);
+    
+    List<StatementOnNode> executions = dryRun.getTotallyOrderedExecutions();
+  }
+
   @Test
   public void testActionIsExecutedOnAllRelevantNodes() throws Exception {
     T action = newClusterActionInstance(EMPTYSET, EMPTYSET);

Reply via email to