brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/8] git commit: add support for extracting flags from $brooklyn:entitySpec declarations and translating them as config
Date Mon, 27 Oct 2014 14:56:06 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master cf5a4fac3 -> 36b81821e


add support for extracting flags from $brooklyn:entitySpec declarations and translating them
as config


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

Branch: refs/heads/master
Commit: d76fa191a60479c4cae15604371ae653ecca0be3
Parents: f4d24b0
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Oct 27 00:17:15 2014 -0700
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Oct 27 07:51:41 2014 -0700

----------------------------------------------------------------------
 .../BrooklynComponentTemplateResolver.java       | 15 ++++++++++++++-
 .../spi/dsl/methods/BrooklynDslCommon.java       |  3 +++
 .../brooklyn/camp/brooklyn/EntitiesYamlTest.java | 19 +++++++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d76fa191/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
index 98149fd..9dbae24 100644
--- a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
+++ b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
@@ -264,6 +264,7 @@ public class BrooklynComponentTemplateResolver {
     }
 
     //called from BrooklynAssemblyTemplateInstantiator as well
+    @SuppressWarnings("unchecked")
     protected <T extends Entity> void populateSpec(EntitySpec<T> spec) {
         String name, templateId=null, planId=null;
         if (template.isPresent()) {
@@ -335,10 +336,22 @@ public class BrooklynComponentTemplateResolver {
         return entity;
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     private void configureEntityConfig(EntitySpec<?> spec) {
         ConfigBag bag = ConfigBag.newInstance((Map<Object, Object>) attrs.getStringKey("brooklyn.config"));
         
+        // first take *recognised* flags and config keys from the top-level, and put them
in the bag (of brooklyn.config)
+        // (for component templates this will have been done already by BrooklynEntityMatcher,
but for specs it is needed here)
+        ConfigBag bagFlags = ConfigBag.newInstanceCopying(attrs);
+        List<FlagConfigKeyAndValueRecord> topLevelApparentConfig = FlagUtils.findAllFlagsAndConfigKeys(null,
spec.getType(), bagFlags);
+        for (FlagConfigKeyAndValueRecord r: topLevelApparentConfig) {
+            if (r.getConfigKeyMaybeValue().isPresent())
+                bag.putIfAbsent((ConfigKey)r.getConfigKey(), r.getConfigKeyMaybeValue().get());
+            if (r.getFlagMaybeValue().isPresent())
+                bag.putAsStringKeyIfAbsent(r.getFlagName(), r.getFlagMaybeValue().get());
+        }
+
+        // now set configuration for all the items in the bag
         List<FlagConfigKeyAndValueRecord> records = FlagUtils.findAllFlagsAndConfigKeys(null,
spec.getType(), bag);
         Set<String> keyNamesUsed = new LinkedHashSet<String>();
         for (FlagConfigKeyAndValueRecord r: records) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d76fa191/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
index a7fb606..b93463a 100644
--- a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
+++ b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
@@ -131,6 +131,7 @@ public class BrooklynDslCommon {
      * to the {@link Map} or a {@link BrooklynDslDeferredSupplier} if the arguments are not
      * yet fully resolved.
      */
+    @SuppressWarnings("unchecked")
     public static Object object(Map<String, Object> arguments) {
         ConfigBag config = ConfigBag.newInstance(arguments);
         String typeName = BrooklynYamlTypeInstantiator.InstantiatorFromKey.extractTypeName("object",
config).orNull();
@@ -202,6 +203,7 @@ public class BrooklynDslCommon {
     }
 
     /** @deprecated since 0.7.0; use {@link DslFormatString} */
+    @SuppressWarnings("serial")
     @Deprecated
     protected static class FormatString extends DslFormatString {
         public FormatString(String pattern, Object[] args) {
@@ -223,6 +225,7 @@ public class BrooklynDslCommon {
             this.config = MutableMap.copyOf(config);
         }
 
+        @SuppressWarnings("unchecked")
         @Override
         public Task<Object> newTask() {
             List<TaskAdaptable<Object>> tasks = Lists.newLinkedList();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d76fa191/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/EntitiesYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/EntitiesYamlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/EntitiesYamlTest.java
index 20334fa..8defc5f 100644
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/EntitiesYamlTest.java
+++ b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/EntitiesYamlTest.java
@@ -605,6 +605,25 @@ public class EntitiesYamlTest extends AbstractYamlTest {
     }
 
     @Test
+    public void testEntitySpecFlags() throws Exception {
+        String yaml =
+                "services:\n"+
+                "- serviceType: brooklyn.test.entity.TestEntity\n"+
+                "  confName: inParent\n"+
+                "  brooklyn.config:\n"+
+                "   test.childSpec:\n"+
+                "     $brooklyn:entitySpec:\n"+
+                "       type: brooklyn.test.entity.TestEntity\n"+
+                "       confName: inchildspec\n";
+        
+        Application app = (Application) createStartWaitAndLogApplication(new StringReader(yaml));
+        TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
+        
+        TestEntity child = (TestEntity) entity.createAndManageChildFromConfig();
+        assertEquals(child.getConfig(TestEntity.CONF_NAME), "inchildspec");
+    }
+
+    @Test
     public void testEntitySpecWithChildren() throws Exception {
         String yaml =
                 "services:\n"+


Mime
View raw message