use of org.opendaylight.controller.cluster.raft.client.messages.FollowerInfo in project controller by opendaylight.
the class RaftActor method onGetOnDemandRaftStats.
private void onGetOnDemandRaftStats() {
// Debugging message to retrieve raft stats.
Map<String, String> peerAddresses = new HashMap<>();
Map<String, Boolean> peerVotingStates = new HashMap<>();
for (PeerInfo info : context.getPeers()) {
peerVotingStates.put(info.getId(), info.isVoting());
peerAddresses.put(info.getId(), info.getAddress() != null ? info.getAddress() : "");
}
final RaftActorBehavior currentBehavior = context.getCurrentBehavior();
OnDemandRaftState.AbstractBuilder<?, ?> builder = newOnDemandRaftStateBuilder().commitIndex(context.getCommitIndex()).currentTerm(context.getTermInformation().getCurrentTerm()).inMemoryJournalDataSize(replicatedLog().dataSize()).inMemoryJournalLogSize(replicatedLog().size()).isSnapshotCaptureInitiated(context.getSnapshotManager().isCapturing()).lastApplied(context.getLastApplied()).lastIndex(replicatedLog().lastIndex()).lastTerm(replicatedLog().lastTerm()).leader(getLeaderId()).raftState(currentBehavior.state().toString()).replicatedToAllIndex(currentBehavior.getReplicatedToAllIndex()).snapshotIndex(replicatedLog().getSnapshotIndex()).snapshotTerm(replicatedLog().getSnapshotTerm()).votedFor(context.getTermInformation().getVotedFor()).isVoting(context.isVotingMember()).peerAddresses(peerAddresses).peerVotingStates(peerVotingStates).customRaftPolicyClassName(context.getConfigParams().getCustomRaftPolicyImplementationClass());
ReplicatedLogEntry lastLogEntry = replicatedLog().last();
if (lastLogEntry != null) {
builder.lastLogIndex(lastLogEntry.getIndex());
builder.lastLogTerm(lastLogEntry.getTerm());
}
if (getCurrentBehavior() instanceof AbstractLeader) {
AbstractLeader leader = (AbstractLeader) getCurrentBehavior();
Collection<String> followerIds = leader.getFollowerIds();
List<FollowerInfo> followerInfoList = Lists.newArrayListWithCapacity(followerIds.size());
for (String id : followerIds) {
final FollowerLogInformation info = leader.getFollower(id);
followerInfoList.add(new FollowerInfo(id, info.getNextIndex(), info.getMatchIndex(), info.isFollowerActive(), DurationFormatUtils.formatDurationHMS(TimeUnit.NANOSECONDS.toMillis(info.nanosSinceLastActivity())), context.getPeerInfo(info.getId()).isVoting()));
}
builder.followerInfoList(followerInfoList);
}
sender().tell(builder.build(), self());
}
Aggregations