brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [2/3] brooklyn-server git commit: better preserve backwards compat (fixing tests) and tidy warnings/comments
Date Wed, 13 Sep 2017 11:49:00 GMT
better preserve backwards compat (fixing tests) and tidy warnings/comments


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

Branch: refs/heads/master
Commit: 4a4dd092f5a63946bf05f624f878b09defa392ef
Parents: 6a8800d
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Sep 11 14:15:29 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Sep 11 14:15:29 2017 +0100

----------------------------------------------------------------------
 .../apache/brooklyn/core/BrooklynVersion.java   | 38 ++++++++++++++------
 .../catalog/internal/BasicBrooklynCatalog.java  | 14 ++++++--
 .../core/typereg/BasicBrooklynTypeRegistry.java | 10 ++++--
 3 files changed, 48 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4a4dd092/core/src/main/java/org/apache/brooklyn/core/BrooklynVersion.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/BrooklynVersion.java b/core/src/main/java/org/apache/brooklyn/core/BrooklynVersion.java
index 4cc1352..fa64665 100644
--- a/core/src/main/java/org/apache/brooklyn/core/BrooklynVersion.java
+++ b/core/src/main/java/org/apache/brooklyn/core/BrooklynVersion.java
@@ -29,6 +29,7 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.jar.Attributes;
 
@@ -36,11 +37,15 @@ import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
+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.catalog.internal.BasicBrooklynCatalog;
 import org.apache.brooklyn.core.mgmt.classloading.OsgiBrooklynClassLoadingContext;
 import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.rt.felix.ManifestHelper;
+import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
@@ -309,16 +314,22 @@ public class BrooklynVersion implements BrooklynVersionService {
             );
 
             Maybe<OsgiManager> osgi = ((ManagementContextInternal)mgmt).getOsgiManager();
-            for (CatalogItem<?, ?> catalogItem : mgmt.getCatalog().getCatalogItems())
{
-                if (osgi.isPresentAndNonNull()) {
-                    for (CatalogItem.CatalogBundle catalogBundle : catalogItem.getLibraries())
{
+            if (osgi.isPresentAndNonNull()) {
+                for (ManagedBundle b: osgi.get().getManagedBundles().values()) {
+                    Maybe<Bundle> osgiBundle = osgi.get().findBundle(b);
+                    if (osgiBundle.isPresentAndNonNull()) {
+                        bundles.add(osgiBundle.get());
+                    }                    
+                }
+                // TODO remove when everything uses osgi bundles tracked by brooklyn above
+                for (RegisteredType t: mgmt.getTypeRegistry().getAll()) {
+                    for (OsgiBundleWithUrl catalogBundle : t.getLibraries()) {
                         Maybe<Bundle> osgiBundle = osgi.get().findBundle(catalogBundle);
                         if (osgiBundle.isPresentAndNonNull()) {
                             bundles.add(osgiBundle.get());
                         }
                     }
                 }
-
             }
 
             // Set over list in case a bundle is reported more than once (e.g. from classpath
and from OSGi).
@@ -332,14 +343,21 @@ public class BrooklynVersion implements BrooklynVersionService {
             }
             return features.build();
         } else {
-            Iterable<URL> manifests = ResourceUtils.create(mgmt).getResources(MANIFEST_PATH);
+            Set<URL> manifests = MutableSet.copyOf(ResourceUtils.create(mgmt).getResources(MANIFEST_PATH));
 
-            for (CatalogItem<?, ?> catalogItem : mgmt.getCatalog().getCatalogItems())
{
-                OsgiBrooklynClassLoadingContext osgiContext = new OsgiBrooklynClassLoadingContext(
-                        mgmt, catalogItem.getCatalogItemId(), catalogItem.getLibraries());
-                manifests = Iterables.concat(manifests, osgiContext.getResources(MANIFEST_PATH));
+            Maybe<OsgiManager> osgi = ((ManagementContextInternal)mgmt).getOsgiManager();
+            if (osgi.isPresentAndNonNull()) {
+                // get manifests for all bundles installed
+                Iterables.addAll(manifests, 
+                    osgi.get().getResources(MANIFEST_PATH, osgi.get().getManagedBundles().values())
);
             }
-
+            
+            // TODO remove when everything uses osgi bundles tracked by brooklyn above
+            for (RegisteredType t: mgmt.getTypeRegistry().getAll()) {
+                OsgiBrooklynClassLoadingContext osgiContext = new OsgiBrooklynClassLoadingContext(mgmt,
t.getId(), t.getLibraries());
+                Iterables.addAll(manifests, osgiContext.getResources(MANIFEST_PATH));
+            }
+            
             // Set over list in case a bundle is reported more than once (e.g. from classpath
and from OSGi).
             // Not sure of validity of this approach over just reporting duplicates.
             ImmutableSet.Builder<BrooklynFeature> features = ImmutableSet.builder();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4a4dd092/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index 3177a50..d170970 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -348,13 +348,19 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
     @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
     public <T,SpecT> CatalogItem<T,SpecT> getCatalogItem(Class<T> type,
String id, String version) {
+        CatalogItem<T, SpecT> item = (CatalogItem) getCatalogItemLegacy(type, id, version);
+        if (item!=null) {
+            return item;
+        }
+        
         RegisteredType rt = mgmt.getTypeRegistry().get(id, version);
         if (rt!=null) {
             if (rt.getSuperTypes().contains(type) || rt.getSuperTypes().contains(type.getName()))
{
                 return (CatalogItem) RegisteredTypes.toPartialCatalogItem(rt);
             }
         }
-        return getCatalogItemLegacy(type, id, version);
+        
+        return null;
     }
 
     @SuppressWarnings("unchecked")
@@ -1805,10 +1811,14 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
             log.debug("Forcing catalog load on access of catalog items");
             load();
         }
-        result.putAll((Map)catalog.getIdCache());
         for (RegisteredType rt: mgmt.getTypeRegistry().getAll()) {
             result.put(rt.getId(), (CatalogItem)RegisteredTypes.toPartialCatalogItem(rt));
         }
+        // prefer locally registered items in this method; prevents conversion to and from
RT;
+        // possibly allows different views if there are diff items in catlaog and type registry
+        // but this means at least it is consistent for user if they are consistent;
+        // and can easily live with this until catalog is entirely replaced to TR 
+        result.putAll((Map)catalog.getIdCache());
         return result.values();
     }
     

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4a4dd092/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index 440d301..983403c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -96,8 +96,14 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
                 Iterables.transform(mgmt.getCatalog().getCatalogItemsLegacy(), RegisteredTypes.CI_TO_RT),

                 filter)) {
             if (!result.containsKey(rt.getId())) {
-                // shouldn't be using this now
-                log.warn("Item '"+rt.getId()+"' not in type registry; only found in legacy
catalog");
+                // TODO ideally never come here, however
+                // legacy cataog currently still used for java-scanned annotations; 
+                // hopefully that will be deprecated and removed in near future
+                // (probably after switch to osgi and using catalog.bom --
+                // though it would not be too hard for java scan code in CatalogClasspath.load
to
+                // make TypeRegistry instances instead of CatalogItem, esp if we had YOML
to write that plan)
+                
+                //log.warn("Item '"+rt.getId()+"' not in type registry; only found in legacy
catalog");
                 result.put(rt.getId(), rt);
             }
         }


Mime
View raw message