You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/02/01 18:49:19 UTC

[15/50] brooklyn-server git commit: Fix JcloudsLocationTest

Fix JcloudsLocationTest

- only throw NoMachinesAvailableException if the last obtain attempt
  threw that; otherwise throw the underlying exception.
- (the problem is probably not that the cloud is full with no more
  machines available!)


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

Branch: refs/heads/0.6.0
Commit: 234103854578abcf0d9c317215c46ae89f9778de
Parents: 4265e66
Author: Aled Sage <al...@gmail.com>
Authored: Wed Nov 6 12:05:31 2013 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Nov 6 16:12:02 2013 +0000

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java        | 19 ++++++++++++++-----
 .../location/jclouds/JcloudsLocationTest.java    | 11 +++++++----
 2 files changed, 21 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/23410385/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
index 736a461..77389b0 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -73,6 +73,7 @@ import brooklyn.management.AccessController;
 import brooklyn.util.ResourceUtils;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.CompoundRuntimeException;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.flags.TypeCoercions;
 import brooklyn.util.internal.Repeater;
@@ -370,19 +371,27 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
     public JcloudsSshMachineLocation obtain(Map<?,?> flags) throws NoMachinesAvailableException {
         ConfigBag setup = ConfigBag.newInstanceExtending(getConfigBag(), flags);
         Integer attempts = setup.get(MACHINE_CREATE_ATTEMPTS);
-        Exception lastThrownException = null;
+        List<Exception> exceptions = Lists.newArrayList();
         if (attempts == null || attempts < 1) attempts = 1;
         for (int i = 1; i <= attempts; i++) {
             try {
                 return obtainOnce(flags, setup);
             } catch (RuntimeException e) {
                 LOG.warn("Attempt #{}/{} to obtain machine threw error: {}", new Object[]{i, attempts, e});
-                lastThrownException = e;
+                exceptions.add(e);
             }
         }
-        throw new NoMachinesAvailableException(
-                String.format("Failed to get VM after %d attempt%s.", attempts, attempts == 1 ? "" : "s"),
-                lastThrownException);
+        String msg = String.format("Failed to get VM after %d attempt%s.", attempts, attempts == 1 ? "" : "s");
+
+        Exception cause = (exceptions.size() == 1) 
+                ? exceptions.get(0)
+                : new CompoundRuntimeException(msg + " Causes include: "+exceptions.get(exceptions.size()-1), exceptions);
+
+        if (exceptions.get(exceptions.size()-1) instanceof NoMachinesAvailableException) {
+            throw new NoMachinesAvailableException(msg, cause);
+        } else {
+            throw Exceptions.propagate(cause);
+        }
     }
 
     protected JcloudsSshMachineLocation obtainOnce(Map<?, ?> flags, ConfigBag setup) throws NoMachinesAvailableException {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/23410385/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java
index aaf9734..75bc7a7 100644
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java
+++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java
@@ -26,6 +26,7 @@ import brooklyn.management.internal.LocalManagementContext;
 import brooklyn.test.Asserts;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.CompoundRuntimeException;
 import brooklyn.util.exceptions.Exceptions;
 
 import com.google.common.base.Function;
@@ -65,8 +66,9 @@ public class JcloudsLocationTest implements JcloudsLocationConfig {
         protected void tryObtainAndCheck(Map<?,?> flags, Predicate<? super ConfigBag> test) {
             try {
                 obtain(flags);
-            } catch (NoMachinesAvailableException e) {
-                if (e.getCause()==BAIL_OUT_FOR_TESTING) {
+            } catch (Exception e) {
+                if (e==BAIL_OUT_FOR_TESTING || e.getCause()==BAIL_OUT_FOR_TESTING 
+                        || (e instanceof CompoundRuntimeException && ((CompoundRuntimeException)e).getAllCauses().contains(BAIL_OUT_FOR_TESTING))) {
                     test.apply(lastConfigBag);
                 } else {
                     throw Exceptions.propagate(e);
@@ -134,6 +136,7 @@ public class JcloudsLocationTest implements JcloudsLocationConfig {
                 .put(ACCESS_CREDENTIAL, "bogus")
                 .put(USER, "fred")
                 .put(MIN_RAM, 16)
+                .put(JcloudsLocation.MACHINE_CREATE_ATTEMPTS, 1)
                 .putAll((Map)config)
                 .build();
         return managementContext.getLocationManager().createLocation(LocationSpec.create(BailOutJcloudsLocation.class)
@@ -275,7 +278,7 @@ public class JcloudsLocationTest implements JcloudsLocationConfig {
         Assert.assertEquals(jcl.buildTemplateCount, 3);
     }
 
-    @Test(groups="Live")
+    @Test(groups={"Live", "Live-sanity"})
     public void testCreateWithInboundPorts() {
         BailOutWithTemplateJcloudsLocation jcloudsLocation = newSampleBailOutWithTemplateJcloudsLocation();
         jcloudsLocation = (BailOutWithTemplateJcloudsLocation) jcloudsLocation.newSubLocation(MutableMap.of());
@@ -284,7 +287,7 @@ public class JcloudsLocationTest implements JcloudsLocationConfig {
         Assert.assertEquals(jcloudsLocation.template.getOptions().getInboundPorts(), ports);
     }
     
-    @Test(groups="Live")
+    @Test(groups={"Live", "Live-sanity"})
     public void testCreateWithInboundPortsOverride() {
         BailOutWithTemplateJcloudsLocation jcloudsLocation = newSampleBailOutWithTemplateJcloudsLocation();
         jcloudsLocation = (BailOutWithTemplateJcloudsLocation) jcloudsLocation.newSubLocation(MutableMap.of());