Add voting state to shard mbean FollowerInfo 78/40178/2
authorTom Pantelis <tpanteli@brocade.com>
Fri, 10 Jun 2016 02:25:05 +0000 (22:25 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Wed, 15 Jun 2016 04:45:26 +0000 (04:45 +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: I1eb963808fd7878dfe1e4935f3ac06a579a3504e
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 4e376fe24685c06c5a00d7fe20ee8f6ebabe0304..548d4a71e37894541093dd896452dcdf05f541b2 100644 (file)
@@ -375,8 +375,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() : "");
         }
 
         OnDemandRaftState.Builder builder = OnDemandRaftState.builder()
@@ -412,7 +412,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;
+    }
 }