Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/173#discussion_r65891559
  
    --- 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 --
    
    That's a really good point! I've confirmed that behaviour in a test. In 
your example, we'd get ENTITY_ID and CLUSTER_NAME, but not APP_NAME.
    
    That feels very hard to fix. We'd have to change the way 
`EntityConfigMap.inheritedConfig` is populated and stored. Currently the entity 
is given a copy of its parent's config (rather than looking it up on the parent 
each time).
    
    In fact, I'm not sure that declaring `brooklyn.parameters` at each level 
would work around it! The `BasicConfigurationSupport.refreshInheritedConfig` 
calls `entity.getAllConfig()`. That just does `Map result; 
result.putAll(inheritedConfig); result.putAll(ownConfig);` so it ignores the 
config key's settings for inheritance.
    
    I'm tempted to leave that as a documented limitation, with the failing test 
marked as WIP+Broken. Does that sound sensible to you @neykov ?


---
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.
---

Reply via email to