Search in sources :

Example 6 with Dispatchers

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

the class ShardManager method removeShardReplica.

private void removeShardReplica(final RemoveShardReplica contextMessage, final String shardName, final String primaryPath, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }
    shardReplicaOperationsInProgress.add(shardName);
    final ShardIdentifier shardId = getShardIdentifier(contextMessage.getMemberName(), shardName);
    final DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
    // inform ShardLeader to remove this shard as a replica by sending an RemoveServer message
    LOG.debug("{}: Sending RemoveServer message to peer {} for shard {}", persistenceId(), primaryPath, shardId);
    Timeout removeServerTimeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration());
    Future<Object> futureObj = ask(getContext().actorSelection(primaryPath), new RemoveServer(shardId.toString()), removeServerTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                shardReplicaOperationsInProgress.remove(shardName);
                String msg = String.format("RemoveServer request to leader %s for shard %s failed", primaryPath, shardName);
                LOG.debug("{}: {}", persistenceId(), msg, failure);
                // FAILURE
                sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
            } else {
                // SUCCESS
                self().tell(new WrappedShardResponse(shardId, response, primaryPath), sender);
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 7 with Dispatchers

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

the class DataChangeListenerRegistrationProxyTest method testCloseBeforeRegistration.

@Test
public void testCloseBeforeRegistration() {
    new TestKit(getSystem()) {

        {
            ActorContext actorContext = mock(ActorContext.class);
            String shardName = "shard-1";
            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(shardName, actorContext, mockListener);
            doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
            doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(actorContext).getClientDispatcher();
            doReturn(getSystem()).when(actorContext).getActorSystem();
            doReturn(Dispatchers.DEFAULT_DISPATCHER_PATH).when(actorContext).getNotificationDispatcherPath();
            doReturn(getSystem().actorSelection(getRef().path())).when(actorContext).actorSelection(getRef().path());
            doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
            doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
            Answer<Future<Object>> answer = invocation -> {
                proxy.close();
                return Futures.successful((Object) new RegisterDataTreeNotificationListenerReply(getRef()));
            };
            doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class), any(Object.class), any(Timeout.class));
            proxy.init(YangInstanceIdentifier.of(TestModel.TEST_QNAME), AsyncDataBroker.DataChangeScope.ONE);
            expectMsgClass(duration("5 seconds"), CloseDataTreeNotificationListenerRegistration.class);
            Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor());
            proxy.close();
        }
    };
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Terminated(akka.actor.Terminated) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) TestModel(org.opendaylight.controller.md.cluster.datastore.model.TestModel) AsyncDataChangeListener(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener) Timeout(akka.util.Timeout) LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) Answer(org.mockito.stubbing.Answer) LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) ActorRef(akka.actor.ActorRef) Matchers.eq(org.mockito.Matchers.eq) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CloseDataTreeNotificationListenerRegistration(org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeNotificationListenerRegistration) Mockito.doReturn(org.mockito.Mockito.doReturn) AsyncDataBroker(org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Future(scala.concurrent.Future) FiniteDuration(scala.concurrent.duration.FiniteDuration) Test(org.junit.Test) ClusteredDOMDataChangeListener(org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataChangeListener) TestKit(akka.testkit.javadsl.TestKit) ExecutionContexts(akka.dispatch.ExecutionContexts) Matchers.any(org.mockito.Matchers.any) Futures(akka.dispatch.Futures) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) RegisterChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener) DataChangeScope(org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope) ActorSystem(akka.actor.ActorSystem) ExecutionContextExecutor(scala.concurrent.ExecutionContextExecutor) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Assert(org.junit.Assert) Props(akka.actor.Props) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Mockito.mock(org.mockito.Mockito.mock) RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) Future(scala.concurrent.Future) TestKit(akka.testkit.javadsl.TestKit) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) Test(org.junit.Test)

Example 8 with Dispatchers

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

the class DispatchersTest method testGetDispatcherPath.

@Test
public void testGetDispatcherPath() {
    akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
    doReturn(true).when(mockDispatchers).hasDispatcher(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 : Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers) Test(org.junit.Test)

Example 9 with Dispatchers

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

the class AbstractShardDataTreeNotificationPublisherActorProxy method publisherActor.

protected final ActorRef publisherActor() {
    if (publisherActor == null) {
        String dispatcher = new Dispatchers(actorContext.system().dispatchers()).getDispatcherPath(Dispatchers.DispatcherType.Notification);
        publisherActor = actorContext.actorOf(props().withDispatcher(dispatcher), actorName);
        log.debug("{}: Created publisher actor {} with name {}", logContext, publisherActor, actorName);
    }
    return publisherActor;
}
Also used : Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 10 with Dispatchers

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

the class DispatchersTest method testGetDefaultDispatcherPath.

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

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