brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [1/2] brooklyn-server git commit: BROOKLYN-248: fix location displayName inheritance
Date Wed, 06 Apr 2016 14:22:16 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 3f8171dc8 -> dc6a313d7


BROOKLYN-248: fix location displayName inheritance


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

Branch: refs/heads/master
Commit: 4e2114d6ebaec4aade56a3b67c83bd0acf26c70c
Parents: cce75a1
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Apr 6 11:09:45 2016 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Apr 6 14:04:43 2016 +0100

----------------------------------------------------------------------
 .../brooklyn/spi/creation/CampResolver.java     |  16 +-
 .../camp/brooklyn/ApplicationsYamlTest.java     | 142 +++++++++++++++
 .../brooklyn/catalog/CatalogYamlAppTest.java    |   6 +-
 .../catalog/CatalogYamlLocationTest.java        | 172 +++++++++++++++++++
 4 files changed, 332 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4e2114d6/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampResolver.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampResolver.java
b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampResolver.java
index 5639945..3813476 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampResolver.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampResolver.java
@@ -25,6 +25,7 @@ import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.api.policy.Policy;
@@ -116,9 +117,18 @@ class CampResolver {
 
         ((AbstractBrooklynObjectSpec<?, ?>)spec).catalogItemIdIfNotNull(item.getId());
 
-        if (Strings.isBlank( ((AbstractBrooklynObjectSpec<?, ?>)spec).getDisplayName()
))
-            ((AbstractBrooklynObjectSpec<?, ?>)spec).displayName(item.getDisplayName());
-
+        if (spec instanceof EntitySpec) {
+            if (Strings.isBlank( ((AbstractBrooklynObjectSpec<?, ?>)spec).getDisplayName()
)) {
+                ((AbstractBrooklynObjectSpec<?, ?>)spec).displayName(item.getDisplayName());
+            }
+        } else {
+            // See https://issues.apache.org/jira/browse/BROOKLYN-248, and the tests in 
+            // ApplicationYamlTest and CatalogYamlLocationTest.
+            if (Strings.isNonBlank(item.getDisplayName())) {
+                ((AbstractBrooklynObjectSpec<?, ?>)spec).displayName(item.getDisplayName());
+            }
+        }
+        
         return spec;
     }
  

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4e2114d6/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ApplicationsYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ApplicationsYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ApplicationsYamlTest.java
index 374df13..979dadc 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ApplicationsYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ApplicationsYamlTest.java
@@ -25,6 +25,8 @@ import static org.testng.Assert.assertTrue;
 import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.camp.brooklyn.TestSensorAndEffectorInitializer.TestConfigurableInitializer;
+import org.apache.brooklyn.camp.brooklyn.catalog.CatalogYamlLocationTest;
+import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
@@ -36,6 +38,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.Test;
 
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 
 @Test
@@ -228,6 +232,144 @@ public class ApplicationsYamlTest extends AbstractYamlTest {
         assertDoesNotWrap(app, BasicApplication.class, "catalogServiceLevel");
     }
 
+    // FIXME Fails with name "My App 1" rather than the overridden value. 
+    // See discussion in https://issues.apache.org/jira/browse/BROOKLYN-248
+    @Test(groups="WIP")
+    public void testTypeInheritance() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  items:",
+                "  - id: app1",
+                "    name: My App 1",
+                "    item:",
+                "      type: " + BasicApplication.class.getName(),
+                "      brooklyn.config:",
+                "        mykey1: myval1",
+                "        mykey1b: myval1b",
+                "  - id: app2",
+                "    name: My App 2",
+                "    item:",
+                "      type: app1",
+                "      brooklyn.config:",
+                "        mykey1: myvalOverridden",
+                "        mykey2: myval2");
+        
+        addCatalogItems(yaml);
+        Entity app1 = createAndStartApplication("services: [ {type: app1} ]");
+        assertDoesNotWrap(app1, BasicApplication.class, "My App 1");
+        CatalogYamlLocationTest.assertContainsAll(((EntityInternal)app1).config().getBag().getAllConfig(),
ImmutableMap.of("mykey1", "myval1", "mykey1b", "myval1b"));
+
+        Entity app2 = createAndStartApplication("services: [ {type: app2} ]");
+        assertDoesNotWrap(app2, BasicApplication.class, "My App 2");
+        CatalogYamlLocationTest.assertContainsAll(((EntityInternal)app2).config().getBag().getAllConfig(),
ImmutableMap.of("mykey1", "myvalOverridden", "mykey1b", "myval1b", "mykey2", "myval2"));
+    }
+    
+    // FIXME Fails for app3b, which gets the name "My name within item 3a" rather than the

