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();
}
}
};
}
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);
}
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));
}
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();
}
}
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();
}
}
Aggregations