brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [6/9] brooklyn-server git commit: Change templateOptions merge to be shallow
Date Mon, 06 Jun 2016 14:46:00 GMT
Change templateOptions merge to be shallow

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/e4e60046
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/e4e60046
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/e4e60046

Branch: refs/heads/master
Commit: e4e60046e433c43b119c72cd01e0402251ca7626
Parents: 03c9832
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Jun 2 11:41:40 2016 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Mon Jun 6 15:10:09 2016 +0100

----------------------------------------------------------------------
 .../ConfigLocationInheritanceYamlTest.java      | 33 ++++++++++++++++++++
 .../location/jclouds/JcloudsLocation.java       |  8 ++---
 2 files changed, 37 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e4e60046/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigLocationInheritanceYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigLocationInheritanceYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigLocationInheritanceYamlTest.java
index 6db3b64..a23b727 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigLocationInheritanceYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigLocationInheritanceYamlTest.java
@@ -230,6 +230,39 @@ public class ConfigLocationInheritanceYamlTest extends AbstractYamlTest
{
     }
     
     @Test(groups="Live")
+    public void testMergeTemplateOptionsIsShallow() throws Exception {
+        addCatalogItems(
+                "brooklyn.catalog:",
+                "  id: jclouds-config-test-with-tempateOptions-mapVal",
+                "  name: stubbed-jclouds-gce",
+                "  itemType: location",
+                "  item:",
+                "    type: jclouds-config-test:"+CLOUD_PROVIDER+":"+CLOUD_REGION,
+                "    brooklyn.config:",
+                "      templateOptions:",
+                "        mymap:",
+                "          key1: val1");
+        
+        String yaml = Joiner.on("\n").join(
+                "location: jclouds-config-test-with-tempateOptions-mapVal",
+                "services:",
+                "- type: org.apache.brooklyn.entity.software.base.EmptySoftwareProcess",
+                "  brooklyn.config:",
+                "    provisioning.properties:",
+                "      templateOptions:",
+                "        mymap:",
+                "          key2: val2");
+        
+        Entity app = createStartWaitAndLogApplication(new StringReader(yaml));
+        Entity entity = Iterables.getOnlyElement(app.getChildren());
+
+        assertMachineConfig(
+                Machines.findUniqueMachineLocation(entity.getLocations()).get(),
+                ImmutableMap.<ConfigKey<?>, Object>of(),
+                ImmutableMap.of("mymap", ImmutableMap.of("key2", "val2")));
+    }
+    
+    @Test(groups="Live")
     public void testMergesCatalogEntityLocationProperties() throws Exception {
         addCatalogItems(
                 "brooklyn.catalog:",

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e4e60046/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
index a019ced..ee67e9d 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
@@ -611,7 +611,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation
im
 
         Map<String, Object> flagTemplateOptions = ConfigBag.newInstance(flags).get(TEMPLATE_OPTIONS);
         Map<String, Object> baseTemplateOptions = config().get(TEMPLATE_OPTIONS);
-        Map<String, Object> templateOptions = (Map<String, Object>) deepMerge(Maybe.fromNullable(flagTemplateOptions),
Maybe.fromNullable(baseTemplateOptions), TEMPLATE_OPTIONS).orNull();
+        Map<String, Object> templateOptions = (Map<String, Object>) shallowMerge(Maybe.fromNullable(flagTemplateOptions),
Maybe.fromNullable(baseTemplateOptions), TEMPLATE_OPTIONS).orNull();
         setup.put(TEMPLATE_OPTIONS, templateOptions);
         
         Integer attempts = setup.get(MACHINE_CREATE_ATTEMPTS);
@@ -3328,8 +3328,8 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation
im
         return new JcloudsBlobStoreBasedObjectStore(this, container);
     }
 
-    // TODO Duplicate of EntityConfigMap.deepMerge
-    private <T> Maybe<?> deepMerge(Maybe<? extends T> val1, Maybe<?
extends T> val2, ConfigKey<?> keyForLogging) {
+    // TODO Very similar to EntityConfigMap.deepMerge
+    private <T> Maybe<?> shallowMerge(Maybe<? extends T> val1, Maybe<?
extends T> val2, ConfigKey<?> keyForLogging) {
         if (val2.isAbsent() || val2.isNull()) {
             return val1;
         } else if (val1.isAbsent()) {
@@ -3337,7 +3337,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation
im
         } else if (val1.isNull()) {
             return val1; // an explicit null means an override; don't merge
         } else if (val1.get() instanceof Map && val2.get() instanceof Map) {
-            return Maybe.of(CollectionMerger.builder().build().merge((Map<?,?>)val1.get(),
(Map<?,?>)val2.get()));
+            return Maybe.of(CollectionMerger.builder().deep(false).build().merge((Map<?,?>)val1.get(),
(Map<?,?>)val2.get()));
         } else {
             // cannot merge; just return val1
             LOG.debug("Cannot merge values for "+keyForLogging.getName()+", because values
are not maps: "+val1.get().getClass()+", and "+val2.get().getClass());


Mime
View raw message