Search in sources :

Example 1 with DataStoreUnavailableException

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());
}
Also used : DataStoreUnavailableException(org.opendaylight.mdsal.common.api.DataStoreUnavailableException) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) DataStoreUnavailableException(org.opendaylight.mdsal.common.api.DataStoreUnavailableException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with DataStoreUnavailableException

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));
}
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 3 with DataStoreUnavailableException

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);
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) DataStoreUnavailableException(org.opendaylight.mdsal.common.api.DataStoreUnavailableException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) Test(org.junit.Test)

Aggregations

NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)3 DataStoreUnavailableException (org.opendaylight.mdsal.common.api.DataStoreUnavailableException)3 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 List (java.util.List)1 Test (org.junit.Test)1 ShardLeaderNotRespondingException (org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException)1 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)1 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)1