Search in sources :

Example 31 with ActorRef

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

the class RaftActor method onShutDown.

private void onShutDown() {
    LOG.debug("{}: onShutDown", persistenceId());
    if (shuttingDown) {
        return;
    }
    shuttingDown = true;
    final RaftActorBehavior currentBehavior = context.getCurrentBehavior();
    switch(currentBehavior.state()) {
        case Leader:
        case PreLeader:
            // Fall-through to more work
            break;
        default:
            // For non-leaders shutdown is a no-op
            self().tell(PoisonPill.getInstance(), self());
            return;
    }
    if (context.hasFollowers()) {
        initiateLeadershipTransfer(new RaftActorLeadershipTransferCohort.OnComplete() {

            @Override
            public void onSuccess(final ActorRef raftActorRef) {
                LOG.debug("{}: leader transfer succeeded - sending PoisonPill", persistenceId());
                raftActorRef.tell(PoisonPill.getInstance(), raftActorRef);
            }

            @Override
            public void onFailure(final ActorRef raftActorRef) {
                LOG.debug("{}: leader transfer failed - sending PoisonPill", persistenceId());
                raftActorRef.tell(PoisonPill.getInstance(), raftActorRef);
            }
        }, null, TimeUnit.MILLISECONDS.convert(2, TimeUnit.SECONDS));
    } else {
        pauseLeader(new TimedRunnable(context.getConfigParams().getElectionTimeOutInterval(), this) {

            @Override
            protected void doRun() {
                self().tell(PoisonPill.getInstance(), self());
            }

            @Override
            protected void doCancel() {
                self().tell(PoisonPill.getInstance(), self());
            }
        });
    }
}
Also used : ActorRef(akka.actor.ActorRef) RaftActorBehavior(org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior) AbstractRaftActorBehavior(org.opendaylight.controller.cluster.raft.behaviors.AbstractRaftActorBehavior)

Example 32 with ActorRef

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

the class RaftActor method onRequestLeadership.

private void onRequestLeadership(final RequestLeadership message) {
    LOG.debug("{}: onRequestLeadership {}", persistenceId(), message);
    if (!isLeader()) {
        // non-leader cannot satisfy leadership request
        LOG.warn("{}: onRequestLeadership {} was sent to non-leader." + " Current behavior: {}. Sending failure response", persistenceId(), getCurrentBehavior().state());
        message.getReplyTo().tell(new LeadershipTransferFailedException("Cannot transfer leader to " + message.getRequestedFollowerId() + ". RequestLeadership message was sent to non-leader " + persistenceId()), getSelf());
        return;
    }
    final String requestedFollowerId = message.getRequestedFollowerId();
    final ActorRef replyTo = message.getReplyTo();
    initiateLeadershipTransfer(new RaftActorLeadershipTransferCohort.OnComplete() {

        @Override
        public void onSuccess(final ActorRef raftActorRef) {
            // sanity check
            if (!requestedFollowerId.equals(getLeaderId())) {
                onFailure(raftActorRef);
            }
            LOG.debug("{}: Leadership transferred successfully to {}", persistenceId(), requestedFollowerId);
            replyTo.tell(new Status.Success(null), getSelf());
        }

        @Override
        public void onFailure(final ActorRef raftActorRef) {
            LOG.debug("{}: LeadershipTransfer request from {} failed", persistenceId(), requestedFollowerId);
            replyTo.tell(new Status.Failure(new LeadershipTransferFailedException("Failed to transfer leadership to " + requestedFollowerId + ". Follower is not ready to become leader")), getSelf());
        }
    }, message.getRequestedFollowerId(), RaftActorLeadershipTransferCohort.USE_DEFAULT_LEADER_TIMEOUT);
}
Also used : ActorRef(akka.actor.ActorRef)

Example 33 with ActorRef

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

the class ExampleRoleChangeListener method sendRegistrationRequests.

@SuppressWarnings("checkstyle:IllegalCatch")
private void sendRegistrationRequests() {
    for (Map.Entry<String, Boolean> entry : notifierRegistrationStatus.entrySet()) {
        if (!entry.getValue()) {
            try {
                LOG.debug("{} registering with {}", getSelf().path().toString(), entry.getKey());
                ActorRef notifier = Await.result(getContext().actorSelection(entry.getKey()).resolveOne(DURATION), DURATION);
                notifier.tell(new RegisterRoleChangeListener(), getSelf());
            } catch (Exception e) {
                LOG.error("ERROR!! Unable to send registration request to notifier {}", entry.getKey());
            }
        }
    }
}
Also used : RegisterRoleChangeListener(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener) ActorRef(akka.actor.ActorRef) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with ActorRef

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

the class RaftActorSnapshotMessageSupport method onGetSnapshot.

private void onGetSnapshot(ActorRef sender) {
    log.debug("{}: onGetSnapshot", context.getId());
    if (context.getPersistenceProvider().isRecoveryApplicable()) {
        CaptureSnapshot captureSnapshot = context.getSnapshotManager().newCaptureSnapshot(context.getReplicatedLog().last(), -1);
        ActorRef snapshotReplyActor = context.actorOf(GetSnapshotReplyActor.props(captureSnapshot, ImmutableElectionTerm.copyOf(context.getTermInformation()), sender, snapshotReplyActorTimeout, context.getId(), context.getPeerServerInfo(true)));
        cohort.createSnapshot(snapshotReplyActor, Optional.empty());
    } else {
        Snapshot snapshot = Snapshot.create(EmptyState.INSTANCE, Collections.<ReplicatedLogEntry>emptyList(), -1, -1, -1, -1, context.getTermInformation().getCurrentTerm(), context.getTermInformation().getVotedFor(), context.getPeerServerInfo(true));
        sender.tell(new GetSnapshotReply(context.getId(), snapshot), context.getActor());
    }
}
Also used : CaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) ApplySnapshot(org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot) GetSnapshot(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot) ActorRef(akka.actor.ActorRef) CaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot) GetSnapshotReply(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshotReply)

Example 35 with ActorRef

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

the class TestDriver method addClients.

// add num clients to all nodes in the system
public void addClients(int num) {
    for (Map.Entry<String, ActorRef> actorRefEntry : actorRefs.entrySet()) {
        for (int i = 0; i < num; i++) {
            String clientName = "client-" + i + "-" + actorRefEntry.getKey();
            ActorRef clientActor = actorSystem.actorOf(ClientActor.props(actorRefEntry.getValue()), clientName);
            clientActorRefs.put(clientName, clientActor);
            System.out.println("Created client-node:" + clientName);
        }
    }
}
Also used : ActorRef(akka.actor.ActorRef) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ActorRef (akka.actor.ActorRef)383 Test (org.junit.Test)253 TestActorRef (akka.testkit.TestActorRef)124 TestKit (akka.testkit.javadsl.TestKit)84 ActorSystem (akka.actor.ActorSystem)53 FiniteDuration (scala.concurrent.duration.FiniteDuration)53 Props (akka.actor.Props)46 Timeout (akka.util.Timeout)43 Configuration (org.apache.flink.configuration.Configuration)42 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)38 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)37 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)33 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)30 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)26 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)26 AddressFromURIString (akka.actor.AddressFromURIString)24 ArrayList (java.util.ArrayList)22 JobID (org.apache.flink.api.common.JobID)22 IOException (java.io.IOException)21 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)20