brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [04/11] git commit: set uniqueTags for many enrichers and policies
Date Wed, 06 Aug 2014 21:16:56 GMT
set uniqueTags for many enrichers and policies


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

Branch: refs/heads/master
Commit: 427d4e1a6889527ce37df94160ebbeaf5227d51b
Parents: 72b52e1
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Sat Aug 2 11:44:49 2014 -0400
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Aug 5 10:40:46 2014 -0400

----------------------------------------------------------------------
 .../main/java/brooklyn/enricher/Enrichers.java  | 23 ++++++++++++++++++++
 .../basic/SensorTransformingEnricher.java       | 12 +++++-----
 .../group/AbstractMembershipTrackingPolicy.java |  4 ++++
 .../brooklyn/enricher/HttpLatencyDetector.java  | 11 ++++++++--
 .../brooklyn/enricher/RollingMeanEnricher.java  |  3 +++
 .../enricher/RollingTimeWindowMeanEnricher.java |  4 ++++
 .../enricher/TimeFractionDeltaEnricher.java     |  5 +++++
 .../enricher/TimeWeightedDeltaEnricher.java     |  5 +++++
 .../java/brooklyn/util/guava/TypeTokens.java    |  6 +++++
 9 files changed, 65 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/427d4e1a/core/src/main/java/brooklyn/enricher/Enrichers.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/enricher/Enrichers.java b/core/src/main/java/brooklyn/enricher/Enrichers.java
index e6f903e..dab423c 100644
--- a/core/src/main/java/brooklyn/enricher/Enrichers.java
+++ b/core/src/main/java/brooklyn/enricher/Enrichers.java
@@ -36,11 +36,13 @@ import brooklyn.event.Sensor;
 import brooklyn.event.SensorEvent;
 import brooklyn.policy.Enricher;
 import brooklyn.policy.EnricherSpec;
+import brooklyn.util.collections.MutableList;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.flags.TypeCoercions;
 import brooklyn.util.text.Strings;
 
 import com.google.common.base.Function;
+import com.google.common.base.Joiner;
 import com.google.common.base.Objects;
 import com.google.common.base.Predicate;
 import com.google.common.collect.ImmutableList;
@@ -190,6 +192,7 @@ public class Enrichers {
             }
             // FIXME excludingBlank; use valueFilter? exclude means ignored entirely or substituted
for defaultMemberValue?
             return EnricherSpec.create(Aggregator.class)
