Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/173#discussion_r65534619
--- Diff:
camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigInheritanceYamlTest.java
---
@@ -300,14 +338,212 @@ public void testOverridesParentConfig() throws
Exception {
ImmutableMap.of("mykey2", "myval2", "templateOptions",
ImmutableMap.of("myOptionsKey2", "myOptionsVal2")));
}
+ @Test
+ public void testEntityTypeInheritanceOptions() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: entity",
+ " items:",
+ " - id: entity-with-keys",
+ " item:",
+ " type:
org.apache.brooklyn.core.test.entity.TestEntity",
+ " brooklyn.parameters:",
+ " - name: map.type-merged",
+ " type: java.util.Map",
+ " inheritance.type: merge",
+ " default: {myDefaultKey: myDefaultVal}",
+ " - name: map.type-always",
+ " type: java.util.Map",
+ " inheritance.type: always",
+ " default: {myDefaultKey: myDefaultVal}",
+ " - name: map.type-never",
+ " type: java.util.Map",
+ " inheritance.type: none",
+ " default: {myDefaultKey: myDefaultVal}",
+ " - id: entity-with-conf",
+ " item:",
+ " type: entity-with-keys",
+ " brooklyn.config:",
+ " map.type-merged:",
+ " mykey: myval",
+ " map.type-always:",
+ " mykey: myval",
+ " map.type-never:",
+ " mykey: myval");
+
+ // Test retrieval of defaults
+ {
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys");
+
+ Entity app = createStartWaitAndLogApplication(new
StringReader(yaml));
+ TestEntity entity = (TestEntity)
Iterables.getOnlyElement(app.getChildren());
+
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ }
+
+ // Test override defaults
+ {
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys",
+ " brooklyn.config:",
+ " map.type-merged:",
+ " mykey2: myval2",
+ " map.type-always:",
+ " mykey2: myval2",
+ " map.type-never:",
+ " mykey2: myval2");
+
+ Entity app = createStartWaitAndLogApplication(new
StringReader(yaml));
+ TestEntity entity = (TestEntity)
Iterables.getOnlyElement(app.getChildren());
+
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
ImmutableMap.of("mykey2", "myval2"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
ImmutableMap.of("mykey2", "myval2"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
ImmutableMap.of("mykey2", "myval2"));
+ }
+
+ // Test retrieval of explicit config
+ // TODO what should "never" mean here? Should we get the default
value?
+ {
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-conf");
+
+ Entity app = createStartWaitAndLogApplication(new
StringReader(yaml));
+ TestEntity entity = (TestEntity)
Iterables.getOnlyElement(app.getChildren());
+
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
ImmutableMap.of("mykey", "myval"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
ImmutableMap.of("mykey", "myval"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ }
+
+ // Test merging/overriding of explicit config
+ {
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-conf",
+ " brooklyn.config:",
+ " map.type-merged:",
+ " mykey2: myval2",
+ " map.type-always:",
+ " mykey2: myval2",
+ " map.type-never:",
+ " mykey2: myval2");
+
+ Entity app = createStartWaitAndLogApplication(new
StringReader(yaml));
+ TestEntity entity = (TestEntity)
Iterables.getOnlyElement(app.getChildren());
+
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
ImmutableMap.of("mykey", "myval", "mykey2", "myval2"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
ImmutableMap.of("mykey2", "myval2"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
ImmutableMap.of("mykey2", "myval2"));
+ }
+ }
+
+ @Test
+ public void testParentInheritanceOptions() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: entity",
+ " items:",
+ " - id: entity-with-keys",
+ " item:",
+ " type:
org.apache.brooklyn.core.test.entity.TestEntity",
+ " brooklyn.parameters:",
+ " - name: map.type-merged",
+ " type: java.util.Map",
+ " inheritance.parent: merge",
+ " default: {myDefaultKey: myDefaultVal}",
+ " - name: map.type-always",
+ " type: java.util.Map",
+ " inheritance.parent: always",
+ " default: {myDefaultKey: myDefaultVal}",
+ " - name: map.type-never",
+ " type: java.util.Map",
+ " inheritance.parent: none",
+ " default: {myDefaultKey: myDefaultVal}");
+
+ // Test retrieval of defaults
+ {
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type:
org.apache.brooklyn.entity.stock.BasicApplication",
+ " brooklyn.children:",
+ " - type: entity-with-keys");
+
+ Entity app = createStartWaitAndLogApplication(new
StringReader(yaml));
+ TestEntity entity = (TestEntity)
Iterables.getOnlyElement(app.getChildren());
+
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ }
+
+ // Test override defaults in parent entity
+ {
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type:
org.apache.brooklyn.entity.stock.BasicApplication",
+ " brooklyn.config:",
+ " map.type-merged:",
+ " mykey: myval",
+ " map.type-always:",
+ " mykey: myval",
+ " map.type-never:",
+ " mykey: myval",
+ " brooklyn.children:",
+ " - type: entity-with-keys");
+
+ Entity app = createStartWaitAndLogApplication(new
StringReader(yaml));
+ TestEntity entity = (TestEntity)
Iterables.getOnlyElement(app.getChildren());
+
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-merged")),
ImmutableMap.of("mykey", "myval"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-always")),
ImmutableMap.of("mykey", "myval"));
+
assertEquals(entity.config().get(entity.getEntityType().getConfigKey("map.type-never")),
ImmutableMap.of("myDefaultKey", "myDefaultVal"));
+ }
+
+ // Test merging/overriding of explicit config
+ {
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type:
org.apache.brooklyn.entity.stock.BasicApplication",
+ " brooklyn.config:",
+ " map.type-merged:",
+ " mykey: myval",
+ " map.type-always:",
+ " mykey: myval",
+ " map.type-never:",
+ " mykey: myval",
+ " brooklyn.children:",
+ " - type: entity-with-keys",
+ " brooklyn.config:",
+ " map.type-merged:",
+ " mykey2: myval2",
+ " map.type-always:",
+ " mykey2: myval2",
+ " map.type-never:",
+ " mykey2: myval2");
--- End diff --
If 3 levels within a map, then if merging it will do a "deep merge", as per
`CollectionMerger`. I agree it's not clear what a user would expect. I suspect
some users would think it will be shallow, and other users will think deep
(depending on the particularly values in the config map, presumably).
Or do you mean 3 levels of entity (e.g. A extends B, and C extends B)? Then
the rules apply at each level: B will merge or override the values of A, and
then C will merge or override those values of B (based on the config key
definition).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---