Search in sources :

Example 1 with ReadFailedException

use of org.opendaylight.mdsal.common.api.ReadFailedException in project controller by opendaylight.

the class DistributedDataStoreIntegrationTest method testTransactionReadsWithShardNotInitiallyReady.

@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionReadsWithShardNotInitiallyReady() throws Exception {
    new IntegrationTestKit(getSystem(), datastoreContextBuilder) {

        {
            final String testName = "testTransactionReadsWithShardNotInitiallyReady";
            final String shardName = "test-1";
            // Setup the InMemoryJournal to block shard recovery to ensure
            // the shard isn't
            // initialized until we create the Tx.
            final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
            final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
            InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, testName, false, shardName)) {
                // Create the read-write Tx
                final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
                assertNotNull("newReadWriteTransaction returned null", readWriteTx);
                // Do some reads on the Tx on a separate thread.
                final AtomicReference<CheckedFuture<Boolean, ReadFailedException>> txExistsFuture = new AtomicReference<>();
                final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>> txReadFuture = new AtomicReference<>();
                final AtomicReference<Exception> caughtEx = new AtomicReference<>();
                final CountDownLatch txReadsDone = new CountDownLatch(1);
                final Thread txThread = new Thread(() -> {
                    try {
                        readWriteTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
                        txExistsFuture.set(readWriteTx.exists(TestModel.TEST_PATH));
                        txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
                    } catch (Exception e) {
                        caughtEx.set(e);
                    } finally {
                        txReadsDone.countDown();
                    }
                });
                txThread.start();
                // Wait for the Tx operations to complete.
                boolean done = Uninterruptibles.awaitUninterruptibly(txReadsDone, 5, TimeUnit.SECONDS);
                if (caughtEx.get() != null) {
                    throw caughtEx.get();
                }
                assertEquals("Tx reads done", true, done);
                // At this point the Tx operations should be waiting for the
                // shard to initialize so
                // trigger the latch to let the shard recovery to continue.
                blockRecoveryLatch.countDown();
                // Wait for the reads to complete and verify.
                assertEquals("exists", true, txExistsFuture.get().checkedGet(5, TimeUnit.SECONDS));
                assertEquals("read", true, txReadFuture.get().checkedGet(5, TimeUnit.SECONDS).isPresent());
                readWriteTx.close();
            }
        }
    };
}
Also used : 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)

Example 2 with ReadFailedException

use of org.opendaylight.mdsal.common.api.ReadFailedException in project controller by opendaylight.

the class RemoteProxyTransaction method sendReadRequest.

private <T> CheckedFuture<T, ReadFailedException> sendReadRequest(final AbstractReadTransactionRequest<?> request, final Consumer<Response<?, ?>> completer, final ListenableFuture<T> future) {
    // Check if a previous operation failed. If it has, do not bother sending anything and report a failure
    final Exception local = operationFailure;
    if (local != null) {
        return Futures.immediateFailedCheckedFuture(new ReadFailedException("Previous operation failed", local));
    }
    // Make sure we send any modifications before issuing a read
    ensureFlushedBuider();
    sendRequest(request, completer);
    return MappingCheckedFuture.create(future, ReadFailedException.MAPPER);
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException)

Example 3 with ReadFailedException

use of org.opendaylight.mdsal.common.api.ReadFailedException in project controller by opendaylight.

the class NoOpTransactionContext method executeRead.

@Override
public <T> void executeRead(AbstractRead<T> readCmd, SettableFuture<T> proxyFuture) {
    LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(), readCmd.getPath());
    final Throwable t;
    if (failure instanceof NoShardLeaderException) {
        t = new DataStoreUnavailableException(failure.getMessage(), failure);
    } else {
        t = failure;
    }
    proxyFuture.setException(new ReadFailedException("Error executeRead " + readCmd.getClass().getSimpleName() + " for path " + readCmd.getPath(), t));
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) DataStoreUnavailableException(org.opendaylight.mdsal.common.api.DataStoreUnavailableException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)

Example 4 with ReadFailedException

use of org.opendaylight.mdsal.common.api.ReadFailedException in project controller by opendaylight.

the class NormalizedNodeAggregatorTest method getRootNode.

public static NormalizedNode<?, ?> getRootNode(NormalizedNode<?, ?> moduleNode, SchemaContext schemaContext) throws ReadFailedException, ExecutionException, InterruptedException {
    try (InMemoryDOMDataStore store = new InMemoryDOMDataStore("test", Executors.newSingleThreadExecutor())) {
        store.onGlobalContextUpdated(schemaContext);
        DOMStoreWriteTransaction writeTransaction = store.newWriteOnlyTransaction();
        writeTransaction.merge(YangInstanceIdentifier.of(moduleNode.getNodeType()), moduleNode);
        DOMStoreThreePhaseCommitCohort ready = writeTransaction.ready();
        ready.canCommit().get();
        ready.preCommit().get();
        ready.commit().get();
        DOMStoreReadTransaction readTransaction = store.newReadOnlyTransaction();
        CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = readTransaction.read(YangInstanceIdentifier.EMPTY);
        Optional<NormalizedNode<?, ?>> nodeOptional = read.checkedGet();
        return nodeOptional.get();
    }
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) Optional(com.google.common.base.Optional) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) InMemoryDOMDataStore(org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)

Example 5 with ReadFailedException

use of org.opendaylight.mdsal.common.api.ReadFailedException in project controller by opendaylight.

the class PrefixedShardConfigWriter method checkDefaultIsPresent.

boolean checkDefaultIsPresent() {
    final NodeIdentifierWithPredicates pag = new NodeIdentifierWithPredicates(ClusterUtils.SHARD_LIST_QNAME, ClusterUtils.SHARD_PREFIX_QNAME, YangInstanceIdentifier.EMPTY);
    final YangInstanceIdentifier defaultId = ClusterUtils.SHARD_LIST_PATH.node(pag);
    final ClientSnapshot snapshot = history.takeSnapshot();
    try {
        return snapshot.exists(defaultId).checkedGet();
    } catch (final ReadFailedException e) {
        LOG.error("Presence check of default shard in configuration failed.", e);
        return false;
    } finally {
        snapshot.abort();
    }
}
Also used : ClientSnapshot(org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)9 Test (org.junit.Test)5 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 Optional (com.google.common.base.Optional)3 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)3 AddressFromURIString (akka.actor.AddressFromURIString)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)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 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)2 TransactionChainClosedException (org.opendaylight.mdsal.common.api.TransactionChainClosedException)2 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)2 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)2 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)2 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)2 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)1 ExistsTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess)1