Stop OSGi catalog items leaking libraries to parent. The loader of the catalog item matching the type was used to load the type itself, while only the loader passed from caller should be used. If the catalog items' symbolicName was matching the java type they expose, they would be leaking their OSGi bundles.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/3b8e5eb7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/3b8e5eb7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/3b8e5eb7 Branch: refs/heads/master Commit: 3b8e5eb7060541b61d914476c4ab040ae3d870b6 Parents: fecec16 Author: Svetoslav Neykov <[email protected]> Authored: Wed Dec 10 16:56:17 2014 +0200 Committer: Svetoslav Neykov <[email protected]> Committed: Thu Jan 29 16:41:25 2015 +0200 ---------------------------------------------------------------------- .../BrooklynComponentTemplateResolver.java | 14 +------------- .../brooklyn/catalog/CatalogYamlEntityTest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3b8e5eb7/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 c1a8e4f..403a40e 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 @@ -217,19 +217,7 @@ public class BrooklynComponentTemplateResolver { /** tries to load the Java entity class */ public Maybe<Class<? extends Entity>> tryLoadEntityClass() { - CatalogItem<Entity, EntitySpec<?>> item = getCatalogItem(); - String typeName = getBrooklynType(); - - if (item!=null) { - // add additional bundles - loader = new BrooklynClassLoadingContextSequential(mgmt, CatalogUtils.newClassLoadingContext(mgmt, item), loader); - - if (item.getJavaType() != null) { - typeName = item.getJavaType(); - } - } - - return loader.tryLoadClass(typeName, Entity.class); + return loader.tryLoadClass(getBrooklynType(), Entity.class); } /** resolves the spec, updating the loader if a catalog item is loaded */ http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3b8e5eb7/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java ---------------------------------------------------------------------- diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java index 5724351..048a75f 100644 --- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java +++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java @@ -421,6 +421,23 @@ public class CatalogYamlEntityTest extends AbstractYamlTest { } } + @Test + public void testOsgiNotLeakingToParent() { + addCatalogOSGiEntity(SIMPLE_ENTITY_TYPE); + try { + addCatalogItem( + "brooklyn.catalog:", + " id: " + SIMPLE_ENTITY_TYPE, + " version: " + TEST_VERSION + "-update", + "", + "services:", + "- type: " + SIMPLE_ENTITY_TYPE); + fail("Catalog addition expected to fail due to non-existent java type " + SIMPLE_ENTITY_TYPE); + } catch (IllegalStateException e) { + assertEquals(e.getMessage(), "Recursive reference to " + SIMPLE_ENTITY_TYPE + " (and cannot be resolved as a Java type)"); + } + } + private void registerAndLaunchAndAssertSimpleEntity(String symbolicName, String serviceType) throws Exception { addCatalogOSGiEntity(symbolicName, serviceType); String yaml = "name: simple-app-yaml\n" +
