Search in sources :

Example 36 with ActorContext

use of org.opendaylight.controller.cluster.datastore.utils.ActorContext in project controller by opendaylight.

the class MdsalLowLevelTestProvider method shutdownShardGracefully.

private SettableFuture<RpcResult<Void>> shutdownShardGracefully(final String shardName) {
    final SettableFuture<RpcResult<Void>> rpcResult = SettableFuture.create();
    final ActorContext context = configDataStore.getActorContext();
    long timeoutInMS = Math.max(context.getDatastoreContext().getShardRaftConfig().getElectionTimeOutInterval().$times(3).toMillis(), 10000);
    final FiniteDuration duration = FiniteDuration.apply(timeoutInMS, TimeUnit.MILLISECONDS);
    final scala.concurrent.Promise<Boolean> shutdownShardAsk = akka.dispatch.Futures.promise();
    context.findLocalShardAsync(shardName).onComplete(new OnComplete<ActorRef>() {

        @Override
        public void onComplete(final Throwable throwable, final ActorRef actorRef) throws Throwable {
            if (throwable != null) {
                shutdownShardAsk.failure(throwable);
            } else {
                shutdownShardAsk.completeWith(Patterns.gracefulStop(actorRef, duration, Shutdown.INSTANCE));
            }
        }
    }, context.getClientDispatcher());
    shutdownShardAsk.future().onComplete(new OnComplete<Boolean>() {

        @Override
        public void onComplete(final Throwable throwable, final Boolean gracefulStopResult) throws Throwable {
            if (throwable != null) {
                final RpcResult<Void> failedResult = RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, "Failed to gracefully shutdown shard", throwable).build();
                rpcResult.set(failedResult);
            } else {
                // according to Patterns.gracefulStop API, we don't have to
                // check value of gracefulStopResult
                rpcResult.set(RpcResultBuilder.<Void>success().build());
            }
        }
    }, context.getClientDispatcher());
    return rpcResult;
}
Also used : ActorRef(akka.actor.ActorRef) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) FiniteDuration(scala.concurrent.duration.FiniteDuration) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext)

Aggregations

ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)36 Test (org.junit.Test)15 ActorRef (akka.actor.ActorRef)13 TestKit (akka.testkit.javadsl.TestKit)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)13 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)11 FiniteDuration (scala.concurrent.duration.FiniteDuration)11 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)10 Before (org.junit.Before)7 ClientActorContext (org.opendaylight.controller.cluster.access.client.ClientActorContext)7 Props (akka.actor.Props)6 LocalShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)6 ClusteredDOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener)6 TestProbe (akka.testkit.TestProbe)5 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)5 DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)5 ActorSelection (akka.actor.ActorSelection)4 ActorSystem (akka.actor.ActorSystem)4 Timeout (akka.util.Timeout)4 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)4