Skip to content
Browse files
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!
  • Loading branch information
ahgittin committed Jan 14, 2016
1 parent 01833f2 commit 70ed345e4b4cb992d92f363f250000b4c00558ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
@@ -374,6 +374,13 @@ public <V> EntitySpec<T> location(Location val) {
return this;

/** clears locations defined in the spec */
public <V> EntitySpec<T> clearLocations() {
return this;

/** adds the supplied locations to the spec */
public <V> EntitySpec<T> locations(Iterable<? extends Location> val) {
@@ -223,9 +223,13 @@ private <T extends Entity> void populateSpec(EntitySpec<T> spec, Set<String> enc
if (planId != null)
spec.configure(BrooklynCampConstants.PLAN_ID, planId);

List<Location> childLocations = new BrooklynYamlLocationResolver(mgmt).resolveLocations(attrs.getAllConfig(), true);
if (childLocations != null)
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

decorateSpec(spec, encounteredRegisteredTypeIds);
@@ -181,6 +181,8 @@ brooklyn.catalog:
my.message: $brooklyn:formatString("connected to Riak at %s",
# 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: []

my.message: "part of the cluster"

0 comments on commit 70ed345

Please sign in to comment.