From 891c8188ea961a3acf73d0be88fecf59d6ea6ce7 Mon Sep 17 00:00:00 2001 From: Mike Zaccardo Date: Wed, 5 Aug 2015 14:42:09 -0400 Subject: [PATCH] Fix logic to ensure that stop will be invoked on both the slaves and master --- .../entity/nosql/redis/RedisClusterImpl.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/redis/RedisClusterImpl.java b/software/nosql/src/main/java/brooklyn/entity/nosql/redis/RedisClusterImpl.java index 89ca43ceae..cca2254f97 100644 --- a/software/nosql/src/main/java/brooklyn/entity/nosql/redis/RedisClusterImpl.java +++ b/software/nosql/src/main/java/brooklyn/entity/nosql/redis/RedisClusterImpl.java @@ -19,6 +19,7 @@ package brooklyn.entity.nosql.redis; import java.util.Collection; +import java.util.List; import brooklyn.enricher.Enrichers; import brooklyn.entity.basic.AbstractEntity; @@ -32,16 +33,18 @@ import brooklyn.event.basic.Sensors; import brooklyn.location.Location; import brooklyn.util.collections.QuorumCheck.QuorumChecks; +import brooklyn.util.exceptions.CompoundRuntimeException; import brooklyn.util.exceptions.Exceptions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; public class RedisClusterImpl extends AbstractEntity implements RedisCluster { - private static AttributeSensor MASTER = Sensors.newSensor(RedisStore.class, "redis.master"); - private static AttributeSensor SLAVES = Sensors.newSensor(DynamicCluster.class, "redis.slaves"); + private static final AttributeSensor MASTER = Sensors.newSensor(RedisStore.class, "redis.master"); + private static final AttributeSensor SLAVES = Sensors.newSensor(DynamicCluster.class, "redis.slaves"); public RedisClusterImpl() { } @@ -119,8 +122,26 @@ public void stop() { } private void doStop() { - getSlaves().invoke(DynamicCluster.STOP, ImmutableMap.of()).getUnchecked(); - getMaster().invoke(RedisStore.STOP, ImmutableMap.of()).getUnchecked(); + StringBuilder message = new StringBuilder(); + List exceptions = Lists.newLinkedList(); + + try { + getSlaves().invoke(DynamicCluster.STOP, ImmutableMap.of()).getUnchecked(); + } catch (Exception e) { + message.append("Failed to stop Redis slaves"); + exceptions.add(e); + } + + try { + getMaster().invoke(RedisStore.STOP, ImmutableMap.of()).getUnchecked(); + } catch (Exception e) { + message.append((message.length() == 0) ? "Failed to stop Redis master" : " and master"); + exceptions.add(e); + } + + if (!exceptions.isEmpty()) { + throw new CompoundRuntimeException(message.toString(), exceptions); + } } @Override