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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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) 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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 mergeNestedMaps(Map
defaultEntries, Map overrideWith) {
+Map result = MutableMap.of();
+result.putAll(defaultEntries);
+for (Map.Entry newEntry: overrideWith.entrySet()) {
+if (!defaultEntries.containsKey(newEntry.getKey())) {
+result.put(newEntry.getKey(), newEntry.getValue());
+} else if (newEntry.getValue() instanceof Map) {
+Map
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) 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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 mergeNestedMaps(Map
defaultEntries, Map 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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 mergeNestedMaps(Map
defaultEntries, Map overrideWith) {
+Map result = MutableMap.of();
+result.putAll(defaultEntries);
+for (Map.Entry newEntry: overrideWith.entrySet()) {
+if (!defaultEntries.containsKey(newEntry.getKey())) {
+result.put(newEntry.getKey(), newEntry.getValue());
+} else if (newEntry.getValue() instanceof Map) {
+Map
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 mergeNestedMaps(Map
defaultEntries, Map overrideWith) {
+Map result = MutableMap.of();
+result.putAll(defaultEntries);
+for (Map.Entry newEntry: overrideWith.entrySet()) {
+if (!defaultEntries.containsKey(newEntry.getKey())) {
+result.put(newEntry.getKey(), newEntry.getValue());
+} else if (newEntry.getValue() instanceof Map) {
+Map 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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 strFlags =
ConfigBag.newInstance(flags).getAllConfig();
+Map 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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 pp =
entity.getConfig(EmptySoftwareProcess.PROVISIONING_PROPERTIES);
+Assert.assertEquals(pp.get("minRam"), 16384);
+Map 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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 strFlags =
ConfigBag.newInstance(flags).getAllConfig();
+Map 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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 strFlags =
ConfigBag.newInstance(flags).getAllConfig();
+Map 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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 pp =
entity.getConfig(EmptySoftwareProcess.PROVISIONING_PROPERTIES);
+Assert.assertEquals(pp.get("minRam"), 16384);
+Map 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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---
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
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---