+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
package org.opendaylight.controller.md.sal.dom.store.impl;
import static com.google.common.base.Preconditions.checkState;
+
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.sal.core.spi.data.AbstractDOMStoreTransaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION", justification = "Void is the only allowed value")
class InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMStoreThreePhaseCommitCohort.class);
private static final ListenableFuture<Void> SUCCESSFUL_FUTURE = Futures.immediateFuture(null);
private final DataTreeModification modification;
private final InMemoryDOMDataStore store;
private DataTreeCandidate candidate;
+ private final Exception operationError;
- public InMemoryDOMStoreThreePhaseCommitCohort(final InMemoryDOMDataStore store, final SnapshotBackedWriteTransaction<String> writeTransaction, final DataTreeModification modification) {
+ InMemoryDOMStoreThreePhaseCommitCohort(final InMemoryDOMDataStore store,
+ final SnapshotBackedWriteTransaction<String> writeTransaction, final DataTreeModification modification,
+ final Exception operationError) {
this.transaction = Preconditions.checkNotNull(writeTransaction);
this.modification = Preconditions.checkNotNull(modification);
this.store = Preconditions.checkNotNull(store);
+ this.operationError = operationError;
}
private static void warnDebugContext(final AbstractDOMStoreTransaction<?> transaction) {
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public final ListenableFuture<Boolean> canCommit() {
+ if (operationError != null) {
+ return Futures.immediateFailedFuture(operationError);
+ }
+
try {
store.validate(modification);
LOG.debug("Store Transaction: {} can be committed", getTransaction().getIdentifier());
// precondition log, it should allow us to understand what went on.
LOG.trace("Store Tx: {} modifications: {} tree: {}", modification, store);
- return Futures.immediateFailedFuture(new TransactionCommitFailedException("Data did not pass validation.", e));
- } catch (Exception e) {
+ return Futures.immediateFailedFuture(new TransactionCommitFailedException(
+ "Data did not pass validation.", e));
+ } catch (RuntimeException e) {
LOG.warn("Unexpected failure in validation phase", e);
return Futures.immediateFailedFuture(e);
}
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public final ListenableFuture<Void> preCommit() {
try {
candidate = store.prepare(modification);
return SUCCESSFUL_FUTURE;
- } catch (Exception e) {
+ } catch (RuntimeException e) {
LOG.warn("Unexpected failure in pre-commit phase", e);
return Futures.immediateFailedFuture(e);
}
store.commit(candidate);
return SUCCESSFUL_FUTURE;
}
-}
\ No newline at end of file
+}
+