Search in sources :

Example 1 with LocalShardNotFound

use of org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound in project controller by opendaylight.

the class ShardManager method findLocalShard.

private void findLocalShard(final String shardName, final ActorRef sender, final Consumer<LocalShardFound> onLocalShardFound) {
    Timeout findLocalTimeout = new Timeout(datastoreContextFactory.getBaseDatastoreContext().getShardInitializationTimeout().duration().$times(2));
    Future<Object> futureObj = ask(getSelf(), new FindLocalShard(shardName, true), findLocalTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                LOG.debug("{}: Received failure from FindLocalShard for shard {}", persistenceId, shardName, failure);
                sender.tell(new Status.Failure(new RuntimeException(String.format("Failed to find local shard %s", shardName), failure)), self());
            } else {
                if (response instanceof LocalShardFound) {
                    getSelf().tell((RunnableMessage) () -> onLocalShardFound.accept((LocalShardFound) response), sender);
                } else if (response instanceof LocalShardNotFound) {
                    String msg = String.format("Local shard %s does not exist", shardName);
                    LOG.debug("{}: {}", persistenceId, msg);
                    sender.tell(new Status.Failure(new IllegalArgumentException(msg)), self());
                } else {
                    String msg = String.format("Failed to find local shard %s: received response: %s", shardName, response);
                    LOG.debug("{}: {}", persistenceId, msg);
                    sender.tell(new Status.Failure(response instanceof Throwable ? (Throwable) response : new RuntimeException(msg)), self());
                }
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) FlipShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) Timeout(akka.util.Timeout) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 2 with LocalShardNotFound

use of org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound in project controller by opendaylight.

the class DataChangeListenerRegistrationProxyTest method testLocalShardNotFound.

@Test(timeout = 10000)
public void testLocalShardNotFound() {
    new TestKit(getSystem()) {

        {
            ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockListener);
            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
            final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
            new Thread(() -> proxy.init(path, scope)).start();
            FiniteDuration timeout = duration("5 seconds");
            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
            reply(new LocalShardNotFound("shard-1"));
            expectNoMsg(duration("1 seconds"));
            proxy.close();
        }
    };
}
Also used : DataChangeScope(org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope) LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) FiniteDuration(scala.concurrent.duration.FiniteDuration) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) Test(org.junit.Test)

Example 3 with LocalShardNotFound

use of org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound in project controller by opendaylight.

the class DataTreeChangeListenerProxyTest method testLocalShardNotFound.

@Test(timeout = 10000)
public void testLocalShardNotFound() {
    new TestKit(getSystem()) {

        {
            ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
            final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, path);
            new Thread(() -> proxy.init("shard-1")).start();
            FiniteDuration timeout = duration("5 seconds");
            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
            reply(new LocalShardNotFound("shard-1"));
            expectNoMsg(duration("1 seconds"));
            proxy.close();
        }
    };
}
Also used : LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener) FiniteDuration(scala.concurrent.duration.FiniteDuration) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) Test(org.junit.Test)

Example 4 with LocalShardNotFound

use of org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound in project controller by opendaylight.

the class ShardManagerTest method testShardPersistenceWithRestoredData.

@Test
public void testShardPersistenceWithRestoredData() throws Exception {
    LOG.info("testShardPersistenceWithRestoredData starting");
    new TestKit(getSystem()) {

        {
            MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).put("people", Arrays.asList("member-1", "member-2")).build());
            String[] restoredShards = { "default", "astronauts" };
            ShardManagerSnapshot snapshot = new ShardManagerSnapshot(Arrays.asList(restoredShards), Collections.emptyMap());
            InMemorySnapshotStore.addSnapshot("shard-manager-" + shardMrgIDSuffix, snapshot);
            // create shardManager to come up with restored data
            TestActorRef<TestShardManager> newRestoredShardManager = actorFactory.createTestActor(newShardMgrProps(mockConfig).withDispatcher(Dispatchers.DefaultDispatcherId()));
            newRestoredShardManager.underlyingActor().waitForRecoveryComplete();
            newRestoredShardManager.tell(new FindLocalShard("people", false), getRef());
            LocalShardNotFound notFound = expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
            assertEquals("for uninitialized shard", "people", notFound.getShardName());
            // Verify a local shard is created for the restored shards,
            // although we expect a NotInitializedException for the shards
            // as the actor initialization
            // message is not sent for them
            newRestoredShardManager.tell(new FindLocalShard("default", false), getRef());
            expectMsgClass(duration("5 seconds"), NotInitializedException.class);
            newRestoredShardManager.tell(new FindLocalShard("astronauts", false), getRef());
            expectMsgClass(duration("5 seconds"), NotInitializedException.class);
        }
    };
    LOG.info("testShardPersistenceWithRestoredData ending");
}
Also used : LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) ShardManagerSnapshot(org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshot) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 5 with LocalShardNotFound

use of org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindLocalShardForNonExistentShard.

@Test
public void testOnReceiveFindLocalShardForNonExistentShard() throws Exception {
    new TestKit(getSystem()) {

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new FindLocalShard("non-existent", false), getRef());
            LocalShardNotFound notFound = expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
            assertEquals("getShardName", "non-existent", notFound.getShardName());
        }
    };
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

LocalShardNotFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound)6 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)5 TestKit (akka.testkit.javadsl.TestKit)4 Test (org.junit.Test)4 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)2 LocalShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)2 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 FiniteDuration (scala.concurrent.duration.FiniteDuration)2 ActorRef (akka.actor.ActorRef)1 AddressFromURIString (akka.actor.AddressFromURIString)1 Status (akka.actor.Status)1 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)1 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)1 TestActorRef (akka.testkit.TestActorRef)1 Timeout (akka.util.Timeout)1 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)1 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)1 FlipShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus)1