brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [05/18] git commit: Set the catalog item id used when creating BOSpecs
Date Tue, 04 Nov 2014 14:29:59 GMT
Set the catalog item id used when creating BOSpecs


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

Branch: refs/heads/master
Commit: d2d4e617f34ac52ae9e8103ed18478aa7335fa0f
Parents: b496958
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Thu Oct 30 13:15:45 2014 +0200
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Thu Oct 30 13:15:45 2014 +0200

----------------------------------------------------------------------
 .../catalog/internal/BasicBrooklynCatalog.java    |  2 +-
 .../brooklyn/catalog/internal/CatalogItemDo.java  |  2 +-
 .../brooklyn/catalog/internal/CatalogUtils.java   | 18 +++++++++++-------
 .../OsgiBrooklynClassLoadingContext.java          | 15 ++++++++++++---
 .../BrooklynComponentTemplateResolver.java        |  1 +
 5 files changed, 26 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d2d4e617/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
index a0a8375..f8bd2c8 100644
--- a/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
@@ -407,7 +407,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
 
         CatalogUtils.installLibraries(mgmt, libraries);
 
-        AbstractBrooklynObjectSpec<?, ?> spec = createSpec(plan, CatalogUtils.newClassLoadingContext(mgmt,
libraries));
+        AbstractBrooklynObjectSpec<?, ?> spec = createSpec(plan, CatalogUtils.newClassLoadingContext(mgmt,
"<not created yet>", libraries, getRootClassLoader()));
 
         CatalogItemBuilder<?> builder = createItemBuilder(spec, registeredTypeName)
             .libraries(libraries)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d2d4e617/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java b/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
