Add voting state to shard mbean FollowerInfo 73/40173/2
authorTom Pantelis <tpanteli@brocade.com>
Fri, 10 Jun 2016 02:25:05 +0000 (22:25 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 14 Jun 2016 02:27:50 +0000 (02:27 +0000)
The shard mbean displays the peer voting states map but it's also useful
to see the voting state in the leader's FollowerInfo.

Also fixed an NPE when JMX accesses the peerAddresses when a peer's
address is null. We use guava's Map.Joiner to output the map but it
throws an NPE for a null entry vlaue. I chnaged RaftActor to put "" in
the map if null.

Change-Id: Ibe9f8ec1bb01231c1aa960e104da58c0ce72d9b6
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FollowerInfo.java

index b207e0b72547158b092156f1cf324b13237e7037..933fde98b9b432f60b545541d0b05cc03ef8da0d 100644 (file)
@@ -411,8 +411,8 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
         Map<String, String> peerAddresses = new HashMap<>();
         Map<String, Boolean> peerVotingStates = new HashMap<>();
         for(PeerInfo info: context.getPeers()) {
-            peerVotingStates.put(info.getId(), info.getVotingState() != VotingState.NON_VOTING);
-            peerAddresses.put(info.getId(), info.getAddress());
+            peerVotingStates.put(info.getId(), info.isVoting());
+            peerAddresses.put(info.getId(), info.getAddress() != null ? info.getAddress() : "");
         }
 
         final RaftActorBehavior currentBehavior = context.getCurrentBehavior();
@@ -449,7 +449,8 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
             for(String id: followerIds) {
                 final FollowerLogInformation info = leader.getFollower(id);
                 followerInfoList.add(new FollowerInfo(id, info.getNextIndex(), info.getMatchIndex(),
-                        info.isFollowerActive(), DurationFormatUtils.formatDurationHMS(info.timeSinceLastActivity())));
+                        info.isFollowerActive(), DurationFormatUtils.formatDurationHMS(info.timeSinceLastActivity()),
+                        context.getPeerInfo(info.getId()).isVoting()));
             }
 
             builder.followerInfoList(followerInfoList);
index 5d2c56a117890b64e65f5feaf71138b8bc93922c..cb991e14ed8c7640a04d31712d5a0bebee714770 100644 (file)
@@ -20,14 +20,17 @@ public class FollowerInfo {
     private final long matchIndex;
     private final boolean isActive;
     private final String timeSinceLastActivity;
+    private final boolean isVoting;
 
-    @ConstructorProperties({"id","nextIndex", "matchIndex", "isActive", "timeSinceLastActivity"})
-    public FollowerInfo(String id, long nextIndex, long matchIndex, boolean isActive, String timeSinceLastActivity) {
+    @ConstructorProperties({"id","nextIndex", "matchIndex", "isActive", "timeSinceLastActivity", "isVoting"})
+    public FollowerInfo(String id, long nextIndex, long matchIndex, boolean isActive, String timeSinceLastActivity,
+            boolean isVoting) {
         this.id = id;
         this.nextIndex = nextIndex;
         this.matchIndex = matchIndex;
         this.isActive = isActive;
         this.timeSinceLastActivity = timeSinceLastActivity;
+        this.isVoting = isVoting;
     }
 
     public String getId() {
@@ -49,4 +52,8 @@ public class FollowerInfo {
     public String getTimeSinceLastActivity() {
         return timeSinceLastActivity;
     }
+
+    public boolean isVoting() {
+        return isVoting;
+    }
 }