You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/05/10 10:04:19 UTC

[1/2] brooklyn-server git commit: Inclusion of catalog files inside other catalog files

Repository: brooklyn-server
Updated Branches:
  refs/heads/master c7da7ea22 -> 6a60dd454


Inclusion of catalog files inside other catalog files


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

Branch: refs/heads/master
Commit: d2f8ff16947dcbafd678841bcf64cb5d0214e0ef
Parents: 917e101
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Fri Apr 22 12:01:56 2016 +0100
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Mon Apr 25 19:19:59 2016 +0300

----------------------------------------------------------------------
 .../camp/brooklyn/ReferencedYamlTest.java       | 117 +++++++++++++++++++
 .../catalog/internal/BasicBrooklynCatalog.java  |  46 ++++++--
 .../main/resources/yaml-ref-back-catalog.bom    |  30 +++++
 .../main/resources/yaml-ref-parent-catalog.bom  |  33 ++++++
 .../osgi/brooklyn-test-osgi-entities.jar        | Bin 16091 -> 17775 bytes
 5 files changed, 217 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d2f8ff16/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java
index 7979f7c..0ebbc56 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java
@@ -20,11 +20,14 @@ package org.apache.brooklyn.camp.brooklyn;
 
 import java.util.Collection;
 
+import org.apache.brooklyn.api.catalog.BrooklynCatalog;
+import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
 import org.apache.brooklyn.entity.stock.BasicApplication;
 import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
+import org.apache.brooklyn.util.osgi.OsgiTestResources;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -154,6 +157,31 @@ public class ReferencedYamlTest extends AbstractYamlTest {
         checkChildEntitySpec(app, entityName);
     }
 
