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 2017/06/08 09:37:37 UTC

[03/11] brooklyn-server git commit: Revert "attempt to have class loading context for items include supertypes in some cases"

Revert "attempt to have class loading context for items include supertypes in some cases"

This reverts commit bdd2cce624285d0f178b272ce5ae7c416b447150.

It's a chicken-and-egg problem as the ClassLoadingContext is needed to create,
but creation is how we attempted to find supertypes. So you get an infinite loop.
Will try a different approach (but keeping this in case we revisit).


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

Branch: refs/heads/master
Commit: 00b580ccb611540f7387e5fc193fadc0429761b4
Parents: bdd2cce
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Jun 7 10:56:08 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Jun 7 10:56:08 2017 +0100

----------------------------------------------------------------------
 .../core/catalog/internal/CatalogUtils.java     | 64 +-------------------
 1 file changed, 3 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/00b580cc/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
index 669efbe..47dab6d 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
@@ -20,7 +20,6 @@ package org.apache.brooklyn.core.catalog.internal;
 
 import java.util.Collection;
 import java.util.List;
-import java.util.Set;
 
 import javax.annotation.Nullable;
 
@@ -28,13 +27,10 @@ import org.apache.brooklyn.api.catalog.BrooklynCatalog;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
 import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
-import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind;
-import org.apache.brooklyn.api.typereg.ManagedBundle;
 import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
 import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.BrooklynLogging;
@@ -53,10 +49,7 @@ import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
 import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.collections.MutableSet;
-import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
-import org.apache.brooklyn.util.osgi.VersionedName;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.time.Time;
 import org.osgi.framework.Bundle;
@@ -79,61 +72,11 @@ public class CatalogUtils {
         if (item.getLibraries() == null) {
             log.debug("CatalogItemDtoAbstract.getLibraries() is null.", new Exception("Trace for null CatalogItemDtoAbstract.getLibraries()"));
         }
-        return newClassLoadingContext(mgmt, item.getId(), getLibraries(mgmt, RegisteredTypes.of(item)));
+        return newClassLoadingContext(mgmt, item.getId(), item.getLibraries());
     }
     
-    /** Returns libraries on the item and any ancestor references we can find, for instance by instantiating specs and looking at those */
-    public static Collection<OsgiBundleWithUrl> getLibraries(ManagementContext mgmt, RegisteredType item) {
-        Set<OsgiBundleWithUrl> result = MutableSet.of();
-        collectLibraries(result, mgmt, item, MutableSet.<String>of());
-        return result;
-    }
-    
-    private static void collectLibraries(Set<OsgiBundleWithUrl> result, ManagementContext mgmt, RegisteredType item, Set<String> visited) {
-        if (item==null || !visited.add(item.getId())) return;
-        
-        result.addAll(item.getLibraries());
-        
-//        if (item.getKind()==RegisteredTypeKind.SPEC) {
-//            try {
-//                // TODO this does not work because attempts to create the spec need to get the class loading context
-//                AbstractBrooklynObjectSpec<?, ?> spec = mgmt.getTypeRegistry().createSpec(item, null, null);
-//                for (String path: spec.getCatalogItemIdSearchPath()) {
-//                    addBundleOrItemLibraries(mgmt, result, path, visited, spec);
-//                }
-//            } catch (Exception e) {
-//                log.warn("Unable to instantiate spec for library class-loading purposes, falling back to declared libraries: "+Exceptions.collapseText(e), e);
-//            }
-//        }
-    }
-    
-    private static void addBundleOrItemLibraries(ManagementContext mgmt, Set<OsgiBundleWithUrl> result, String path, Set<String> visited, AbstractBrooklynObjectSpec<?, ?> specContext) {
-        if (path==null || !visited.add(path)) return;
-        Maybe<OsgiManager> osgi = ((ManagementContextInternal)mgmt).getOsgiManager();
-        if (osgi.isPresent()) {
-            try {
-                ManagedBundle bundle = osgi.get().getManagedBundle(VersionedName.fromString(path));
-                result.add(bundle);
-                return;
-            } catch (Exception e) {
-                Exceptions.propagateIfFatal(e);
-                if (log.isTraceEnabled()) log.trace("Ignoring potential bundle reference error to "+path+", probably it isn't a bundle: "+e);
-                // probably not a bundle, ignore for now, as search path supports catalog items also, for now (June 2017)
-            }
-        }
-        
-        // not a bundle, check if it's an item
-        Maybe<RegisteredType> item = mgmt.getTypeRegistry().getMaybe(path, null);
-        if (item.isPresent()) {
-            collectLibraries(result, mgmt, item.get(), visited);
-            return;
-        }
-        
-        log.warn("Unrecognised item "+path+" in search path of "+specContext);
-    }
-
     public static BrooklynClassLoadingContext newClassLoadingContext(ManagementContext mgmt, RegisteredType item) {
-        return newClassLoadingContext(mgmt, item.getId(), getLibraries(mgmt, item), null);
+        return newClassLoadingContext(mgmt, item.getId(), item.getLibraries(), null);
     }
     
     /** made @Beta in 0.9.0 because we're not sure to what extent to support stacking loaders; 
@@ -141,7 +84,7 @@ public class CatalogUtils {
      * and life gets hard if we support complex stacking! */
     @Beta 
     public static BrooklynClassLoadingContext newClassLoadingContext(ManagementContext mgmt, RegisteredType item, BrooklynClassLoadingContext loader) {
-        return newClassLoadingContext(mgmt, item.getId(), getLibraries(mgmt, item), loader);
+        return newClassLoadingContext(mgmt, item.getId(), item.getLibraries(), loader);
     }
     
     public static BrooklynClassLoadingContext getClassLoadingContext(Entity entity) {
@@ -153,7 +96,6 @@ public class CatalogUtils {
             log.warn("Cannot load "+catId+" to get classloader for "+entity+"; will try with standard loader, but might fail subsequently");
             return JavaBrooklynClassLoadingContext.create(mgmt);
         }
-        // TODO use entity search path, plus catalog item ID
         return newClassLoadingContext(mgmt, cat.get());
     }