Search in sources :

Example 1 with Cluster

use of akka.cluster.Cluster in project controller by opendaylight.

the class Follower method isLeaderAvailabilityKnown.

private boolean isLeaderAvailabilityKnown() {
    if (leaderId == null) {
        return false;
    }
    Optional<Cluster> cluster = context.getCluster();
    if (!cluster.isPresent()) {
        return false;
    }
    ActorSelection leaderActor = context.getPeerActorSelection(leaderId);
    if (leaderActor == null) {
        return false;
    }
    Address leaderAddress = leaderActor.anchorPath().address();
    CurrentClusterState state = cluster.get().state();
    Set<Member> unreachable = state.getUnreachable();
    log.debug("{}: Checking for leader {} in the cluster unreachable set {}", logName(), leaderAddress, unreachable);
    for (Member m : unreachable) {
        if (leaderAddress.equals(m.address())) {
            log.info("{}: Leader {} is unreachable", logName(), leaderAddress);
            return false;
        }
    }
    for (Member m : state.getMembers()) {
        if (leaderAddress.equals(m.address())) {
            if (m.status() == MemberStatus.up() || m.status() == MemberStatus.weaklyUp()) {
                log.debug("{}: Leader {} cluster status is {} - leader is available", logName(), leaderAddress, m.status());
                return true;
            } else {
                log.debug("{}: Leader {} cluster status is {} - leader is unavailable", logName(), leaderAddress, m.status());
                return false;
            }
        }
    }
    log.debug("{}: Leader {} not found in the cluster member set", logName(), leaderAddress);
    return false;
}
Also used : CurrentClusterState(akka.cluster.ClusterEvent.CurrentClusterState) ActorSelection(akka.actor.ActorSelection) Address(akka.actor.Address) Cluster(akka.cluster.Cluster) Member(akka.cluster.Member)

Example 2 with Cluster

use of akka.cluster.Cluster in project controller by opendaylight.

the class EntityOwnershipShard method initializeDownPeerMemberNamesFromClusterState.

private void initializeDownPeerMemberNamesFromClusterState() {
    java.util.Optional<Cluster> cluster = getRaftActorContext().getCluster();
    if (!cluster.isPresent()) {
        return;
    }
    CurrentClusterState state = cluster.get().state();
    Set<Member> unreachable = state.getUnreachable();
    LOG.debug("{}: initializeDownPeerMemberNamesFromClusterState - current downPeerMemberNames: {}, unreachable: {}", persistenceId(), downPeerMemberNames, unreachable);
    downPeerMemberNames.clear();
    for (Member m : unreachable) {
        downPeerMemberNames.add(MemberName.forName(m.getRoles().iterator().next()));
    }
    for (Member m : state.getMembers()) {
        if (m.status() != MemberStatus.up() && m.status() != MemberStatus.weaklyUp()) {
            LOG.debug("{}: Adding down member with status {}", persistenceId(), m.status());
            downPeerMemberNames.add(MemberName.forName(m.getRoles().iterator().next()));
        }
    }
    LOG.debug("{}: new downPeerMemberNames: {}", persistenceId(), downPeerMemberNames);
}
Also used : CurrentClusterState(akka.cluster.ClusterEvent.CurrentClusterState) Cluster(akka.cluster.Cluster) Member(akka.cluster.Member)

Aggregations

Cluster (akka.cluster.Cluster)2 CurrentClusterState (akka.cluster.ClusterEvent.CurrentClusterState)2 Member (akka.cluster.Member)2 ActorSelection (akka.actor.ActorSelection)1 Address (akka.actor.Address)1