Make SwitchShardBehavior transport RaftState 57/36557/1
authorRobert Varga <rovarga@cisco.com>
Tue, 22 Mar 2016 14:38:14 +0000 (15:38 +0100)
committerRobert Varga <rovarga@cisco.com>
Tue, 22 Mar 2016 14:38:14 +0000 (15:38 +0100)
Instead of passing around generic strings (and potential failures from that),
make sure the message carries a proper raft state.

Change-Id: Id2c97773464d2a643f67a391247d58917c62d0c4
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shardmanager/ShardManagerInfo.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/SwitchShardBehavior.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java

index aec94ec..33b3810 100644 (file)
@@ -853,7 +853,7 @@ public class ShardManager extends AbstractUntypedPersistentActorWithMetering {
 
         if(shardInformation != null && shardInformation.getActor() != null) {
             shardInformation.getActor().tell(
-                    new SwitchBehavior(RaftState.valueOf(message.getNewState()), message.getTerm()), getSelf());
+                    new SwitchBehavior(message.getNewState(), message.getTerm()), getSelf());
         } else {
             LOG.warn("Could not switch the behavior of shard {} to {} - shard is not yet available",
                     message.getShardName(), message.getNewState());
index 7a02a46..394b14b 100644 (file)
@@ -87,7 +87,8 @@ public class ShardManagerInfo extends AbstractMXBean implements ShardManagerInfo
         Preconditions.checkArgument(localShards.contains(shardName), shardName + " is not local");
         Preconditions.checkArgument(ACCEPTABLE_STATES.contains(newState));
 
-        shardManager.getSelf().tell(new SwitchShardBehavior(shardName, newState, term), ActorRef.noSender());
+        shardManager.getSelf().tell(new SwitchShardBehavior(shardName, RaftState.valueOf(newState), term),
+            ActorRef.noSender());
     }
 
     public void setSyncStatus(boolean syncStatus){
index f1c2a07..4e9f9cb 100644 (file)
@@ -8,14 +8,17 @@
 
 package org.opendaylight.controller.cluster.datastore.messages;
 
-public class SwitchShardBehavior {
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.cluster.raft.RaftState;
+
+public final class SwitchShardBehavior {
     private final String shardName;
-    private final String newState;
+    private final RaftState newState;
     private final long term;
 
-    public SwitchShardBehavior(String shardName, String newState, long term) {
-        this.shardName = shardName;
-        this.newState = newState;
+    public SwitchShardBehavior(String shardName, RaftState newState, long term) {
+        this.shardName = Preconditions.checkNotNull(shardName);
+        this.newState = Preconditions.checkNotNull(newState);
         this.term = term;
     }
 
@@ -23,7 +26,7 @@ public class SwitchShardBehavior {
         return shardName;
     }
 
-    public String getNewState() {
+    public RaftState getNewState() {
         return newState;
     }
 
index bb80b2c..94ca074 100644 (file)
@@ -1171,7 +1171,7 @@ public class ShardManagerTest extends AbstractActorTest {
             shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
             shardManager.tell(new ActorInitialized(), mockShardActor);
 
-            shardManager.tell(new SwitchShardBehavior(mockShardName, "Leader", 1000), getRef());
+            shardManager.tell(new SwitchShardBehavior(mockShardName, RaftState.Leader, 1000), getRef());
 
             SwitchBehavior switchBehavior = MessageCollectorActor.expectFirstMatching(mockShardActor, SwitchBehavior.class);