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 2017/03/09 15:45:56 UTC

[1/5] brooklyn-server git commit: add original failing test from @sjcorbett

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 40af35c42 -> 025a3d82d


add original failing test from @sjcorbett

for failure to set inherited config keys - https://issues.apache.org/jira/browse/BROOKLYN-445


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

Branch: refs/heads/master
Commit: d7cbaeed46d7fedf8e49df015baa812352060f45
Parents: 17aa622
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Feb 28 12:43:14 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Feb 28 12:43:14 2017 +0000

----------------------------------------------------------------------
 rest/rest-server/pom.xml                        |   6 +
 .../BrooklynRestApiLauncherTestFixture.java     |   2 +-
 .../entity/RedisClusterIntegrationTest.java     | 109 +++++++++++++++++++
 3 files changed, 116 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7cbaeed/rest/rest-server/pom.xml
----------------------------------------------------------------------
diff --git a/rest/rest-server/pom.xml b/rest/rest-server/pom.xml
index a269b72..bcd271b 100644
--- a/rest/rest-server/pom.xml
+++ b/rest/rest-server/pom.xml
@@ -153,6 +153,12 @@
         </dependency>
         <dependency>
             <groupId>org.apache.brooklyn</groupId>
+            <artifactId>brooklyn-software-nosql</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.brooklyn</groupId>
             <artifactId>brooklyn-locations-jclouds</artifactId>
             <version>${project.version}</version>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7cbaeed/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncherTestFixture.java
