Search in sources :

Example 36 with ActorSelection

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

the class AbstractDataStoreClientBehaviorTest 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(SHARD)).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 37 with ActorSelection

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

the class ActorContext method onPrimaryShardFound.

private PrimaryShardInfo onPrimaryShardFound(String shardName, String primaryActorPath, short primaryVersion, DataTree localShardDataTree) {
    ActorSelection actorSelection = actorSystem.actorSelection(primaryActorPath);
    PrimaryShardInfo info = localShardDataTree == null ? new PrimaryShardInfo(actorSelection, primaryVersion) : new PrimaryShardInfo(actorSelection, primaryVersion, localShardDataTree);
    primaryShardInfoCache.putSuccessful(shardName, info);
    return info;
}
Also used : ActorSelection(akka.actor.ActorSelection) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)

Example 38 with ActorSelection

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

the class EntityOwnershipShard method tryCommitModifications.

void tryCommitModifications(final BatchedModifications modifications) {
    if (isLeader()) {
        LOG.debug("{}: Committing BatchedModifications {} locally", persistenceId(), modifications.getTransactionId());
        // Note that it's possible the commit won't get consensus and will timeout and not be applied
        // to the state. However we don't need to retry it in that case b/c it will be committed to
        // the journal first and, once a majority of followers come back on line and it is replicated,
        // it will be applied at that point.
        handleBatchedModificationsLocal(modifications, self());
    } else {
        final ActorSelection leader = getLeader();
        if (leader != null) {
            possiblyRemoveAllInitialCandidates(leader);
            LOG.debug("{}: Sending BatchedModifications {} to leader {}", persistenceId(), modifications.getTransactionId(), leader);
            Future<Object> future = Patterns.ask(leader, modifications, TimeUnit.SECONDS.toMillis(getDatastoreContext().getShardTransactionCommitTimeoutInSeconds()));
            Patterns.pipe(future, getContext().dispatcher()).pipeTo(getSelf(), ActorRef.noSender());
        }
    }
}
Also used : ActorSelection(akka.actor.ActorSelection)

Example 39 with ActorSelection

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

the class ShardDataTreeListenerInfoMXBeanImpl method getListenerActorsInfo.

@SuppressWarnings("checkstyle:IllegalCatch")
private List<DataTreeListenerInfo> getListenerActorsInfo(Collection<ActorSelection> actors) {
    final Timeout timeout = new Timeout(20, TimeUnit.SECONDS);
    final List<Future<Object>> futureList = new ArrayList<>(actors.size());
    for (ActorSelection actor : actors) {
        futureList.add(Patterns.ask(actor, GetInfo.INSTANCE, timeout));
    }
    try {
        final List<DataTreeListenerInfo> listenerInfoList = new ArrayList<>();
        Await.result(Futures.sequence(futureList, ExecutionContext.Implicits$.MODULE$.global()), timeout.duration()).forEach(obj -> listenerInfoList.add((DataTreeListenerInfo) obj));
        return listenerInfoList;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DataTreeListenerInfo(org.opendaylight.controller.cluster.datastore.messages.DataTreeListenerInfo) ActorSelection(akka.actor.ActorSelection) Timeout(akka.util.Timeout) ArrayList(java.util.ArrayList) Future(scala.concurrent.Future)

Example 40 with ActorSelection

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

the class RaftActorLeadershipTransferCohort method init.

void init() {
    RaftActorContext context = raftActor.getRaftActorContext();
    RaftActorBehavior currentBehavior = raftActor.getCurrentBehavior();
    transferTimer.start();
    Optional<ActorRef> roleChangeNotifier = raftActor.getRoleChangeNotifier();
    if (roleChangeNotifier.isPresent()) {
        roleChangeNotifier.get().tell(raftActor.newLeaderStateChanged(context.getId(), null, currentBehavior.getLeaderPayloadVersion()), raftActor.self());
    }
    for (String peerId : context.getPeerIds()) {
        ActorSelection followerActor = context.getPeerActorSelection(peerId);
        if (followerActor != null) {
            followerActor.tell(new LeaderTransitioning(context.getId()), context.getActor());
        }
    }
    raftActor.pauseLeader(new TimedRunnable(context.getConfigParams().getElectionTimeOutInterval(), raftActor) {

        @Override
        protected void doRun() {
            LOG.debug("{}: pauseLeader successfully completed - doing transfer", raftActor.persistenceId());
            doTransfer();
        }

        @Override
        protected void doCancel() {
            LOG.debug("{}: pauseLeader timed out - continuing with transfer", raftActor.persistenceId());
            doTransfer();
        }
    });
}
Also used : ActorSelection(akka.actor.ActorSelection) ActorRef(akka.actor.ActorRef) RaftActorBehavior(org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior) LeaderTransitioning(org.opendaylight.controller.cluster.raft.base.messages.LeaderTransitioning)

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