brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #173: BROOKLYN-286: merge config keys map value...
Date Thu, 02 Jun 2016 13:09:56 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/173#discussion_r65535553
  
    --- 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 --
    
    I meant 3 levels of entity. Say a root `env`, a cluster `env` and per-node `env`. For
example:
    - root : env{APP_NAME="XXX"}
    -+ group1
    --+ cluster1 env{CLUSTER_NAME="XXX"}
    ---+ entity env{ENTITY_ID="XXX"}
    
    Then we need to declare env in `brooklyn.parameters` at each level (even those that don't
have a value for it - group1), so the entity will inherit all the way to the root, correct?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message