+    // overridden value. See discussion in https://issues.apache.org/jira/browse/BROOKLYN-248
+    @Test(groups="WIP")
+    public void testNamePrecedence() throws Exception {
+        String yaml1 = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  name: My name in top-level metadata",
+                "  items:",
+                "  - id: app1",
+                "    name: My name in item metadata",
+                "    item:",
+                "      type: " + BasicApplication.class.getName(),
+                "      name: My name within item");
+
+        String yaml2 = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  name: My name in top-level metadata",
+                "  items:",
+                "  - id: app2",
+                "    item:",
+                "      type: " + BasicApplication.class.getName(),
+                "      name: My name within item");
+
+        String yaml3 = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  items:",
+                "  - id: app3a",
+                "    name: My name in item 3a metadata",
+                "    item:",
+                "      type: " + BasicApplication.class.getName(),
+                "      name: My name within item 3a",
+                "  items:",
+                "  - id: app3b",
+                "    item:",
+                "      type: app3a",
+                "      name: My name within item 3b");
+        
+        addCatalogItems(yaml1);
+        addCatalogItems(yaml2);
+        addCatalogItems(yaml3);
+
+        Entity app1 = createAndStartApplication("services: [ {type: app1} ]");
+        assertDoesNotWrap(app1, BasicApplication.class, "My name within item");
+
+        Entity app2 = createAndStartApplication("services: [ {type: app2} ]");
+        assertDoesNotWrap(app2, BasicApplication.class, "My name within item");
+
+        Entity app3b = createAndStartApplication("services: [ {type: app3b} ]");
+        assertDoesNotWrap(app3b, BasicApplication.class, "My name within item 3b");
+    }
+    
+    @Test
+    public void testNameInCatalogMetadata() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  name: My name in top-level",
+                "  items:",
+                "  - id: app1",
+                "    item:",
+                "      type: " + BasicApplication.class.getName());
+        
+        addCatalogItems(yaml);
+
+        Entity app1 = createAndStartApplication("services: [ {type: app1} ]");
+        assertDoesNotWrap(app1, BasicApplication.class, "My name in top-level");
+    }
+    
+    @Test
+    public void testNameInItemMetadata() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  items:",
+                "  - id: app1",
+                "    name: My name in item metadata",
+                "    item:",
+                "      type: " + BasicApplication.class.getName());
+        
+        addCatalogItems(yaml);
+
+        Entity app1 = createAndStartApplication("services: [ {type: app1} ]");
+        assertDoesNotWrap(app1, BasicApplication.class, "My name in item metadata");
+    }
+    
+    @Test
+    public void testNameWithinItem() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  items:",
+                "  - id: app1",
+                "    item:",
+                "      type: " + BasicApplication.class.getName(),
+                "      name: My name within item");
+        
+        addCatalogItems(yaml);
+
+        Entity app1 = createAndStartApplication("services: [ {type: app1} ]");
+        assertDoesNotWrap(app1, BasicApplication.class, "My name within item");
+    }
+    
     @Override
     protected Logger getLogger() {
         return log;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4e2114d6/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlAppTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlAppTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlAppTest.java
index f4e58be..2deeb3d 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlAppTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlAppTest.java
@@ -21,10 +21,14 @@ package org.apache.brooklyn.camp.brooklyn.catalog;
 import org.testng.annotations.Test;
 
 import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
+import org.apache.brooklyn.camp.brooklyn.ApplicationsYamlTest;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 
-
+/**
+ * Also see related tests in {@link ApplicationsYamlTest}.
+ * TODO Not clear what the difference is between these two test classes!
+ */
 public class CatalogYamlAppTest extends AbstractYamlTest {
 
     @Override

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4e2114d6/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
index 9dd9118..ae269a4 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
@@ -18,11 +18,14 @@
  */
 package org.apache.brooklyn.camp.brooklyn.catalog;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.location.Location;
@@ -46,7 +49,9 @@ import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
+import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
@@ -180,6 +185,173 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
         deleteCatalogEntity(symbolicName);
     }
     
+    // See https://issues.apache.org/jira/browse/BROOKLYN-248
+    @Test
+    public void testTypeInheritance() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  itemType: location",
+                "  items:",
+                "  - id: loc1",
+                "    name: My Loc 1",
+                "    item:",
+                "      type: localhost",
+                "      brooklyn.config:",
+                "        mykey1: myval1",
+                "        mykey1b: myval1b",
+                "  - id: loc2",
+                "    name: My Loc 2",
+                "    item:",
+                "      type: loc1",
+                "      brooklyn.config:",
+                "        mykey1: myvalOverridden",
+                "        mykey2: myval2");
+        
+        addCatalogItems(yaml);
+
+        Map<String, LocationDefinition> defs = mgmt().getLocationRegistry().getDefinedLocations();
+        LocationDefinition def1 = checkNotNull(defs.get("loc1"), "loc1 missing; has %s",
defs.keySet());
+        LocationDefinition def2 = checkNotNull(defs.get("loc2"), "loc2 missing; has %s",
defs.keySet());
+        LocationSpec<? extends Location> spec1 = mgmt().getLocationRegistry().getLocationSpec(def1).get();
+        LocationSpec<? extends Location> spec2 = mgmt().getLocationRegistry().getLocationSpec(def2).get();
+        
+        assertEquals(spec1.getCatalogItemId(), "loc1:0.1.2");
+        assertEquals(spec1.getDisplayName(), "My Loc 1");
+        assertContainsAll(spec1.getFlags(), ImmutableMap.of("mykey1", "myval1", "mykey1b",
"myval1b"));
+        assertEquals(spec2.getCatalogItemId(), "loc2:0.1.2");
+        assertEquals(spec2.getDisplayName(), "My Loc 2");
+        assertContainsAll(spec2.getFlags(), ImmutableMap.of("mykey1", "myvalOverridden",
"mykey1b", "myval1b", "mykey2", "myval2"));
+    }
+    
+    // TODO Debatable whether loc1/loc2 should use "My name within item" instead (which was
Aled's 
+    // initial expectation). That would be more consistent with the way entities behave -
see
+    // {@link ApplicationYamlTest#testNamePrecedence()}.
+    // See discussion in https://issues.apache.org/jira/browse/BROOKLYN-248.
+    @Test
+    public void testNamePrecedence() throws Exception {
+        String yaml1 = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  itemType: location",
+                "  name: My name in top-level metadata",
+                "  items:",
+                "  - id: loc1",
+                "    name: My name in item metadata",
+                "    item:",
+                "      type: localhost",
+                "      name: My name within item");
+
+        String yaml2 = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  itemType: location",
+                "  name: My name in top-level metadata",
+                "  items:",
+                "  - id: loc2",
+                "    item:",
+                "      type: localhost",
+                "      name: My name within item");
+
+        String yaml3 = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  itemType: location",
+                "  items:",
+                "  - id: loc3a",
+                "    name: My name in item 3a metadata",
+                "    item:",
+                "      type: localhost",
+                "      name: My name within item 3a",
+                "  items:",
+                "  - id: loc3b",
+                "    item:",
+                "      type: loc3a",
+                "      name: My name within item 3b");
+        
+        addCatalogItems(yaml1);
+        addCatalogItems(yaml2);
+        addCatalogItems(yaml3);
+
+        LocationDefinition def1 = mgmt().getLocationRegistry().getDefinedLocations().get("loc1");
+        LocationSpec<? extends Location> spec1 = mgmt().getLocationRegistry().getLocationSpec(def1).get();
+        assertEquals(spec1.getDisplayName(), "My name in item metadata");
+        
+        LocationDefinition def2 = mgmt().getLocationRegistry().getDefinedLocations().get("loc2");
+        LocationSpec<? extends Location> spec2 = mgmt().getLocationRegistry().getLocationSpec(def2).get();
+        assertEquals(spec2.getDisplayName(), "My name in top-level metadata");
+        
+        LocationDefinition def3b = mgmt().getLocationRegistry().getDefinedLocations().get("loc3b");
+        LocationSpec<? extends Location> spec3b = mgmt().getLocationRegistry().getLocationSpec(def3b).get();
+        assertEquals(spec3b.getDisplayName(), "My name within item 3b");
+    }
+    
+    @Test
+    public void testNameInCatalogMetadata() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  itemType: location",
+                "  name: My name in top-level",
+                "  items:",
+                "  - id: loc1",
+                "    item:",
+                "      type: localhost");
+        
+        addCatalogItems(yaml);
+
+        LocationDefinition def = mgmt().getLocationRegistry().getDefinedLocations().get("loc1");
+        LocationSpec<? extends Location> spec = mgmt().getLocationRegistry().getLocationSpec(def).get();
+        assertEquals(spec.getDisplayName(), "My name in top-level");
+    }
+    
+    @Test
+    public void testNameInItemMetadata() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  itemType: location",
+                "  items:",
+                "  - id: loc1",
+                "    name: My name in item metadata",
+                "    item:",
+                "      type: localhost");
+        
+        addCatalogItems(yaml);
+
+        LocationDefinition def = mgmt().getLocationRegistry().getDefinedLocations().get("loc1");
+        LocationSpec<? extends Location> spec = mgmt().getLocationRegistry().getLocationSpec(def).get();
+        assertEquals(spec.getDisplayName(), "My name in item metadata");
+    }
+    
+    @Test
+    public void testNameWithinItem() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: 0.1.2",
+                "  itemType: location",
+                "  items:",
+                "  - id: loc1",
+                "    item:",
+                "      type: localhost",
+                "      name: My name within item");
+        
+        addCatalogItems(yaml);
+
+        LocationDefinition def = mgmt().getLocationRegistry().getDefinedLocations().get("loc1");
+        LocationSpec<? extends Location> spec = mgmt().getLocationRegistry().getLocationSpec(def).get();
+        assertEquals(spec.getDisplayName(), "My name within item");
+    }
+    
+    // TODO Can move to common test utility, if proves more generally useful
+    public static void assertContainsAll(Map<?,?> actual, Map<?,?> expectedSubset)
{
+        String errMsg = "actual="+actual+"; expetedSubset="+expectedSubset;
+        for (Map.Entry<?, ?> entry : expectedSubset.entrySet()) {
+            assertTrue(actual.containsKey(entry.getKey()), errMsg);
+            assertEquals(actual.get(entry.getKey()), entry.getValue(), errMsg);
+        }
+    }
+    
     protected void runLaunchApplicationReferencingLocation(String locTypeInYaml, String locType)
throws Exception {
         Entity app = createAndStartApplication(
             "name: simple-app-yaml",


Mime
View raw message