use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.
the class TransactionProxyTest method testReadyWithReadWrite.
@Test
public void testReadyWithReadWrite() throws Exception {
ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
expectBatchedModificationsReady(actorRef, true);
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
transactionProxy.read(TestModel.TEST_PATH);
transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
assertTrue(ready instanceof SingleCommitCohortProxy);
verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
verifyBatchedModifications(batchedModifications.get(0), true, true, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
assertEquals("getTotalMessageCount", 1, batchedModifications.get(0).getTotalMessagesSent());
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.
the class ConcurrentDOMDataBroker method doCanCommit.
private void doCanCommit(final AsyncNotifyingSettableFuture clientSubmitFuture, final DOMDataTreeWriteTransaction transaction, final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
final long startTime = System.nanoTime();
final Iterator<DOMStoreThreePhaseCommitCohort> cohortIterator = cohorts.iterator();
// Not using Futures.allAsList here to avoid its internal overhead.
FutureCallback<Boolean> futureCallback = new FutureCallback<Boolean>() {
@Override
public void onSuccess(final Boolean result) {
if (result == null || !result) {
handleException(clientSubmitFuture, transaction, cohorts, CAN_COMMIT, CAN_COMMIT_ERROR_MAPPER, new TransactionCommitFailedException("Can Commit failed, no detailed cause available."));
} else if (!cohortIterator.hasNext()) {
// All cohorts completed successfully - we can move on to the preCommit phase
doPreCommit(startTime, clientSubmitFuture, transaction, cohorts);
} else {
Futures.addCallback(cohortIterator.next().canCommit(), this, MoreExecutors.directExecutor());
}
}
@Override
public void onFailure(final Throwable failure) {
handleException(clientSubmitFuture, transaction, cohorts, CAN_COMMIT, CAN_COMMIT_ERROR_MAPPER, failure);
}
};
ListenableFuture<Boolean> canCommitFuture = cohortIterator.next().canCommit();
Futures.addCallback(canCommitFuture, futureCallback, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.
the class ConcurrentDOMDataBroker method handleException.
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "Pertains to the assignment of the 'clientException' var. FindBugs flags this as an " + "uncomfirmed cast but the generic type in TransactionCommitFailedExceptionMapper is " + "TransactionCommitFailedException and thus should be deemed as confirmed.")
private static void handleException(final AsyncNotifyingSettableFuture clientSubmitFuture, final DOMDataTreeWriteTransaction transaction, final Collection<DOMStoreThreePhaseCommitCohort> cohorts, final String phase, final TransactionCommitFailedExceptionMapper exMapper, final Throwable throwable) {
if (clientSubmitFuture.isDone()) {
// We must have had failures from multiple cohorts.
return;
}
// Use debug instead of warn level here because this exception gets propagate back to the caller via the Future
LOG.debug("Tx: {} Error during phase {}, starting Abort", transaction.getIdentifier(), phase, throwable);
// Transaction failed - tell all cohorts to abort.
@SuppressWarnings("unchecked") ListenableFuture<Void>[] canCommitFutures = new ListenableFuture[cohorts.size()];
int index = 0;
for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
canCommitFutures[index++] = cohort.abort();
}
// Propagate the original exception
final Exception e;
if (throwable instanceof NoShardLeaderException || throwable instanceof ShardLeaderNotRespondingException) {
e = new DataStoreUnavailableException(throwable.getMessage(), throwable);
} else if (throwable instanceof Exception) {
e = (Exception) throwable;
} else {
e = new RuntimeException("Unexpected error occurred", throwable);
}
clientSubmitFuture.setException(exMapper.apply(e));
ListenableFuture<List<Void>> combinedFuture = Futures.allAsList(canCommitFutures);
Futures.addCallback(combinedFuture, new FutureCallback<List<Void>>() {
@Override
public void onSuccess(final List<Void> notUsed) {
// Propagate the original exception to the client.
LOG.debug("Tx: {} aborted successfully", transaction.getIdentifier());
}
@Override
public void onFailure(final Throwable failure) {
LOG.error("Tx: {} Error during Abort.", transaction.getIdentifier(), failure);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method writeCarsNodeAndVerify.
private static NormalizedNode<?, ?> writeCarsNodeAndVerify(AbstractDataStore writeToStore, AbstractDataStore readFromStore) throws Exception {
DOMStoreWriteTransaction writeTx = writeToStore.newWriteOnlyTransaction();
NormalizedNode<?, ?> carsNode = CarsModel.create();
writeTx.write(CarsModel.BASE_PATH, carsNode);
DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
Boolean canCommit = cohort.canCommit().get(7, TimeUnit.SECONDS);
assertEquals("canCommit", TRUE, canCommit);
cohort.preCommit().get(5, TimeUnit.SECONDS);
cohort.commit().get(5, TimeUnit.SECONDS);
readCarsNodeAndVerify(readFromStore, carsNode);
return carsNode;
}
use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort 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();
}
}
Aggregations