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 2016/01/15 00:54:26 UTC

[12/24] incubator-brooklyn git commit: allow locations to be overridden when referring to a type

allow locations to be overridden when referring to a type

not sure of the cleanest way to achieve this, but where a type includes a location,
a caller may wish to override it, such as in the default catalog references to template 2.

previously i think locations in referenced types were just dropped (?)
but then it was changed to be additive, which makes sense and is consistent, but
breaks the examples and means there was no way to override a location in a referenced type.

this changes it so that *if* a location block is included on the *referencer*, even if empty,
it overrides the locations on the referenced type. examples are updated accordingly.

an alternative would be to introduce a new explicit field to clear locations;
or a very different alternative would be to put locations in comments in the examples,
and clarify in the code templates/applications (as presently the presence of a location
is what triggers something being editable!); those are worth considering, especially the latter,
but the present change actually seems sensible as it is rare a caller would want to *add*
a location to a referenced type!


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

Branch: refs/heads/master
Commit: 70ed345e4b4cb992d92f363f250000b4c00558ae
Parents: 01833f2
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Jan 14 12:16:23 2016 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Jan 14 14:43:00 2016 +0000

----------------------------------------------------------------------
 .../java/org/apache/brooklyn/api/entity/EntitySpec.java   |  7 +++++++
 .../spi/creation/BrooklynComponentTemplateResolver.java   | 10 +++++++---
 .../src/main/resources/brooklyn/default.catalog.bom       |  4 ++++
 3 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/70ed345e/brooklyn-server/api/src/main/java/org/apache/brooklyn/api/entity/EntitySpec.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/api/src/main/java/org/apache/brooklyn/api/entity/EntitySpec.java b/brooklyn-server/api/src/main/java/org/apache/brooklyn/api/entity/EntitySpec.java
index 7440221..58cf946 100644
--- a/brooklyn-server/api/src/main/java/org/apache/brooklyn/api/entity/EntitySpec.java
+++ b/brooklyn-server/api/src/main/java/org/apache/brooklyn/api/entity/EntitySpec.java
@@ -374,6 +374,13 @@ public class EntitySpec<T extends Entity> extends AbstractBrooklynObjectSpec<T,E
         return this;
     }
     
+    /** clears locations defined in the spec */
+    public <V> EntitySpec<T> clearLocations() {
+        checkMutable();
+        locations.clear();
+        return this;        
+    }
+    
     /** adds the supplied locations to the spec */
     public <V> EntitySpec<T> locations(Iterable<? extends Location> val) {
         checkMutable();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/70ed345e/brooklyn-server/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java b/brooklyn-server/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
index b1a4764..90ed899 100644
--- a/brooklyn-server/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
+++ b/brooklyn-server/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
@@ -223,9 +223,13 @@ public class BrooklynComponentTemplateResolver {
         if (planId != null)
             spec.configure(BrooklynCampConstants.PLAN_ID, planId);
 
-        List<Location> childLocations = new BrooklynYamlLocationResolver(mgmt).resolveLocations(attrs.getAllConfig(), true);
-        if (childLocations != null)
-            spec.locations(childLocations);
+        List<Location> locations = new BrooklynYamlLocationResolver(mgmt).resolveLocations(attrs.getAllConfig(), true);
+        if (locations != null) {
+            // override locations defined in the type if locations are specified here
+            // empty list can be used by caller to clear, so they are inherited
+            spec.clearLocations();
+            spec.locations(locations);
+        }
 
         decorateSpec(spec, encounteredRegisteredTypeIds);
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/70ed345e/brooklyn-server/server-cli/src/main/resources/brooklyn/default.catalog.bom
----------------------------------------------------------------------
diff --git a/brooklyn-server/server-cli/src/main/resources/brooklyn/default.catalog.bom b/brooklyn-server/server-cli/src/main/resources/brooklyn/default.catalog.bom
index 483f04d..08deb81 100644
--- a/brooklyn-server/server-cli/src/main/resources/brooklyn/default.catalog.bom
+++ b/brooklyn-server/server-cli/src/main/resources/brooklyn/default.catalog.bom
@@ -181,6 +181,8 @@ brooklyn.catalog:
         brooklyn.config:
           my.message:   $brooklyn:formatString("connected to Riak at %s",
                             $brooklyn:entity("riak-cluster").attributeWhenReady("main.uri"))
+        # and clear the location defined there so it is taken from this template
+        locations:      []
                             
       # use the off-the-shelf Riak cluster
       - type:           org.apache.brooklyn.entity.nosql.riak.RiakCluster
@@ -240,6 +242,8 @@ brooklyn.catalog:
               # and a lot of sensors defined
               type:           2-bash-web-server-template
               name:           My Bash Web Server VM with Sensors
+              # and clear the location defined there so it is taken from this template
+              locations:      []
               
               brooklyn.config:
                 my.message:   "part of the cluster"