Turn SendHeartBeat into a singleton
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / RaftActorServerConfigurationSupport.java
index 3db0316dd11b02816975d3b15c971e6553230f2c..db9088ebae7b78477f8a11ede661a49748dcf8d4 100644 (file)
@@ -78,7 +78,10 @@ class RaftActorServerConfigurationSupport {
     private void onRemoveServer(RemoveServer removeServer, ActorRef sender) {
         LOG.debug("{}: onRemoveServer: {}, state: {}", raftContext.getId(), removeServer, currentOperationState);
         boolean isSelf = removeServer.getServerId().equals(raftActor.getId());
-        if(!isSelf && !raftContext.getPeerIds().contains(removeServer.getServerId())) {
+        if(isSelf && !raftContext.hasFollowers()) {
+            sender.tell(new RemoveServerReply(ServerChangeStatus.NOT_SUPPORTED, raftActor.getLeaderId()),
+                    raftActor.getSelf());
+        } else if(!isSelf && !raftContext.getPeerIds().contains(removeServer.getServerId())) {
             sender.tell(new RemoveServerReply(ServerChangeStatus.DOES_NOT_EXIST, raftActor.getLeaderId()),
                     raftActor.getSelf());
         } else {
@@ -571,7 +574,10 @@ class RaftActorServerConfigurationSupport {
 
         @Override
         public void initiate() {
-            raftContext.removePeer(getRemoveServerContext().getOperation().getServerId());
+            String serverId = getRemoveServerContext().getOperation().getServerId();
+            raftContext.removePeer(serverId);
+            ((AbstractLeader)raftActor.getCurrentBehavior()).removeFollower(serverId);
+
             persistNewServerConfiguration(getRemoveServerContext());
         }
     }