Fix testRebindWithCatalogAndApp with mode == DELETE_CATALOG.

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

Branch: refs/heads/master
Commit: 0bb7eb4a6b1a9603c25fe97aab91110bf556d1c6
Parents: d26e705
Author: Geoff Macartney <[email protected]>
Authored: Thu Sep 29 18:06:15 2016 +0100
Committer: Geoff Macartney <[email protected]>
Committed: Thu Apr 20 11:20:35 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/core/mgmt/rebind/RebindIteration.java   | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/0bb7eb4a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java 
b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
index 0054a19..dc47c2d 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
@@ -31,6 +31,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 import org.apache.brooklyn.api.catalog.BrooklynCatalog;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Application;
@@ -843,8 +844,9 @@ public abstract class RebindIteration {
 
             //As a last resort go through all catalog items trying to load the 
type and use the first that succeeds.
             //But first check if can be loaded from the default classpath
-            if 
(JavaBrooklynClassLoadingContext.create(managementContext).tryLoadClass(entityManifest.getType()).isPresent())
-                return null;
+            if 
(JavaBrooklynClassLoadingContext.create(managementContext).tryLoadClass(entityManifest.getType()).isPresent())
 {
+                return ImmutableList.of();
+            }
 
             // TODO get to the point when we can deprecate this behaviour!:
             for (RegisteredType item : types.getAll()) {
@@ -946,24 +948,25 @@ public abstract class RebindIteration {
             List<String> idsFromReboundCatalog = MutableList.of();
             if (catalogItemIds != null && !catalogItemIds.isEmpty()) {
                 findCatalogIdsInReboundCatalog(bType, catalogItemIds, 
contextSuchAsId, idsFromReboundCatalog);
-                if (!idsFromReboundCatalog.isEmpty()) {
+                if (idsFromReboundCatalog.size() == catalogItemIds.size()) {
                     BrooklynClassLoadingContext loader = 
CatalogUtils.newClassLoadingContextForCatalogItems(managementContext, 
idsFromReboundCatalog);
                     return new LoadedClass<T>(loader.loadClass(jType, bType), 
catalogItemIds);
                 } else {
-                    LOG.warn("Unable to load catalog items "+ catalogItemIds 
+" for "+contextSuchAsId
+                    LOG.warn("Unable to load all catalog items "+ 
Iterables.toString(catalogItemIds) +" for "+contextSuchAsId
                             +" ("+bType.getSimpleName()+"); will try default 
class loader");
                 }
             }
             
             try {
-                return new LoadedClass<T>((Class<T>)loadClass(jType), 
idsFromReboundCatalog);
+                return new LoadedClass<T>((Class<T>)loadClass(jType), 
catalogItemIds);
             } catch (Exception e) {
                 Exceptions.propagateIfFatal(e);
                 LOG.warn("Unable to load "+jType+" using reflections; will try 
standard context");
             }
 
             if (catalogItemIds != null && !catalogItemIds.isEmpty()) {
-                throw new IllegalStateException("Unable to load catalog item 
"+ catalogItemIds +" for "+contextSuchAsId+", or load class from classpath");
+                throw new IllegalStateException("Unable to load catalog items 
" + Iterables.toString(catalogItemIds)
+                    + " for "+contextSuchAsId+", or load class from 
classpath");
             } else if 
(BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_BACKWARDS_COMPATIBILITY_INFER_CATALOG_ITEM_ON_REBIND))
 {
                 //Try loading from whichever catalog bundle succeeds.
                 BrooklynCatalog catalog = managementContext.getCatalog();

Reply via email to