brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geom...@apache.org
Subject [02/17] brooklyn-server git commit: record the containing bundle for any catalog item / registered type
Date Tue, 06 Jun 2017 12:25:22 GMT
record the containing bundle for any catalog item / registered type


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

Branch: refs/heads/master
Commit: 8a4886fd72709ae13fb6b4ed312df2826d8123ba
Parents: bc11ab2
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed May 3 15:44:38 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri May 5 12:43:59 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/api/catalog/BrooklynCatalog.java      | 15 ++++++++++++---
 .../apache/brooklyn/api/catalog/CatalogItem.java   |  2 ++
 .../brooklyn/api/typereg/RegisteredType.java       |  1 +
 .../catalog/CatalogOsgiVersionMoreEntityTest.java  |  1 +
 .../catalog/internal/BasicBrooklynCatalog.java     | 15 ++++++++++++++-
 .../core/catalog/internal/CatalogBundleLoader.java |  7 ++++++-
 .../core/catalog/internal/CatalogItemDo.java       |  5 +++++
 .../catalog/internal/CatalogItemDtoAbstract.java   | 17 +++++++++++++++--
 .../apache/brooklyn/core/mgmt/ha/OsgiManager.java  |  6 ++++++
 .../brooklyn/core/typereg/BasicRegisteredType.java |  6 ++++++
 .../brooklyn/core/typereg/RegisteredTypes.java     | 10 ++++++++++
 11 files changed, 78 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java b/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
index 3bda040..75fe634 100644
--- a/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
+++ b/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
@@ -21,7 +21,11 @@ package org.apache.brooklyn.api.catalog;
 import java.util.Collection;
 import java.util.NoSuchElementException;
 
+import javax.annotation.Nullable;
+
 import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
+import org.apache.brooklyn.api.typereg.ManagedBundle;
+
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Predicate;
 
