Search in sources :

Example 6 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class Leader method tryToCompleteLeadershipTransfer.

private void tryToCompleteLeadershipTransfer(String followerId) {
    if (leadershipTransferContext == null) {
        return;
    }
    final Optional<String> requestedFollowerIdOptional = leadershipTransferContext.transferCohort.getRequestedFollowerId();
    if (requestedFollowerIdOptional.isPresent() && !requestedFollowerIdOptional.get().equals(followerId)) {
        // we want to transfer leadership to specific follower
        return;
    }
    FollowerLogInformation followerInfo = getFollower(followerId);
    if (followerInfo == null) {
        return;
    }
    long lastIndex = context.getReplicatedLog().lastIndex();
    boolean isVoting = context.getPeerInfo(followerId).isVoting();
    log.debug("{}: tryToCompleteLeadershipTransfer: followerId: {}, matchIndex: {}, lastIndex: {}, isVoting: {}", logName(), followerId, followerInfo.getMatchIndex(), lastIndex, isVoting);
    if (isVoting && followerInfo.getMatchIndex() == lastIndex) {
        log.debug("{}: Follower's log matches - sending ElectionTimeout", logName());
        // We can't be sure if the follower has applied all its log entries to its state so send an
        // additional AppendEntries with the latest commit index.
        sendAppendEntries(0, false);
        // Now send a TimeoutNow message to the matching follower to immediately start an election.
        ActorSelection followerActor = context.getPeerActorSelection(followerId);
        followerActor.tell(TimeoutNow.INSTANCE, context.getActor());
        log.debug("{}: Leader transfer complete", logName());
        leadershipTransferContext.transferCohort.transferComplete();
        leadershipTransferContext = null;
    }
}
Also used : FollowerLogInformation(org.opendaylight.controller.cluster.raft.FollowerLogInformation) ActorSelection(akka.actor.ActorSelection)

Example 7 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class RaftActorServerConfigurationSupport method onNewOperation.

private void onNewOperation(final ServerOperationContext<?> operationContext) {
    if (raftActor.isLeader()) {
        currentOperationState.onNewOperation(operationContext);
    } else {
        ActorSelection leader = raftActor.getLeader();
        if (leader != null) {
            LOG.debug("{}: Not leader - forwarding to leader {}", raftContext.getId(), leader);
            leader.tell(operationContext.getOperation(), operationContext.getClientRequestor());
        } else {
            LOG.debug("{}: No leader - returning NO_LEADER reply", raftContext.getId());
            operationContext.getClientRequestor().tell(operationContext.newReply(ServerChangeStatus.NO_LEADER, null), raftActor.self());
        }
    }
}
Also used : ActorSelection(akka.actor.ActorSelection)

Example 8 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class AbstractClientHandleTest method createActorContextMock.

private static ActorContext createActorContextMock(final ActorSystem system, final ActorRef actor) {
    final ActorContext mock = mock(ActorContext.class);
    final Promise<PrimaryShardInfo> promise = new scala.concurrent.impl.Promise.DefaultPromise<>();
    final ActorSelection selection = system.actorSelection(actor.path());
    final PrimaryShardInfo shardInfo = new PrimaryShardInfo(selection, (short) 0);
    promise.success(shardInfo);
    when(mock.findPrimaryShardAsync(any())).thenReturn(promise.future());
    return mock;
}
Also used : ActorSelection(akka.actor.ActorSelection) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext)

Example 9 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class ShardedDataTreeActor method onProducerRemoved.

private void onProducerRemoved(final ProducerRemoved message) {
    LOG.debug("Received ProducerRemoved: {}", message);
    final List<CompletableFuture<Object>> futures = new ArrayList<>();
    for (final String address : resolver.getShardingServicePeerActorAddresses()) {
        final ActorSelection selection = actorSystem.actorSelection(address);
        futures.add(FutureConverters.toJava(actorContext.executeOperationAsync(selection, new NotifyProducerRemoved(message.getSubtrees()))).toCompletableFuture());
    }
    final CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]));
    final ActorRef respondTo = getSender();
    combinedFuture.thenRun(() -> respondTo.tell(new Status.Success(null), self())).exceptionally(e -> {
        respondTo.tell(new Status.Failure(null), self());
        return null;
    });
}
Also used : Status(akka.actor.Status) CompletableFuture(java.util.concurrent.CompletableFuture) ActorSelection(akka.actor.ActorSelection) ActorRef(akka.actor.ActorRef) ArrayList(java.util.ArrayList) NotifyProducerRemoved(org.opendaylight.controller.cluster.sharding.messages.NotifyProducerRemoved) Success(akka.actor.Status.Success)

Example 10 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class ShardedDataTreeActor method onProducerCreated.

private void onProducerCreated(final ProducerCreated message) {
    LOG.debug("Received ProducerCreated: {}", message);
    // fastpath if we have no peers
    if (resolver.getShardingServicePeerActorAddresses().isEmpty()) {
        getSender().tell(new Status.Success(null), noSender());
    }
    final ActorRef sender = getSender();
    final Collection<DOMDataTreeIdentifier> subtrees = message.getSubtrees();
    final List<CompletableFuture<Object>> futures = new ArrayList<>();
    for (final String address : resolver.getShardingServicePeerActorAddresses()) {
        final ActorSelection actorSelection = actorSystem.actorSelection(address);
        futures.add(FutureConverters.toJava(actorContext.executeOperationAsync(actorSelection, new NotifyProducerCreated(subtrees), DEFAULT_ASK_TIMEOUT)).toCompletableFuture());
    }
    final CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]));
    combinedFuture.thenRun(() -> sender.tell(new Success(null), noSender())).exceptionally(throwable -> {
        sender.tell(new Status.Failure(throwable), self());
        return null;
    });
}
Also used : Status(akka.actor.Status) ActorRef(akka.actor.ActorRef) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ArrayList(java.util.ArrayList) Success(akka.actor.Status.Success) Success(akka.actor.Status.Success) CompletableFuture(java.util.concurrent.CompletableFuture) ActorSelection(akka.actor.ActorSelection) NotifyProducerCreated(org.opendaylight.controller.cluster.sharding.messages.NotifyProducerCreated)

Aggregations

ActorSelection (akka.actor.ActorSelection)43 ActorRef (akka.actor.ActorRef)9 Test (org.junit.Test)6 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)5 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)4 FollowerLogInformation (org.opendaylight.controller.cluster.raft.FollowerLogInformation)4 InvalidActorNameException (akka.actor.InvalidActorNameException)3 Status (akka.actor.Status)3 TestActorRef (akka.testkit.TestActorRef)3 TestKit (akka.testkit.javadsl.TestKit)3 Timeout (akka.util.Timeout)3 ArrayList (java.util.ArrayList)3 ClientActorContext (org.opendaylight.controller.cluster.access.client.ClientActorContext)3 AkkaException (akka.AkkaException)2 ActorIdentity (akka.actor.ActorIdentity)2 Identify (akka.actor.Identify)2 Failure (akka.actor.Status.Failure)2 Success (akka.actor.Status.Success)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)2