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>
if(shardInformation != null && shardInformation.getActor() != null) {
shardInformation.getActor().tell(
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());
} else {
LOG.warn("Could not switch the behavior of shard {} to {} - shard is not yet available",
message.getShardName(), message.getNewState());
Preconditions.checkArgument(localShards.contains(shardName), shardName + " is not local");
Preconditions.checkArgument(ACCEPTABLE_STATES.contains(newState));
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){
}
public void setSyncStatus(boolean syncStatus){
package org.opendaylight.controller.cluster.datastore.messages;
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 shardName;
- private final String newState;
+ private final RaftState newState;
- 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);
- public String getNewState() {
+ public RaftState getNewState() {
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
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);
SwitchBehavior switchBehavior = MessageCollectorActor.expectFirstMatching(mockShardActor, SwitchBehavior.class);