Search in sources :

Example 1 with NotInitializedException

use of org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException in project controller by opendaylight.

the class ActorContext method findPrimaryShardAsync.

public Future<PrimaryShardInfo> findPrimaryShardAsync(final String shardName) {
    Future<PrimaryShardInfo> ret = primaryShardInfoCache.getIfPresent(shardName);
    if (ret != null) {
        return ret;
    }
    Future<Object> future = executeOperationAsync(shardManager, new FindPrimary(shardName, true), shardInitializationTimeout);
    return future.transform(new Mapper<Object, PrimaryShardInfo>() {

        @Override
        public PrimaryShardInfo checkedApply(Object response) throws UnknownMessageException {
            if (response instanceof RemotePrimaryShardFound) {
                LOG.debug("findPrimaryShardAsync received: {}", response);
                RemotePrimaryShardFound found = (RemotePrimaryShardFound) response;
                return onPrimaryShardFound(shardName, found.getPrimaryPath(), found.getPrimaryVersion(), null);
            } else if (response instanceof LocalPrimaryShardFound) {
                LOG.debug("findPrimaryShardAsync received: {}", response);
                LocalPrimaryShardFound found = (LocalPrimaryShardFound) response;
                return onPrimaryShardFound(shardName, found.getPrimaryPath(), DataStoreVersions.CURRENT_VERSION, found.getLocalShardDataTree());
            } else if (response instanceof NotInitializedException) {
                throw (NotInitializedException) response;
            } else if (response instanceof PrimaryNotFoundException) {
                throw (PrimaryNotFoundException) response;
            } else if (response instanceof NoShardLeaderException) {
                throw (NoShardLeaderException) response;
            }
            throw new UnknownMessageException(String.format("FindPrimary returned unkown response: %s", response));
        }
    }, FIND_PRIMARY_FAILURE_TRANSFORMER, getClientDispatcher());
}
Also used : PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) UnknownMessageException(org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)

Example 2 with NotInitializedException

use of org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException in project controller by opendaylight.

the class DistributedDataStoreIntegrationTest method testTransactionCommitFailureWithShardNotInitialized.

@Test(expected = NotInitializedException.class)
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionCommitFailureWithShardNotInitialized() throws Exception {
    new IntegrationTestKit(getSystem(), datastoreContextBuilder) {

        {
            final String testName = "testTransactionCommitFailureWithShardNotInitialized";
            final String shardName = "test-1";
            // Set the shard initialization timeout low for the test.
            datastoreContextBuilder.shardInitializationTimeout(300, TimeUnit.MILLISECONDS);
            // Setup the InMemoryJournal to block shard recovery
            // indefinitely.
            final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
            final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
            InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
            InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");
            final AbstractDataStore dataStore = setupAbstractDataStore(testParameter, testName, false, shardName);
            // Create the write Tx
            final DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
            assertNotNull("newReadWriteTransaction returned null", writeTx);
            // Do some modifications and ready the Tx on a separate
            // thread.
            final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
            final AtomicReference<Exception> caughtEx = new AtomicReference<>();
            final CountDownLatch txReady = new CountDownLatch(1);
            final Thread txThread = new Thread(() -> {
                try {
                    writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
                    txCohort.set(writeTx.ready());
                } catch (Exception e) {
                    caughtEx.set(e);
                } finally {
                    txReady.countDown();
                }
            });
            txThread.start();
            // Wait for the Tx operations to complete.
            boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
            if (caughtEx.get() != null) {
                throw caughtEx.get();
            }
            assertEquals("Tx ready", true, done);
            // have timed out and throw an appropriate exception cause.
            try {
                txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
                fail("Expected NotInitializedException");
            } catch (final Exception e) {
                final Throwable root = Throwables.getRootCause(e);
                Throwables.throwIfUnchecked(root);
                throw new RuntimeException(root);
            } finally {
                blockRecoveryLatch.countDown();
            }
        }
    };
}
Also used : DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) AtomicReference(java.util.concurrent.atomic.AtomicReference) AddressFromURIString(akka.actor.AddressFromURIString) CountDownLatch(java.util.concurrent.CountDownLatch) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) TransactionChainClosedException(org.opendaylight.mdsal.common.api.TransactionChainClosedException) RequestTimeoutException(org.opendaylight.controller.cluster.access.client.RequestTimeoutException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) IOException(java.io.IOException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 3 with NotInitializedException

use of org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException in project controller by opendaylight.

the class DataChangeListenerRegistrationProxyTest method testLocalShardNotInitialized.

@Test(timeout = 10000)
public void testLocalShardNotInitialized() {
    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 NotInitializedException("not initialized"));
            expectNoMsg(duration("1 seconds"));
            proxy.close();
        }
    };
}
Also used : DataChangeScope(org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) 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 4 with NotInitializedException

