brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [2/3] git commit: Movest the logic for creating child specs from BrooklynAssemblyTemplateInstantiator.resolveSpec to BrooklynComponentTemplateResolver.populateSpec
Date Wed, 15 Oct 2014 11:13:13 GMT
Movest the logic for creating child specs from BrooklynAssemblyTemplateInstantiator.resolveSpec
to BrooklynComponentTemplateResolver.populateSpec


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

Branch: refs/heads/master
Commit: 14366025e7c160f5381355d654b5db9ebca31dea
Parents: 66da981
Author: Martin Harris <github@nakomis.com>
Authored: Mon Oct 13 17:50:10 2014 +0100
Committer: Martin Harris <github@nakomis.com>
Committed: Mon Oct 13 17:50:10 2014 +0100

----------------------------------------------------------------------
 .../BrooklynAssemblyTemplateInstantiator.java   | 13 +------------
 .../BrooklynComponentTemplateResolver.java      | 16 +++++++++++++++-
 .../camp/brooklyn/EntitiesYamlTest.java         | 20 ++++++++++++++++----
 3 files changed, 32 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/14366025/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
index 2383a27..5f594c4 100644
--- a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
+++ b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java
@@ -164,7 +164,7 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
         return result;
     }
 
-    private EntitySpec<?> resolveSpec(
+    protected EntitySpec<?> resolveSpec(
             BrooklynComponentTemplateResolver entityResolver, 
             Set<String> encounteredCatalogTypes) {
         ManagementContext mgmt = entityResolver.loader.getManagementContext();
@@ -206,8 +206,6 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
             }
         }
 
-        BrooklynClassLoadingContext newLoader = entityResolver.loader;
-        buildChildrenEntitySpecs(newLoader, spec, entityResolver.getChildren(entityResolver.attrs.getAllConfig()),
encounteredCatalogTypes);
         return spec;
     }
 
@@ -277,13 +275,4 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe
         }
     }
 
-    protected void buildChildrenEntitySpecs(BrooklynClassLoadingContext loader, EntitySpec<?>
parent, List<Map<String, Object>> childConfig, Set<String> encounteredCatalogTypes)
{
-        if (childConfig != null) {
-            for (Map<String, Object> childAttrs : childConfig) {
-                BrooklynComponentTemplateResolver entityResolver = BrooklynComponentTemplateResolver.Factory.newInstance(loader,
childAttrs);
-                EntitySpec<? extends Entity> spec = resolveSpec(entityResolver, encounteredCatalogTypes);
-                parent.child(spec);
-            }
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/14366025/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 2e407da..98149fd 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
@@ -104,7 +104,7 @@ public class BrooklynComponentTemplateResolver {
             return null;
         }
 
-        public static BrooklynComponentTemplateResolver newInstance(BrooklynClassLoadingContext
loader, Map<String, Object> childAttrs) {
+        public static BrooklynComponentTemplateResolver newInstance(BrooklynClassLoadingContext
loader, Map<String, ?> childAttrs) {
             return newInstance(loader, ConfigBag.newInstance(childAttrs), null);
         }
 
@@ -276,6 +276,20 @@ public class BrooklynComponentTemplateResolver {
         if (planId==null)
             planId = (String) attrs.getStringKey(BrooklynCampConstants.PLAN_ID_FLAG);
 
+        Object children = attrs.getStringKey("brooklyn.children");
+        if (children != null) {
+            Set<String> encounteredCatalogTypes = MutableSet.of();
+            for (Map<String,?> childAttrs : (Iterable<Map<String,?>>)children)
{
+                BrooklynComponentTemplateResolver entityResolver = BrooklynComponentTemplateResolver.Factory.newInstance(loader,
childAttrs);
+                BrooklynAssemblyTemplateInstantiator instantiator = new BrooklynAssemblyTemplateInstantiator();
+                // TODO: Creating a new set of encounteredCatalogTypes prevents the recursive
definition check in
+                // BrooklynAssemblyTemplateInstantiator.resolveSpec from correctly determining
if a YAML entity is
+                // defined recursively. However, the number of overrides of newInstance,
and the number of places
+                // calling populateSpec make it difficult to pass encounteredCatalogTypes
in as a parameter
+                EntitySpec<? extends Entity> childSpec = instantiator.resolveSpec(entityResolver,
encounteredCatalogTypes);
+                spec.child(childSpec);
+            }
+        }
         if (!Strings.isBlank(name))
             spec.displayName(name);
         if (templateId != null)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/14366025/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 d2a3525..20334fa 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
@@ -604,7 +604,7 @@ public class EntitiesYamlTest extends AbstractYamlTest {
         assertEquals(child.getConfig(TestEntity.CONF_NAME), "inchildspec");
     }
 
-    @Test(groups = {"WIP"})
+    @Test
     public void testEntitySpecWithChildren() throws Exception {
         String yaml =
                 "services:\n"+
@@ -613,18 +613,30 @@ public class EntitiesYamlTest extends AbstractYamlTest {
                 "   test.childSpec:\n"+
                 "     $brooklyn:entitySpec:\n"+
                 "       type: brooklyn.test.entity.TestEntity\n"+
+                "       brooklyn.config:\n"+
+                "         test.confName: child\n"+
                 "       brooklyn.children:\n"+
-                "       - type: brooklyn.test.entity.TestEntity3\n" +
-                "         brooklyn.confName: grandchild\n";
+                "       - type: brooklyn.test.entity.TestEntity\n" +
+                "         brooklyn.config:\n" +
+                "           test.confName: grandchild\n" +
+                "         brooklyn.children:\n"+
+                "         - type: brooklyn.test.entity.TestEntity\n" +
+                "           brooklyn.config:\n" +
+                "             test.confName: greatgrandchild\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), "child");
+        assertEquals(child.getChildren().size(), 1, "Child entity should have exactly one
child of its own");
 
-        assertEquals(child.getChildren().size(), 1, "Child entity should have one child of
its own");
         TestEntity grandchild = (TestEntity) Iterables.getOnlyElement(child.getChildren());
         assertEquals(grandchild.getConfig(TestEntity.CONF_NAME), "grandchild");
+        assertEquals(grandchild.getChildren().size(), 1, "Grandchild entity should have exactly
one child of its own");
+
+        TestEntity greatgrandchild = (TestEntity) Iterables.getOnlyElement(grandchild.getChildren());
+        assertEquals(greatgrandchild.getConfig(TestEntity.CONF_NAME), "greatgrandchild");
     }
     
     @Test


Mime
View raw message