----------------------------------------------------------------------
diff --git a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncherTestFixture.java b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncherTestFixture.java
index b84dbcf..642ef87 100644
--- a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncherTestFixture.java
+++ b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncherTestFixture.java
@@ -47,7 +47,7 @@ import static org.testng.Assert.assertTrue;
 
 public abstract class BrooklynRestApiLauncherTestFixture {
 
-    Server server = null;
+    protected Server server = null;
     
     @AfterMethod(alwaysRun=true)
     public void stopServer() throws Exception {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7cbaeed/rest/rest-server/src/test/java/org/apache/brooklyn/rest/test/entity/RedisClusterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/test/entity/RedisClusterIntegrationTest.java b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/test/entity/RedisClusterIntegrationTest.java
new file mode 100644
index 0000000..79b162b
--- /dev/null
+++ b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/test/entity/RedisClusterIntegrationTest.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.brooklyn.rest.test.entity;
+
+import static org.apache.brooklyn.test.Asserts.assertTrue;
+import static org.testng.Assert.assertNotNull;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.core.entity.Attributes;
+import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityAsserts;
+import org.apache.brooklyn.entity.brooklynnode.BrooklynNode;
+import org.apache.brooklyn.entity.nosql.redis.RedisCluster;
+import org.apache.brooklyn.entity.nosql.redis.RedisStore;
+import org.apache.brooklyn.entity.software.base.SoftwareProcess;
+import org.apache.brooklyn.rest.BrooklynRestApiLauncherTestFixture;
+import org.apache.brooklyn.util.http.HttpAsserts;
+import org.apache.brooklyn.util.http.HttpToolResponse;
+import org.apache.brooklyn.util.text.Strings;
+import org.apache.brooklyn.util.time.Duration;
+import org.apache.brooklyn.util.yaml.Yamls;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class RedisClusterIntegrationTest extends BrooklynRestApiLauncherTestFixture {
+
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        useServerForTest(newServer());
+    }
+
+    @Test(groups = "Integration")
+    public void testDeployRedisCluster() throws InterruptedException, ExecutionException, TimeoutException {
+        final URI webConsoleUri = URI.create(getBaseUriRest());
+
+        // Test setup
+        final EntitySpec<BrooklynNode> spec = EntitySpec.create(BrooklynNode.class);
+        final ManagementContext mgmt = getManagementContextFromJettyServerAttributes(server);
+        final BrooklynNode node = mgmt.getEntityManager().createEntity(spec);
+        node.sensors().set(BrooklynNode.WEB_CONSOLE_URI, webConsoleUri);
+
+        // Deploy it.
+        final String blueprint = "location: localhost\n" +
+                "services:\n" +
+                "- type: org.apache.brooklyn.entity.nosql.redis.RedisCluster";
+        HttpToolResponse response = node.http().post(
+                "/applications",
+                ImmutableMap.of("Content-Type", "text/yaml"),
+                blueprint.getBytes());
+        HttpAsserts.assertHealthyStatusCode(response.getResponseCode());
+
+        // Assert application is eventually running and not on fire.
+        final Entity entity = mgmt.getApplications().iterator().next().getChildren().iterator().next();
+        assertTrue(entity instanceof RedisCluster,
+                "expected " + RedisCluster.class.getName() + ", found: " + entity);
+        RedisCluster cluster = RedisCluster.class.cast(entity);
+        Entities.dumpInfo(cluster);
+        assertDownloadUrl(cluster.getMaster());
+        for (Entity slave : cluster.getSlaves().getMembers()) {
+            assertDownloadUrl(slave);
+        }
+
+        @SuppressWarnings("unchecked")
+        String taskId = Strings.toString( ((Map<String,Object>) Yamls.parseAll(response.getContentAsString()).iterator().next()).get("id") );
+        Task<?> task = mgmt.getExecutionManager().getTask(taskId);
+        Assert.assertNotNull(task);
+        
+        task.get(Duration.minutes(20));
+        
+        Entities.dumpInfo(cluster);
+        
+        EntityAsserts.assertAttributeEquals(entity, SoftwareProcess.SERVICE_UP, true);
+    }
+    
+    private void assertDownloadUrl(Entity entity) {
+        assertNotNull(entity.config().get(RedisStore.DOWNLOAD_URL), "RedisStore.DOWNLOAD_URL");
+        assertNotNull(entity.config().get(SoftwareProcess.DOWNLOAD_URL), "SoftwareProcess.DOWNLOAD_URL");
+        assertNotNull(entity.config().get(Attributes.DOWNLOAD_URL), "Attributes.DOWNLOAD_URL");
+    }
+
+}
\ No newline at end of file


[3/5] brooklyn-server git commit: apply the fix for previous failing tests and https://issues.apache.org/jira/browse/BROOKLYN-445

Posted by sv...@apache.org.
apply the fix for previous failing tests and https://issues.apache.org/jira/browse/BROOKLYN-445

do not use a context catalog item id.  this is a significant change and release notes should be updated,
but it doesn't seem to break any of our tests; presumably most catalog items are already refactoring
so each item is declared as its own 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/9c38c94e
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/9c38c94e
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/9c38c94e

Branch: refs/heads/master
Commit: 9c38c94eeeb5a3de2a082f81546440980b1abb5c
Parents: edaf054
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Feb 28 12:55:24 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Feb 28 12:55:24 2017 +0000

----------------------------------------------------------------------
 .../brooklyn/api/internal/AbstractBrooklynObjectSpec.java |  8 ++++++--
 .../brooklyn/core/objs/proxy/InternalEntityFactory.java   | 10 ++++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9c38c94e/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java b/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
index e725885..6ca5f9d 100644
--- a/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
+++ b/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
@@ -75,7 +75,6 @@ public abstract class AbstractBrooklynObjectSpec<T,SpecT extends AbstractBrookly
     protected AbstractBrooklynObjectSpec(Class<? extends T> type) {
         checkValidType(type);
         this.type = type;
-        this.catalogItemId = ApiObjectsFactory.get().getCatalogItemIdFromContext();
     }
     
     @SuppressWarnings("unchecked")
@@ -98,13 +97,18 @@ public abstract class AbstractBrooklynObjectSpec<T,SpecT extends AbstractBrookly
         return self();
     }
     
