From: Tom Pantelis Date: Fri, 10 Jun 2016 02:25:05 +0000 (-0400) Subject: Add voting state to shard mbean FollowerInfo X-Git-Tag: release/boron~132 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=61e85d54cfcd70053993f910092eba1ab3fcc850;hp=a740ebb4e83668a2a41e9facb4632d8379258df7 Add voting state to shard mbean FollowerInfo 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 --- diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java index b207e0b725..933fde98b9 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java @@ -411,8 +411,8 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor { Map peerAddresses = new HashMap<>(); Map 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); diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FollowerInfo.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FollowerInfo.java index 5d2c56a117..cb991e14ed 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FollowerInfo.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FollowerInfo.java @@ -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; + } }