index 178ef90..cb409fa 100644
--- a/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
+++ b/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
@@ -127,7 +127,7 @@ public class CatalogItemDo<T,SpecT> implements CatalogItem<T,SpecT>
{
     @SuppressWarnings("unchecked")
     Class<? extends T> loadJavaClass(final ManagementContext mgmt) {
         if (javaClass!=null) return javaClass;
-        javaClass = (Class<T>)CatalogUtils.newClassLoadingContext(mgmt, getLibraries(),
catalog.getRootClassLoader()).loadClass(getJavaType());
+        javaClass = (Class<T>)CatalogUtils.newClassLoadingContext(mgmt, getId(), getLibraries(),
catalog.getRootClassLoader()).loadClass(getJavaType());
         return javaClass;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d2d4e617/core/src/main/java/brooklyn/catalog/internal/CatalogUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/CatalogUtils.java b/core/src/main/java/brooklyn/catalog/internal/CatalogUtils.java
index 31a519e..c0ad54f 100644
--- a/core/src/main/java/brooklyn/catalog/internal/CatalogUtils.java
+++ b/core/src/main/java/brooklyn/catalog/internal/CatalogUtils.java
@@ -51,20 +51,16 @@ public class CatalogUtils {
         if (libraries == null) {
             log.debug("CatalogItemDtoAbstract.getLibraries() is null.", new Exception("Trace
for null CatalogItemDtoAbstract.getLibraries()"));
         }
-        return newClassLoadingContext(mgmt, libraries);
+        return newClassLoadingContext(mgmt, item.getId(), libraries, mgmt.getCatalog().getRootClassLoader());
     }
 
-    public static BrooklynClassLoadingContext newClassLoadingContext(@Nullable ManagementContext
mgmt, CatalogItemLibraries libraries) {
-        return newClassLoadingContext(mgmt, libraries, mgmt.getCatalog().getRootClassLoader());
-    }
-
-    public static BrooklynClassLoadingContext newClassLoadingContext(@Nullable ManagementContext
mgmt, CatalogItemLibraries libraries, ClassLoader classLoader) {
+    public static BrooklynClassLoadingContext newClassLoadingContext(@Nullable ManagementContext
mgmt, String catalogItemId, CatalogItemLibraries libraries, ClassLoader classLoader) {
         BrooklynClassLoadingContextSequential result = new BrooklynClassLoadingContextSequential(mgmt);
 
         if (libraries!=null) {
             List<String> bundles = libraries.getBundles();
             if (bundles!=null && !bundles.isEmpty()) {
-                result.add(new OsgiBrooklynClassLoadingContext(mgmt, bundles));
+                result.add(new OsgiBrooklynClassLoadingContext(mgmt, catalogItemId, bundles));
             }
         }
 
@@ -101,4 +97,12 @@ public class CatalogUtils {
         }
     }
 
+    public static String getContextCatalogItemIdFromLoader(BrooklynClassLoadingContext loader)
{
+        if (loader instanceof OsgiBrooklynClassLoadingContext) {
+            return ((OsgiBrooklynClassLoadingContext)loader).getContextCatalogId();
+        } else {
+            return null;
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d2d4e617/core/src/main/java/brooklyn/management/classloading/OsgiBrooklynClassLoadingContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/classloading/OsgiBrooklynClassLoadingContext.java
b/core/src/main/java/brooklyn/management/classloading/OsgiBrooklynClassLoadingContext.java
index 2b9058a..498d440 100644
--- a/core/src/main/java/brooklyn/management/classloading/OsgiBrooklynClassLoadingContext.java
+++ b/core/src/main/java/brooklyn/management/classloading/OsgiBrooklynClassLoadingContext.java
@@ -31,10 +31,12 @@ import com.google.common.base.Objects;
 public class OsgiBrooklynClassLoadingContext extends AbstractBrooklynClassLoadingContext
{
 
     private final List<String> bundles;
+    private final String contextCatalogId;
 
-    public OsgiBrooklynClassLoadingContext(ManagementContext mgmt, List<String> bundles)
{
+    public OsgiBrooklynClassLoadingContext(ManagementContext mgmt, String catalogItemId,
List<String> bundles) {
         super(mgmt);
         this.bundles = bundles;
+        this.contextCatalogId = catalogItemId;
     }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
@@ -69,14 +71,17 @@ public class OsgiBrooklynClassLoadingContext extends AbstractBrooklynClassLoadin
     
     @Override
     public int hashCode() {
-        return Objects.hashCode(super.hashCode(), bundles);
+        return Objects.hashCode(super.hashCode(), bundles, contextCatalogId);
     }
     
     @Override
     public boolean equals(Object obj) {
         if (!super.equals(obj)) return false;
         if (!(obj instanceof OsgiBrooklynClassLoadingContext)) return false;
-        if (!Objects.equal(bundles, ((OsgiBrooklynClassLoadingContext)obj).bundles)) return
false;
+
+        OsgiBrooklynClassLoadingContext other = (OsgiBrooklynClassLoadingContext)obj;
+        if (!contextCatalogId.equals(other.contextCatalogId)) return false;
+        if (!Objects.equal(bundles, other.bundles)) return false;
         return true;
     }
 
@@ -91,4 +96,8 @@ public class OsgiBrooklynClassLoadingContext extends AbstractBrooklynClassLoadin
         return null;
     }
     
+    public String getContextCatalogId() {
+        return contextCatalogId;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d2d4e617/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
index 98149fd..d4192b4 100644
--- a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
+++ b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
@@ -257,6 +257,7 @@ public class BrooklynComponentTemplateResolver {
             List<Class<?>> additionalInterfaceClazzes = Reflections.getAllInterfaces(type);
             spec = EntitySpec.create(interfaceclazz).impl(type).additionalInterfaces(additionalInterfaceClazzes);
         }
+        spec.contextCatalogItemId(CatalogUtils.getContextCatalogItemIdFromLoader(loader));
         if (template.isPresent() && template.get().getSourceCode()!=null)
             spec.tag(BrooklynTags.newYamlSpecTag(template.get().getSourceCode()));
 


Mime
View raw message