Search in sources :

Example 1 with FollowerInfo

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());
}
Also used : HashMap(java.util.HashMap) RaftActorBehavior(org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior) AbstractRaftActorBehavior(org.opendaylight.controller.cluster.raft.behaviors.AbstractRaftActorBehavior) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) OnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState) FollowerInfo(org.opendaylight.controller.cluster.raft.client.messages.FollowerInfo) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) AbstractLeader(org.opendaylight.controller.cluster.raft.behaviors.AbstractLeader)

Aggregations

HashMap (java.util.HashMap)1 AbstractLeader (org.opendaylight.controller.cluster.raft.behaviors.AbstractLeader)1 AbstractRaftActorBehavior (org.opendaylight.controller.cluster.raft.behaviors.AbstractRaftActorBehavior)1 RaftActorBehavior (org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior)1 FollowerInfo (org.opendaylight.controller.cluster.raft.client.messages.FollowerInfo)1 GetOnDemandRaftState (org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState)1 OnDemandRaftState (org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState)1 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)1