You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/09/23 11:39:56 UTC

[2/4] brooklyn-server git commit: JcloudsLocation loads image chooser class with ClassLoaderUtils

JcloudsLocation loads image chooser class with ClassLoaderUtils


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

Branch: refs/heads/master
Commit: 5b019f01e042b7bf49732a1e141835b2b4c099a9
Parents: 136dd11
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Thu Sep 22 16:02:59 2016 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Thu Sep 22 17:06:37 2016 +0100

----------------------------------------------------------------------
 .../apache/brooklyn/location/jclouds/JcloudsLocation.java   | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5b019f01/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
index 29fbfce..b957130 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
@@ -90,6 +90,7 @@ import org.apache.brooklyn.util.collections.CollectionMerger;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.collections.MutableSet;
+import org.apache.brooklyn.util.core.ClassLoaderUtils;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.core.config.ResolvingConfigBag;
@@ -1606,7 +1607,13 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
         Object rawVal = config.getStringKey(JcloudsLocationConfig.IMAGE_CHOOSER.getName());
         if (rawVal instanceof String && Strings.isNonBlank((String)rawVal)) {
             // Configured with a string: it could be a class that we need to instantiate
-            Maybe<?> instance = Reflections.invokeConstructorFromArgs(getManagementContext().getCatalogClassLoader(), (String)rawVal);
+            Class<?> clazz;
+            try {
+                clazz = new ClassLoaderUtils(this.getClass(), getManagementContext()).loadClass((String)rawVal);
+            } catch (ClassNotFoundException e) {
+                throw new IllegalStateException("Could not load configured ImageChooser " + rawVal, e);
+            }
+            Maybe<?> instance = Reflections.invokeConstructorFromArgs(clazz);
             if (!instance.isPresent()) {
                 throw new IllegalStateException("Failed to create ImageChooser "+rawVal+" for location "+this);
             } else if (!(instance.get() instanceof Function)) {