+    /** Set the catalog item ID that defined this object, also used for searching for type and resources referenced */
+    // since https://issues.apache.org/jira/browse/BROOKLYN-445 this must no longer be used to indicate
+    // a caller-context catalog item that should be used for search purposes;
+    // if that behaviour is desired, the child should be refactored to be its own item in the catalog BOM
+    // (or TODO we add a separate field to record other catalog item IDs that could be applied for searching, see below)
     public SpecT catalogItemId(String val) {
         catalogItemId = val;
         return self();
     }
     // TODO in many places (callers to this method) we prefer a wrapper item ID;
     // that is right, because the wrapper's defn will refer to the wrapped,
-    // but we might need also to collect the item ID's so that *all* can be searched.
+    // but we might need also to collect the item ID's so that *all* can be searched, see #catalogItemId.
     // e.g. if R3 references R2 which references R1 any one of these might supply config keys 
     // referencing resources or types in their local bundles. 
     @Beta

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9c38c94e/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java b/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
index 401b312..6090c5b 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
@@ -271,8 +271,14 @@ public class InternalEntityFactory extends InternalFactory {
     }
 
     private void addSpecParameters(EntitySpec<?> spec, EntityDynamicType edType) {
-        // if coming from a catalog item, the spec list of parameters is canonical, 
-        // ie it has just the right ones from the class, so clear the parameters on the type
+        // if coming from a catalog item, parsed by CAMP, then the spec list of parameters is canonical,
+        // the parent item has had its config keys set as parameters here with those non-inheritable
+        // via type definition removed, so wipe those on the EDT to make sure non-inheritable ones are removed; 
+        // OTOH if item is blank, it was set as a java type, not inheriting it,
+        // and the config keys on the dynamic type are the correct ones to use, and usually there is nothing in spec.parameters,
+        // except what is being added programmatically.
+        // (this logic could get confused if catalog item ID referred to some runtime-inherited context,
+        // but those semantics should no longer be used -- https://issues.apache.org/jira/browse/BROOKLYN-445)
         if (Strings.isNonBlank(spec.getCatalogItemId())) {
             edType.clearConfigKeys();
         }


[2/5] brooklyn-server git commit: add similar tests, including one failing, isolating the error

Posted by sv...@apache.org.
add similar tests, including one failing, isolating the error


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

Branch: refs/heads/master
Commit: edaf05441ee46d05e4479a79aee055e6cbfe1237
Parents: d7cbaee
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Feb 28 12:44:17 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Feb 28 12:44:17 2017 +0000

----------------------------------------------------------------------
 .../camp/brooklyn/ConfigParametersYamlTest.java | 83 ++++++++++++++++++++
 1 file changed, 83 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/edaf0544/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
index 6e2d899..c26c3e5 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
@@ -23,14 +23,17 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.entity.ImplementedBy;
 import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
+import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.PortRange;
 import org.apache.brooklyn.camp.brooklyn.catalog.SpecParameterUnwrappingTest;
 import org.apache.brooklyn.config.ConfigKey;
@@ -40,6 +43,7 @@ import org.apache.brooklyn.core.config.ConfigPredicates;
 import org.apache.brooklyn.core.config.ConstraintViolationException;
 import org.apache.brooklyn.core.entity.AbstractEntity;
 import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
+import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.location.PortRanges;
 import org.apache.brooklyn.core.sensor.Sensors;
 import org.apache.brooklyn.core.test.entity.TestEntity;
@@ -792,6 +796,85 @@ public class ConfigParametersYamlTest extends AbstractYamlRebindTest {
     }
     
     @Test
+    public void testManuallyAddSpec() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "services:",
+                "- type: "+TestEntity.class.getName());
+
+        Entity app = createStartWaitAndLogApplication(yaml);
+        TestEntity entity1 = (TestEntity) Iterables.getOnlyElement(app.getChildren());
+
+        TestEntity entity2 = entity1.addChild(EntitySpec.create(TestEntity.class));
+        entity2.start(Collections.<Location>emptyList());
+        
+        Entities.dumpInfo(app);
+        
+        LOG.info("E1 keys: "+entity1.getEntityType().getConfigKeys());
+        LOG.info("E2 keys: "+entity2.getEntityType().getConfigKeys());
+        Assert.assertEquals(entity2.getEntityType().getConfigKeys(), entity1.getEntityType().getConfigKeys());
+    }
+    
+    @Test
+    public void testManuallyAddSpecFromCatalog() throws Exception {
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  itemType: entity",
+            "  items:",
+            "  - id: test-entity",
+            "    item:",
+            "      type: "+TestEntity.class.getName());
+        
+        String yaml = Joiner.on("\n").join(
+                "services:",
+                "- type: test-entity");
+
+        Entity app = createStartWaitAndLogApplication(yaml);
+        TestEntity entity1 = (TestEntity) Iterables.getOnlyElement(app.getChildren());
+
+        TestEntity entity2 = entity1.addChild(EntitySpec.create(TestEntity.class));
+        entity2.start(Collections.<Location>emptyList());
+        
+        Entities.dumpInfo(app);
+        
+        LOG.info("E1 keys: "+entity1.getEntityType().getConfigKeys());
+        LOG.info("E2 keys: "+entity2.getEntityType().getConfigKeys());
+        Assert.assertEquals(entity2.getEntityType().getConfigKeys(), entity1.getEntityType().getConfigKeys());
+    }
+    
+
+    @Test
+    public void testManuallyAddSpecInTaskOfOtherEntity() throws Exception {
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  itemType: entity",
+            "  items:",
+            "  - id: test-entity",
+            "    item:",
+            "      type: "+TestEntity.class.getName());
+        
+        String yaml = Joiner.on("\n").join(
+                "services:",
+                "- type: test-entity");
+
+        Entity app = createStartWaitAndLogApplication(yaml);
+        final TestEntity entity1 = (TestEntity) Iterables.getOnlyElement(app.getChildren());
+
+        TestEntity entity2 = entity1.getExecutionContext().submit(new Callable<TestEntity>() {
+            public TestEntity call() {
+                TestEntity entity2 = entity1.addChild(EntitySpec.create(TestEntity.class));
+                entity2.start(Collections.<Location>emptyList());
+                return entity2;
+            } 
+        }).get();
+        
+        Entities.dumpInfo(app);
+        
+        LOG.info("E1 keys: "+entity1.getEntityType().getConfigKeys());
+        LOG.info("E2 keys: "+entity2.getEntityType().getConfigKeys());
+        Assert.assertEquals(entity2.getEntityType().getConfigKeys(), entity1.getEntityType().getConfigKeys());
+    }
+    
+    @Test
     public void testPortSetAsAttributeOnSoftwareProcess() throws Exception {
         addCatalogItems(
                 "brooklyn.catalog:",


[5/5] brooklyn-server git commit: Closes #573

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

Do not runtime-inherit catalog item in the spec to fix config key list problem

fixes https://issues.apache.org/jira/browse/BROOKLYN-445 and failing tests included here

means catalog BOMs should be written such that any entity/policy/etc which wants to access resources in the bundle is defined as its own 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/025a3d82
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/025a3d82
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/025a3d82

Branch: refs/heads/master
Commit: 025a3d82ddbb9a440c9510892d6da2a1b6bae660
Parents: 40af35c 4033060
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Thu Mar 9 17:45:44 2017 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Thu Mar 9 17:45:44 2017 +0200

----------------------------------------------------------------------
 .../internal/AbstractBrooklynObjectSpec.java    |  10 +-
 .../camp/brooklyn/ConfigParametersYamlTest.java |  97 +++++++++++++++
 .../catalog/CatalogOsgiLibraryTest.java         | 119 +++++++++++++++++++
 .../core/catalog/internal/CatalogUtils.java     |   1 +
 .../apache/brooklyn/core/entity/Entities.java   |   4 +
 .../core/objs/AbstractBrooklynObject.java       |  19 +--
 .../core/objs/proxy/InternalEntityFactory.java  |  10 +-
 .../brooklyn/util/core/ClassLoaderUtils.java    |  33 +++--
 rest/rest-server/pom.xml                        |   6 +
 .../BrooklynRestApiLauncherTestFixture.java     |   2 +-
 .../entity/RedisClusterIntegrationTest.java     | 109 +++++++++++++++++
 11 files changed, 387 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/025a3d82/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
----------------------------------------------------------------------


[4/5] brooklyn-server git commit: comment and test for catalog item ID being set from context/parent

Posted by sv...@apache.org.
comment and test for catalog item ID being set from context/parent

added comments about what should change for this to properly set a search path instead.
we don't have other inheritance problems with actual BrooklynObject's recording a wrong
catalog item id instead of null (the way we did with Spec, hence the other change);
so we can leave that which may be useful until we have search paths done properly

also better logging if an invalid bundle is passed when trying to load
(discovered this when trying to pass a URL where `osgi_bundle:resource` semantics were expected)


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

Branch: refs/heads/master
Commit: 40330602af958d1e3486feea81933168d44e936d
Parents: 9c38c94
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Mar 6 11:09:47 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Mar 7 15:25:42 2017 +0000

----------------------------------------------------------------------
 .../internal/AbstractBrooklynObjectSpec.java    |   2 +-
 .../camp/brooklyn/ConfigParametersYamlTest.java |  20 +++-
 .../catalog/CatalogOsgiLibraryTest.java         | 119 +++++++++++++++++++
 .../core/catalog/internal/CatalogUtils.java     |   1 +
 .../apache/brooklyn/core/entity/Entities.java   |   4 +
 .../core/objs/AbstractBrooklynObject.java       |  19 +--
 .../brooklyn/util/core/ClassLoaderUtils.java    |  33 +++--
 7 files changed, 177 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/40330602/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java b/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
index 6ca5f9d..c3d45af 100644
--- a/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
+++ b/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
@@ -114,7 +114,7 @@ public abstract class AbstractBrooklynObjectSpec<T,SpecT extends AbstractBrookly
     @Beta
     public SpecT catalogItemIdIfNotNull(String val) {
         if (val!=null) {
-            catalogItemId = val;
+            catalogItemId(val);
         }
         return self();
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/40330602/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
index c26c3e5..f3ce7f7 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
@@ -796,7 +796,7 @@ public class ConfigParametersYamlTest extends AbstractYamlRebindTest {
     }
     
     @Test
-    public void testManuallyAddSpec() throws Exception {
+    public void testManuallyAdd() throws Exception {
         String yaml = Joiner.on("\n").join(
                 "services:",
                 "- type: "+TestEntity.class.getName());
@@ -812,10 +812,12 @@ public class ConfigParametersYamlTest extends AbstractYamlRebindTest {
         LOG.info("E1 keys: "+entity1.getEntityType().getConfigKeys());
         LOG.info("E2 keys: "+entity2.getEntityType().getConfigKeys());
         Assert.assertEquals(entity2.getEntityType().getConfigKeys(), entity1.getEntityType().getConfigKeys());
+        Assert.assertEquals(entity1.getCatalogItemId(), null);
+        Assert.assertEquals(entity2.getCatalogItemId(), null);
     }
     
     @Test
-    public void testManuallyAddSpecFromCatalog() throws Exception {
+    public void testManuallyAddWithParentFromCatalog() throws Exception {
         addCatalogItems(
             "brooklyn.catalog:",
             "  itemType: entity",
@@ -839,11 +841,17 @@ public class ConfigParametersYamlTest extends AbstractYamlRebindTest {
         LOG.info("E1 keys: "+entity1.getEntityType().getConfigKeys());
         LOG.info("E2 keys: "+entity2.getEntityType().getConfigKeys());
         Assert.assertEquals(entity2.getEntityType().getConfigKeys(), entity1.getEntityType().getConfigKeys());
+        Assert.assertEquals(entity1.getCatalogItemId(), "test-entity:0.0.0.SNAPSHOT");
+        
+        // TODO currently the child has item ID set from CatalogUtils.setCatalogItemIdOnAddition
+        // that should set a search path instead of setting the actual item
+        // (ideally we'd assert null here)
+        Assert.assertEquals(entity2.getCatalogItemId(), "test-entity:0.0.0.SNAPSHOT");
     }
     
 
     @Test
-    public void testManuallyAddSpecInTaskOfOtherEntity() throws Exception {
+    public void testManuallyAddInTaskOfOtherEntity() throws Exception {
         addCatalogItems(
             "brooklyn.catalog:",
             "  itemType: entity",
@@ -872,6 +880,12 @@ public class ConfigParametersYamlTest extends AbstractYamlRebindTest {
         LOG.info("E1 keys: "+entity1.getEntityType().getConfigKeys());
         LOG.info("E2 keys: "+entity2.getEntityType().getConfigKeys());
         Assert.assertEquals(entity2.getEntityType().getConfigKeys(), entity1.getEntityType().getConfigKeys());
+        Assert.assertEquals(entity1.getCatalogItemId(), "test-entity:0.0.0.SNAPSHOT");
+        
+        // TODO currently the child has item ID set from context in constructor of AbstractBrooklynObject;
+        // that should set a search path instead of setting the actual item
+        // (ideally we'd assert null here)
+        Assert.assertEquals(entity2.getCatalogItemId(), "test-entity:0.0.0.SNAPSHOT");
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/40330602/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiLibraryTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiLibraryTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiLibraryTest.java
index c504047..111ec4b 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiLibraryTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiLibraryTest.java
@@ -28,17 +28,23 @@ import java.util.Map;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
 import org.apache.brooklyn.core.config.external.AbstractExternalConfigSupplier;
+import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.mgmt.internal.ExternalConfigSupplierRegistry;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.entity.stock.BasicApplication;
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.test.http.TestHttpRecordingRequestInterceptor;
 import org.apache.brooklyn.test.http.TestHttpRequestHandler;
 import org.apache.brooklyn.test.http.TestHttpServer;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
+import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.net.Urls;
 import org.apache.brooklyn.util.osgi.OsgiTestResources;
 import org.apache.brooklyn.util.stream.Streams;
@@ -46,6 +52,7 @@ import org.apache.http.Header;
 import org.apache.http.HttpRequest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -220,6 +227,118 @@ public class CatalogOsgiLibraryTest extends AbstractYamlTest {
         assertCatalogLibraryUrl(item, classpathUrl);
     }
 
+    @Test
+    public void testLibraryIsUsedByAppDeclaredInCatalog() throws Exception {
+        // simplest case, an app in the bundle, can resolve files in the same bundle
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  id: item-from-library",
+            "  version: \"1.0\"",
+            "  itemType: template",
+            "  libraries:",
+            "  - " + classpathUrl,
+            "  item:",
+            "    services:",
+            "    - type: org.apache.brooklyn.test.osgi.entities.SimpleApplication");
+        Entity app = createAndStartApplication("services: [ { type: item-from-library } ]");
+        assertCanFindMessages( app );
+    }
+    
+    @Test
+    public void testLibraryIsUsedByStockEntityDeclaredInCatalog() throws Exception {
+        // slightly trickier case, an entity NOT in the bundle, declared as an item, can resolve files in its library bundles
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  id: item-from-library",
+            "  version: \"1.0\"",
+            "  itemType: template",
+            "  libraries:",
+            "  - " + classpathUrl,
+            "  item:",
+            "    services:",
+            "    - type: "+TestEntity.class.getName());
+        Entity app = createAndStartApplication("services: [ { type: item-from-library } ]");
+        assertCanFindMessages( app.getChildren().iterator().next() );
+    }
+
+    protected void assertCanFindMessages(Entity entity) {
+        ResourceUtils ru = ResourceUtils.create(entity);
+        Iterable<URL> files = ru.getResources("org/apache/brooklyn/test/osgi/resources/message.txt");
+        if (!files.iterator().hasNext()) {
+            Entities.dumpInfo(entity);
+            Assert.fail("Expected to find 'messages.txt'");
+        }
+    }
+    
+    @Test
+    public void testLibraryIsUsedByChildInCatalogItem() throws Exception {
+        // even trickier, something added as a child can resolve bundles
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  id: item-from-library",
+            "  version: \"1.0\"",
+            "  itemType: template",
+            "  libraries:",
+            "  - " + classpathUrl,
+            "  item:",
+            "    services:",
+            "    - type: "+TestEntity.class.getName(),
+            "      name: parent",
+            "      brooklyn.children:",
+            "      - type: "+TestEntity.class.getName(),
+            "        name: child");
+        
+        RegisteredType item = mgmt().getTypeRegistry().get("item-from-library", "1.0");
+        Assert.assertNotNull(item, "Should have had item-from-library in catalog");
+        AbstractBrooklynObjectSpec<?, ?> spec = mgmt().getTypeRegistry().createSpec(item, null, null);
+        Assert.assertNotNull(spec, "Should have had spec");
+        // the spec has no catalog item ID except at the root Application
+        
+        Entity app = createAndStartApplication("services: [ { type: item-from-library } ]");
+        Entity entity = app.getChildren().iterator().next();
+        entity = entity.getChildren().iterator().next();
+        Entities.dumpInfo(entity);
+        
+        // TODO re-enable when we've converted to a search path;
+        // currently this test method passes because of CatalogUtils.setCatalogItemIdOnAddition
+        // but we don't want to be doing that, we only want the search path
+        //Assert.assertNull(entity.getCatalogItemId(), "Entity had a catalog item ID, even though it was stockj");
+        
+        assertCanFindMessages( entity );
+    }
+    
+    @Test
+    public void testLibraryIsUsedByChildInCatalogItemIfItIsFromCatalogItem() throws Exception {
+        // even trickier, something added as a child can resolve bundles
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  version: \"1.0\"",
+            "  itemType: template",
+            "  libraries:",
+            "  - " + classpathUrl,
+            "  items:",
+            "  - id: child-from-library",
+            "    item:",
+            "      services:",
+            "      - type: "+TestEntity.class.getName(),
+            "  - id: parent-with-child-from-library",
+            "    item:",
+            "      services:",
+            "      - type: "+TestEntity.class.getName(),
+            "        brooklyn.children:",
+            "        - type: child-from-library");
+        
+        Entity app = createAndStartApplication("services: [ { type: parent-with-child-from-library } ]");
+        Entity entity = app.getChildren().iterator().next();
+        entity = entity.getChildren().iterator().next();
+        
+        assertCanFindMessages( entity );
+    }
+
     @Test(groups="Broken")
     public void testLibraryUrlUsingExternalizedConfigForCredentials() throws Exception {
         runLibraryUrlUsingExternalizedConfigForCredentials(true);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/40330602/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
index 078ff0f..ff96ae5 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
@@ -175,6 +175,7 @@ public class CatalogUtils {
         }
     }
 
+    // TODO should be addToCatalogSearchPathOnAddition
     public static void setCatalogItemIdOnAddition(Entity entity, BrooklynObject itemBeingAdded) {
         if (entity.getCatalogItemId()!=null) {
             if (itemBeingAdded.getCatalogItemId()==null) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/40330602/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
index 9df6e93..da5adf7 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
@@ -94,6 +94,7 @@ import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.repeat.Repeater;
 import org.apache.brooklyn.util.stream.Streams;
+import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.time.Duration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -324,6 +325,9 @@ public class Entities {
         out.append(currentIndentation+e.toString()+" "+e.getId()+"\n");
 
         out.append(currentIndentation+tab+tab+"displayName = "+e.getDisplayName()+"\n");
+        if (Strings.isNonBlank(e.getCatalogItemId())) {
+            out.append(currentIndentation+tab+tab+"catalogItemId = "+e.getCatalogItemId()+"\n");
+        }
 
         out.append(currentIndentation+tab+tab+"locations = "+e.getLocations()+"\n");
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/40330602/core/src/main/java/org/apache/brooklyn/core/objs/AbstractBrooklynObject.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractBrooklynObject.java b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractBrooklynObject.java
index 7b77628..d435135 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractBrooklynObject.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractBrooklynObject.java
@@ -22,14 +22,6 @@ import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
 import org.apache.brooklyn.api.internal.ApiObjectsFactory;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.entity.AbstractEntity;
@@ -40,6 +32,13 @@ import org.apache.brooklyn.core.relations.ByObjectBasicRelationSupport;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
 import org.apache.brooklyn.util.text.Identifiers;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 
 public abstract class AbstractBrooklynObject implements BrooklynObjectInternal {
 
@@ -80,6 +79,10 @@ public abstract class AbstractBrooklynObject implements BrooklynObjectInternal {
             _legacyConstruction = true;
         }
 
+        // TODO this will be overridden if the spec has a catalog item ID
+        // correct behaviour should be to inherit context's search path, perhaps, though maybe that's better done as spec?
+        // in any case, should not define it as _the_ catalog item ID; also see assignment based on parent
+        // in CatalogUtils.setCatalogItemIdOnAddition
         catalogItemId = ApiObjectsFactory.get().getCatalogItemIdFromContext();
 
         // rely on sub-class to call configure(properties), because otherwise its fields will not have been initialised

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/40330602/core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java b/core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java
index dab7238..afb45ba 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/ClassLoaderUtils.java
@@ -39,6 +39,7 @@ import org.apache.brooklyn.util.core.osgi.Osgis;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.osgi.OsgiUtils;
+import org.apache.brooklyn.util.text.Strings;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
@@ -48,7 +49,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Joiner;
-import com.google.common.base.Objects;
+import com.google.common.base.MoreObjects;
 import com.google.common.base.Predicate;
 import com.google.common.collect.ImmutableList;
 
@@ -220,7 +221,27 @@ public class ClassLoaderUtils {
             // Very explicit; do as we're told!
             return tryLoadFromBundle(dispatcher, symbolicName, version, className);
         }
+        
+        if (symbolicName != null) {
+            cls = tryLoadFromBundle(dispatcher, symbolicName, version, className);
+            if (cls.isPresent()) {
+                return cls;
+            }
+            Maybe<T> result = loadClass(name, dispatcher, className);
+            
+            String notFoundWithSymbolicNameMessage = "No class '"+className+"' in bundle '"+symbolicName+"' (using spec '"+name+"')";
+            if (result.isPresent()) {
+                log.warn(notFoundWithSymbolicNameMessage+"; found using deprecated no-bundle syntax, but this behaviour is deprecated and likely to be unsupported in future. Change so invalid bundle is not supplied.");
+            } else {
+                return Maybe.absent(notFoundWithSymbolicNameMessage);
+            }
+        }
 
+        return loadClass(name, dispatcher, className);
+    }
+    
+    private <T> Maybe<T> loadClass(String name, LoaderDispatcher<T> dispatcher, String className) {
+        Maybe<T> cls;
         if (entity != null && mgmt != null) {
             String catalogItemId = entity.getCatalogItemId();
             if (catalogItemId != null) {
@@ -254,13 +275,6 @@ public class ClassLoaderUtils {
             }
         }
 
-        if (symbolicName != null) {
-            cls = tryLoadFromBundle(dispatcher, symbolicName, version, className);
-            if (cls.isPresent()) {
-                return cls;
-            }
-        }
-
         return Maybe.absentNull();
     }
 
@@ -276,6 +290,7 @@ public class ClassLoaderUtils {
             }
             return dispatcher.tryLoadFrom(bundle.get(), name);
         } else {
+            log.warn("Request for bundle '"+symbolicName+"' "+(Strings.isNonBlank(version) ? "("+version+") " : "")+"will be ignored, loading '"+name+"' as no framework available");
             return dispatcher.tryLoadFrom(classLoader, name);
         }
     }
@@ -389,7 +404,7 @@ public class ClassLoaderUtils {
     
     @Override
     public String toString() {
-        return getClass().getSimpleName() + "[" + Objects.toStringHelper(this)
+        return getClass().getSimpleName() + "[" + MoreObjects.toStringHelper(this)
             .add("claddLoader", classLoader)
             .add("entity", entity)
             .add("mgmt", mgmt) + "]";