+                    .uniqueTag("aggregator:"+publishing)
                     .configure(MutableMap.builder()
                             .putIfNotNull(Aggregator.PRODUCER, fromEntity)
                             .put(Aggregator.TARGET_SENSOR, publishing)
@@ -288,6 +291,7 @@ public class Enrichers {
         }
         public EnricherSpec<?> build() {
             return EnricherSpec.create(Combiner.class)
+                    .uniqueTag("combiner:"+publishing)
                     .configure(MutableMap.builder()
                             .putIfNotNull(Combiner.PRODUCER, fromEntity)
                             .put(Combiner.TARGET_SENSOR, publishing)
@@ -347,6 +351,7 @@ public class Enrichers {
         }
         public EnricherSpec<?> build() {
             return EnricherSpec.create(Transformer.class)
+                    .uniqueTag("transformer:"+publishing)
                     .configure(MutableMap.builder()
                             .putIfNotNull(Transformer.PRODUCER, fromEntity)
                             .put(Transformer.TARGET_SENSOR, publishing)
@@ -399,7 +404,25 @@ public class Enrichers {
             return self();
         }
         public EnricherSpec<? extends Enricher> build() {
+            List<String> summary = MutableList.of();
+            if (propagating!=null) {
+                for (Map.Entry<? extends Sensor<?>, ? extends Sensor<?>>
entry: propagating.entrySet()) {
+                    if (entry.getKey().getName().equals(entry.getValue().getName()))
+                        summary.add(entry.getKey().getName());
+                    else
+                        summary.add(entry.getKey().getName()+"->"+entry.getValue().getName());
+                }
+            }
+            if (Boolean.TRUE.equals(propagatingAll))
+                summary.add("ALL");
+            if (propagatingAllBut!=null && !Iterables.isEmpty(propagatingAllBut))
{
+                List<String> allBut = MutableList.of();
+                for (Sensor<?> s: propagatingAllBut) allBut.add(s.getName());
+                summary.add("ALL_BUT:"+Joiner.on(",").join(allBut));
+            }
+            
             return EnricherSpec.create(Propagator.class)
+                    .uniqueTag("propagating["+fromEntity.getId()+":"+Joiner.on(",").join(summary)+"]")
                     .configure(MutableMap.builder()
                             .putIfNotNull(Propagator.PRODUCER, fromEntity)
                             .putIfNotNull(Propagator.SENSOR_MAPPING, propagating)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/427d4e1a/core/src/main/java/brooklyn/enricher/basic/SensorTransformingEnricher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/enricher/basic/SensorTransformingEnricher.java b/core/src/main/java/brooklyn/enricher/basic/SensorTransformingEnricher.java
index 806b5a7..314e833 100644
--- a/core/src/main/java/brooklyn/enricher/basic/SensorTransformingEnricher.java
+++ b/core/src/main/java/brooklyn/enricher/basic/SensorTransformingEnricher.java
@@ -24,6 +24,8 @@ import brooklyn.event.AttributeSensor;
 import brooklyn.event.Sensor;
 import brooklyn.event.SensorEvent;
 import brooklyn.util.GroovyJavaMethods;
+import brooklyn.util.javalang.JavaClassNames;
+import brooklyn.util.time.Duration;
 
 import com.google.common.base.Function;
 
@@ -38,21 +40,19 @@ public class SensorTransformingEnricher<T,U> extends AbstractTypeTransformingEnr
     public SensorTransformingEnricher(Entity producer, Sensor<T> source, Sensor<U>
target, Function<? super T, ? extends U> transformation) {
         super(producer, source, target);
         this.transformation = transformation;
+        this.uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"*->"+target.getName();;
     }
 
     public SensorTransformingEnricher(Entity producer, Sensor<T> source, Sensor<U>
target, Closure transformation) {
-        super(producer, source, target);
-        this.transformation = GroovyJavaMethods.functionFromClosure(transformation);
+        this(producer, source, target, GroovyJavaMethods.functionFromClosure(transformation));
     }
 
     public SensorTransformingEnricher(Sensor<T> source, Sensor<U> target, Function<T,U>
transformation) {
-        super(null, source, target);
-        this.transformation = transformation;
+        this(null, source, target, transformation);
     }
 
     public SensorTransformingEnricher(Sensor<T> source, Sensor<U> target, Closure
transformation) {
-        super(null, source, target);
-        this.transformation = GroovyJavaMethods.functionFromClosure(transformation);
+        this(null, source, target, GroovyJavaMethods.functionFromClosure(transformation));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/427d4e1a/core/src/main/java/brooklyn/entity/group/AbstractMembershipTrackingPolicy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/group/AbstractMembershipTrackingPolicy.java
b/core/src/main/java/brooklyn/entity/group/AbstractMembershipTrackingPolicy.java
index e3f0dce..12100cd 100644
--- a/core/src/main/java/brooklyn/entity/group/AbstractMembershipTrackingPolicy.java
+++ b/core/src/main/java/brooklyn/entity/group/AbstractMembershipTrackingPolicy.java
@@ -38,6 +38,7 @@ import brooklyn.event.SensorEvent;
 import brooklyn.event.SensorEventListener;
 import brooklyn.policy.basic.AbstractPolicy;
 import brooklyn.util.collections.MutableMap;
+import brooklyn.util.javalang.JavaClassNames;
 
 import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
@@ -85,6 +86,9 @@ public abstract class AbstractMembershipTrackingPolicy extends AbstractPolicy
{
         super.setEntity(entity);
         Group group = getGroup();
         if (group != null) {
+            if (uniqueTag==null) {
+                uniqueTag = JavaClassNames.simpleClassName(this)+":"+group;
+            }
             subscribeToGroup(group);
         } else {
             LOG.warn("Deprecated use of "+AbstractMembershipTrackingPolicy.class.getSimpleName()+";
group should be set as config");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/427d4e1a/policy/src/main/java/brooklyn/enricher/HttpLatencyDetector.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/brooklyn/enricher/HttpLatencyDetector.java b/policy/src/main/java/brooklyn/enricher/HttpLatencyDetector.java
index 7645980..bd1dd00 100644
--- a/policy/src/main/java/brooklyn/enricher/HttpLatencyDetector.java
+++ b/policy/src/main/java/brooklyn/enricher/HttpLatencyDetector.java
@@ -44,8 +44,10 @@ import brooklyn.event.feed.http.HttpPollConfig;
 import brooklyn.event.feed.http.HttpValueFunctions;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.flags.SetFromFlag;
+import brooklyn.util.guava.TypeTokens;
 import brooklyn.util.javalang.AtomicReferences;
 import brooklyn.util.javalang.Boxing;
+import brooklyn.util.javalang.JavaClassNames;
 import brooklyn.util.math.MathFunctions;
 import brooklyn.util.net.Urls;
 import brooklyn.util.text.StringFunctions;
@@ -72,12 +74,13 @@ public class HttpLatencyDetector extends AbstractEnricher {
     @SetFromFlag("url")
     public static final ConfigKey<String> URL = ConfigKeys.newStringConfigKey("latencyDetector.url");
     
+    @SuppressWarnings("serial")
     @SetFromFlag("urlSensor")
     public static final ConfigKey<AttributeSensor<String>> URL_SENSOR = ConfigKeys.newConfigKey(new
TypeToken<AttributeSensor<String>>() {}, "latencyDetector.urlSensor");
 
     @SetFromFlag("urlPostProcessing")
     public static final ConfigKey<Function<String,String>> URL_POST_PROCESSING
= ConfigKeys.newConfigKey(
-            new TypeToken<Function<String,String>>() {}, 
+            TypeTokens.functionOf(String.class, String.class), 
             "latencyDetector.urlPostProcessing",
             "Function applied to the urlSensor value, to determine the URL to use");
 
@@ -103,7 +106,7 @@ public class HttpLatencyDetector extends AbstractEnricher {
     public HttpLatencyDetector() { // for rebinding, and for EnricherSpec usage
     }
     
-    protected HttpLatencyDetector(Map flags) {
+    protected HttpLatencyDetector(Map<?,?> flags) {
         super(flags);
     }
     
@@ -139,6 +142,10 @@ public class HttpLatencyDetector extends AbstractEnricher {
                         .setOnException(null))
                 .suspended()
                 .build();
+        
+        if (getUniqueTag()==null) 
+            uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+
+                (getConfig(URL)!=null ? getConfig(URL) : getConfig(URL_SENSOR));
     }
 
     protected void startSubscriptions(EntityLocal entity) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/427d4e1a/policy/src/main/java/brooklyn/enricher/RollingMeanEnricher.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/brooklyn/enricher/RollingMeanEnricher.java b/policy/src/main/java/brooklyn/enricher/RollingMeanEnricher.java
index 8f5452c..49e1241 100644
--- a/policy/src/main/java/brooklyn/enricher/RollingMeanEnricher.java
+++ b/policy/src/main/java/brooklyn/enricher/RollingMeanEnricher.java
@@ -25,6 +25,7 @@ import brooklyn.entity.Entity;
 import brooklyn.event.AttributeSensor;
 import brooklyn.event.SensorEvent;
 import brooklyn.util.flags.SetFromFlag;
+import brooklyn.util.javalang.JavaClassNames;
 
 
 /**
@@ -44,6 +45,8 @@ public class RollingMeanEnricher<T extends Number> extends AbstractTypeTransform
             int windowSize) {
         super(producer, source, target);
         this.windowSize = windowSize;
+        if (source!=null && target!=null)
+            this.uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"->"+target.getName();
     }
     
     /** @returns null when no data has been received or windowSize is 0 */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/427d4e1a/policy/src/main/java/brooklyn/enricher/RollingTimeWindowMeanEnricher.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/brooklyn/enricher/RollingTimeWindowMeanEnricher.java b/policy/src/main/java/brooklyn/enricher/RollingTimeWindowMeanEnricher.java
index 2485abc..b196efa 100644
--- a/policy/src/main/java/brooklyn/enricher/RollingTimeWindowMeanEnricher.java
+++ b/policy/src/main/java/brooklyn/enricher/RollingTimeWindowMeanEnricher.java
@@ -29,6 +29,7 @@ import brooklyn.event.AttributeSensor;
 import brooklyn.event.Sensor;
 import brooklyn.event.SensorEvent;
 import brooklyn.util.flags.SetFromFlag;
+import brooklyn.util.javalang.JavaClassNames;
 import brooklyn.util.time.Duration;
 
 /**
@@ -79,6 +80,9 @@ public class RollingTimeWindowMeanEnricher<T extends Number> extends
AbstractTyp
         AttributeSensor<Double> target, Duration timePeriod) {
         super(producer, source, target);
         this.timePeriod = Preconditions.checkNotNull(timePeriod, "timePeriod");
+        
+        if (source!=null && target!=null)
+            this.uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"/"+timePeriod+"->"+target.getName();
     }
 
     /** @deprecated since 0.6.0 use Duration parameter rather than long with millis */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/427d4e1a/policy/src/main/java/brooklyn/enricher/TimeFractionDeltaEnricher.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/brooklyn/enricher/TimeFractionDeltaEnricher.java b/policy/src/main/java/brooklyn/enricher/TimeFractionDeltaEnricher.java
index f6af440..253cdc6 100644
--- a/policy/src/main/java/brooklyn/enricher/TimeFractionDeltaEnricher.java
+++ b/policy/src/main/java/brooklyn/enricher/TimeFractionDeltaEnricher.java
@@ -29,6 +29,8 @@ import brooklyn.event.AttributeSensor;
 import brooklyn.event.Sensor;
 import brooklyn.event.SensorEvent;
 import brooklyn.util.flags.SetFromFlag;
+import brooklyn.util.javalang.JavaClassNames;
+import brooklyn.util.time.Duration;
 
 /**
  * Converts an absolute measure of time into a fraction of time, based on the delta between
consecutive values 
@@ -58,6 +60,9 @@ public class TimeFractionDeltaEnricher<T extends Number> extends AbstractTypeTra
     public TimeFractionDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double>
target, long nanosPerOrigUnit) {
         super(producer, source, target);
         this.nanosPerOrigUnit = nanosPerOrigUnit;
+        
+        if (source!=null && target!=null)
+            this.uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"*"+Duration.nanos(nanosPerOrigUnit)+"->"+target.getName();
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/427d4e1a/policy/src/main/java/brooklyn/enricher/TimeWeightedDeltaEnricher.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/brooklyn/enricher/TimeWeightedDeltaEnricher.java b/policy/src/main/java/brooklyn/enricher/TimeWeightedDeltaEnricher.java
index 73d1389..d344dd4 100644
--- a/policy/src/main/java/brooklyn/enricher/TimeWeightedDeltaEnricher.java
+++ b/policy/src/main/java/brooklyn/enricher/TimeWeightedDeltaEnricher.java
@@ -30,6 +30,8 @@ import brooklyn.event.Sensor;
 import brooklyn.event.SensorEvent;
 import brooklyn.util.GroovyJavaMethods;
 import brooklyn.util.flags.SetFromFlag;
+import brooklyn.util.javalang.JavaClassNames;
+import brooklyn.util.time.Duration;
 
 import com.google.common.base.Function;
 import com.google.common.base.Functions;
@@ -73,6 +75,9 @@ public class TimeWeightedDeltaEnricher<T extends Number> extends AbstractTypeTra
         super(producer, source, target);
         this.unitMillis = unitMillis;
         this.postProcessor = postProcessor;
+        
+        if (source!=null && target!=null)
+            this.uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"/"+Duration.millis(unitMillis)+"->"+target.getName();
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/427d4e1a/utils/common/src/main/java/brooklyn/util/guava/TypeTokens.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/guava/TypeTokens.java b/utils/common/src/main/java/brooklyn/util/guava/TypeTokens.java
index d16d2df..ee7099b 100644
--- a/utils/common/src/main/java/brooklyn/util/guava/TypeTokens.java
+++ b/utils/common/src/main/java/brooklyn/util/guava/TypeTokens.java
@@ -24,6 +24,7 @@ import java.util.Set;
 
 import javax.annotation.Nullable;
 
+import com.google.common.base.Function;
 import com.google.common.reflect.TypeToken;
 
 public class TypeTokens {
@@ -87,5 +88,10 @@ public class TypeTokens {
     public static <T> TypeToken<List<T>> listOf(Class<T> type) {
         return (TypeToken) TypeToken.of(List.class);
     }
+
+    @SuppressWarnings("serial")
+    public static <I,O> TypeToken<Function<I,O>> functionOf(Class<I>
input, Class<O> output) {
+        return new TypeToken<Function<I,O>>() {};
+    }
     
 }


Mime
View raw message