Search in sources :

Example 1 with CurrentClusterState

use of akka.cluster.ClusterEvent.CurrentClusterState in project controller by opendaylight.

the class IntegrationTestKit method waitForMembersUp.

public void waitForMembersUp(final String... otherMembers) {
    Set<String> otherMembersSet = Sets.newHashSet(otherMembers);
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
        CurrentClusterState state = Cluster.get(getSystem()).state();
        for (Member m : state.getMembers()) {
            if (m.status() == MemberStatus.up() && otherMembersSet.remove(m.getRoles().iterator().next()) && otherMembersSet.isEmpty()) {
                return;
            }
        }
        Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
    }
    fail("Member(s) " + otherMembersSet + " are not Up");
}
Also used : CurrentClusterState(akka.cluster.ClusterEvent.CurrentClusterState) Stopwatch(com.google.common.base.Stopwatch) Member(akka.cluster.Member)

Example 2 with CurrentClusterState

use of akka.cluster.ClusterEvent.CurrentClusterState 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 3 with CurrentClusterState

use of akka.cluster.ClusterEvent.CurrentClusterState 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)

Example 4 with CurrentClusterState

use of akka.cluster.ClusterEvent.CurrentClusterState in project controller by opendaylight.

the class MemberNode method waitForMemberDown.

public void waitForMemberDown(final String member) {
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
        CurrentClusterState state = Cluster.get(kit.getSystem()).state();
        for (Member m : state.getUnreachable()) {
            if (member.equals(m.getRoles().iterator().next())) {
                return;
            }
        }
        for (Member m : state.getMembers()) {
            if (m.status() != MemberStatus.up() && member.equals(m.getRoles().iterator().next())) {
                return;
            }
        }
        Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
    }
    fail("Member " + member + " is now down");
}
Also used : CurrentClusterState(akka.cluster.ClusterEvent.CurrentClusterState) Stopwatch(com.google.common.base.Stopwatch) Member(akka.cluster.Member)

Example 5 with CurrentClusterState

use of akka.cluster.ClusterEvent.CurrentClusterState in project controller by opendaylight.

the class RpcRegistryTest method waitForMembersUp.

static void waitForMembersUp(final ActorSystem node, final UniqueAddress... addresses) {
    Set<UniqueAddress> otherMembersSet = Sets.newHashSet(addresses);
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
        CurrentClusterState state = Cluster.get(node).state();
        for (Member m : state.getMembers()) {
            if (m.status() == MemberStatus.up() && otherMembersSet.remove(m.uniqueAddress()) && otherMembersSet.isEmpty()) {
                return;
            }
        }
        Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
    }
    fail("Member(s) " + otherMembersSet + " are not Up");
}
Also used : CurrentClusterState(akka.cluster.ClusterEvent.CurrentClusterState) Stopwatch(com.google.common.base.Stopwatch) Member(akka.cluster.Member) UniqueAddress(akka.cluster.UniqueAddress)

Aggregations

CurrentClusterState (akka.cluster.ClusterEvent.CurrentClusterState)5 Member (akka.cluster.Member)5 Stopwatch (com.google.common.base.Stopwatch)3 Cluster (akka.cluster.Cluster)2 ActorSelection (akka.actor.ActorSelection)1 Address (akka.actor.Address)1 UniqueAddress (akka.cluster.UniqueAddress)1