brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [6/8] git commit: Change EntityAdjuncts.findWithUniqueTag to tryFindWithUniqueTag
Date Sun, 07 Sep 2014 21:28:55 GMT
Change EntityAdjuncts.findWithUniqueTag to tryFindWithUniqueTag

- Make it consistent with guava naming


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

Branch: refs/heads/master
Commit: 3d231e8dcc7fb6b471331171a3aa2cd45d7385de
Parents: 0fd9477
Author: Aled Sage <aled.sage@gmail.com>
Authored: Fri Sep 5 20:02:12 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Fri Sep 5 21:52:51 2014 +0100

----------------------------------------------------------------------
 core/src/main/java/brooklyn/entity/basic/EntityAdjuncts.java  | 7 ++++---
 .../main/java/brooklyn/entity/basic/ServiceStateLogic.java    | 7 ++++---
 .../java/brooklyn/entity/basic/ServiceStateLogicTest.java     | 4 ++--
 3 files changed, 10 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3d231e8d/core/src/main/java/brooklyn/entity/basic/EntityAdjuncts.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/EntityAdjuncts.java b/core/src/main/java/brooklyn/entity/basic/EntityAdjuncts.java
index ab1d003..242a61d 100644
--- a/core/src/main/java/brooklyn/entity/basic/EntityAdjuncts.java
+++ b/core/src/main/java/brooklyn/entity/basic/EntityAdjuncts.java
@@ -28,6 +28,7 @@ import brooklyn.entity.basic.ServiceStateLogic.ServiceNotUpLogic;
 import brooklyn.policy.Enricher;
 import brooklyn.policy.EntityAdjunct;
 import brooklyn.util.collections.MutableList;
+import brooklyn.util.guava.Maybe;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
@@ -37,12 +38,12 @@ import com.google.common.collect.ImmutableList;
  */
 public class EntityAdjuncts {
 
-    public static <T extends EntityAdjunct> T findWithUniqueTag(Iterable<T> adjuncts,
Object tag) {
+    public static <T extends EntityAdjunct> Maybe<T> tryFindWithUniqueTag(Iterable<T>
adjuncts, Object tag) {
         Preconditions.checkNotNull(tag, "tag");
         for (T adjunct: adjuncts)
             if (tag.equals(adjunct.getUniqueTag())) 
-                return adjunct;
-        return null;
+                return Maybe.of(adjunct);
+        return Maybe.absent("Not found with tag "+tag);
     }
     
     public static final List<String> SYSTEM_ENRICHER_UNIQUE_TAGS = ImmutableList.of(

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3d231e8d/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java b/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
index 4597230..fd524ec 100644
--- a/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
+++ b/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
@@ -50,6 +50,7 @@ import brooklyn.util.collections.MutableList;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.collections.MutableSet;
 import brooklyn.util.guava.Functionals;
+import brooklyn.util.guava.Maybe;
 import brooklyn.util.text.Strings;
 
 import com.google.common.base.Function;
@@ -115,9 +116,9 @@ public class ServiceStateLogic {
     public static void setExpectedState(Entity entity, Lifecycle state) {
         ((EntityInternal)entity).setAttribute(Attributes.SERVICE_STATE_EXPECTED, new Lifecycle.Transition(state,
new Date()));
         
-        Enricher enricher = EntityAdjuncts.findWithUniqueTag(entity.getEnrichers(), ComputeServiceState.DEFAULT_ENRICHER_UNIQUE_TAG);
-        if (enricher instanceof ComputeServiceState) {
-            ((ComputeServiceState)enricher).onEvent(null);
+        Maybe<Enricher> enricher = EntityAdjuncts.tryFindWithUniqueTag(entity.getEnrichers(),
ComputeServiceState.DEFAULT_ENRICHER_UNIQUE_TAG);
+        if (enricher.isPresent() && enricher.get() instanceof ComputeServiceState)
{
+            ((ComputeServiceState)enricher.get()).onEvent(null);
         }
     }
     public static Lifecycle getExpectedState(Entity entity) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3d231e8d/core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java b/core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java
index ca5d8c1..bd61031 100644
--- a/core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/ServiceStateLogicTest.java
@@ -36,6 +36,7 @@ import brooklyn.policy.Enricher;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.guava.Maybe;
 import brooklyn.util.time.Duration;
 
 import com.google.common.collect.ImmutableList;
@@ -180,8 +181,7 @@ public class ServiceStateLogicTest extends BrooklynAppUnitTestSupport
{
         assertAttributeEquals(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
         // if we change the state quorum check for the app to be "all are healthy and at
least one running" *then* it shows stopped
         // (normally this would be done in `initEnrichers` of course)
-        Enricher appChildrenBasedEnricher = EntityAdjuncts.findWithUniqueTag(app.getEnrichers(),
ComputeServiceIndicatorsFromChildrenAndMembers.DEFAULT_UNIQUE_TAG);
-        Assert.assertNotNull(appChildrenBasedEnricher, "Expected enricher not found");
+        Enricher appChildrenBasedEnricher = EntityAdjuncts.tryFindWithUniqueTag(app.getEnrichers(),
ComputeServiceIndicatorsFromChildrenAndMembers.DEFAULT_UNIQUE_TAG).get();
         appChildrenBasedEnricher.setConfig(ComputeServiceIndicatorsFromChildrenAndMembers.RUNNING_QUORUM_CHECK,
QuorumChecks.allAndAtLeastOne());
         assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
         


Mime
View raw message