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 2016/07/12 10:03:42 UTC

[1/2] brooklyn-server git commit: Use entity's classpath when loading resources

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 34c28995e -> d5462fbbf


Use entity's classpath when loading resources

In addition to any libraries provided by the catalog item


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

Branch: refs/heads/master
Commit: c8129867eb174e632c3c616c1462a14a323d812d
Parents: 10613d1
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Fri Jul 8 15:50:06 2016 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Tue Jul 12 13:01:51 2016 +0300

----------------------------------------------------------------------
 .../brooklyn/catalog/CatalogYamlEntityTest.java | 71 ++++++++++++++++++++
 .../internal/AbstractManagementContext.java     |  7 +-
 2 files changed, 77 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c8129867/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
index 60eed64..ea62643 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
@@ -32,6 +32,7 @@ import org.apache.brooklyn.api.catalog.BrooklynCatalog;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
+import org.apache.brooklyn.api.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
 import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
@@ -892,6 +893,76 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
         deleteCatalogEntity(symbolicName);
     }
 
+    @Test
+    public void testIndirectCatalogItemCanLoadResources() throws Exception {
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+
+        String symbolicNameInner = "my.catalog.app.id.inner";
+        String symbolicNameOuter = "my.catalog.app.id.outer";
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  version: " + TEST_VERSION,
+            "  items:",
+            "  - id: " + symbolicNameInner,
+            "    name: My Catalog App",
+            "    description: My description",
+            "    icon_url: classpath://path/to/myicon.jpg",
+            "    libraries:",
+            "    - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+            "    item: " + SIMPLE_ENTITY_TYPE,
+            "  - id: " + symbolicNameOuter,
+            "    item: " + symbolicNameInner);
+
+        String yaml = "name: " + symbolicNameOuter + "\n" +
+                "services: \n" +
+                "  - serviceType: "+ver(symbolicNameOuter);
+        Entity app = createAndStartApplication(yaml);
+        Entity entity = app.getChildren().iterator().next();
+
+        ResourceUtils.create(entity).getResourceAsString("classpath://yaml-ref-osgi-entity.yaml");
+
+        deleteCatalogEntity(symbolicNameInner);
+        deleteCatalogEntity(symbolicNameOuter);
+    }
+
+    // The test is disabled as it fails. The entity will get assigned the outer-most catalog
+    // item which doesn't have the necessary libraries with visibility to the entity's classpath
+    // When loading resources from inside the entity then we will use the wrong BCLCS. A workaround
+    // has been implemented which explicitly adds the entity's class loader to the fallbacks.
+    @Test(groups="WIP")
+    public void testCatalogItemIdInReferencedItems() throws Exception {
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+
+        String symbolicNameInner = "my.catalog.app.id.inner";
+        String symbolicNameOuter = "my.catalog.app.id.outer";
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  version: " + TEST_VERSION,
+            "  items:",
+            "  - id: " + symbolicNameInner,
+            "    name: My Catalog App",
+            "    description: My description",
+            "    icon_url: classpath://path/to/myicon.jpg",
+            "    libraries:",
+            "    - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+            "    item: " + SIMPLE_ENTITY_TYPE,
+            "  - id: " + symbolicNameOuter,
+            "    item: " + symbolicNameInner);
+
+        String yaml = "name: " + symbolicNameOuter + "\n" +
+                "services: \n" +
+                "  - serviceType: "+ver(symbolicNameOuter);
+
+        Entity app = createAndStartApplication(yaml);
+        Entity entity = app.getChildren().iterator().next();
+
+        // Fails
+        assertEquals(entity.getCatalogItemId(), ver(symbolicNameInner));
+
+        deleteCatalogEntity(symbolicNameInner);
+        deleteCatalogEntity(symbolicNameOuter);
+    }
+
     private void registerAndLaunchAndAssertSimpleEntity(String symbolicName, String serviceType) throws Exception {
         addCatalogOSGiEntity(symbolicName, serviceType);
         String yaml = "name: simple-app-yaml\n" +

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c8129867/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
index 67bcd11..ea84f3c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
@@ -66,6 +66,7 @@ import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
 import org.apache.brooklyn.core.internal.storage.impl.inmemory.InMemoryDataGridFactory;
 import org.apache.brooklyn.core.location.BasicLocationRegistry;
 import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
+import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContextSequential;
 import org.apache.brooklyn.core.mgmt.classloading.JavaBrooklynClassLoadingContext;
 import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
 import org.apache.brooklyn.core.mgmt.ha.HighAvailabilityManagerImpl;
@@ -131,7 +132,11 @@ public abstract class AbstractManagementContext implements ManagementContextInte
                         RegisteredType item = internal.getManagementContext().getTypeRegistry().get(internal.getCatalogItemId());
 
                         if (item != null) {
-                            return CatalogUtils.newClassLoadingContext(internal.getManagementContext(), item);
+                            BrooklynClassLoadingContext itemLoader = CatalogUtils.newClassLoadingContext(internal.getManagementContext(), item);
+                            // Falls back to the entity's class loader
+                            JavaBrooklynClassLoadingContext entityLoader = JavaBrooklynClassLoadingContext.create(input.getClass().getClassLoader());
+                            BrooklynClassLoadingContext seqLoader = new BrooklynClassLoadingContextSequential(internal.getManagementContext(), itemLoader, entityLoader);
+                            return seqLoader;
                         } else {
                             log.error("Can't find catalog item " + internal.getCatalogItemId() +
                                     " used for instantiating entity " + internal +


[2/2] brooklyn-server git commit: Closes #240

Posted by sv...@apache.org.
Closes #240

Use entity's classpath when loading resources

In addition to any libraries provided by the catalog item.

We are actually assigning the wrong catalog item ID to the entity (should be the inner-most instead of the outer-most). That's more of a workaround, than fixing the root cause.


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

Branch: refs/heads/master
Commit: d5462fbbfb1cc1341e62ca753b77c3fef0ddc1c3
Parents: 34c2899 c812986
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Tue Jul 12 13:03:17 2016 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Tue Jul 12 13:03:17 2016 +0300

----------------------------------------------------------------------
 .../brooklyn/catalog/CatalogYamlEntityTest.java | 71 ++++++++++++++++++++
 .../internal/AbstractManagementContext.java     |  7 +-
 2 files changed, 77 insertions(+), 1 deletion(-)
----------------------------------------------------------------------