brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geom...@apache.org
Subject [1/3] brooklyn-server git commit: allow tags to be set on catalog items
Date Sun, 06 May 2018 19:38:02 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 4ba79791b -> dedaffd52


allow tags to be set on catalog items


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

Branch: refs/heads/master
Commit: bfe8766e33e05392d908abe91ab4a9722d1c84ee
Parents: 4ba7979
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri May 4 22:28:45 2018 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri May 4 22:28:45 2018 +0100

----------------------------------------------------------------------
 .../CatalogYamlEntityOsgiTypeRegistryTest.java  | 44 ++++++++++++++++++++
 .../catalog/internal/BasicBrooklynCatalog.java  | 21 ++++++----
 2 files changed, 57 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfe8766e/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityOsgiTypeRegistryTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityOsgiTypeRegistryTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityOsgiTypeRegistryTest.java
index aff1ac0..389e3b7 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityOsgiTypeRegistryTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityOsgiTypeRegistryTest.java
@@ -24,9 +24,11 @@ import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.collections.CollectionFunctionals;
 import org.apache.brooklyn.util.osgi.VersionedName;
 import org.testng.annotations.Test;
 
+import com.google.common.base.Predicates;
 import com.google.common.collect.Iterables;
 
 /** Variant of parent tests using OSGi, bundles, and type registry, instead of lightweight
non-osgi catalog */
@@ -126,6 +128,48 @@ public class CatalogYamlEntityOsgiTypeRegistryTest extends CatalogYamlEntityTest
             "      type: " + TestEntity.class.getName());
     }
     
+    // tags supported only with osgi catalog
+    
+    @Test
+    public void testAddCatalogItemWithTags() throws Exception {
+        String symbolicName = "my.catalog.app.id.load";
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  id: " + symbolicName,
+            "  version: " + TEST_VERSION,
+            "  tags: [ foo, bar ]",
+            "  itemType: entity",
+            "  item: " + BasicEntity.class.getName());
+
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
+        Asserts.assertThat(item.getTags(), CollectionFunctionals.contains("foo"));
+        Asserts.assertThat(item.getTags(), CollectionFunctionals.contains("bar"));
+        Asserts.assertThat(item.getTags(), Predicates.not(CollectionFunctionals.contains("baz")));
+
+        deleteCatalogEntity(symbolicName);
+    }
+    @Test
+    public void testAddCatalogItemWithInheritedTags() throws Exception {
+        String symbolicName = "my.catalog.app.id.load";
+        addCatalogItems(
+            "brooklyn.catalog:",
+            "  version: " + TEST_VERSION,
+            "  tags: [ foo ]",
+            "  items:",
+            "  - ",
+            "    id: " + symbolicName,
+            "    tags: [ bar ]",
+            "    itemType: entity",
+            "    item: " + BasicEntity.class.getName());
+
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
+        Asserts.assertThat(item.getTags(), CollectionFunctionals.contains("foo"));
+        Asserts.assertThat(item.getTags(), CollectionFunctionals.contains("bar"));
+        Asserts.assertThat(item.getTags(), Predicates.not(CollectionFunctionals.contains("baz")));
+
+        deleteCatalogEntity(symbolicName);
+    }
+    
     // also runs many other tests from super, here using the osgi/type-registry appraoch
     
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfe8766e/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 636742b..5b98cb0 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
@@ -658,6 +658,9 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
                 .putIfNotNull("item", itemMetadata.get("item"))
                 .putIfNotNull("items", itemMetadata.get("items"))
                 .build();
+        // tags we treat specially to concatenate as a set (treating as config with merge
might be cleaner)
+        catalogMetadata.put("tags", MutableSet.copyOf(getFirstAs(parentMetadata, Collection.class,
"tags").orNull())
+            .putAll(getFirstAs(itemMetadataWithoutItemDef, Collection.class, "tags").orNull())
);
 
         // brooklyn.libraries we treat specially, to append the list, with the child's list
preferred in classloading order
         // `libraries` is supported in some places as a legacy syntax; it should always be
`brooklyn.libraries` for new apps
@@ -934,15 +937,17 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         String sourcePlanYaml = planInterpreter.getPlanYaml();
 
         if (resultLegacyFormat==null) {
-            // horrible API but basically if `result` is null then add to local unpersisted
registry instead,
-            // without forcing resolution and ignoring errors; this lets us deal with forward
references, but
-            // we'll have to do a validation step subsequently.  (already we let bundles
deal with persistence,
-            // just need TODO to make sure we delete previously-persisted things which now
come through this path.)  
-            // NB: when everything is a bundle and we've removed all scanning then this can
be the _only_ path
-            // and code can be massively simpler
-            // TODO allow these to be set in catalog.bom ?
+            // horrible API but basically `resultLegacyFormat==null` means use the new-style,
+            // adding from persisted bundles to type registry (which is not persisted)
+            // instead of old way which persisted catalog items (and not their bundles).
+            // this lets us deal with forward references, with a subsequent step to validate.
+
+            Set<Object> tags = MutableSet.of().putAll(getFirstAs(catalogMetadata, Collection.class,
"tags").orNull());
+            
             List<String> aliases = MutableList.of();
-            List<Object> tags = MutableList.of();
+            // could easily allow aliases to be set in catalog.bom, as done for tags above,
+            // but currently we don't, we only allow the official type name
+            
             Boolean catalogDisabled = null;
             
             MutableList<Object> superTypes = MutableList.of();


Mime
View raw message