You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2015/11/09 13:55:19 UTC

[10/21] incubator-brooklyn git commit: Add root scope in CAMP DSL - the application

Add root scope in CAMP DSL - the application


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

Branch: refs/heads/master
Commit: 1da725f4a4809d655b77a1cdfaae20a2ab3e18be
Parents: f16cbe0
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Nov 4 14:57:58 2015 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Thu Nov 5 15:23:39 2015 +0200

----------------------------------------------------------------------
 .../camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java    | 3 +++
 .../camp/brooklyn/spi/dsl/methods/DslComponent.java         | 8 +++++++-
 .../org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java | 9 ++++++++-
 .../brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java   | 4 ++++
 .../camp/src/test/resources/test-referencing-entities.yaml  | 7 +++++++
 5 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1da725f4/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
index cb41f20..422dac3 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
@@ -84,6 +84,9 @@ public class BrooklynDslCommon {
     public static DslComponent ancestor(String id) {
         return new DslComponent(Scope.ANCESTOR, id);
     }
+    public static DslComponent root() {
+        return new DslComponent(Scope.ROOT, null);
+    }
     // prefer the syntax above to the below now, but not deprecating the below
     public static DslComponent component(String id) {
         return component("global", id);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1da725f4/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
index 149a88a..d5f3078 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
@@ -108,6 +108,8 @@ public class DslComponent extends BrooklynDslDeferredSupplier<Entity> {
                     entitiesToSearch = ((EntityManagerInternal)getEntity().getManagementContext().getEntityManager())
                         .getAllEntitiesInApplication( entity().getApplication() );
                     break;
+                case ROOT:
+                    return getEntity().getApplication();
                 case DESCENDANT:
                     entitiesToSearch = Entities.descendants(getEntity());
                     break;
@@ -155,6 +157,9 @@ public class DslComponent extends BrooklynDslDeferredSupplier<Entity> {
     public DslComponent ancestor(String scopeOrId) {
         return new DslComponent(this, Scope.ANCESTOR, scopeOrId);
     }
+    public DslComponent root() {
+        return new DslComponent(this, Scope.ROOT, "");
+    }
     
     @Deprecated /** @deprecated since 0.7.0 */
     public DslComponent component(String scopeOrId) {
@@ -277,9 +282,10 @@ public class DslComponent extends BrooklynDslDeferredSupplier<Entity> {
         SIBLING ("sibling"),
         DESCENDANT ("descendant"),
         ANCESTOR("ancestor"),
+        ROOT("root"),
         THIS ("this");
         
-        public static final Set<Scope> VALUES = ImmutableSet.of(GLOBAL, CHILD, PARENT, SIBLING, DESCENDANT, ANCESTOR, THIS);
+        public static final Set<Scope> VALUES = ImmutableSet.of(GLOBAL, CHILD, PARENT, SIBLING, DESCENDANT, ANCESTOR, ROOT, THIS);
         
         private final String name;
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1da725f4/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
index 6dd636d..266772b 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
@@ -402,12 +402,18 @@ public class EntitiesYamlTest extends AbstractYamlTest {
         final Entity app = createAndStartApplication(loadYaml("test-referencing-entities.yaml"));
         waitForApplicationTasks(app);
         
+        Entity root1 = Tasks.resolving(new DslComponent(Scope.ROOT, "xxx").newTask(), Entity.class).context( ((EntityInternal)app).getExecutionContext() ).embedResolutionInTask(true).get();
+        Assert.assertEquals(root1, app);
+        
         Entity c1 = Tasks.resolving(new DslComponent("c1").newTask(), Entity.class).context( ((EntityInternal)app).getExecutionContext() ).embedResolutionInTask(true).get();
         Assert.assertEquals(c1, Entities.descendants(app, EntityPredicates.displayNameEqualTo("child 1")).iterator().next());
         
         Entity e1 = Tasks.resolving(new DslComponent(Scope.PARENT, "xxx").newTask(), Entity.class).context( ((EntityInternal)c1).getExecutionContext() ).embedResolutionInTask(true).get();
         Assert.assertEquals(e1, Entities.descendants(app, EntityPredicates.displayNameEqualTo("entity 1")).iterator().next());
         
+        Entity root2 = Tasks.resolving(new DslComponent(Scope.ROOT, "xxx").newTask(), Entity.class).context( ((EntityInternal)c1).getExecutionContext() ).embedResolutionInTask(true).get();
+        Assert.assertEquals(root2, app);
+        
         Entity c1a = Tasks.resolving(BrooklynDslCommon.descendant("c1").newTask(), Entity.class).context( ((EntityInternal)e1).getExecutionContext() ).embedResolutionInTask(true).get();
         Assert.assertEquals(c1a, c1);
         Entity e1a = Tasks.resolving(BrooklynDslCommon.ancestor("e1").newTask(), Entity.class).context( ((EntityInternal)c1).getExecutionContext() ).embedResolutionInTask(true).get();
@@ -460,6 +466,7 @@ public class EntitiesYamlTest extends AbstractYamlTest {
         Assert.assertNotNull(grandchild2);
 
         Map<ConfigKey<Entity>, Entity> keyToEntity = new ImmutableMap.Builder<ConfigKey<Entity>, Entity>()
+            .put(ReferencingYamlTestEntity.TEST_REFERENCE_ROOT, app)
             .put(ReferencingYamlTestEntity.TEST_REFERENCE_APP, app)
             .put(ReferencingYamlTestEntity.TEST_REFERENCE_ENTITY1, entity1)
             .put(ReferencingYamlTestEntity.TEST_REFERENCE_ENTITY1_ALT, entity1)
@@ -491,7 +498,7 @@ public class EntitiesYamlTest extends AbstractYamlTest {
     private void checkReferences(final Entity entity, Map<ConfigKey<Entity>, Entity> keyToEntity) throws Exception {
         for (final ConfigKey<Entity> key : keyToEntity.keySet()) {
             try {
-                Assert.assertEquals(getResolvedConfigInTask(entity, key).get(), keyToEntity.get(key));
+                Assert.assertEquals(getResolvedConfigInTask(entity, key).get(), keyToEntity.get(key), "For entity " + entity.toString() + ":");
             } catch (Throwable t) {
                 Exceptions.propagateIfFatal(t);
                 Assert.fail("Wrong value for "+entity+":"+key+", "+((EntityInternal)entity).config().getLocalRaw(key)+": "+t, t);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1da725f4/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java
index 8cbd780..089343c 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java
@@ -28,6 +28,10 @@ import com.google.common.reflect.TypeToken;
 @ImplementedBy(ReferencingYamlTestEntityImpl.class)
 public interface ReferencingYamlTestEntity extends Entity {
     @SuppressWarnings("serial")
+    public static final ConfigKey<Entity> TEST_REFERENCE_ROOT = BasicConfigKey.builder(new TypeToken<Entity>(){})
+            .name("test.reference.root")
+            .build();
+    @SuppressWarnings("serial")
     public static final ConfigKey<Entity> TEST_REFERENCE_APP = BasicConfigKey.builder(new TypeToken<Entity>(){})
             .name("test.reference.app")
             .build();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1da725f4/usage/camp/src/test/resources/test-referencing-entities.yaml
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/resources/test-referencing-entities.yaml b/usage/camp/src/test/resources/test-referencing-entities.yaml
index 19944c3..ebe4662 100644
--- a/usage/camp/src/test/resources/test-referencing-entities.yaml
+++ b/usage/camp/src/test/resources/test-referencing-entities.yaml
@@ -37,6 +37,7 @@ description: Test multi-layer application with each entity referencing all other
 origin: https://github.com/apache/incubator-brooklyn
 id: app1
 brooklyn.config:
+  test.reference.root: $brooklyn:root()
   test.reference.app: $brooklyn:component("app1")
   test.reference.entity1: $brooklyn:entity("e1")
   test.reference.entity1a: $brooklyn:config("test.reference.entity1")
@@ -51,6 +52,7 @@ services:
   id: e1
   name: entity 1
   brooklyn.config:
+    test.reference.root: $brooklyn:root()
     test.reference.app: $brooklyn:component("parent", "ignored")
     test.reference.entity1: $brooklyn:component("this", "ignored")
     test.reference.entity1a: $brooklyn:ancestor("app1").child("e1")
@@ -66,6 +68,7 @@ services:
       name: child 1
       brooklyn.config:
         self: $brooklyn:entity("c1")
+        test.reference.root: $brooklyn:root()
         test.reference.app: $brooklyn:parent().parent()
         test.reference.entity1: $brooklyn:parent()
         test.reference.entity1a: $brooklyn:entity("e1").parent().child("e1")
@@ -80,6 +83,7 @@ services:
         id: gc1
         name: grandchild 1
         brooklyn.config:
+          test.reference.root: $brooklyn:root()
           test.reference.app: $brooklyn:component("app1")
           test.reference.entity1: $brooklyn:component("e1")
           test.reference.entity2: $brooklyn:component("e2")
@@ -91,6 +95,7 @@ services:
         id: gc2
         name: grandchild 2
         brooklyn.config:
+          test.reference.root: $brooklyn:root()
           test.reference.app: $brooklyn:component("app1")
           test.reference.entity1: $brooklyn:component("e1")
           test.reference.entity2: $brooklyn:component("e2")
@@ -102,6 +107,7 @@ services:
       id: c2
       name: child 2
       brooklyn.config:
+        test.reference.root: $brooklyn:root()
         test.reference.app: $brooklyn:parent().parent().descendant("app1")
         test.reference.entity1: $brooklyn:component("e1")
         test.reference.entity2: $brooklyn:component("e2")
@@ -113,6 +119,7 @@ services:
   id: e2
   name: entity 2
   brooklyn.config:
+    test.reference.root: $brooklyn:root()
     test.reference.app: $brooklyn:component("app1")
     test.reference.entity1: $brooklyn:component("e1")
     test.reference.entity2: $brooklyn:component("e2")