X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2Fsal%2Ftx%2FWriteCandidateTx.java;h=012cbac8c50c78315468fbbba8894045958690f2;hb=a0833fb27c69d919a4420c6ecbd11a3b2a1119cb;hp=1d429022c1da73a611224a993030f2f2fa776987;hpb=1cf7c291c406d759c55c5ed0b15d28b32926e312;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/WriteCandidateTx.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/WriteCandidateTx.java index 1d429022c1..012cbac8c5 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/WriteCandidateTx.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/WriteCandidateTx.java @@ -8,18 +8,14 @@ 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 java.util.Optional; +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.mdsal.dom.api.DOMRpcResult; import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps; import org.opendaylight.netconf.sal.connect.netconf.util.NetconfRpcFutureCallback; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; @@ -56,8 +52,13 @@ public class WriteCandidateTx extends AbstractWriteTx { private static final Logger LOG = LoggerFactory.getLogger(WriteCandidateTx.class); - public WriteCandidateTx(final RemoteDeviceId id, final NetconfBaseOps rpc, final boolean rollbackSupport) { - super(rpc, id, rollbackSupport); + public WriteCandidateTx(final RemoteDeviceId id, final NetconfBaseOps netconfOps, final boolean rollbackSupport) { + this(id, netconfOps, rollbackSupport, true); + } + + public WriteCandidateTx(RemoteDeviceId id, NetconfBaseOps netconfOps, boolean rollbackSupport, + boolean isLockAllowed) { + super(id, netconfOps, rollbackSupport, isLockAllowed); } @Override @@ -67,9 +68,13 @@ public class WriteCandidateTx extends AbstractWriteTx { } private void lock() { + if (!isLockAllowed) { + LOG.trace("Lock is not allowed."); + return; + } final FutureCallback lockCandidateCallback = new FutureCallback() { @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"); @@ -81,7 +86,7 @@ public class WriteCandidateTx extends AbstractWriteTx { @Override public void onFailure(final Throwable throwable) { - LOG.warn("Lock candidate operation failed. {}", throwable); + LOG.warn("Lock candidate operation failed", throwable); discardChanges(); } }; @@ -94,19 +99,6 @@ public class WriteCandidateTx extends AbstractWriteTx { cleanupOnSuccess(); } - @Override - public synchronized CheckedFuture submit() { - final ListenableFuture commitFutureAsVoid = Futures.transform(commit(), - (Function, Void>) input -> { - Preconditions.checkArgument(input.isSuccessful() && input.getErrors().isEmpty(), - "Submit failed with errors: %s", input.getErrors()); - return null; - }); - - return Futures.makeChecked(commitFutureAsVoid, input -> 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. @@ -116,13 +108,13 @@ public class WriteCandidateTx extends AbstractWriteTx { } @Override - public synchronized ListenableFuture> performCommit() { + public synchronized ListenableFuture> performCommit() { resultsFutures.add(netOps.commit(new NetconfRpcFutureCallback("Commit", id))); - final ListenableFuture> txResult = resultsToTxStatus(); + final ListenableFuture> txResult = resultsToTxStatus(); - Futures.addCallback(txResult, new FutureCallback>() { + Futures.addCallback(txResult, new FutureCallback>() { @Override - public void onSuccess(@Nullable final RpcResult result) { + public void onSuccess(@Nullable final RpcResult result) { cleanupOnSuccess(); } @@ -163,7 +155,11 @@ public class WriteCandidateTx extends AbstractWriteTx { * and its netty threadpool that is really sensitive to blocking calls. */ private void unlock() { - netOps.unlockCandidate(new NetconfRpcFutureCallback("Unlock candidate", id)); + if (isLockAllowed) { + netOps.unlockCandidate(new NetconfRpcFutureCallback("Unlock candidate", id)); + } else { + LOG.trace("Unlock is not allowed: {}", id); + } } }