Remove DocumentedException.ErrorTag
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / sal / tx / AbstractWriteTx.java
index 874ad32ff2e77cba99e0b9afdba558c30c06c2d8..3e6201df86c692ae605c7a35e312768c52c207e1 100644 (file)
@@ -27,11 +27,13 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.ModifyAction;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -49,7 +51,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
     protected final RemoteDeviceId id;
     protected final NetconfBaseOps netOps;
     protected final boolean rollbackSupport;
-    protected final List<ListenableFuture<DOMRpcResult>> resultsFutures = new ArrayList<>();
+    protected final List<ListenableFuture<? extends DOMRpcResult>> resultsFutures = new ArrayList<>();
     private final List<TxListener> listeners = new CopyOnWriteArrayList<>();
     // Allow commit to be called only once
     protected volatile boolean finished = false;
@@ -98,7 +100,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
 
     @Override
     public synchronized void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
-                                 final NormalizedNode<?, ?> data) {
+                                 final NormalizedNode data) {
         checkEditable(store);
 
         // Trying to write only mixin nodes (not visible when serialized).
@@ -108,14 +110,14 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
             return;
         }
 
-        final DataContainerChild<?, ?> editStructure = netOps.createEditConfigStrcture(Optional.ofNullable(data),
+        final DataContainerChild editStructure = netOps.createEditConfigStrcture(Optional.ofNullable(data),
                         Optional.of(ModifyAction.REPLACE), path);
         editConfig(path, Optional.ofNullable(data), editStructure, Optional.empty(), "put");
     }
 
     @Override
     public synchronized void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
-                                   final NormalizedNode<?, ?> data) {
+                                   final NormalizedNode data) {
         checkEditable(store);
 
         // Trying to write only mixin nodes (not visible when serialized).
@@ -125,7 +127,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
             return;
         }
 
-        final DataContainerChild<?, ?> editStructure =  netOps.createEditConfigStrcture(Optional.ofNullable(data),
+        final DataContainerChild editStructure =  netOps.createEditConfigStrcture(Optional.ofNullable(data),
             Optional.empty(), path);
         editConfig(path, Optional.ofNullable(data), editStructure, Optional.empty(), "merge");
     }
@@ -133,8 +135,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
     /**
      * Check whether the data to be written consists only from mixins.
      */
-    private static boolean containsOnlyNonVisibleData(final YangInstanceIdentifier path,
-                                                      final NormalizedNode<?, ?> data) {
+    private static boolean containsOnlyNonVisibleData(final YangInstanceIdentifier path, final NormalizedNode data) {
         // There's only one such case:top level list (pathArguments == 1 && data is Mixin)
         // any other mixin nodes are contained by a "regular" node thus visible when serialized
         return path.getPathArguments().size() == 1 && data instanceof MixinNode;
@@ -143,7 +144,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
     @Override
     public synchronized void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
         checkEditable(store);
-        final DataContainerChild<?, ?> editStructure = netOps.createEditConfigStrcture(Optional.empty(),
+        final DataContainerChild editStructure = netOps.createEditConfigStrcture(Optional.empty(),
                         Optional.of(ModifyAction.DELETE), path);
         editConfig(path, Optional.empty(), editStructure, Optional.of(ModifyAction.NONE), "delete");
     }
@@ -209,8 +210,8 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
                 "Can edit only configuration data, not %s", store);
     }
 
-    protected abstract void editConfig(YangInstanceIdentifier path, Optional<NormalizedNode<?, ?>> data,
-                                       DataContainerChild<?, ?> editStructure,
+    protected abstract void editConfig(YangInstanceIdentifier path, Optional<NormalizedNode> data,
+                                       DataContainerChild editStructure,
                                        Optional<ModifyAction> defaultOperation, String operation);
 
     protected ListenableFuture<RpcResult<Void>> resultsToTxStatus() {
@@ -229,10 +230,9 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
                 final NetconfDocumentedException exception =
                         new NetconfDocumentedException(
                                 id + ":RPC during tx returned an exception" + throwable.getMessage(),
+                                // FIXME: add proper unmask/wrap to ExecutionException
                                 new Exception(throwable),
-                                DocumentedException.ErrorType.APPLICATION,
-                                DocumentedException.ErrorTag.OPERATION_FAILED,
-                                DocumentedException.ErrorSeverity.ERROR);
+                                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
                 transformed.setException(exception);
             }
         }, MoreExecutors.directExecutor());
@@ -244,8 +244,8 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
             justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private void extractResult(final List<DOMRpcResult> domRpcResults,
                                final SettableFuture<RpcResult<Void>> transformed) {
-        DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
-        DocumentedException.ErrorSeverity errSeverity = DocumentedException.ErrorSeverity.ERROR;
+        ErrorType errType = ErrorType.APPLICATION;
+        ErrorSeverity errSeverity = ErrorSeverity.ERROR;
         StringBuilder msgBuilder = new StringBuilder();
         boolean errorsEncouneterd = false;
         String errorTag = "operation-failed";
@@ -254,46 +254,17 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
             if (!domRpcResult.getErrors().isEmpty()) {
                 errorsEncouneterd = true;
                 final RpcError error = domRpcResult.getErrors().iterator().next();
-                final RpcError.ErrorType errorType = error.getErrorType();
-                switch (errorType) {
-                    case RPC:
-                        errType = DocumentedException.ErrorType.RPC;
-                        break;
-                    case PROTOCOL:
-                        errType = DocumentedException.ErrorType.PROTOCOL;
-                        break;
-                    case TRANSPORT:
-                        errType = DocumentedException.ErrorType.TRANSPORT;
-                        break;
-                    case APPLICATION:
-                        errType = DocumentedException.ErrorType.APPLICATION;
-                        break;
-                    default:
-                        errType = DocumentedException.ErrorType.APPLICATION;
-                        break;
-                }
-                final RpcError.ErrorSeverity severity = error.getSeverity();
-                switch (severity) {
-                    case ERROR:
-                        errSeverity = DocumentedException.ErrorSeverity.ERROR;
-                        break;
-                    case WARNING:
-                        errSeverity = DocumentedException.ErrorSeverity.WARNING;
-                        break;
-                    default:
-                        errSeverity = DocumentedException.ErrorSeverity.ERROR;
-                        break;
-                }
+
+                errType = error.getErrorType().toNetconf();
+                errSeverity = error.getSeverity().toNetconf();
                 msgBuilder.append(error.getMessage());
+                msgBuilder.append(error.getInfo());
                 errorTag = error.getTag();
             }
         }
         if (errorsEncouneterd) {
-            final NetconfDocumentedException exception = new NetconfDocumentedException(id
-                    + ":RPC during tx failed. " + msgBuilder.toString(),
-                    errType,
-                    DocumentedException.ErrorTag.from(errorTag),
-                    errSeverity);
+            final NetconfDocumentedException exception = new NetconfDocumentedException(
+                    id + ":RPC during tx failed. " + msgBuilder, errType, new ErrorTag(errorTag), errSeverity);
             transformed.setException(exception);
             return;
         }