NETCONF-553 : Stack traces need to suppressed and error messages should 97/75597/2
authorBalaji Varadaraju <bvaradar@luminanetworks.com>
Thu, 30 Aug 2018 23:23:35 +0000 (18:23 -0500)
committerJakub Morvay <jmorvay@frinx.io>
Mon, 24 Sep 2018 12:25:40 +0000 (14:25 +0200)
be propagated for mounted devices

Traversed entire error info to capture all error messages returned by the
NETCONF device. Also suppressed the stack traces in the RESTCONF output.

Change-Id: I9afc5948a9b48c12e649b9960d011870a4d9ee73
Signed-off-by: Balaji Varadaraju <bvaradar@luminanetworks.com>
Signed-off-by: Jakub Morvay <jmorvay@frinx.io>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/AbstractWriteTx.java
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfError.java

index eb48fdbd96ba56f49e372172855823758bf7ffee..835b0506ba5210e27bea72bef7fa551eec181eff 100644 (file)
@@ -230,7 +230,7 @@ public abstract class AbstractWriteTx implements DOMDataWriteTransaction {
             public void onFailure(final Throwable throwable) {
                 final NetconfDocumentedException exception =
                         new NetconfDocumentedException(
-                                id + ":RPC during tx returned an exception",
+                                id + ":RPC during tx returned an exception" + throwable.getMessage(),
                                 new Exception(throwable),
                                 DocumentedException.ErrorType.APPLICATION,
                                 DocumentedException.ErrorTag.OPERATION_FAILED,
@@ -244,56 +244,59 @@ public abstract class AbstractWriteTx implements DOMDataWriteTransaction {
 
     private void extractResult(final List<DOMRpcResult> domRpcResults,
                                final SettableFuture<RpcResult<Void>> transformed) {
+        DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
+        DocumentedException.ErrorSeverity errSeverity = DocumentedException.ErrorSeverity.ERROR;
+        StringBuilder msgBuilder = new StringBuilder();
+        boolean errorsEncouneterd = false;
+        String errorTag = "operation-failed";
+
         for (final DOMRpcResult domRpcResult : domRpcResults) {
             if (!domRpcResult.getErrors().isEmpty()) {
+                errorsEncouneterd = true;
                 final RpcError error = domRpcResult.getErrors().iterator().next();
                 final RpcError.ErrorType errorType = error.getErrorType();
-                final DocumentedException.ErrorType eType;
                 switch (errorType) {
                     case RPC:
-                        eType = DocumentedException.ErrorType.RPC;
+                        errType = DocumentedException.ErrorType.RPC;
                         break;
                     case PROTOCOL:
-                        eType = DocumentedException.ErrorType.PROTOCOL;
+                        errType = DocumentedException.ErrorType.PROTOCOL;
                         break;
                     case TRANSPORT:
-                        eType = DocumentedException.ErrorType.TRANSPORT;
+                        errType = DocumentedException.ErrorType.TRANSPORT;
                         break;
                     case APPLICATION:
-                        eType = DocumentedException.ErrorType.APPLICATION;
+                        errType = DocumentedException.ErrorType.APPLICATION;
                         break;
                     default:
-                        eType = DocumentedException.ErrorType.APPLICATION;
+                        errType = DocumentedException.ErrorType.APPLICATION;
                         break;
                 }
                 final RpcError.ErrorSeverity severity = error.getSeverity();
-                final DocumentedException.ErrorSeverity eSeverity;
                 switch (severity) {
                     case ERROR:
-                        eSeverity = DocumentedException.ErrorSeverity.ERROR;
+                        errSeverity = DocumentedException.ErrorSeverity.ERROR;
                         break;
                     case WARNING:
-                        eSeverity = DocumentedException.ErrorSeverity.WARNING;
+                        errSeverity = DocumentedException.ErrorSeverity.WARNING;
                         break;
                     default:
-                        eSeverity = DocumentedException.ErrorSeverity.ERROR;
+                        errSeverity = DocumentedException.ErrorSeverity.ERROR;
                         break;
                 }
-                final String message;
-                if (error.getMessage() == null || error.getMessage().isEmpty()) {
-                    message = id + ":RPC during tx failed";
-                } else {
-                    message = error.getMessage();
-                }
-                final NetconfDocumentedException exception = new NetconfDocumentedException(message,
-                        eType,
-                        DocumentedException.ErrorTag.from(error.getTag()),
-                        eSeverity);
-                transformed.setException(exception);
-                return;
+                msgBuilder.append(error.getMessage());
+                errorTag = error.getTag();
             }
         }
-
+        if (errorsEncouneterd) {
+            final NetconfDocumentedException exception = new NetconfDocumentedException(id
+                    + ":RPC during tx failed. " + msgBuilder.toString(),
+                    errType,
+                    DocumentedException.ErrorTag.from(errorTag),
+                    errSeverity);
+            transformed.setException(exception);
+            return;
+        }
         transformed.set(RpcResultBuilder.<Void>success().build());
     }
 
index 590ddf3b5a92daffca3d9bfefd23ef25de91cbf7..fcf350f0d87489e00ed02f63aac81a23c6121e01 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.restconf.common.errors;
 
 import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
 import java.io.Serializable;
 import java.util.Locale;
 import org.opendaylight.yangtools.yang.common.RpcError;
@@ -226,7 +225,7 @@ public class RestconfError implements Serializable {
         String localErrorInfo = null;
         if (rpcError.getInfo() == null) {
             if (rpcError.getCause() != null) {
-                localErrorInfo = Throwables.getStackTraceAsString(rpcError.getCause());
+                localErrorInfo = rpcError.getCause().getMessage();
             } else if (rpcError.getSeverity() != null) {
                 localErrorInfo = "<severity>" + rpcError.getSeverity().toString().toLowerCase(Locale.ROOT)
                         + "</severity>";