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 2015/12/17 13:08:43 UTC

[1/3] incubator-brooklyn git commit: Add timeout to attributeWhenReady if entity is in destructive state

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 08b814117 -> 1c80fb4d1


Add timeout to attributeWhenReady if entity is in destructive state


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

Branch: refs/heads/master
Commit: a6c2ae960381f05678f2508a91a6fe8f8a2627d5
Parents: 89440c3
Author: Mike Zaccardo <mi...@cloudsoftcorp.com>
Authored: Fri Dec 4 19:27:03 2015 -0800
Committer: Mike Zaccardo <mi...@cloudsoftcorp.com>
Committed: Fri Dec 4 19:27:03 2015 -0800

----------------------------------------------------------------------
 .../core/sensor/DependentConfiguration.java       | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a6c2ae96/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java b/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
index 6c251a7..98cedb0 100644
--- a/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
@@ -635,10 +635,12 @@ public class DependentConfiguration {
     public static class ProtoBuilder {
         /**
          * Will wait for the attribute on the given entity.
-         * If that entity reports {@link Lifecycle#ON_FIRE} for its {@link Attributes#SERVICE_STATE} then it will abort. 
+         * If that entity reports {@link Lifecycle#ON_FIRE} for its {@link Attributes#SERVICE_STATE} then it will abort.
+         * If that entity reports {@link Lifecycle#STOPPING}, {@link Lifecycle#STOPPED}, or {@link Lifecycle#DESTROYED}
+         * then it will timeout after 1 minute.
          */
         public <T2> Builder<T2,T2> attributeWhenReady(Entity source, AttributeSensor<T2> sensor) {
-            return new Builder<T2,T2>(source, sensor).abortIfOnFire();
+            return new Builder<T2,T2>(source, sensor).abortIfOnFireOrTimeoutIfNecessary();
         }
 
         /**
@@ -722,6 +724,13 @@ public class DependentConfiguration {
             abortIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.ON_FIRE));
             return this;
         }
+        public Builder<T,V> abortIfOnFireOrTimeoutIfNecessary() {
+            abortIfOnFire();
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.STOPPING), Duration.ONE_MINUTE);
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.STOPPED), Duration.ONE_MINUTE);
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.DESTROYED), Duration.ONE_MINUTE);
+            return this;
+        }
         public Builder<T,V> blockingDetails(String val) {
             blockingDetails = val;
             return this;
@@ -731,6 +740,11 @@ public class DependentConfiguration {
             timeout = val;
             return this;
         }
+        /** specifies the supplied timeout if the condition is met */
+        public <T2> Builder<T,V> timeoutIf(Entity source, AttributeSensor<T2> sensor, Predicate<? super T2> predicate, Duration val) {
+            if (predicate.apply(source.sensors().get(sensor))) timeout(val);
+            return this;
+        }
         public Builder<T,V> onTimeoutReturn(V val) {
             onTimeout = Maybe.of(val);
             return this;


[2/3] incubator-brooklyn git commit: This closes #1090

Posted by he...@apache.org.
This closes #1090


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

Branch: refs/heads/master
Commit: 9df3f2b8e4e540242267309dcb83cedea984b38a
Parents: 08b8141 a6c2ae9
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Dec 17 12:03:36 2015 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Dec 17 12:03:36 2015 +0000

----------------------------------------------------------------------
 .../core/sensor/DependentConfiguration.java       | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[3/3] incubator-brooklyn git commit: tidy of dependent configuration methods

Posted by he...@apache.org.
tidy of dependent configuration methods


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

Branch: refs/heads/master
Commit: 1c80fb4d1a8dc06138246d2558c30c6dff41db68
Parents: 9df3f2b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Dec 17 12:08:17 2015 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Dec 17 12:08:17 2015 +0000

----------------------------------------------------------------------
 .../core/sensor/DependentConfiguration.java     | 23 +++++++++++---------
 1 file changed, 13 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1c80fb4d/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java b/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
index 98cedb0..ac4bef5 100644
--- a/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/sensor/DependentConfiguration.java
@@ -35,7 +35,6 @@ import java.util.concurrent.TimeUnit;
 import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.api.mgmt.ExecutionContext;
 import org.apache.brooklyn.api.mgmt.SubscriptionHandle;
 import org.apache.brooklyn.api.mgmt.Task;
@@ -504,6 +503,7 @@ public class DependentConfiguration {
         );
     }
 
+    @SuppressWarnings("unchecked")
     private static List<TaskAdaptable<Object>> getTaskAdaptable(Object... args){
         List<TaskAdaptable<Object>> taskArgs = Lists.newArrayList();
         for (Object arg: args) {
@@ -634,13 +634,13 @@ public class DependentConfiguration {
     @Beta
     public static class ProtoBuilder {
         /**
-         * Will wait for the attribute on the given entity.
-         * If that entity reports {@link Lifecycle#ON_FIRE} for its {@link Attributes#SERVICE_STATE} then it will abort.
-         * If that entity reports {@link Lifecycle#STOPPING}, {@link Lifecycle#STOPPED}, or {@link Lifecycle#DESTROYED}
+         * Will wait for the attribute on the given entity, with default behaviour:
+         * If that entity reports {@link Lifecycle#ON_FIRE} for its {@link Attributes#SERVICE_STATE} then it will abort;
+         * If that entity is stopping or destroyed (see {@link Builder#timeoutIfStoppingOrDestroyed(Duration)}),
          * then it will timeout after 1 minute.
          */
         public <T2> Builder<T2,T2> attributeWhenReady(Entity source, AttributeSensor<T2> sensor) {
-            return new Builder<T2,T2>(source, sensor).abortIfOnFireOrTimeoutIfNecessary();
+            return new Builder<T2,T2>(source, sensor).abortIfOnFire().timeoutIfStoppingOrDestroyed(Duration.ONE_MINUTE);
         }
 
         /**
@@ -720,15 +720,18 @@ public class DependentConfiguration {
             abortSensorConditions.add(new AttributeAndSensorCondition<T2>(source, sensor, predicate));
             return this;
         }
+        /** Causes the depender to abort immediately if {@link Attributes#SERVICE_STATE_ACTUAL}
+         * is {@link Lifecycle#ON_FIRE}. */
         public Builder<T,V> abortIfOnFire() {
             abortIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.ON_FIRE));
             return this;
         }
-        public Builder<T,V> abortIfOnFireOrTimeoutIfNecessary() {
-            abortIfOnFire();
-            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.STOPPING), Duration.ONE_MINUTE);
-            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.STOPPED), Duration.ONE_MINUTE);
-            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.DESTROYED), Duration.ONE_MINUTE);
+        /** Causes the depender to timeout after the given time if {@link Attributes#SERVICE_STATE_ACTUAL}
+         * is one of {@link Lifecycle#STOPPING}, {@link Lifecycle#STOPPED}, or {@link Lifecycle#DESTROYED}. */
+        public Builder<T,V> timeoutIfStoppingOrDestroyed(Duration time) {
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.STOPPING), time);
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.STOPPED), time);
+            timeoutIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.DESTROYED), time);
             return this;
         }
         public Builder<T,V> blockingDetails(String val) {