use of org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException in project controller by opendaylight.

the class DataTreeChangeListenerProxyTest method testLocalShardNotInitialized.

@Test(timeout = 10000)
public void testLocalShardNotInitialized() {
    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 NotInitializedException("not initialized"));
            within(duration("1 seconds"), () -> {
                expectNoMsg();
                return null;
            });
            proxy.close();
        }
    };
}
Also used : NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) 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 5 with NotInitializedException

use of org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException in project controller by opendaylight.

the class DistributedDataStoreIntegrationTest method testTransactionReadFailureWithShardNotInitialized.

@Test(expected = NotInitializedException.class)
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionReadFailureWithShardNotInitialized() throws Exception {
    new IntegrationTestKit(getSystem(), datastoreContextBuilder) {

        {
            final String testName = "testTransactionReadFailureWithShardNotInitialized";
            final String shardName = "test-1";
            // Set the shard initialization timeout low for the test.
            datastoreContextBuilder.shardInitializationTimeout(300, TimeUnit.MILLISECONDS);
            // Setup the InMemoryJournal to block shard recovery
            // indefinitely.
            final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
            final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
            InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
            InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, testName, false, shardName)) {
                // Create the read-write Tx
                final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
                assertNotNull("newReadWriteTransaction returned null", readWriteTx);
                // Do a read on the Tx on a separate thread.
                final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>> txReadFuture = new AtomicReference<>();
                final AtomicReference<Exception> caughtEx = new AtomicReference<>();
                final CountDownLatch txReadDone = new CountDownLatch(1);
                final Thread txThread = new Thread(() -> {
                    try {
                        readWriteTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
                        txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
                        readWriteTx.close();
                    } catch (Exception e) {
                        caughtEx.set(e);
                    } finally {
                        txReadDone.countDown();
                    }
                });
                txThread.start();
                // Wait for the Tx operations to complete.
                boolean done = Uninterruptibles.awaitUninterruptibly(txReadDone, 5, TimeUnit.SECONDS);
                if (caughtEx.get() != null) {
                    throw caughtEx.get();
                }
                assertEquals("Tx read done", true, done);
                // have timed out and throw an appropriate exception cause.
                try {
                    txReadFuture.get().checkedGet(5, TimeUnit.SECONDS);
                    fail("Expected NotInitializedException");
                } catch (final ReadFailedException e) {
                    final Throwable root = Throwables.getRootCause(e);
                    Throwables.throwIfUnchecked(root);
                    throw new RuntimeException(root);
                } finally {
                    blockRecoveryLatch.countDown();
                }
            }
        }
    };
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) AtomicReference(java.util.concurrent.atomic.AtomicReference) AddressFromURIString(akka.actor.AddressFromURIString) CountDownLatch(java.util.concurrent.CountDownLatch) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) TransactionChainClosedException(org.opendaylight.mdsal.common.api.TransactionChainClosedException) RequestTimeoutException(org.opendaylight.controller.cluster.access.client.RequestTimeoutException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) IOException(java.io.IOException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)5 Test (org.junit.Test)4 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)3 AddressFromURIString (akka.actor.AddressFromURIString)2 TestKit (akka.testkit.javadsl.TestKit)2 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 RequestTimeoutException (org.opendaylight.controller.cluster.access.client.RequestTimeoutException)2 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)2 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)2 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)2 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)2 TransactionChainClosedException (org.opendaylight.mdsal.common.api.TransactionChainClosedException)2 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 FiniteDuration (scala.concurrent.duration.FiniteDuration)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)1 PrimaryNotFoundException (org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException)1