package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
-import com.google.common.base.Function;
import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfRpcFutureCallback;
import org.slf4j.LoggerFactory;
/**
- * Tx implementation for netconf devices that support only candidate datastore and no writable running
+ * Tx implementation for netconf devices that support only candidate datastore and no writable running.
* The sequence goes as:
* <ol>
* <li>Lock candidate datastore on tx construction
* </li>
* <li>Edit-config in candidate N times
* <ul>
- * <li>If any issue occurs during edit, datastore is discarded using discard-changes rpc, unlocked and an exception is thrown async</li>
+ * <li>If any issue occurs during edit,
+ * datastore is discarded using discard-changes rpc, unlocked and an exception is thrown async</li>
* </ul>
* </li>
* <li>Commit and Unlock candidate datastore async</li>
private void lock() {
final FutureCallback<DOMRpcResult> lockCandidateCallback = new FutureCallback<DOMRpcResult>() {
@Override
- public void onSuccess(final DOMRpcResult result) {
+ public void onSuccess(@Nonnull final DOMRpcResult result) {
if (isSuccess(result)) {
if (LOG.isTraceEnabled()) {
LOG.trace("Lock candidate successful");
}
@Override
- public void onFailure(final Throwable t) {
- LOG.warn("Lock candidate operation failed. {}", t);
+ public void onFailure(final Throwable throwable) {
+ LOG.warn("Lock candidate operation failed. {}", throwable);
discardChanges();
}
};
cleanupOnSuccess();
}
- @Override
- public synchronized CheckedFuture<Void, TransactionCommitFailedException> submit() {
- final ListenableFuture<Void> commitFutureAsVoid = Futures.transform(commit(), new Function<RpcResult<TransactionStatus>, Void>() {
- @Override
- public Void apply(final RpcResult<TransactionStatus> input) {
- Preconditions.checkArgument(input.isSuccessful() && input.getErrors().isEmpty(), "Submit failed with errors: %s", input.getErrors());
- return null;
- }
- });
-
- return Futures.makeChecked(commitFutureAsVoid, new Function<Exception, TransactionCommitFailedException>() {
- @Override
- public TransactionCommitFailedException apply(final Exception input) {
- return new TransactionCommitFailedException("Submit of transaction " + getIdentifier() + " failed", input);
- }
- });
- }
-
/**
- * This has to be non blocking since it is called from a callback on commit and its netty threadpool that is really sensitive to blocking calls
+ * This has to be non blocking since it is called from a callback on commit
+ * and its netty threadpool that is really sensitive to blocking calls.
*/
private void discardChanges() {
netOps.discardChanges(new NetconfRpcFutureCallback("Discarding candidate", id));
}
@Override
- public synchronized ListenableFuture<RpcResult<TransactionStatus>> performCommit() {
+ public synchronized ListenableFuture<RpcResult<Void>> performCommit() {
resultsFutures.add(netOps.commit(new NetconfRpcFutureCallback("Commit", id)));
- final ListenableFuture<RpcResult<TransactionStatus>> txResult = resultsToTxStatus();
+ final ListenableFuture<RpcResult<Void>> txResult = resultsToTxStatus();
- Futures.addCallback(txResult, new FutureCallback<RpcResult<TransactionStatus>>() {
+ Futures.addCallback(txResult, new FutureCallback<RpcResult<Void>>() {
@Override
- public void onSuccess(@Nullable final RpcResult<TransactionStatus> result) {
+ public void onSuccess(@Nullable final RpcResult<Void> result) {
cleanupOnSuccess();
}
@Override
- public void onFailure(final Throwable t) {
+ public void onFailure(final Throwable throwable) {
// TODO If lock is cause of this failure cleanup will issue warning log
// cleanup is trying to do unlock, but this will fail
cleanup();
}
- });
+ }, MoreExecutors.directExecutor());
return txResult;
}
}
/**
- * This has to be non blocking since it is called from a callback on commit and its netty threadpool that is really sensitive to blocking calls
+ * This has to be non blocking since it is called from a callback on commit
+ * and its netty threadpool that is really sensitive to blocking calls.
*/
private void unlock() {
netOps.unlockCandidate(new NetconfRpcFutureCallback("Unlock candidate", id));