brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [08/50] [abbrv] brooklyn-server git commit: expand string-to-sensor coercion to make sensors easier to write in yaml
Date Mon, 01 Feb 2016 17:50:05 GMT
expand string-to-sensor coercion to make sensors easier to write in yaml


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

Branch: refs/heads/0.7.0-incubating
Commit: 5eefb7bf7094e56116968e6b0e77ee06e32d7082
Parents: 55441e0
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Sun Jun 21 11:58:50 2015 -0700
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Jun 24 00:40:33 2015 -0700

----------------------------------------------------------------------
 .../brooklyn/enricher/basic/Propagator.java     |  5 ++-
 .../java/brooklyn/util/flags/TypeCoercions.java | 32 ++++++++++++++++++--
 2 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5eefb7bf/core/src/main/java/brooklyn/enricher/basic/Propagator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/enricher/basic/Propagator.java b/core/src/main/java/brooklyn/enricher/basic/Propagator.java
index 7d6e383..86795c6 100644
--- a/core/src/main/java/brooklyn/enricher/basic/Propagator.java
+++ b/core/src/main/java/brooklyn/enricher/basic/Propagator.java
@@ -36,6 +36,8 @@ import brooklyn.event.SensorEvent;
 import brooklyn.event.SensorEventListener;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.flags.SetFromFlag;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
@@ -93,7 +95,8 @@ public class Propagator extends AbstractEnricher implements SensorEventListener<
                 throw new IllegalStateException("Propagator enricher "+this+" must not have
'propagating' set at same time as either 'propagatingAll' or 'propagatingAllBut'");
             }
             
-            for (Sensor<?> sensor : getConfig(PROPAGATING)) {
+            for (Object sensorO : getConfig(PROPAGATING)) {
+                Sensor<?> sensor = Tasks.resolving(sensorO).as(Sensor.class).timeout(Duration.millis(50)).context(producer).get();
                 if (!sensorMappingTemp.containsKey(sensor)) {
                     sensorMappingTemp.put(sensor, sensor);
                 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5eefb7bf/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/flags/TypeCoercions.java b/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
index 55649e8..c2876bd 100644
--- a/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
+++ b/core/src/main/java/brooklyn/util/flags/TypeCoercions.java
@@ -45,11 +45,14 @@ import javax.annotation.concurrent.GuardedBy;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.BrooklynTaskTags;
 import brooklyn.entity.basic.ClosureEntityFactory;
 import brooklyn.entity.basic.ConfigurableEntityFactory;
 import brooklyn.entity.basic.ConfigurableEntityFactoryFromEntityFactory;
 import brooklyn.event.AttributeSensor;
-import brooklyn.event.basic.BasicAttributeSensor;
+import brooklyn.event.Sensor;
+import brooklyn.event.basic.Sensors;
 import brooklyn.internal.BrooklynInitialization;
 import brooklyn.util.JavaGroovyEquivalents;
 import brooklyn.util.collections.MutableSet;
@@ -61,6 +64,7 @@ import brooklyn.util.javalang.Enums;
 import brooklyn.util.net.Cidr;
 import brooklyn.util.net.Networking;
 import brooklyn.util.net.UserAndHostAndPort;
+import brooklyn.util.task.Tasks;
 import brooklyn.util.text.StringEscapes.JavaStringEscapes;
 import brooklyn.util.text.Strings;
 import brooklyn.util.time.Duration;
@@ -723,7 +727,31 @@ public class TypeCoercions {
         registerAdapter(String.class, AttributeSensor.class, new Function<String,AttributeSensor>()
{
             @Override
             public AttributeSensor apply(final String input) {
-                return new BasicAttributeSensor<Object>(Object.class, input);
+                Entity entity = BrooklynTaskTags.getContextEntity(Tasks.current());
+                if (entity!=null) {
+                    Sensor<?> result = null;
+                    if (entity!=null) {
+                        result = entity.getEntityType().getSensor(input);
+                        if (result instanceof AttributeSensor) 
+                            return (AttributeSensor) result;
+                    }
+                }
+                return Sensors.newSensor(Object.class, input);
+            }
+        });
+        registerAdapter(String.class, Sensor.class, new Function<String,Sensor>() {
+            @Override
+            public AttributeSensor apply(final String input) {
+                Entity entity = BrooklynTaskTags.getContextEntity(Tasks.current());
+                if (entity!=null) {
+                    Sensor<?> result = null;
+                    if (entity!=null) {
+                        result = entity.getEntityType().getSensor(input);
+                        if (result != null) 
+                            return (AttributeSensor) result;
+                    }
+                }
+                return Sensors.newSensor(Object.class, input);
             }
         });
         registerAdapter(String.class, List.class, new Function<String,List>() {


Mime
View raw message