Search in sources :

Example 11 with Dispatchers

use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.

the class DispatchersTest method testGetDispatcher.

@Test
public void testGetDispatcher() {
    akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
    MessageDispatcher mockDispatcher = mock(MessageDispatcher.class);
    doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
    doReturn(mockDispatcher).when(mockDispatchers).lookup(anyString());
    Dispatchers dispatchers = new Dispatchers(mockDispatchers);
    assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH, dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
    assertEquals(Dispatchers.TXN_DISPATCHER_PATH, dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
    assertEquals(Dispatchers.SHARD_DISPATCHER_PATH, dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
    assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH, dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));
}
Also used : MessageDispatcher(akka.dispatch.MessageDispatcher) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers) Test(org.junit.Test)

Example 12 with Dispatchers

use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.

the class DispatchersTest method testGetDefaultDispatcher.

@Test
public void testGetDefaultDispatcher() {
    akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
    MessageDispatcher mockGlobalDispatcher = mock(MessageDispatcher.class);
    doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
    doReturn(mockGlobalDispatcher).when(mockDispatchers).defaultGlobalDispatcher();
    Dispatchers dispatchers = new Dispatchers(mockDispatchers);
    for (Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
        assertEquals(mockGlobalDispatcher, dispatchers.getDispatcher(type));
    }
}
Also used : MessageDispatcher(akka.dispatch.MessageDispatcher) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers) Test(org.junit.Test)

Example 13 with Dispatchers

use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.

the class ShardManager method onShutDown.

private void onShutDown() {
    List<Future<Boolean>> stopFutures = new ArrayList<>(localShards.size());
    for (ShardInformation info : localShards.values()) {
        if (info.getActor() != null) {
            LOG.debug("{}: Issuing gracefulStop to shard {}", persistenceId(), info.getShardId());
            FiniteDuration duration = info.getDatastoreContext().getShardRaftConfig().getElectionTimeOutInterval().$times(2);
            stopFutures.add(Patterns.gracefulStop(info.getActor(), duration, Shutdown.INSTANCE));
        }
    }
    LOG.info("Shutting down ShardManager {} - waiting on {} shards", persistenceId(), stopFutures.size());
    ExecutionContext dispatcher = new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client);
    Future<Iterable<Boolean>> combinedFutures = Futures.sequence(stopFutures, dispatcher);
    combinedFutures.onComplete(new OnComplete<Iterable<Boolean>>() {

        @Override
        public void onComplete(final Throwable failure, final Iterable<Boolean> results) {
            LOG.debug("{}: All shards shutdown - sending PoisonPill to self", persistenceId());
            self().tell(PoisonPill.getInstance(), self());
            if (failure != null) {
                LOG.warn("{}: An error occurred attempting to shut down the shards", persistenceId(), failure);
            } else {
                int nfailed = 0;
                for (Boolean result : results) {
                    if (!result) {
                        nfailed++;
                    }
                }
                if (nfailed > 0) {
                    LOG.warn("{}: {} shards did not shut down gracefully", persistenceId(), nfailed);
                }
            }
        }
    }, dispatcher);
}
Also used : ArrayList(java.util.ArrayList) FiniteDuration(scala.concurrent.duration.FiniteDuration) ExecutionContext(scala.concurrent.ExecutionContext) Future(scala.concurrent.Future) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 14 with Dispatchers

use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.

the class ShardManager method removeShard.

@SuppressWarnings("checkstyle:IllegalCatch")
private void removeShard(final ShardIdentifier shardId) {
    final String shardName = shardId.getShardName();
    final ShardInformation shardInformation = localShards.remove(shardName);
    if (shardInformation == null) {
        LOG.debug("{} : Shard replica {} is not present in list", persistenceId(), shardId.toString());
        return;
    }
    final ActorRef shardActor = shardInformation.getActor();
    if (shardActor != null) {
        long timeoutInMS = Math.max(shardInformation.getDatastoreContext().getShardRaftConfig().getElectionTimeOutInterval().$times(3).toMillis(), 10000);
        LOG.debug("{} : Sending Shutdown to Shard actor {} with {} ms timeout", persistenceId(), shardActor, timeoutInMS);
        final Future<Boolean> stopFuture = Patterns.gracefulStop(shardActor, FiniteDuration.apply(timeoutInMS, TimeUnit.MILLISECONDS), Shutdown.INSTANCE);
        final CompositeOnComplete<Boolean> onComplete = new CompositeOnComplete<Boolean>() {

            @Override
            public void onComplete(final Throwable failure, final Boolean result) {
                if (failure == null) {
                    LOG.debug("{} : Successfully shut down Shard actor {}", persistenceId(), shardActor);
                } else {
                    LOG.warn("{}: Failed to shut down Shard actor {}", persistenceId(), shardActor, failure);
                }
                self().tell((RunnableMessage) () -> {
                    // At any rate, invalidate primaryShardInfo cache
                    primaryShardInfoCache.remove(shardName);
                    shardActorsStopping.remove(shardName);
                    notifyOnCompleteTasks(failure, result);
                }, ActorRef.noSender());
            }
        };
        shardActorsStopping.put(shardName, onComplete);
        stopFuture.onComplete(onComplete, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
    }
    LOG.debug("{} : Local Shard replica for shard {} has been removed", persistenceId(), shardName);
    persistShardList();
}
Also used : CompositeOnComplete(org.opendaylight.controller.cluster.datastore.utils.CompositeOnComplete) ActorRef(akka.actor.ActorRef) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 15 with Dispatchers

use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.

the class ShardManager method findPrimary.

private void findPrimary(final String shardName, final FindPrimaryResponseHandler handler) {
    Timeout findPrimaryTimeout = new Timeout(datastoreContextFactory.getBaseDatastoreContext().getShardInitializationTimeout().duration().$times(2));
    Future<Object> futureObj = ask(getSelf(), new FindPrimary(shardName, true), findPrimaryTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                handler.onFailure(failure);
            } else {
                if (response instanceof RemotePrimaryShardFound) {
                    handler.onRemotePrimaryShardFound((RemotePrimaryShardFound) response);
                } else if (response instanceof LocalPrimaryShardFound) {
                    handler.onLocalPrimaryFound((LocalPrimaryShardFound) response);
                } else {
                    handler.onUnknownResponse(response);
                }
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) RemoteFindPrimary(org.opendaylight.controller.cluster.datastore.messages.RemoteFindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) Timeout(akka.util.Timeout) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Aggregations

Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)16 Timeout (akka.util.Timeout)8 Test (org.junit.Test)6 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)5 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)5 ActorRef (akka.actor.ActorRef)4 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)3 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)3 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)3 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)3 LocalShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)3 LocalShardNotFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound)3 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)3 ActorSystem (akka.actor.ActorSystem)2 Props (akka.actor.Props)2 Status (akka.actor.Status)2 Terminated (akka.actor.Terminated)2 ExecutionContexts (akka.dispatch.ExecutionContexts)2 Futures (akka.dispatch.Futures)2 MessageDispatcher (akka.dispatch.MessageDispatcher)2