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=6df2239f5140698f9072809366524d63ceeffecd;hb=21de57f022619e82a72e69aa1d4da36cff2612f2;hp=f607089dc01b9a1881ed9d0d7fda7e9f621f5195;hpb=4c0c091813aea131d32dc70c5121a450eb9b7291;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 f607089dc0..6df2239f51 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 @@ -12,12 +12,13 @@ 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 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.api.NetconfDocumentedException; 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; @@ -71,42 +72,36 @@ public class WriteCandidateTx extends AbstractWriteTx { } }; - public WriteCandidateTx(final RemoteDeviceId id, final NetconfBaseOps rpc, final boolean rollbackSupport, long requestTimeoutMillis) { - super(requestTimeoutMillis, rpc, id, rollbackSupport); + public WriteCandidateTx(final RemoteDeviceId id, final NetconfBaseOps rpc, final boolean rollbackSupport) { + super(rpc, id, rollbackSupport); } @Override protected synchronized void init() { LOG.trace("{}: Initializing {} transaction", id, getClass().getSimpleName()); - - try { - lock(); - } catch (final NetconfDocumentedException e) { - try { - LOG.warn("{}: Failed to lock candidate, attempting discard changes", id); - discardChanges(); - LOG.warn("{}: Changes discarded successfully, attempting lock", id); - lock(); - } catch (final NetconfDocumentedException secondE) { - LOG.error("{}: Failed to prepare candidate. Failed to initialize transaction", id, secondE); - throw new RuntimeException(id + ": Failed to prepare candidate. Failed to initialize transaction", secondE); - } - } + lock(); } - private void lock() throws NetconfDocumentedException { - final String operation = "Lock candidate"; - try { - invokeBlocking(operation, new Function>() { - @Override - public ListenableFuture apply(final NetconfBaseOps input) { - return perfomRequestWithTimeout(operation, input.lockCandidate(new NetconfRpcFutureCallback(operation, id))); + private void lock() { + final FutureCallback lockCandidateCallback = new FutureCallback() { + @Override + public void onSuccess(DOMRpcResult result) { + if (isSuccess(result)) { + if (LOG.isTraceEnabled()) { + LOG.trace("Lock candidate successful"); + } + } else { + LOG.warn("{}: lock candidate invoked unsuccessfully: {}", id, result.getErrors()); } - }); - } catch (final NetconfDocumentedException e) { - LOG.warn("{}: Failed to lock candidate", id, e); - throw e; - } + } + + @Override + public void onFailure(Throwable t) { + LOG.warn("Lock candidate operation failed. {}", t); + discardChanges(); + } + }; + resultsFutures.add(netOps.lockCandidate(lockCandidateCallback)); } @Override @@ -115,20 +110,6 @@ public class WriteCandidateTx extends AbstractWriteTx { cleanupOnSuccess(); } - @Override - protected void handleEditException(final YangInstanceIdentifier path, final NormalizedNode data, final NetconfDocumentedException e, final String editType) { - LOG.warn("{}: Error {} data to (candidate){}, data: {}, canceling", id, editType, path, data, e); - cancel(); - throw new RuntimeException(id + ": Error while " + editType + ": (candidate)" + path, e); - } - - @Override - protected void handleDeleteException(final YangInstanceIdentifier path, final NetconfDocumentedException e) { - LOG.warn("{}: Error deleting data (candidate){}, canceling", id, path, e); - cancel(); - throw new RuntimeException(id + ": Error while deleting (candidate)" + path, e); - } - @Override public synchronized CheckedFuture submit() { final ListenableFuture commitFutureAsVoid = Futures.transform(commit(), new Function, Void>() { @@ -156,28 +137,24 @@ public class WriteCandidateTx extends AbstractWriteTx { @Override public synchronized ListenableFuture> performCommit() { - final ListenableFuture rpcResult = netOps.commit(new NetconfRpcFutureCallback("Commit", id) { - @Override - public void onSuccess(final DOMRpcResult result) { - super.onSuccess(result); - LOG.debug("{}: Write successful, transaction: {}. Unlocking", id, getIdentifier()); - cleanupOnSuccess(); - } + resultsFutures.add(netOps.commit(new NetconfRpcFutureCallback("Commit", id))); + ListenableFuture> txResult = resultsToTxStatus(); + Futures.addCallback(txResult, new FutureCallback>() { @Override - protected void onUnsuccess(final DOMRpcResult result) { - LOG.error("{}: Write failed, transaction {}, discarding changes, unlocking: {}", id, getIdentifier(), result.getErrors()); - cleanup(); + public void onSuccess(@Nullable RpcResult result) { + cleanupOnSuccess(); } @Override - public void onFailure(final Throwable t) { - LOG.error("{}: Write failed, transaction {}, discarding changes, unlocking", id, getIdentifier(), t); + public void onFailure(Throwable t) { + // TODO If lock is cause of this failure cleanup will issue warning log + // cleanup is trying to do unlock, but this will fail cleanup(); } }); - return Futures.transform(rpcResult, RPC_RESULT_TO_TX_STATUS); + return txResult; } protected void cleanupOnSuccess() { @@ -185,19 +162,20 @@ public class WriteCandidateTx extends AbstractWriteTx { } @Override - protected void editConfig(final DataContainerChild editStructure, final Optional defaultOperation) throws NetconfDocumentedException { - final String operation = "Edit candidate"; - invokeBlocking(operation, new Function>() { - @Override - public ListenableFuture apply(final NetconfBaseOps input) { - - return perfomRequestWithTimeout(operation, defaultOperation.isPresent() - ? input.editConfigCandidate(new NetconfRpcFutureCallback(operation, id), editStructure, defaultOperation.get(), - rollbackSupport) - : input.editConfigCandidate(new NetconfRpcFutureCallback(operation, id), editStructure, - rollbackSupport)); - } - }); + protected void editConfig(final YangInstanceIdentifier path, + final Optional> data, + final DataContainerChild editStructure, + final Optional defaultOperation, + final String operation) { + + NetconfRpcFutureCallback editConfigCallback = new NetconfRpcFutureCallback("Edit candidate", id); + + if (defaultOperation.isPresent()) { + resultsFutures.add(netOps.editConfigCandidate( + editConfigCallback, editStructure, defaultOperation.get(), rollbackSupport)); + } else { + resultsFutures.add(netOps.editConfigCandidate(editConfigCallback, editStructure, rollbackSupport)); + } } /**