From: Tomas Cere Date: Tue, 1 Jun 2021 08:41:51 +0000 (+0200) Subject: Handle NetconfDocumentedExceptions correctly X-Git-Tag: v1.13.3~4 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=085b8e7324b78e8a786cd8465bef06615be16574;p=netconf.git Handle NetconfDocumentedExceptions correctly These need to be wrapped in TransactionCommitFailedException so they are handled correctly, so restconf can map these and return correct status code on failure. JIRA: NETCONF-777 Change-Id: Id4833bfe46da6f97a216163452dd2a44af599063 Signed-off-by: Tomas Cere Signed-off-by: Robert Varga (cherry picked from commit 6003f0788533a61a3e2a0f16dff94f618379677b) --- diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java index 14c19b1c26..7689c26578 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java @@ -28,6 +28,7 @@ import java.util.stream.Collectors; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.TransactionCommitFailedException; import org.opendaylight.mdsal.dom.api.DOMRpcResult; import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult; import org.opendaylight.netconf.api.DocumentedException; @@ -131,7 +132,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction { final Collection errors = result.getErrors(); if (!allWarnings(errors)) { Futures.whenAllComplete(discardAndUnlock()).run( - () -> commitResult.setException(mapRpcErrorsToNetconfDocException(errors)), + () -> commitResult.setException(toCommitFailedException(errors)), MoreExecutors.directExecutor()); return; } @@ -152,7 +153,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction { MoreExecutors.directExecutor()); } else { Futures.whenAllComplete(discardAndUnlock()).run( - () -> commitResult.setException(mapRpcErrorsToNetconfDocException(errors)), + () -> commitResult.setException(toCommitFailedException(errors)), MoreExecutors.directExecutor()); } } @@ -247,16 +248,15 @@ final class NetconfRestconfTransaction extends RestconfTransaction { } @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", - justification = "https://github.com/spotbugs/spotbugs/issues/811") - private static NetconfDocumentedException mapRpcErrorsToNetconfDocException( - final Collection errors) { + justification = "https://github.com/spotbugs/spotbugs/issues/811") + private static TransactionCommitFailedException toCommitFailedException( + final Collection errors) { DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION; DocumentedException.ErrorSeverity errSeverity = DocumentedException.ErrorSeverity.ERROR; StringJoiner msgBuilder = new StringJoiner(" "); String errorTag = "operation-failed"; for (final RpcError error : errors) { - final RpcError.ErrorType errorType = error.getErrorType(); - switch (errorType) { + switch (error.getErrorType()) { case RPC: errType = DocumentedException.ErrorType.RPC; break; @@ -271,8 +271,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction { errType = DocumentedException.ErrorType.APPLICATION; break; } - final RpcError.ErrorSeverity severity = error.getSeverity(); - switch (severity) { + switch (error.getSeverity()) { case WARNING: errSeverity = DocumentedException.ErrorSeverity.WARNING; break; @@ -285,8 +284,10 @@ final class NetconfRestconfTransaction extends RestconfTransaction { msgBuilder.add(error.getInfo()); errorTag = error.getTag(); } - return new NetconfDocumentedException("RPC during tx failed. " + msgBuilder.toString(), errType, - DocumentedException.ErrorTag.from(errorTag), errSeverity); + + return new TransactionCommitFailedException("Netconf transaction commit failed", + new NetconfDocumentedException("RPC during tx failed. " + msgBuilder.toString(), errType, + DocumentedException.ErrorTag.from(errorTag), errSeverity)); } private static void executeWithLogging(final Supplier> operation) {