You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ri...@apache.org on 2014/05/30 15:25:12 UTC
[1/2] git commit: attributeWhenReady defaults to abort if entity
on-fire
Repository: incubator-brooklyn
Updated Branches:
refs/heads/master 9237ba4b3 -> 25b41f202
attributeWhenReady defaults to abort if entity on-fire
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/39ea2d95
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/39ea2d95
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/39ea2d95
Branch: refs/heads/master
Commit: 39ea2d957366abca11a507b8e6dab841fd29c804
Parents: 3dfcd6f
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 29 20:18:15 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Thu May 29 20:18:15 2014 +0100
----------------------------------------------------------------------
.../event/basic/DependentConfiguration.java | 10 ++++++-
.../basic/DependentConfigurationTest.java | 31 ++++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/39ea2d95/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java b/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
index dcedab5..ceac653 100644
--- a/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
+++ b/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
@@ -20,9 +20,11 @@ import org.slf4j.LoggerFactory;
import brooklyn.config.ConfigKey;
import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Attributes;
import brooklyn.entity.basic.BrooklynTaskTags;
import brooklyn.entity.basic.EntityInternal;
import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.basic.Lifecycle;
import brooklyn.event.AttributeSensor;
import brooklyn.event.SensorEvent;
import brooklyn.event.SensorEventListener;
@@ -47,6 +49,7 @@ import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@@ -375,9 +378,14 @@ public class DependentConfiguration {
protected Function<?, ? extends V> postProcessFromMultiple;
protected List<AttributeAndSensorCondition<?>> abortConditions = Lists.newArrayList();
+ /**
+ * Will wait for the attribute on the given entity.
+ * If that entity report {@link Lifecycle#ON_FIRE} for its {@link Attributes#SERVICE_STATE} then it will abort.
+ */
public <T2> Builder<T2,T2> attributeWhenReady(Entity source, AttributeSensor<T2> sensor) {
this.source = checkNotNull(source, "source");
this.sensor = (AttributeSensor) checkNotNull(sensor, "sensor");
+ abortIf(source, Attributes.SERVICE_STATE, Predicates.equalTo(Lifecycle.ON_FIRE));
return (Builder<T2, T2>) this;
}
/** returns a task for parallel execution returning a list of values of the given sensor list on the given entity,
@@ -443,7 +451,7 @@ public class DependentConfiguration {
}
});
} else {
- // FIXME Do we really want to try to support the list-of-entities?
+ // TODO Do we really want to try to support the list-of-entities?
final Task<V> task = (Task<V>) new ParallelTask<Object>(Iterables.transform(multiSource, new Function<AttributeAndSensorCondition<?>, Task<T>>() {
@Override public Task<T> apply(AttributeAndSensorCondition<?> it) {
return (Task) builder().attributeWhenReady(it.source, it.sensor).readiness((Predicate)it.predicate).build();
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/39ea2d95/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java b/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
index 8585568..3169926 100644
--- a/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
@@ -175,6 +175,37 @@ public class DependentConfigurationTest {
}
@Test
+ public void testAttributeWhenReadyAbortsWhenOnfireByDefault() throws Exception {
+ final Task<String> t = submit(DependentConfiguration.builder()
+ .attributeWhenReady(entity, TestEntity.NAME)
+ .build());
+
+ entity.setAttribute(Attributes.SERVICE_STATE, Lifecycle.ON_FIRE);
+ try {
+ assertDoneEventually(t);
+ fail();
+ } catch (Exception e) {
+ if (!e.toString().contains("Aborted waiting for ready")) throw e;
+ }
+ }
+
+ @Test
+ public void testAttributeWhenReadyAbortsWhenAlreadyOnfireByDefault() throws Exception {
+ entity.setAttribute(Attributes.SERVICE_STATE, Lifecycle.ON_FIRE);
+
+ final Task<String> t = submit(DependentConfiguration.builder()
+ .attributeWhenReady(entity, TestEntity.NAME)
+ .build());
+
+ try {
+ assertDoneEventually(t);
+ fail();
+ } catch (Exception e) {
+ if (!e.toString().contains("Aborted waiting for ready")) throw e;
+ }
+ }
+
+ @Test
public void testListAttributeWhenReadyFromMultipleEntities() throws Exception {
final Task<List<String>> t = submit(DependentConfiguration.builder()
.attributeWhenReadyFromMultiple(ImmutableList.of(entity, entity2), TestEntity.NAME)
[2/2] git commit: Merge pull request #1429 from
aledsage/feature/attributeWhenReady-aborts-if-entityOnFire
Posted by ri...@apache.org.
Merge pull request #1429 from aledsage/feature/attributeWhenReady-aborts-if-entityOnFire
attributeWhenReady defaults to abort if entity on-fire
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/25b41f20
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/25b41f20
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/25b41f20
Branch: refs/heads/master
Commit: 25b41f20201808c36e6c35fbebaac0255cefdb5d
Parents: 9237ba4 39ea2d9
Author: Andrew Kennedy <gr...@apache.org>
Authored: Fri May 30 14:24:38 2014 +0100
Committer: Andrew Kennedy <gr...@apache.org>
Committed: Fri May 30 14:24:38 2014 +0100
----------------------------------------------------------------------
.../event/basic/DependentConfiguration.java | 10 ++++++-
.../basic/DependentConfigurationTest.java | 31 ++++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------