use of org.opendaylight.mdsal.common.api.DataStoreUnavailableException 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.common.api.DataStoreUnavailableException 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.DataStoreUnavailableException in project controller by opendaylight.
the class ConcurrentDOMDataBrokerTest method testSubmitWithCanCommitDataStoreUnavailableException.
@Test
public void testSubmitWithCanCommitDataStoreUnavailableException() throws Exception {
doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
doReturn(Futures.immediateFuture(null)).when(mockCohort1).abort();
NoShardLeaderException rootCause = new NoShardLeaderException("mock");
DataStoreUnavailableException cause = new DataStoreUnavailableException(rootCause.getMessage(), rootCause);
doReturn(Futures.immediateFailedFuture(rootCause)).when(mockCohort2).canCommit();
doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(transaction, Arrays.asList(mockCohort1, mockCohort2));
assertFailure(future, cause, mockCohort1, mockCohort2);
}
Aggregations