You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/11/09 15:33:04 UTC

[1/3] brooklyn-server git commit: testing map config dot syntax, isolating known lookup failure

Repository: brooklyn-server
Updated Branches:
  refs/heads/master fd0097803 -> 5f07cbc56


testing map config dot syntax, isolating known lookup failure


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

Branch: refs/heads/master
Commit: 42a7cd2bfcc555635a6dbc8d743e10babc5d761c
Parents: 0bf8280
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Nov 9 12:03:28 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Nov 9 13:29:57 2016 +0000

----------------------------------------------------------------------
 .../camp/brooklyn/ConfigNestedYamlTest.java     | 148 +++++++++++++++++++
 .../camp/brooklyn/config-nested-test.bom        |  76 ++++++++++
 .../camp/brooklyn/config-nested-test.yaml       |  29 ++++
 3 files changed, 253 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/42a7cd2b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigNestedYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigNestedYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigNestedYamlTest.java
new file mode 100644
index 0000000..2d6526f
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigNestedYamlTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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 java.util.Map;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityInternal;
+import org.apache.brooklyn.entity.group.DynamicCluster;
+import org.apache.brooklyn.entity.software.base.SoftwareProcess;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.core.text.TemplateProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+
+public class ConfigNestedYamlTest extends AbstractYamlTest {
+    private static final Logger log = LoggerFactory.getLogger(ConfigNestedYamlTest.class);
+    
+    @Test
+    public void testSimpleYamlBlueprint() throws Exception {
+        doTestWithBlueprint( loadYaml("config-nested-test.yaml"), false );
+    }
+
+    @Test
+    public void testCatalogNoParameter() throws Exception {
+        addCatalogItems( loadYaml("config-nested-test.bom") );
+        doTestWithBlueprint( "services: [ { type: test-no-parameter } ]", false);
+    }
+
+    @Test
+    public void testCatalogParameterFromSuperYamlType() throws Exception {
+        addCatalogItems( loadYaml("config-nested-test.bom") );
+        Entity ent = doTestWithBlueprint( "services: [ { type: test-map-parameter } ]", false);
+        Entities.dumpInfo(ent);
+    }
+
+    @Test
+    public void testCatalogParameterFromSuperYamlTypeAfterTemplateAccess() throws Exception {
+        addCatalogItems( loadYaml("config-nested-test.bom") );
+        Entity ent = makeBlueprint( "services: [ { type: test-map-parameter } ]");
+        
+        checkEntity(ent, false);
+    }
+
+    protected void checkTemplates(EntityInternal ent) {
+        Map<String, Object> substitutions = MutableMap.copyOf(ent.config().get(SoftwareProcess.TEMPLATE_SUBSTITUTIONS)).asUnmodifiable();
+        String out0 = TemplateProcessor.processTemplateContents("hello "+"${field}", substitutions);
+        Assert.assertEquals(out0, "hello val");
+        
+        String out1 = TemplateProcessor.processTemplateContents("hello "+"${config['template.substitutions']['field']}", ent, substitutions);
+        Assert.assertEquals(out1, "hello val");
+    }
+
+    @Test
+    public void testCatalogParameterFromSuperYamlTypeInCluster() throws Exception {
+        addCatalogItems( loadYaml("config-nested-test.bom") );
+        Entity cluster = makeBlueprint("services: [ { type: test-cluster-with-map-parameter } ]");
+        Entities.dumpInfo(cluster.getApplication());
+        Entity parentInCluster = Iterables.getOnlyElement( ((DynamicCluster)cluster).getMembers() );
+        Entity target = Iterables.getOnlyElement(parentInCluster.getChildren());
+        checkEntity( target, false );
+    }
+    
+
+    @Test
+    public void testCatalogParameterFromSuperYamlTypeAsSoftware() throws Exception {
+        addCatalogItems( loadYaml("config-nested-test.bom") );
+        Entity ent = doTestWithBlueprint( "services: [ { type: test-map-parameter-software } ]", true);
+        Entities.dumpInfo(ent);
+    }
+
+    @Test
+    public void testCatalogNoParameterAsSoftware() throws Exception {
+        addCatalogItems( loadYaml("config-nested-test.bom") );
+        doTestWithBlueprint( "services: [ { type: test-no-parameter-software } ]", true);
+    }
+
+    protected Entity doTestWithBlueprint(String bp, boolean expectDotSyntaxToWork) throws Exception {
+        return checkEntity(makeBlueprint(bp), expectDotSyntaxToWork);
+    }
+    
+    protected Entity makeBlueprint(String bp) throws Exception {
+        Entity app = createAndStartApplication( bp );
+        waitForApplicationTasks(app);
+        return Iterables.getOnlyElement( app.getChildren() );
+    }
+    
+    protected Entity checkEntity(Entity ent, boolean expectDotSyntaxToWork) throws Exception {
+        String dotSyntax = ent.getConfig( ConfigKeys.newStringConfigKey("template.substitutions.field") );
+        Assert.assertEquals(dotSyntax, expectDotSyntaxToWork ? "val" : null, "wrong value for dot syntax: "+dotSyntax);
+        // observed in some situations we get the dot syntax instead!
+        // Assert.assertEquals(dotSyntax, "val", "wrong value for dot syntax: "+dotSyntax);
+        
+        // might be okay if the above does happen (though I can't get it reproduced);
+        // however the following must _always_ work
+        
+        // strongly typed
+        Map<?,?> map1 = ent.getConfig(SoftwareProcess.TEMPLATE_SUBSTITUTIONS);
+        Assert.assertNotNull(map1, "Nothing found for 'template.substitutions'");
+        Assert.assertTrue(map1.containsKey("field"), "missing 'field' in "+map1);
+        Assert.assertEquals(map1.get("field"), "val", "wrong value for 'field' in "+map1);
+        
+        // because SoftwareProcess declares TEMPLATE_SUBSTITUTIONS it rewrites where map entries are put
+        // (to use dot syntax) so if the entity is a software process (ie expectDotSyntaxToWork)
+        // neither "anonymous key" lookup nor template processing deep-map works,
+        // unless we switch from the query key to own key when we do the key value lookup
+        // (we should probably be doing that any way however!)
+        
+        // (those two tests deliberately fail in this commit, fixed in following commit)
+        
+        // anonymous key
+        Map<?,?> map2 = ent.getConfig(ConfigKeys.newConfigKey(Map.class, "template.substitutions")); 
+        Assert.assertNotNull(map2, "Nothing found for 'template.substitutions'");
+        Assert.assertTrue(map2.containsKey("field"), "missing 'field' in "+map2);
+        Assert.assertEquals(map2.get("field"), "val", "wrong value for 'field' in "+map2);
+        
+        checkTemplates((EntityInternal) ent);
+        
+        return ent;
+    }
+    
+    @Override
+    protected Logger getLogger() {
+        return log;
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/42a7cd2b/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/config-nested-test.bom
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/config-nested-test.bom b/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/config-nested-test.bom
new file mode 100644
index 0000000..ff1f7c3
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/config-nested-test.bom
@@ -0,0 +1,76 @@
+#
+# 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.
+#
+
+brooklyn.catalog:
+  version: 1
+  items:
+  - id: test-no-parameter
+    itemType: entity
+    item:
+      type: org.apache.brooklyn.entity.stock.BasicEntity
+      brooklyn.config:
+        template.substitutions:
+          field: val
+  - id: base-map-parameter
+    itemType: entity
+    item:
+      type: org.apache.brooklyn.entity.stock.BasicEntity
+      brooklyn.parameters:
+        - name: template.substitutions
+          type: java.util.Map
+  - id: test-map-parameter
+    itemType: entity
+    item:
+      type: base-map-parameter
+      brooklyn.config:
+        template.substitutions:
+          field: val
+  - id: test-cluster-with-map-parameter
+    itemType: entity
+    item:
+      type: cluster
+      initialSize: 1
+      dynamiccluster.memberspec:
+        $brooklyn:entitySpec:
+          type: org.apache.brooklyn.entity.stock.BasicEntity
+          brooklyn.children:
+          - type: test-map-parameter
+  - id: base-map-parameter-software
+    itemType: entity
+    item:
+      type: org.apache.brooklyn.entity.software.base.EmptySoftwareProcess
+      brooklyn.parameters:
+        - name: template.substitutions
+          type: java.util.Map
+  - id: test-map-parameter-software
+    itemType: entity
+    item:
+      type: base-map-parameter-software
+      brooklyn.config:
+        template.substitutions:
+          field: val
+      location: localhost
+  - id: test-no-parameter-software
+    itemType: entity
+    item:
+      type: org.apache.brooklyn.entity.software.base.EmptySoftwareProcess
+      brooklyn.config:
+        template.substitutions:
+          field: val
+      location: localhost

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/42a7cd2b/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/config-nested-test.yaml
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/config-nested-test.yaml b/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/config-nested-test.yaml
new file mode 100644
index 0000000..64525a1
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/config-nested-test.yaml
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+services:
+- type: org.apache.brooklyn.entity.stock.BasicEntity
+  brooklyn.config:
+    template.substitutions:
+      field: $brooklyn:attributeWhenReady("sensor")
+  brooklyn.initializers:
+  - type: org.apache.brooklyn.core.sensor.StaticSensor
+    brooklyn.config:
+      name: sensor
+      static.value: val


[3/3] brooklyn-server git commit: Closes #419

Posted by sv...@apache.org.
Closes #419

Fix key lookup

fixes subtle bug which prevents some evaluation strategies for map subkeys


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

Branch: refs/heads/master
Commit: 5f07cbc56e8f003a777093cb84424e55e2b71699
Parents: fd00978 d081492
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Nov 9 17:32:39 2016 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Nov 9 17:32:39 2016 +0200

----------------------------------------------------------------------
 .../camp/brooklyn/ConfigNestedYamlTest.java     | 148 +++++++++++++++++++
 .../camp/brooklyn/config-nested-test.bom        |  76 ++++++++++
 .../camp/brooklyn/config-nested-test.yaml       |  29 ++++
 .../config/internal/AbstractConfigMapImpl.java  |  10 +-
 4 files changed, 259 insertions(+), 4 deletions(-)
----------------------------------------------------------------------



[2/3] brooklyn-server git commit: resolve values using the key declared on an entity etc

Posted by sv...@apache.org.
resolve values using the key declared on an entity etc


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

Branch: refs/heads/master
Commit: d081492bf0934448b2a68c364cd549410bcc24c7
Parents: 42a7cd2
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Nov 9 13:30:48 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Nov 9 13:30:48 2016 +0000

----------------------------------------------------------------------
 .../core/config/internal/AbstractConfigMapImpl.java       | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d081492b/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java b/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
index 788e5da..98d20ad 100644
--- a/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/config/internal/AbstractConfigMapImpl.java
@@ -332,8 +332,9 @@ public abstract class AbstractConfigMapImpl<TContainer extends BrooklynObject> i
                 return getKeyAtContainer(input, queryKey);
             }
         };
-        ConfigKey<T> ownKey = keyFn.apply(getContainer());
-        if (ownKey==null) ownKey = queryKey;
+        ConfigKey<T> ownKey1 = keyFn.apply(getContainer());
+        if (ownKey1==null) ownKey1 = queryKey;
+        final ConfigKey<T> ownKey = ownKey1;
         @SuppressWarnings("unchecked")
         final Class<T> type = (Class<T>) ownKey.getType();
         
@@ -356,8 +357,9 @@ public abstract class AbstractConfigMapImpl<TContainer extends BrooklynObject> i
             
             Function<TContainer, Maybe<Object>> lookupFn = new Function<TContainer, Maybe<Object>>() {
                 @Override public Maybe<Object> apply(TContainer input) {
-                    Maybe<Object> result = getRawValueAtContainer(input, queryKey);
-                    if (!raw) result = resolveRawValueFromContainer(input, queryKey, result);
+                    // lookup against ownKey as it may do extra resolution (eg grab *.* subkeys if a map)
+                    Maybe<Object> result = getRawValueAtContainer(input, ownKey);
+                    if (!raw) result = resolveRawValueFromContainer(input, ownKey, result);
                     return result;
                 }
             };