You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by bostko <gi...@git.apache.org> on 2016/05/23 10:00:18 UTC

[GitHub] brooklyn-server pull request: Merge Map values in config

GitHub user bostko opened a pull request:

    https://github.com/apache/brooklyn-server/pull/151

    Merge Map values in config

    Merge location configuration and application's provisioning.properties

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/bostko/brooklyn-server merge_map_values_in_config

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/151.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #151
    
----
commit 2f4e6278299ae56c63c4dda0f4d07ea50be32a1b
Author: Valentin Aitken <bo...@gmail.com>
Date:   2016-05-23T09:59:36Z

    Merge Map values in config
    
    Merge location configuration and application's provisioning.properties

----


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64207286
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionHelpers.java ---
    @@ -0,0 +1,52 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.util.collections;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.Map;
    +
    +public class CollectionHelpers {
    +    private static final Logger log = LoggerFactory.getLogger(CollectionHelpers.class);
    +
    +    public static Map<String, Object> mergeNestedMaps(Map<String, Object> defaultEntries, Map<String, Object> overrideWith) {
    +        Map<String, Object> result = MutableMap.of();
    +        result.putAll(defaultEntries);
    +        for (Map.Entry<String, Object> newEntry: overrideWith.entrySet()) {
    +            if (!defaultEntries.containsKey(newEntry.getKey())) {
    +                result.put(newEntry.getKey(), newEntry.getValue());
    +            } else if (newEntry.getValue() instanceof Map) {
    +                Map<Object, Object> mergedValue = MutableMap.of();
    +                if (defaultEntries.get(newEntry.getKey()) instanceof Map) {
    +                    mergedValue.putAll((Map) defaultEntries.get(newEntry.getKey()));
    +                } else {
    +                    log.warn("defaultEntries {} is expected to be Map but it is {}", newEntry.getKey(), defaultEntries);
    --- End diff --
    
    it is again the non-map behavior. Such values will be overridden by the code bellow. This was the case for all the values previously. 


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by nakomis <gi...@git.apache.org>.
Github user nakomis commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64197677
  
    --- Diff: core/src/main/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocation.java ---
    @@ -345,7 +346,7 @@ protected void updateMachineConfig(T machine, Map<?, ?> flags) {
                 // For backwards compatibility, where peristed state did not have this.
                 origConfigs = Maps.newLinkedHashMap();
             }
    -        Map<String, Object> strFlags = ConfigBag.newInstance(flags).getAllConfig();
    +        Map<String, Object> strFlags = ConfigBag.newInstanceExtending(((AbstractConfigurationSupportInternal)machine.config()).getBag(), flags).getAllConfig();
    --- End diff --
    
    Does this need to be applied to the other implementations of `MachineProvisioningLocation.obtain()`?
    
    Will this effect the behaviour of existing blueprints? 


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by nakomis <gi...@git.apache.org>.
Github user nakomis commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64203567
  
    --- Diff: core/src/main/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocation.java ---
    @@ -345,7 +346,7 @@ protected void updateMachineConfig(T machine, Map<?, ?> flags) {
                 // For backwards compatibility, where peristed state did not have this.
                 origConfigs = Maps.newLinkedHashMap();
             }
    -        Map<String, Object> strFlags = ConfigBag.newInstance(flags).getAllConfig();
    +        Map<String, Object> strFlags = ConfigBag.newInstanceExtending(((AbstractConfigurationSupportInternal)machine.config()).getBag(), flags).getAllConfig();
    --- End diff --
    
    Ok, didn't see that. Is this changing `FixedListMachineProvisioningLocation` to work in the same way as `JcloudsLocation`? If so, it should use `ResolvingConfigBag` for consistency with `JcloudsLocation`
    



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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64207206
  
    --- Diff: core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java ---
    @@ -126,7 +127,11 @@ public void markUsed(String key) {
         /** As {@link #newInstanceExtending(ConfigBag)} but also putting the supplied values. */
         @Beta
         public static ConfigBag newInstanceExtending(final ConfigBag configBag, Map<?,?> optionalAdditionalValues) {
    -        return newInstanceExtending(configBag).putAll(optionalAdditionalValues);
    +        if (optionalAdditionalValues != null) {
    +            return newInstance(CollectionHelpers.mergeNestedMaps(configBag.getAllConfig(), (Map<String, Object>) optionalAdditionalValues));
    +        } else {
    +            return newInstanceExtending(configBag);
    +        }
    --- End diff --
    
    I think we shouldn't do this, too intrusive. Better make the merging behaviour specific to `provisioning.properties`.


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

[GitHub] brooklyn-server pull request: Merge Map values in Location config

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64374027
  
    --- Diff: camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptySoftwareProcessYamlTest.java ---
    @@ -60,6 +62,31 @@ public void testProvisioningProperties() throws Exception {
         }
     
         @Test(groups="Integration")
    +    public void testProvisioningPropertiesOverrideValues() throws Exception {
    +        Entity app = createAndStartApplication(
    +                "location:",
    +                "  localhost:",
    +                "    templateOptions:",
    +                "      testKey: testValue",
    --- End diff --
    
    I'd include in the test an assertion about what takes precedence. (and you can turn off all attempts to ssh to the machine). For example, have:
    
        location:
          useJcloudsSshInit: false
          waitForSshable: false
          minRam: 1G
          minCores: 1
          templateOptions:
            locKey1: locVal1
            locKey2: locVal2
        services:
        - type: EmptySoftwareProcess
          brooklyn.config:
            onbox.base.dir.skipResolution: true
            sshMonitoring.enabled: false
            provisioning.properties:
              minRam: 2G
              templateOptions:
                locKey1: overriddenLocVal1
                entKey1: entVal1



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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64207370
  
    --- Diff: core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java ---
    @@ -126,7 +127,11 @@ public void markUsed(String key) {
         /** As {@link #newInstanceExtending(ConfigBag)} but also putting the supplied values. */
         @Beta
         public static ConfigBag newInstanceExtending(final ConfigBag configBag, Map<?,?> optionalAdditionalValues) {
    -        return newInstanceExtending(configBag).putAll(optionalAdditionalValues);
    +        if (optionalAdditionalValues != null) {
    +            return newInstance(CollectionHelpers.mergeNestedMaps(configBag.getAllConfig(), (Map<String, Object>) optionalAdditionalValues));
    +        } else {
    +            return newInstanceExtending(configBag);
    +        }
    --- End diff --
    
    Or even more constrained to `templateOptions`.


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by nakomis <gi...@git.apache.org>.
Github user nakomis commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64197753
  
    --- Diff: core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java ---
    @@ -126,7 +127,11 @@ public void markUsed(String key) {
         /** As {@link #newInstanceExtending(ConfigBag)} but also putting the supplied values. */
    --- End diff --
    
    This is now merging, not putting existing values


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

[GitHub] brooklyn-server pull request: Merge Map values in Location config

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:

    https://github.com/apache/brooklyn-server/pull/151#issuecomment-221247724
  
    I agree with @neykov : "I like the idea of the PR, but feel that it should be more constrained in scope. Either having this behaviour only for `prosivioning.properties` or even more to `templateOptions`".
    
    If doing this across the board, we'd need to think *very* carefully about its implications for entities extending entities, write lots of test cases, discuss the desired behaviour on dev@brooklyn, etc.
    
    Right now, I'm not sure what the consequences are of changing `ConfigBag.newInstanceExtending`, which is called in a lot of places.


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

[GitHub] brooklyn-server pull request: Merge Map values in Location config

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64376428
  
    --- Diff: core/src/main/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocation.java ---
    @@ -279,7 +280,7 @@ public T obtain() throws NoMachinesAvailableException {
         public T obtain(Map<?,?> flags) throws NoMachinesAvailableException {
             T machine;
             T desiredMachine = (T) flags.get("desiredMachine");
    -        ConfigBag allflags = ConfigBag.newInstanceExtending(config().getBag()).putAll(flags);
    +        ConfigBag allflags = ConfigBag.newInstanceExtending(config().getBag(), flags);
    --- End diff --
    
    This change looks like it makes no difference (now that you've backed out your changes to the `newInstanceExtending()` method). I'm fine with leaving this change in though.


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by nakomis <gi...@git.apache.org>.
Github user nakomis commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64203063
  
    --- Diff: camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptySoftwareProcessYamlTest.java ---
    @@ -60,6 +62,31 @@ public void testProvisioningProperties() throws Exception {
         }
     
         @Test(groups="Integration")
    +    public void testProvisioningPropertiesOverrideValues() throws Exception {
    +        Entity app = createAndStartApplication(
    +                "location:",
    +                "  localhost:",
    +                "    templateOptions:",
    +                "      test: test",
    +                "services:",
    +                "- type: "+EmptySoftwareProcess.class.getName(),
    +                "  provisioning.properties:",
    +                "    minRam: 16384",
    +                "    templateOptions:",
    +                "      overrideLoginUser: test");
    +        waitForApplicationTasks(app);
    +
    +        log.info("App started:");
    +        Entities.dumpInfo(app);
    +
    +        EmptySoftwareProcess entity = (EmptySoftwareProcess) app.getChildren().iterator().next();
    +        Map<String, Object> pp = entity.getConfig(EmptySoftwareProcess.PROVISIONING_PROPERTIES);
    +        Assert.assertEquals(pp.get("minRam"), 16384);
    +        Map<String, Object> templateOptions = entity.getLocations().iterator().next().getConfig(JcloudsLocationConfig.TEMPLATE_OPTIONS);
    +        Assert.assertEquals(templateOptions, ImmutableMap.of("overrideLoginUser", "test", "test", "test"));
    --- End diff --
    
    The name of the util class is ok, but line 86 of `EmptySoftwareProcessYamlTest` (the line I commented on) would be clearer if it read `Assert.assertEquals(templateOptions, ImmutableMap.of("overrideLoginUser", "testUser", "testKey", "testValue"));`


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64197998
  
    --- Diff: core/src/main/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocation.java ---
    @@ -345,7 +346,7 @@ protected void updateMachineConfig(T machine, Map<?, ?> flags) {
                 // For backwards compatibility, where peristed state did not have this.
                 origConfigs = Maps.newLinkedHashMap();
             }
    -        Map<String, Object> strFlags = ConfigBag.newInstance(flags).getAllConfig();
    +        Map<String, Object> strFlags = ConfigBag.newInstanceExtending(((AbstractConfigurationSupportInternal)machine.config()).getBag(), flags).getAllConfig();
    --- End diff --
    
    It is already used in `JcloudsLocation.obtain()`


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

[GitHub] brooklyn-server pull request: Merge Map values in Location config

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:

    https://github.com/apache/brooklyn-server/pull/151#issuecomment-221614931
  
    +1 absolutely must be more constrained -- taking to ML


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by nakomis <gi...@git.apache.org>.
Github user nakomis commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64198015
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionHelpers.java ---
    @@ -0,0 +1,55 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.util.collections;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.Map;
    +
    +/**
    + * @author valentin
    --- End diff --
    
    We typically avoid author javadocs


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

[GitHub] brooklyn-server pull request: Merge Map values in Location config

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64376720
  
    --- Diff: core/src/main/java/org/apache/brooklyn/util/core/config/ConfigBag.java ---
    @@ -126,7 +126,11 @@ public void markUsed(String key) {
         /** As {@link #newInstanceExtending(ConfigBag)} but also putting the supplied values. */
         @Beta
         public static ConfigBag newInstanceExtending(final ConfigBag configBag, Map<?,?> optionalAdditionalValues) {
    -        return newInstanceExtending(configBag).putAll(optionalAdditionalValues);
    --- End diff --
    
    As per @neykov 's comments, do we really want this change?
    
        I think we shouldn't do this, too intrusive. Better make the merging behaviour specific to provisioning.properties.
        Or even more constrained to templateOptions.
        I like the idea of the PR, but feel that it should be more constrained in scope. Either having this behaviour only for prosivioning.properties or even more to templateOptions
    
    It feels high risk. It's unclear what impact it will have on other users (e.g. someone writing a YAML entity that extends another entity, overriding a config key; for that particular example, we need to discuss it on dev@brooklyn a lot more first).


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64206445
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionHelpers.java ---
    @@ -0,0 +1,52 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.util.collections;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.Map;
    +
    +public class CollectionHelpers {
    +    private static final Logger log = LoggerFactory.getLogger(CollectionHelpers.class);
    +
    +    public static Map<String, Object> mergeNestedMaps(Map<String, Object> defaultEntries, Map<String, Object> overrideWith) {
    +        Map<String, Object> result = MutableMap.of();
    +        result.putAll(defaultEntries);
    +        for (Map.Entry<String, Object> newEntry: overrideWith.entrySet()) {
    +            if (!defaultEntries.containsKey(newEntry.getKey())) {
    +                result.put(newEntry.getKey(), newEntry.getValue());
    +            } else if (newEntry.getValue() instanceof Map) {
    +                Map<Object, Object> mergedValue = MutableMap.of();
    +                if (defaultEntries.get(newEntry.getKey()) instanceof Map) {
    +                    mergedValue.putAll((Map) defaultEntries.get(newEntry.getKey()));
    +                } else {
    +                    log.warn("defaultEntries {} is expected to be Map but it is {}", newEntry.getKey(), defaultEntries);
    +                }
    +                for (Map.Entry<Object, Object> innerValue : ((Map<Object,Object>) newEntry.getValue()).entrySet()) {
    +                    mergedValue.put(innerValue.getKey(), innerValue.getValue());
    --- End diff --
    
    Why not `putAll(newEntry.getValue())`?


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the pull request:

    https://github.com/apache/brooklyn-server/pull/151#issuecomment-220959515
  
    I like the idea of the PR, but feel that it should be more constrained in scope. Either having this behaviour only for `prosivioning.properties` or even more to `templateOptions` 


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by nakomis <gi...@git.apache.org>.
Github user nakomis commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64197284
  
    --- Diff: camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptySoftwareProcessYamlTest.java ---
    @@ -60,6 +62,31 @@ public void testProvisioningProperties() throws Exception {
         }
     
         @Test(groups="Integration")
    +    public void testProvisioningPropertiesOverrideValues() throws Exception {
    +        Entity app = createAndStartApplication(
    +                "location:",
    +                "  localhost:",
    +                "    templateOptions:",
    +                "      test: test",
    +                "services:",
    +                "- type: "+EmptySoftwareProcess.class.getName(),
    +                "  provisioning.properties:",
    +                "    minRam: 16384",
    +                "    templateOptions:",
    +                "      overrideLoginUser: test");
    +        waitForApplicationTasks(app);
    +
    +        log.info("App started:");
    +        Entities.dumpInfo(app);
    +
    +        EmptySoftwareProcess entity = (EmptySoftwareProcess) app.getChildren().iterator().next();
    +        Map<String, Object> pp = entity.getConfig(EmptySoftwareProcess.PROVISIONING_PROPERTIES);
    +        Assert.assertEquals(pp.get("minRam"), 16384);
    +        Map<String, Object> templateOptions = entity.getLocations().iterator().next().getConfig(JcloudsLocationConfig.TEMPLATE_OPTIONS);
    +        Assert.assertEquals(templateOptions, ImmutableMap.of("overrideLoginUser", "test", "test", "test"));
    --- End diff --
    
    A minor point (shouldn't hold up this PR), but `testKey`, `testValue`, and `testUser` would be clearer here


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

[GitHub] brooklyn-server pull request: Merge Map values in Location config

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64442082
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java ---
    @@ -459,7 +459,7 @@ public ConfigBag getLocalBag() {
     
             @Override
             public void addToLocalBag(Map<String, ?> vals) {
    -            configBag.putAll(vals);
    +            configBag = ConfigBag.newInstanceExtending(configBag, vals);
    --- End diff --
    
    The exact answer here is, that the properties are set twice in `FixedListMachineProvisioningLocation#obtain`
    1. when allflags is constructed and used in `provisionMore` call
    2. after that the configuration of the object is updated for a second time in `updateMachineConfig` call


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on the pull request:

    https://github.com/apache/brooklyn-server/pull/151#issuecomment-220939386
  
    Is the naming OK. Do you think I named properly the util class?


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

[GitHub] brooklyn-server pull request #151: Merge Map values in Location config

Posted by bostko <gi...@git.apache.org>.
Github user bostko closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/151


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

[GitHub] brooklyn-server pull request: Merge Map values in Location config

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64378310
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java ---
    @@ -459,7 +459,7 @@ public ConfigBag getLocalBag() {
     
             @Override
             public void addToLocalBag(Map<String, ?> vals) {
    -            configBag.putAll(vals);
    +            configBag = ConfigBag.newInstanceExtending(configBag, vals);
    --- End diff --
    
    It merges the values that the location has in config with vals flags come from provisioning.properties


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64206361
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionHelpers.java ---
    @@ -0,0 +1,52 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.util.collections;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.Map;
    +
    +public class CollectionHelpers {
    +    private static final Logger log = LoggerFactory.getLogger(CollectionHelpers.class);
    +
    +    public static Map<String, Object> mergeNestedMaps(Map<String, Object> defaultEntries, Map<String, Object> overrideWith) {
    +        Map<String, Object> result = MutableMap.of();
    +        result.putAll(defaultEntries);
    +        for (Map.Entry<String, Object> newEntry: overrideWith.entrySet()) {
    +            if (!defaultEntries.containsKey(newEntry.getKey())) {
    +                result.put(newEntry.getKey(), newEntry.getValue());
    +            } else if (newEntry.getValue() instanceof Map) {
    +                Map<Object, Object> mergedValue = MutableMap.of();
    +                if (defaultEntries.get(newEntry.getKey()) instanceof Map) {
    +                    mergedValue.putAll((Map) defaultEntries.get(newEntry.getKey()));
    +                } else {
    +                    log.warn("defaultEntries {} is expected to be Map but it is {}", newEntry.getKey(), defaultEntries);
    --- End diff --
    
    For incompatible types better keep non-map behaviour of overriding the key.


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

[GitHub] brooklyn-server pull request: Merge Map values in config

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64206860
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionHelpers.java ---
    @@ -0,0 +1,52 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.util.collections;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.Map;
    +
    +public class CollectionHelpers {
    +    private static final Logger log = LoggerFactory.getLogger(CollectionHelpers.class);
    +
    +    public static Map<String, Object> mergeNestedMaps(Map<String, Object> defaultEntries, Map<String, Object> overrideWith) {
    --- End diff --
    
    Not clear from the name that it's a shallow merge.


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

[GitHub] brooklyn-server issue #151: Merge Map values in Location config

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the issue:

    https://github.com/apache/brooklyn-server/pull/151
  
    This has been superseded by https://github.com/apache/brooklyn-server/pull/173.
    
    @bostko can you please confirm that PR #173 does what you want?


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

[GitHub] brooklyn-server pull request: Merge Map values in Location config

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:

    https://github.com/apache/brooklyn-server/pull/151#issuecomment-221830275
  
    This has now been discussed as part of the dev@brooklyn email thread "[PROPOSAL] merging config keys".
    
    I'm working on a general solution for that, so please DO NOT MERGE this PR.


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

[GitHub] brooklyn-server pull request: Merge Map values in Location config

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64376301
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java ---
    @@ -459,7 +459,7 @@ public ConfigBag getLocalBag() {
     
             @Override
             public void addToLocalBag(Map<String, ?> vals) {
    -            configBag.putAll(vals);
    +            configBag = ConfigBag.newInstanceExtending(configBag, vals);
    --- End diff --
    
    I don't understand what this change is fixing. Can you explain the reasoning please?


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

[GitHub] brooklyn-server pull request: Merge Map values in Location config

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/151#discussion_r64377246
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionHelpers.java ---
    @@ -0,0 +1,53 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.util.collections;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.Map;
    +
    +public class CollectionHelpers {
    +    private static final Logger log = LoggerFactory.getLogger(CollectionHelpers.class);
    +
    +    /**
    +     * Does a shallow merge of two maps.
    +     */
    +    public static Map<String, Object> mergeMapsAndTheirInnerMapValues(Map<String, Object> defaultEntries, Map<String, Object> overrideWith) {
    --- End diff --
    
    This is the sort of method that it's really easy to write great test coverage for. We should do that, including where default entry is of different type than overriding entry etc.
    
    It's unclear what a user would expect, when merging maps. Why stop at one level down? What about merging or overriding lists?


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