+    @Test(groups="WIP") //Not able to use caller provided catalog items when referencing entity specs (as opposed to catalog meta)
+    public void testYamlUrlReferencingCallerCatalogItem() throws Exception {
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  items:",
+            "  - id: yaml.standalone",
+            "    version: " + TEST_VERSION,
+            "    item:",
+            "      services:",
+            "      - type: org.apache.brooklyn.entity.stock.BasicApplication",
+            "  - id: yaml.reference",
+            "    version: " + TEST_VERSION,
+            "    item:",
+            "      services:",
+            "      - type: classpath://yaml-ref-parent-catalog.yaml");
+
+        String entityName = "YAML -> catalog item -> yaml url";
+        Entity app = createAndStartApplication(
+            "services:",
+            "- name: " + entityName,
+            "  type: " + ver("yaml.reference"));
+        
+        checkChildEntitySpec(app, entityName);
+    }
+
     /**
      * Tests that a YAML referenced by URL from a catalog item
      * will have access to the catalog item's bundles.
@@ -185,6 +213,95 @@ public class ReferencedYamlTest extends AbstractYamlTest {
         deleteCatalogEntity(parentCatalogId);
     }
 
+    @Test
+    public void testCatalogReference() throws Exception {
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  brooklyn.libraries:",
+            "  - " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+            "  items:",
+            "  - classpath://yaml-ref-parent-catalog.bom");
+
+        assertCatalogReference();
+    }
+
+    @Test
+    public void testCatalogReferenceByExplicitUrl() throws Exception {
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  brooklyn.libraries:",
+            "  - " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+            "  items:",
+            "  - include: classpath://yaml-ref-parent-catalog.bom");
+
+        assertCatalogReference();
+    }
+
+    @Test
+    public void testCatalogReferenceSeesPreviousItems() throws Exception {
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  brooklyn.libraries:",
+            "  - " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+            "  items:",
+            "  - id: yaml.nested.catalog.simple",
+            "    item:",
+            "      type: " + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY,
+            "  - include: classpath://yaml-ref-back-catalog.bom");
+
+        String entityNameSimple = "YAML -> catalog -> catalog (osgi)";
+        Entity app = createAndStartApplication(
+            "services:",
+            "- name: " + entityNameSimple,
+            "  type: back-reference");
+        
+        Collection<Entity> children = app.getChildren();
+        Assert.assertEquals(children.size(), 1);
+        Entity childSimple = Iterables.getOnlyElement(children);
+        Assert.assertEquals(childSimple.getDisplayName(), entityNameSimple);
+        Assert.assertEquals(childSimple.getEntityType().getName(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY);
+    }
+
+    @Test
+    public void testCatalogReferenceMixesMetaAndUrl() throws Exception {
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  brooklyn.libraries:",
+            "  - " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+            "  items:",
+            "  - include: classpath://yaml-ref-parent-catalog.bom",
+            "    items:",
+            "    - id: yaml.nested.catalog.nested",
+            "      item:",
+            "        type: " + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY);
+
+        BrooklynCatalog catalog = mgmt().getCatalog();
+        Assert.assertNotNull(catalog.getCatalogItem("yaml.nested.catalog.nested", BrooklynCatalog.DEFAULT_VERSION));
+        Assert.assertNotNull(catalog.getCatalogItem("yaml.nested.catalog.simple", BrooklynCatalog.DEFAULT_VERSION));
+        Assert.assertNotNull(catalog.getCatalogItem("yaml.nested.catalog.more", BrooklynCatalog.DEFAULT_VERSION));
+    }
+
+    protected void assertCatalogReference() throws Exception {
+        String entityNameSimple = "YAML -> catalog -> catalog simple (osgi)";
+        String entityNameMore = "YAML -> catalog -> catalog more (osgi)";
+        Entity app = createAndStartApplication(
+            "services:",
+            "- name: " + entityNameSimple,
+            "  type: yaml.nested.catalog.simple",
+            "- name: " + entityNameMore,
+            "  type: yaml.nested.catalog.more");
+        
+        Collection<Entity> children = app.getChildren();
+        Assert.assertEquals(children.size(), 2);
+        Entity childSimple = Iterables.get(children, 0);
+        Assert.assertEquals(childSimple.getDisplayName(), entityNameSimple);
+        Assert.assertEquals(childSimple.getEntityType().getName(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY);
+
+        Entity childMore = Iterables.get(children, 1);
+        Assert.assertEquals(childMore.getDisplayName(), entityNameMore);
+        Assert.assertEquals(childMore.getEntityType().getName(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY);
+    }
+
     private void checkChildEntitySpec(Entity app, String entityName) {
         Collection<Entity> children = app.getChildren();
         Assert.assertEquals(children.size(), 1);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d2f8ff16/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index c259ca3..3587976 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -47,6 +47,7 @@ import org.apache.brooklyn.core.typereg.BrooklynTypePlanTransformer;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.collections.MutableSet;
+import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.core.flags.TypeCoercions;
 import org.apache.brooklyn.util.core.task.Tasks;
 import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -69,6 +70,7 @@ import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSortedSet;
 import com.google.common.collect.Iterables;
 
@@ -364,16 +366,20 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
     }
 
     private List<CatalogItemDtoAbstract<?,?>> collectCatalogItems(String yaml) {
+        List<CatalogItemDtoAbstract<?, ?>> result = MutableList.of();
+        collectCatalogItems(yaml, result, ImmutableMap.of());
+        return result;
+    }
+
+    private void collectCatalogItems(String yaml, List<CatalogItemDtoAbstract<?, ?>> result, Map<?, ?> parentMeta) {
         Map<?,?> itemDef = Yamls.getAs(Yamls.parseAll(yaml), Map.class);
         Map<?,?> catalogMetadata = getFirstAsMap(itemDef, "brooklyn.catalog").orNull();
         if (catalogMetadata==null)
             log.warn("No `brooklyn.catalog` supplied in catalog request; using legacy mode for "+itemDef);
         catalogMetadata = MutableMap.copyOf(catalogMetadata);
 
-        List<CatalogItemDtoAbstract<?, ?>> result = MutableList.of();
-        
         collectCatalogItems(Yamls.getTextOfYamlAtPath(yaml, "brooklyn.catalog").getMatchedYamlTextOrWarn(), 
-            catalogMetadata, result, null);
+            catalogMetadata, result, parentMeta);
         
         itemDef.remove("brooklyn.catalog");
         catalogMetadata.remove("item");
@@ -390,8 +396,6 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
             }
             collectCatalogItems("item:\n"+makeAsIndentedObject(rootItemYaml), rootItem, result, catalogMetadata);
         }
-        
-        return result;
     }
 
     @SuppressWarnings("unchecked")
@@ -458,17 +462,26 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         
         Object items = catalogMetadata.remove("items");
         Object item = catalogMetadata.remove("item");
+        Object url = catalogMetadata.remove("include");
 
         if (items!=null) {
             int count = 0;
             for (Object ii: checkType(items, "items", List.class)) {
-                Map<?,?> i = checkType(ii, "entry in items list", Map.class);
-                collectCatalogItems(Yamls.getTextOfYamlAtPath(sourceYaml, "items", count).getMatchedYamlTextOrWarn(),
-                        i, result, catalogMetadata);
+                if (ii instanceof String) {
+                    collectUrlReferencedCatalogItems((String) ii, result, catalogMetadata);
+                } else {
+                    Map<?,?> i = checkType(ii, "entry in items list", Map.class);
+                    collectCatalogItems(Yamls.getTextOfYamlAtPath(sourceYaml, "items", count).getMatchedYamlTextOrWarn(),
+                            i, result, catalogMetadata);
+                }
                 count++;
             }
         }
-        
+
+        if (url != null) {
+            collectUrlReferencedCatalogItems(checkType(url, "include in catalog meta", String.class), result, catalogMetadata);
+        }
+
         if (item==null) return;
 
         // now look at the actual item, first correcting the sourceYaml and interpreting the catalog metadata
@@ -604,6 +617,21 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         result.add(dto);
     }
 
+    private void collectUrlReferencedCatalogItems(String url, List<CatalogItemDtoAbstract<?, ?>> result, Map<Object, Object> parentMeta) {
+        @SuppressWarnings("unchecked")
+        List<?> parentLibrariesRaw = MutableList.copyOf(getFirstAs(parentMeta, List.class, "brooklyn.libraries", "libraries").orNull());
+        Collection<CatalogBundle> parentLibraries = CatalogItemDtoAbstract.parseLibraries(parentLibrariesRaw);
+        BrooklynClassLoadingContext loader = CatalogUtils.newClassLoadingContext(mgmt, "<catalog url reference loader>:0.0.0", parentLibraries);
+        String yaml;
+        try {
+            yaml = ResourceUtils.create(loader).getResourceAsString(url);
+        } catch (Exception e) {
+            Exceptions.propagateIfFatal(e);
+            throw new IllegalStateException("Remote catalog url " + url + " can't be fetched.", e);
+        }
+        collectCatalogItems(yaml, result, parentMeta);
+    }
+
     @SuppressWarnings("unchecked")
     private <T> T checkType(Object x, String description, Class<T> type) {
         if (type.isInstance(x)) return (T)x;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d2f8ff16/utils/common/dependencies/osgi/entities/src/main/resources/yaml-ref-back-catalog.bom
----------------------------------------------------------------------
diff --git a/utils/common/dependencies/osgi/entities/src/main/resources/yaml-ref-back-catalog.bom b/utils/common/dependencies/osgi/entities/src/main/resources/yaml-ref-back-catalog.bom
new file mode 100644
index 0000000..d41663b
--- /dev/null
+++ b/utils/common/dependencies/osgi/entities/src/main/resources/yaml-ref-back-catalog.bom
@@ -0,0 +1,30 @@
+# 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.
+
+
+brooklyn.catalog:
+  version: 0.1.2
+  displayName: I Haz Catalog
+  libraries:
+    # References a bundle which doesn't contain SimpleEntity on purpose
+    # Expects that the caller will already include a reference to the bundle
+    # and checks that this doesn't override parent's libraries, but adds to them
+  - classpath:/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.2.0.jar
+  items:
+  - id: back-reference
+    item:
+      type: yaml.nested.catalog.simple

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d2f8ff16/utils/common/dependencies/osgi/entities/src/main/resources/yaml-ref-parent-catalog.bom
----------------------------------------------------------------------
diff --git a/utils/common/dependencies/osgi/entities/src/main/resources/yaml-ref-parent-catalog.bom b/utils/common/dependencies/osgi/entities/src/main/resources/yaml-ref-parent-catalog.bom
new file mode 100644
index 0000000..c19e305
--- /dev/null
+++ b/utils/common/dependencies/osgi/entities/src/main/resources/yaml-ref-parent-catalog.bom
@@ -0,0 +1,33 @@
+# 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.
+
+
+brooklyn.catalog:
+  version: 0.1.2
+  displayName: I Haz Catalog
+  libraries:
+    # References a bundle which doesn't contain SimpleEntity on purpose
+    # Expects that the caller will already include a reference to the bundle
+    # and checks that this doesn't override parent's libraries, but adds to them
+  - classpath:/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.2.0.jar
+  items:
+  - id: yaml.nested.catalog.simple
+    item:
+      type: org.apache.brooklyn.test.osgi.entities.SimpleEntity
+  - id: yaml.nested.catalog.more
+    item:
+      type: org.apache.brooklyn.test.osgi.entities.more.MoreEntity

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d2f8ff16/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
----------------------------------------------------------------------
diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar
index 807e855..63edc5d 100644
Binary files a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar and b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-entities.jar differ


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

Posted by he...@apache.org.
This closes #124


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

Branch: refs/heads/master
Commit: 6a60dd45468228966b9c157156d977dc6b1a0b9b
Parents: c7da7ea d2f8ff1
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue May 10 12:03:59 2016 +0200
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue May 10 12:03:59 2016 +0200

----------------------------------------------------------------------
 .../camp/brooklyn/ReferencedYamlTest.java       | 117 +++++++++++++++++++
 .../catalog/internal/BasicBrooklynCatalog.java  |  46 ++++++--
 .../main/resources/yaml-ref-back-catalog.bom    |  30 +++++
 .../main/resources/yaml-ref-parent-catalog.bom  |  33 ++++++
 .../osgi/brooklyn-test-osgi-entities.jar        | Bin 16091 -> 17775 bytes
 5 files changed, 217 insertions(+), 9 deletions(-)
----------------------------------------------------------------------