brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/3] brooklyn-server git commit: fix for issue where $brooklyn:external refs in provisioning.properties are resolved too early
Date Thu, 09 Jun 2016 19:12:19 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 0150e2b7c -> 6a75c8ac5


fix for issue where $brooklyn:external refs in provisioning.properties are resolved too early

several more tests, including one which failed before the fix -- and of course the fix itself


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

Branch: refs/heads/master
Commit: 23aa9e87d8f4a587fb0ad8630638dd42112a5c70
Parents: 0150e2b
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Jun 9 17:01:49 2016 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Thu Jun 9 17:48:37 2016 +0100

----------------------------------------------------------------------
 .../LocationExternalConfigYamlTest.java         | 153 +++++++++++++++++++
 .../software/base/SoftwareProcessImpl.java      |  18 ++-
 2 files changed, 170 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/23aa9e87/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationExternalConfigYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationExternalConfigYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationExternalConfigYamlTest.java
new file mode 100644
index 0000000..0485a17
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationExternalConfigYamlTest.java
@@ -0,0 +1,153 @@
+/*
+ * 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.camp.brooklyn;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.StringReader;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.camp.brooklyn.ExternalConfigYamlTest.MyExternalConfigSupplier;
+import org.apache.brooklyn.camp.brooklyn.ExternalConfigYamlTest.MyExternalConfigSupplierWithoutMapArg;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.entity.StartableApplication;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.core.objs.BrooklynObjectInternal;
+import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess;
+import org.apache.brooklyn.util.core.task.DeferredSupplier;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+
+public class LocationExternalConfigYamlTest extends AbstractYamlRebindTest {
+
+	private static final Logger log = LoggerFactory.getLogger(ExternalConfigYamlTest.class);
+
+    private static final ConfigKey<String> MY_CONFIG_KEY = ConfigKeys.newStringConfigKey("my.config.key");
+    
+    @Override
+    protected BrooklynProperties createBrooklynProperties() {
+        BrooklynProperties props = super.createBrooklynProperties();
+        props.put("brooklyn.external.myprovider", MyExternalConfigSupplier.class.getName());
+        props.put("brooklyn.external.myprovider.mykey", "myval");
+        props.put("brooklyn.external.myproviderWithoutMapArg", MyExternalConfigSupplierWithoutMapArg.class.getName());
+        return props;
+    }
+
+    @Test(groups="Integration")
+    public void testLocalhostInheritance() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "services:",
+                "- type: "+EmptySoftwareProcess.class.getName(),
+                "location:",
+                "  localhost:",
+                "    my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")");
+
+        origApp = (StartableApplication) createAndStartApplication(new StringReader(yaml));
+
+        Entity entity = Iterables.getOnlyElement( origApp.getChildren() );
+        Location l = Iterables.getOnlyElement( entity.getLocations() );
+        log.info("Location: "+l);
+        assertEquals(l.config().get(MY_CONFIG_KEY), "myval");
+                
+        Maybe<Object> rawConfig = ((BrooklynObjectInternal.ConfigurationSupportInternal)l.config()).getRaw(MY_CONFIG_KEY);
+        log.info("Raw config: "+rawConfig);
+        Assert.assertTrue(rawConfig.isPresentAndNonNull());
+        Assert.assertTrue(rawConfig.get() instanceof DeferredSupplier, "Expected deferred
raw value; got "+rawConfig.get());
+    }
+    
+    @Test(groups="Integration")
+    public void testLocationFromCatalogInheritanceAndRebind() throws Exception {
+        ImmutableList.Builder<String> yamlL = ImmutableList.<String>builder().add(
+                "brooklyn.catalog:",
+                "  id: l1",
+                "  item.type: location",
+                "  item:",
+                "    type: localhost",
+                "    brooklyn.config:",
+                "      simple: 42",
+                "      my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")");
+        addCatalogItems(yamlL.build());
+
+        String yaml = Joiner.on("\n").join(
+                "services:",
+                "- type: "+EmptySoftwareProcess.class.getName(),
+                "location: l1");
+
+        origApp = (StartableApplication) createAndStartApplication(new StringReader(yaml));
+
+        Entity entity = Iterables.getOnlyElement( origApp.getChildren() );
+        Location l = Iterables.getOnlyElement( entity.getLocations() );
+        log.info("Location: "+l);
+        assertEquals(l.config().get(ConfigKeys.builder(Integer.class, "simple").build()),
(Integer)42);
+        assertEquals(l.config().get(MY_CONFIG_KEY), "myval");
+                
+        Maybe<Object> rawConfig = ((BrooklynObjectInternal.ConfigurationSupportInternal)l.config()).getRaw(MY_CONFIG_KEY);
+        log.info("Raw config: "+rawConfig);
+        Assert.assertTrue(rawConfig.isPresentAndNonNull());
+        Assert.assertTrue(rawConfig.get() instanceof DeferredSupplier, "Expected deferred
raw value; got "+rawConfig.get());
+        
+        newApp = rebind();
+        log.info("After catalog rebind: "+newApp);
+        
+        entity = Iterables.getOnlyElement( newApp.getChildren() );
+        l = Iterables.getOnlyElement( entity.getLocations() );
+        log.info("Location: "+l);
+        assertEquals(l.config().get(ConfigKeys.builder(Integer.class, "simple").build()),
(Integer)42);
+        assertEquals(l.config().get(MY_CONFIG_KEY), "myval");
+                
+        rawConfig = ((BrooklynObjectInternal.ConfigurationSupportInternal)l.config()).getRaw(MY_CONFIG_KEY);
+        log.info("Raw config: "+rawConfig);
+        Assert.assertTrue(rawConfig.isPresentAndNonNull());
+        Assert.assertTrue(rawConfig.get() instanceof DeferredSupplier, "Expected deferred
raw value; got "+rawConfig.get());
+    }
+    
+    @Test(groups="Integration")
+    public void testProvisioningPropertyInheritance() throws Exception {
+        String yaml = Joiner.on("\n").join(
+                "services:",
+                "- type: "+EmptySoftwareProcess.class.getName(),
+                "  provisioning.properties:",
+                "      simple: 42",
+                "      my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")",
+                "location: localhost");
+
+        origApp = (StartableApplication) createAndStartApplication(new StringReader(yaml));
+
+        Entity entity = Iterables.getOnlyElement( origApp.getChildren() );
+        Location l = Iterables.getOnlyElement( entity.getLocations() );
+        log.info("Location: "+l);
+        assertEquals(l.config().get(ConfigKeys.builder(Integer.class, "simple").build()),
(Integer)42);
+        assertEquals(l.config().get(MY_CONFIG_KEY), "myval");
+                
+        Maybe<Object> rawConfig = ((BrooklynObjectInternal.ConfigurationSupportInternal)l.config()).getRaw(MY_CONFIG_KEY);
+        log.info("Raw config: "+rawConfig);
+        Assert.assertTrue(rawConfig.isPresentAndNonNull());
+        Assert.assertTrue(rawConfig.get() instanceof DeferredSupplier, "Expected deferred
raw value; got "+rawConfig.get());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/23aa9e87/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
index 4bf6543..c4acf01 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
@@ -482,7 +482,23 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements
Soft
 
     protected Map<String,Object> obtainProvisioningFlags(MachineProvisioningLocation
location) {
         ConfigBag result = ConfigBag.newInstance(location.getProvisioningFlags(ImmutableList.of(getClass().getName())));
-        result.putAll(getConfig(PROVISIONING_PROPERTIES));
+
+        // copy provisioning properties raw in case they contain deferred values
+        // normal case is to have provisioning.properties.xxx in the map, so this is how
we get it
+        Map<String, Object> raw1 = PROVISIONING_PROPERTIES.rawValue(config().getBag().getAllConfigRaw());
+        // do this also, just in case a map is stored at the key itself (not sure this is
needed, raw1 may include it already)
+        Maybe<Object> raw2 = config().getRaw(PROVISIONING_PROPERTIES);
+        if (raw2.isPresentAndNonNull()) {
+            Object pp = raw2.get();
+            if (!(pp instanceof Map)) {
+                log.debug("When obtaining provisioning properties for "+this+" to deploy
to "+location+", detected that coercion was needed, so coercing sooner than we would otherwise");
+                pp = config().get(PROVISIONING_PROPERTIES);
+            }
+            result.putAll((Map<?,?>)pp);
+        }
+        // finally write raw1 on top
+        result.putAll(raw1);
+
         if (result.get(CloudLocationConfig.INBOUND_PORTS) == null) {
             Collection<Integer> ports = getRequiredOpenPorts();
             Object requiredPorts = result.get(CloudLocationConfig.ADDITIONAL_INBOUND_PORTS);


Mime
View raw message