You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by gr...@apache.org on 2016/12/12 18:17:41 UTC

[2/4] brooklyn-server git commit: Save location information as sensor data on LocationEntity

Save location information as sensor data on LocationEntity


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

Branch: refs/heads/master
Commit: 6615ddf70d63a7c71e93d6b25a7987ca269b2f02
Parents: b119889
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Authored: Fri Nov 11 12:17:25 2016 +0000
Committer: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Committed: Tue Nov 22 13:52:15 2016 +0000

----------------------------------------------------------------------
 .../org/apache/brooklyn/entity/stock/LocationEntity.java  | 10 ++++++++++
 .../apache/brooklyn/entity/stock/LocationEntityImpl.java  |  3 +++
 2 files changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6615ddf7/core/src/main/java/org/apache/brooklyn/entity/stock/LocationEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/stock/LocationEntity.java b/core/src/main/java/org/apache/brooklyn/entity/stock/LocationEntity.java
index 4e8cfd1..9a72bee 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/stock/LocationEntity.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/stock/LocationEntity.java
@@ -20,6 +20,7 @@ package org.apache.brooklyn.entity.stock;
 
 import java.util.Collection;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
@@ -39,6 +40,10 @@ import com.google.common.reflect.TypeToken;
  * <p>
  * Can use the class name of the {@link MachineProvisioningLocation} or the value of the
  * {@code provider} or {@code iso3166} configuration keys on the provisioning location.
+ * The values used to make the decision are set as sensors on this entity. The decision
+ * is made based on the first match found, checking the class name first, then the
+ * provider and finally the country codes, and map keys representing any or all of these
+ * can be used at the same time.
  * <pre>
  * - type: org.apache.brooklyn.entity.stock.LocationEntity
  *   brooklyn.config:
@@ -74,6 +79,11 @@ public interface LocationEntity extends BasicStartable {
     ConfigKey<Collection<AttributeSensor<?>>> LOCATION_ENTITY_SENSOR_LIST = ConfigKeys.newConfigKey(new TypeToken<Collection<AttributeSensor<?>>>() { },
             "location.entity.sensors", "Collection of sensors that are to be propagated from the child entity (all usual sensors if not set, or empty)");
 
+    AttributeSensor<String> LOCATION_TYPE = Sensors.newStringSensor("location.entity.type", "The class name of the entity location");
+    AttributeSensor<String> LOCATION_PROVIDER = Sensors.newStringSensor("location.entity.provider", "The provider name for the entity location");
+    AttributeSensor<Set<String>> LOCATION_COUNTRY_CODES = Sensors.newSensor(new TypeToken<Set<String>>() { },
+            "location.entity.countryCode", "The ISO 3166 country codes for the entity location");
+
     AttributeSensor<Entity> LOCATION_ENTITY = Sensors.newSensor(Entity.class,
             "location.entity", "The created entity");
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6615ddf7/core/src/main/java/org/apache/brooklyn/entity/stock/LocationEntityImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/stock/LocationEntityImpl.java b/core/src/main/java/org/apache/brooklyn/entity/stock/LocationEntityImpl.java
index 95c9efa..fbfcdc5 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/stock/LocationEntityImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/stock/LocationEntityImpl.java
@@ -100,6 +100,9 @@ public class LocationEntityImpl extends BasicStartableImpl implements LocationEn
                 String locationType = provisioner.getClass().getSimpleName();
                 String provider = provisioner.config().get(LocationConfigKeys.CLOUD_PROVIDER);
                 Set<String> countryCodes = MutableSet.copyOf(provisioner.config().get(LocationConfigKeys.ISO_3166));
+                sensors().set(LOCATION_TYPE, locationType);
+                sensors().set(LOCATION_PROVIDER, provider);
+                sensors().set(LOCATION_COUNTRY_CODES, countryCodes);
                 EntitySpec<?> spec = specMap.get(DEFAULT);
                 if (specMap.containsKey(locationType)) {
                     LOG.debug("Matched location type {} for entity: {}", locationType, this);