Bump upstreams to SNAPSHOTs
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / sal / tx / AbstractWriteTx.java
index 98fb17d8563f1156c3481e007df15ad7946ef3c7..924e2216ed45d788427e91a0ade1eb605af2518f 100644 (file)
@@ -18,7 +18,6 @@ import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -27,12 +26,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;
@@ -56,9 +56,10 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
     protected volatile boolean finished = false;
     protected final boolean isLockAllowed;
 
-    public AbstractWriteTx(final RemoteDeviceId id, final NetconfBaseOps netconfOps, final boolean rollbackSupport,
+    @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Behavior-only subclasses")
+    AbstractWriteTx(final RemoteDeviceId id, final NetconfBaseOps netconfOps, final boolean rollbackSupport,
             final boolean isLockAllowed) {
-        this.netOps = netconfOps;
+        netOps = netconfOps;
         this.id = id;
         this.rollbackSupport = rollbackSupport;
         this.isLockAllowed = isLockAllowed;
@@ -88,6 +89,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
         return true;
     }
 
+    // FIXME: only called from ctor which needs @SuppressDBWarnings. Refactor class hierarchy without this method (here)
     protected abstract void init();
 
     protected abstract void cleanup();
@@ -109,7 +111,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
             return;
         }
 
-        final DataContainerChild editStructure = netOps.createEditConfigStrcture(Optional.ofNullable(data),
+        final DataContainerChild editStructure = netOps.createEditConfigStructure(Optional.ofNullable(data),
                         Optional.of(ModifyAction.REPLACE), path);
         editConfig(path, Optional.ofNullable(data), editStructure, Optional.empty(), "put");
     }
@@ -126,7 +128,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
             return;
         }
 
-        final DataContainerChild editStructure =  netOps.createEditConfigStrcture(Optional.ofNullable(data),
+        final DataContainerChild editStructure =  netOps.createEditConfigStructure(Optional.ofNullable(data),
             Optional.empty(), path);
         editConfig(path, Optional.ofNullable(data), editStructure, Optional.empty(), "merge");
     }
@@ -143,7 +145,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.createEditConfigStructure(Optional.empty(),
                         Optional.of(ModifyAction.DELETE), path);
         editConfig(path, Optional.empty(), editStructure, Optional.of(ModifyAction.NONE), "delete");
     }
@@ -155,10 +157,9 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
             @Override
             public void onSuccess(final RpcResult<Void> result) {
                 if (!result.isSuccessful()) {
-                    final Collection<RpcError> errors = result.getErrors();
                     resultFuture.setException(new TransactionCommitFailedException(
                         String.format("Commit of transaction %s failed", getIdentifier()),
-                            errors.toArray(new RpcError[errors.size()])));
+                        result.getErrors().toArray(new RpcError[0])));
                     return;
                 }
 
@@ -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,
-                                ErrorSeverity.ERROR);
+                                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
                 transformed.setException(exception);
             }
         }, MoreExecutors.directExecutor());
@@ -240,51 +240,29 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
         return transformed;
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            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;
+        ErrorType errType = ErrorType.APPLICATION;
         ErrorSeverity errSeverity = ErrorSeverity.ERROR;
         StringBuilder msgBuilder = new StringBuilder();
         boolean errorsEncouneterd = false;
-        String errorTag = "operation-failed";
+        ErrorTag errorTag = 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();
-                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;
-                }
 
-                errSeverity = error.getSeverity().toNetconf();
+                errType = error.getErrorType();
+                errSeverity = error.getSeverity();
                 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, errorTag, errSeverity);
             transformed.setException(exception);
             return;
         }