You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2016/12/22 20:08:37 UTC

[1/2] brooklyn-server git commit: BROOKLYN-410: rebind locations from bundles

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 7b5d367b8 -> b629f1b98


BROOKLYN-410: rebind locations from bundles


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

Branch: refs/heads/master
Commit: c964e36b82652e61220ad41d367dd09762b88c7d
Parents: 923abe7
Author: Aled Sage <al...@gmail.com>
Authored: Wed Dec 14 15:33:04 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Dec 20 11:34:14 2016 +0000

----------------------------------------------------------------------
 .../CatalogOsgiVersionMoreEntityRebindTest.java | 43 ++++++++++++++++++++
 .../core/mgmt/rebind/RebindIteration.java       |  2 +-
 2 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c964e36b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
index 5c131f5..b4af697 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
@@ -21,18 +21,24 @@ package org.apache.brooklyn.camp.brooklyn.catalog;
 import static org.testng.Assert.assertEquals;
 
 import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.camp.brooklyn.AbstractYamlRebindTest;
+import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.entity.StartableApplication;
 import org.apache.brooklyn.core.mgmt.osgi.OsgiVersionMoreEntityTest;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.entity.stock.BasicApplication;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
+import org.apache.brooklyn.util.core.ClassLoaderUtils;
+import org.apache.brooklyn.util.javalang.Reflections;
 import org.apache.brooklyn.util.osgi.OsgiTestResources;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.Test;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 
 /** Many of the same tests as per {@link OsgiVersionMoreEntityTest} but using YAML for catalog and entities, so catalog item ID is set automatically */
@@ -85,4 +91,41 @@ public class CatalogOsgiVersionMoreEntityRebindTest extends AbstractYamlRebindTe
         Policy newPolicy = Iterables.getOnlyElement(newEntity.policies());
         assertEquals(newPolicy.getPolicyType().getName(), policyType);
     }
+    
+    // See https://issues.apache.org/jira/browse/BROOKLYN-410
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testRebindsLocationFromBundle() throws Exception {
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH);
+        
+        String locationType = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_LOCATION;
+        String locationTypeWithBundlePrefix = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_SYMBOLIC_NAME_FULL + ":" + locationType;
+
+        addCatalogItems(
+                "brooklyn.catalog:",
+                "  id: with-library",
+                "  version: 1.0",
+                "  brooklyn.libraries:",
+                "  - classpath:" + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH,
+                "  item:",
+                "    services:",
+                "    - type: " + BasicApplication.class.getName(),
+                "      brooklyn.children:",
+                "      - type: " + TestEntity.class.getName());
+        
+        Entity app = createAndStartApplication("services: [ { type: 'with-library:1.0' } ]");
+        Entity entity = Iterables.getOnlyElement(app.getChildren());
+        
+        // Add a location that can only be classloaded from the `brooklyn.libraries` bundle
+        Reflections reflections = new Reflections(CatalogOsgiVersionMoreEntityRebindTest.class.getClassLoader());
+        Class<? extends Location> locationClazz = (Class<? extends Location>) new ClassLoaderUtils(reflections.getClassLoader(), mgmt()).loadClass(locationTypeWithBundlePrefix);
+        Location loc = mgmt().getLocationManager().createLocation(LocationSpec.create(locationClazz));
+        ((EntityInternal)entity).addLocations(ImmutableList.of(loc));
+
+        // Confirm that we can rebind, and thus instantiate that location
+        StartableApplication newApp = rebind();
+        Entity newEntity = Iterables.getOnlyElement(newApp.getChildren());
+        Location newLoc = Iterables.getOnlyElement(newEntity.getLocations());
+        assertEquals(newLoc.getClass().getName(), locationType);
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c964e36b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
index 4aee9a8..2164814 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
@@ -988,7 +988,7 @@ public abstract class RebindIteration {
             } catch (Exception e) {
                 Exceptions.propagateIfFatal(e);
             }
-            return new ClassLoaderUtils(reflections.getClassLoader()).loadClass(jType);
+            return new ClassLoaderUtils(reflections.getClassLoader(), managementContext).loadClass(jType);
         }
 
         @SuppressWarnings("unchecked")


[2/2] brooklyn-server git commit: This closes #490

Posted by al...@apache.org.
This closes #490


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

Branch: refs/heads/master
Commit: b629f1b98a0fed02ee1d705b008690fa151889da
Parents: 7b5d367 c964e36
Author: Aled Sage <al...@gmail.com>
Authored: Thu Dec 22 20:08:16 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Dec 22 20:08:16 2016 +0000

----------------------------------------------------------------------
 .../CatalogOsgiVersionMoreEntityRebindTest.java | 43 ++++++++++++++++++++
 .../core/mgmt/rebind/RebindIteration.java       |  2 +-
 2 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------