@@ -111,12 +115,17 @@ public interface BrooklynCatalog {
     CatalogItem<?,?> addItem(String yaml, boolean forceUpdate);
     
     /**
-     * Adds items (represented in yaml) to the catalog.
-     * Fails if the same version exists in catalog.
+     * As {@link #addItemsFromBundle(String, ManagedBundle)} with a null bundle.
+     */
+    Iterable<? extends CatalogItem<?,?>> addItems(String yaml);
+    
+    /**
+     * Adds items (represented in yaml) to the catalog coming from the indicated managed
bundle.
+     * Fails if the same version exists in catalog (unless snapshot).
      *
      * @throws IllegalArgumentException if the yaml was invalid
      */
-    Iterable<? extends CatalogItem<?,?>> addItems(String yaml);
+    Iterable<? extends CatalogItem<?,?>> addItems(String yaml, @Nullable ManagedBundle
definingBundle);
     
     /**
      * Adds items (represented in yaml) to the catalog.

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/api/src/main/java/org/apache/brooklyn/api/catalog/CatalogItem.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/catalog/CatalogItem.java b/api/src/main/java/org/apache/brooklyn/api/catalog/CatalogItem.java
index 6f27af7..342cd2a 100644
--- a/api/src/main/java/org/apache/brooklyn/api/catalog/CatalogItem.java
+++ b/api/src/main/java/org/apache/brooklyn/api/catalog/CatalogItem.java
@@ -123,6 +123,8 @@ public interface CatalogItem<T,SpecT> extends BrooklynObject, Rebindable
{
     @Nullable public String getIconUrl();
 
     public String getSymbolicName();
+    
+    public String getContainingBundle();
 
     public String getVersion();
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java b/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
index 1eb7391..fad3d35 100644
--- a/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
+++ b/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
@@ -37,6 +37,7 @@ public interface RegisteredType extends Identifiable {
     
     String getSymbolicName();
     String getVersion();
+    String getContainingBundle();
 
     Collection<OsgiBundleWithUrl> getLibraries();
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
index 5c28c8b..cb38df5 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
@@ -83,6 +83,7 @@ public class CatalogOsgiVersionMoreEntityTest extends AbstractYamlTest implement
         // types installed
         RegisteredType t = mgmt().getTypeRegistry().get(BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY);
         Assert.assertNotNull(t);
+        Assert.assertEquals(t.getContainingBundle(), b.getSymbolicName()+":"+b.getVersion());
         
         // can deploy
         createAndStartApplication("services: [ { type: "+BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY+"
} ]");

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/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 2634ecf..9769f7e 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
@@ -39,6 +39,7 @@ import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.classloading.BrooklynClassLoadingContext;
+import org.apache.brooklyn.api.typereg.ManagedBundle;
 import org.apache.brooklyn.core.catalog.CatalogPredicates;
 import org.apache.brooklyn.core.catalog.internal.CatalogClasspathDo.CatalogScanningModes;
 import org.apache.brooklyn.core.location.BasicLocationRegistry;
@@ -980,7 +981,12 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
 
     @Override
     public List<? extends CatalogItem<?,?>> addItems(String yaml) {
-        return addItems(yaml, false);
+        return addItems(yaml, null);
+    }
+    
+    @Override
+    public List<? extends CatalogItem<?, ?>> addItems(String yaml, ManagedBundle
bundle) {
+        return addItems(yaml, bundle, false);
     }
 
     @Override
@@ -990,12 +996,19 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
     
     @Override
     public List<? extends CatalogItem<?,?>> addItems(String yaml, boolean forceUpdate)
{
+        return addItems(yaml, null, forceUpdate);
+    }
+    
+    private List<? extends CatalogItem<?,?>> addItems(String yaml, ManagedBundle
bundle, boolean forceUpdate) {
         log.debug("Adding manual catalog item to "+mgmt+": "+yaml);
         checkNotNull(yaml, "yaml");
         List<CatalogItemDtoAbstract<?, ?>> result = collectCatalogItems(yaml);
 
         // do this at the end for atomic updates; if there are intra-yaml references, we
handle them specially
         for (CatalogItemDtoAbstract<?, ?> item: result) {
+            if (bundle!=null && bundle.getVersionedName()!=null) {
+                item.setContainingBundle(bundle.getVersionedName());
+            }
             addItemDto(item, forceUpdate);
         }
         return result;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
index b1f8fd3..4bf8824 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
@@ -29,8 +29,11 @@ import java.util.Map;
 
 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.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.osgi.VersionedName;
 import org.apache.brooklyn.util.stream.Streams;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.yaml.Yamls;
@@ -69,6 +72,8 @@ public class CatalogBundleLoader {
      * @throws RuntimeException if the catalog items failed to be added to the catalog
      */
     public Iterable<? extends CatalogItem<?, ?>> scanForCatalog(Bundle bundle)
{
+        ManagedBundle mb = ((ManagementContextInternal)managementContext).getOsgiManager().get().getManagedBundle(
+            new VersionedName(bundle));
 
         Iterable<? extends CatalogItem<?, ?>> catalogItems = MutableList.of();
 
@@ -77,7 +82,7 @@ public class CatalogBundleLoader {
             LOG.debug("Found catalog BOM in {} {} {}", CatalogUtils.bundleIds(bundle));
             String bomText = readBom(bom);
             String bomWithLibraryPath = addLibraryDetails(bundle, bomText);
-            catalogItems = this.managementContext.getCatalog().addItems(bomWithLibraryPath);
+            catalogItems = this.managementContext.getCatalog().addItems(bomWithLibraryPath,
mb);
             for (CatalogItem<?, ?> item : catalogItems) {
                 LOG.debug("Added to catalog: {}, {}", item.getSymbolicName(), item.getVersion());
             }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
index 90697fe..cf3c2d7 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
@@ -197,6 +197,11 @@ public class CatalogItemDo<T,SpecT> implements CatalogItem<T,SpecT>,
BrooklynObj
     public String getSymbolicName() {
         return itemDto.getSymbolicName();
     }
+    
+    @Override
+    public String getContainingBundle() {
+        return itemDto.getContainingBundle();
+    }
 
     @Override
     public String getVersion() {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
index 5aec768..e072b80 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
@@ -20,7 +20,6 @@ package org.apache.brooklyn.core.catalog.internal;
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -37,6 +36,8 @@ import org.apache.brooklyn.core.relations.EmptyRelationSupport;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.core.flags.FlagUtils;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
+import org.apache.brooklyn.util.osgi.VersionedName;
+import org.apache.brooklyn.util.text.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,6 +53,7 @@ public abstract class CatalogItemDtoAbstract<T, SpecT> extends AbstractBrooklynO
 
     private @SetFromFlag String symbolicName;
     private @SetFromFlag String version = BasicBrooklynCatalog.NO_VERSION;
+    private @SetFromFlag String containingBundle;
 
     private @SetFromFlag String displayName;
     private @SetFromFlag String description;
@@ -120,6 +122,11 @@ public abstract class CatalogItemDtoAbstract<T, SpecT> extends
AbstractBrooklynO
     public String getRegisteredTypeName() {
         return getSymbolicName();
     }
+    
+    @Override
+    public String getContainingBundle() {
+        return containingBundle;
+    }
 
     @Override
     public String getDisplayName() {
@@ -191,7 +198,7 @@ public abstract class CatalogItemDtoAbstract<T, SpecT> extends AbstractBrooklynO
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(symbolicName, planYaml, javaType, nullIfEmpty(libraries),
version, getCatalogItemId(),
+        return Objects.hashCode(symbolicName, containingBundle, planYaml, javaType, nullIfEmpty(libraries),
version, getCatalogItemId(),
             getCatalogItemIdSearchPath());
     }
 
@@ -202,6 +209,7 @@ public abstract class CatalogItemDtoAbstract<T, SpecT> extends AbstractBrooklynO
         if (getClass() != obj.getClass()) return false;
         CatalogItemDtoAbstract<?,?> other = (CatalogItemDtoAbstract<?,?>) obj;
         if (!Objects.equal(symbolicName, other.symbolicName)) return false;
+        if (!Objects.equal(containingBundle, other.containingBundle)) return false;
         if (!Objects.equal(planYaml, other.planYaml)) return false;
         if (!Objects.equal(javaType, other.javaType)) return false;
         if (!Objects.equal(nullIfEmpty(libraries), nullIfEmpty(other.libraries))) return
false;
@@ -360,6 +368,10 @@ public abstract class CatalogItemDtoAbstract<T, SpecT> extends
AbstractBrooklynO
         this.version = version;
     }
 
+    public void setContainingBundle(VersionedName versionedName) {
+        this.containingBundle = Strings.toString(versionedName);
+    }
+    
     protected void setDescription(String description) {
         this.description = description;
     }
@@ -439,4 +451,5 @@ public abstract class CatalogItemDtoAbstract<T, SpecT> extends AbstractBrooklynO
         Object val = map.get(key);
         return val != null ? String.valueOf(val) : null;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
index a56bb52..cdb40f4 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
@@ -221,6 +221,12 @@ public class OsgiManager {
             return managedBundleIds.get(vn);
         }
     }
+    
+    public ManagedBundle getManagedBundle(VersionedName vn) {
+        synchronized (managedBundles) {
+            return managedBundles.get(managedBundleIds.get(vn));
+        }
+    }
 
     public Bundle installUploadedBundle(ManagedBundle bundleMetadata, InputStream zipIn,
boolean loadCatalogBom) {
         try {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/core/src/main/java/org/apache/brooklyn/core/typereg/BasicRegisteredType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicRegisteredType.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicRegisteredType.java
index e0e2305..f345ec9 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicRegisteredType.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicRegisteredType.java
@@ -39,6 +39,7 @@ public class BasicRegisteredType implements RegisteredType {
     final RegisteredTypeKind kind;
     final String symbolicName;
     final String version;
+    String containingBundle;
     
     final List<OsgiBundleWithUrl> bundles = MutableList.of();
     String displayName;
@@ -84,6 +85,11 @@ public class BasicRegisteredType implements RegisteredType {
     }
     
     @Override
+    public String getContainingBundle() {
+        return containingBundle;
+    }
+    
+    @Override
     public Collection<OsgiBundleWithUrl> getLibraries() {
         return ImmutableSet.copyOf(bundles);
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a4886fd/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
index b3886bd..72feedd 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
@@ -33,6 +33,7 @@ import org.apache.brooklyn.api.mgmt.ManagementContext;
 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.RegisteredType;
 import org.apache.brooklyn.api.typereg.RegisteredType.TypeImplementationPlan;
 import org.apache.brooklyn.api.typereg.RegisteredTypeLoadingContext;
@@ -47,6 +48,7 @@ import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.guava.Maybe.Absent;
 import org.apache.brooklyn.util.text.NaturalOrderComparator;
+import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.text.VersionComparator;
 import org.apache.brooklyn.util.yaml.Yamls;
 import org.slf4j.Logger;
@@ -100,6 +102,7 @@ public class RegisteredTypes {
         }
         
         BasicRegisteredType type = (BasicRegisteredType) spec(item.getSymbolicName(), item.getVersion(),
impl, item.getCatalogItemJavaType());
+        type.containingBundle = item.getContainingBundle();
         type.displayName = item.getDisplayName();
         type.description = item.getDescription();
         type.iconUrl = item.getIconUrl();
@@ -167,6 +170,13 @@ public class RegisteredTypes {
     }
 
     @Beta
+    public static RegisteredType setContainingBundle(RegisteredType type, @Nullable ManagedBundle
bundle) {
+        ((BasicRegisteredType)type).containingBundle =
+            bundle==null ? null : Strings.toString(bundle.getVersionedName());
+        return type;
+    }
+
+    @Beta
     public static RegisteredType addSuperType(RegisteredType type, @Nullable Class<?>
superType) {
         if (superType!=null) {
             ((BasicRegisteredType)type).superTypes.add(superType);


Mime
View raw message