Remove DocumentedException.ErrorSeverity 26/97026/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Jul 2021 13:22:59 +0000 (15:22 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Jul 2021 19:30:28 +0000 (21:30 +0200)
Use ErrorServerity from yang-common, eliminating some amount of
duplication. This also allows us to take advantage of bidirectional
mapping to (now legacy) RpcError.ErrorSeverity.

Also modernize test suite to perform correct asserts.

JIRA: NETCONF-793
Change-Id: Ie7e592233e6a948a9a991e4309315e1fb857b8d2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
44 files changed:
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractConfigOperation.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfig.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/DiscardChanges.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Lock.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Unlock.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Validate.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/AbstractGet.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/Get.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/GetConfig.java
netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfigTest.java
netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java
netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpcTest.java
netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/ValidateTest.java
netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/GetSchema.java
netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java
netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfDocumentedException.java
netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/MissingNameSpaceException.java
netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/UnexpectedElementException.java
netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/UnexpectedNamespaceException.java
netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlElement.java
netconf/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionListener.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/mapping/operations/DefaultCloseSession.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/mapping/operations/DefaultStartExi.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/util/DeserializerExceptionHandler.java
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/mapping/operations/DefaultCloseSessionTest.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/netconf/ProxyNetconfServiceTest.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/ProxyReadWriteTransactionTest.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperation.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/AbstractWriteTx.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfMessageTransformUtil.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/customrpc/SettableRpc.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/Get.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableRpc.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java

index e41f019c9fdb37ceed08785023127ab4edb1d880..1a7c42d699cd108bfeb0097e5d5ceb8ae32efcc7 100644 (file)
@@ -18,9 +18,9 @@ import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index f6b827c25296bf565ef889bfed0739723cb46029..5201ec112e2148736d2c3ee3f7d65d606c16cf46 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -62,7 +63,7 @@ abstract class AbstractConfigOperation extends AbstractSingletonNetconfOperation
             throw new DocumentedException("Invalid RPC, neither <config> not <url> element is present",
                 DocumentedException.ErrorType.PROTOCOL,
                 DocumentedException.ErrorTag.MISSING_ELEMENT,
-                DocumentedException.ErrorSeverity.ERROR);
+                ErrorSeverity.ERROR);
         }
 
         final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
@@ -86,17 +87,17 @@ abstract class AbstractConfigOperation extends AbstractSingletonNetconfOperation
             throw new DocumentedException(url + " URL is invalid or unsupported", e,
                 DocumentedException.ErrorType.APPLICATION,
                 DocumentedException.ErrorTag.INVALID_VALUE,
-                DocumentedException.ErrorSeverity.ERROR);
+                ErrorSeverity.ERROR);
         } catch (IOException e) {
-            throw new DocumentedException("Could not open URL:" + url, e,
+            throw new DocumentedException("Could not open URL " + url, e,
                 DocumentedException.ErrorType.APPLICATION,
                 DocumentedException.ErrorTag.OPERATION_FAILED,
-                DocumentedException.ErrorSeverity.ERROR);
+                ErrorSeverity.ERROR);
         } catch (SAXException e) {
             throw new DocumentedException("Could not parse XML at" + url, e,
                 DocumentedException.ErrorType.APPLICATION,
                 DocumentedException.ErrorTag.OPERATION_FAILED,
-                DocumentedException.ErrorSeverity.ERROR);
+                ErrorSeverity.ERROR);
         }
     }
 
index c3e888c16505fe745ecc719dfaca374326558dad..f5126387b1ce4eb66829ce539414aeba92959334 100644 (file)
@@ -11,17 +11,16 @@ import com.google.common.collect.ImmutableMap;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.Optional;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
@@ -106,10 +105,8 @@ abstract class AbstractEdit extends AbstractConfigOperation {
         final NodeList elementsByTagName = getElementsByTagName(operationElement, TARGET_KEY);
         // Direct lookup instead of using XmlElement class due to performance
         if (elementsByTagName.getLength() == 0) {
-            final Map<String, String> errorInfo = ImmutableMap.of("bad-attribute", TARGET_KEY, "bad-element",
-                operationName);
             throw new DocumentedException("Missing target element", ErrorType.PROTOCOL, ErrorTag.MISSING_ATTRIBUTE,
-                ErrorSeverity.ERROR, errorInfo);
+                ErrorSeverity.ERROR, ImmutableMap.of("bad-attribute", TARGET_KEY, "bad-element", operationName));
         } else if (elementsByTagName.getLength() > 1) {
             throw new DocumentedException("Multiple target elements", ErrorType.RPC, ErrorTag.UNKNOWN_ATTRIBUTE,
                 ErrorSeverity.ERROR);
index 5d9c043c71cc530d9ff6619a8da57025606099cc..cebf3e5590dc8ec1ca3bbf6bbfe5b8232c5d3c15 100644 (file)
@@ -26,7 +26,6 @@ import javax.xml.transform.dom.DOMResult;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
@@ -34,6 +33,7 @@ import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
@@ -125,7 +125,7 @@ public final class CopyConfig extends AbstractEdit {
             throw new DocumentedException("<source> element is missing",
                 DocumentedException.ErrorType.PROTOCOL,
                 DocumentedException.ErrorTag.MISSING_ELEMENT,
-                DocumentedException.ErrorSeverity.ERROR);
+                ErrorSeverity.ERROR);
         }
 
         return sourceElement.get();
index 726a1606830a57bfc4a79429fb0703fb2759a944..ea9ad094fa7f741bfcf08010f008cb21a16907ff 100644 (file)
@@ -10,13 +10,13 @@ package org.opendaylight.netconf.mdsal.connector.ops;
 import java.util.HashMap;
 import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -57,5 +57,4 @@ public class DiscardChanges extends AbstractSingletonNetconfOperation {
     protected String getOperationName() {
         return OPERATION_NAME;
     }
-
 }
index 9e85e5cccf0ccf35901e318289f759e8557ac19d..6b5f080499383283816dd6a1d99338f0ac6abeb7 100644 (file)
@@ -7,14 +7,14 @@
  */
 package org.opendaylight.netconf.mdsal.connector.ops;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+
 import java.util.List;
 import java.util.ListIterator;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.ModifyAction;
@@ -22,6 +22,7 @@ import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
@@ -146,7 +147,7 @@ public final class EditConfig extends AbstractEdit {
                 .getDataSchemaNode();
 
             // we should have the schema node that points to the parent list now, enforce it
-            Preconditions.checkState(schemaNode instanceof ListSchemaNode, "Schema node is not pointing to a list.");
+            checkState(schemaNode instanceof ListSchemaNode, "Schema node is not pointing to a list.");
 
             //merge empty ordered or unordered map
             if (((ListSchemaNode) schemaNode).isUserOrdered()) {
index aac3f1e87506c80f3bcde22926bae4d07857cf8b..6518fa4d5df11f98410b106a6d29c8456161d42a 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -42,7 +43,7 @@ public class Lock extends AbstractSingletonNetconfOperation {
 
         throw new DocumentedException("Unable to lock " + targetDatastore + " datastore",
                 DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
-                DocumentedException.ErrorSeverity.ERROR);
+                ErrorSeverity.ERROR);
     }
 
     static Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException {
index b84098d93ab82cd13d71385e491a3675abc4ece9..97f852ce9428086a7dc16c3eecc4f3e2d3d90589 100644 (file)
@@ -21,7 +21,6 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
@@ -32,6 +31,7 @@ import org.opendaylight.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
index 3690e1cc175cfadd4205d16d71f7211a8de2c1bf..5145cc2bda0ae5f0ff741906cad7d6bcc0f59420 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -21,9 +22,7 @@ import org.w3c.dom.Element;
    operations/UnLock.java
 */
 public class Unlock extends AbstractSingletonNetconfOperation {
-
     private static final Logger LOG = LoggerFactory.getLogger(Unlock.class);
-
     private static final String OPERATION_NAME = "unlock";
 
     public Unlock(final String netconfSessionIdForReporting) {
@@ -41,12 +40,11 @@ public class Unlock extends AbstractSingletonNetconfOperation {
 
         throw new DocumentedException("Unable to unlock " + targetDatastore + " datastore",
                 DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
-                DocumentedException.ErrorSeverity.ERROR);
+                ErrorSeverity.ERROR);
     }
 
     @Override
     protected String getOperationName() {
         return OPERATION_NAME;
     }
-
 }
index 165e7eee948aa8c5eb7c57589ae6c50f3b2c8f86..a7f224832fa89dadf7ccf9b32a964b5c4c4c7990 100644 (file)
@@ -8,14 +8,13 @@
 package org.opendaylight.netconf.mdsal.connector.ops;
 
 import com.google.common.collect.ImmutableMap;
-import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -55,10 +54,8 @@ public final class Validate extends AbstractConfigOperation {
         final NodeList elementsByTagName = getElementsByTagName(operationElement, SOURCE_KEY);
         // Direct lookup instead of using XmlElement class due to performance
         if (elementsByTagName.getLength() == 0) {
-            final Map<String, String> errorInfo = ImmutableMap.of("bad-attribute", SOURCE_KEY, "bad-element",
-                operationName);
             throw new DocumentedException("Missing source element", ErrorType.PROTOCOL, ErrorTag.MISSING_ELEMENT,
-                ErrorSeverity.ERROR, errorInfo);
+                ErrorSeverity.ERROR, ImmutableMap.of("bad-attribute", SOURCE_KEY, "bad-element", operationName));
         } else if (elementsByTagName.getLength() > 1) {
             throw new DocumentedException("Multiple source elements", ErrorType.RPC, ErrorTag.UNKNOWN_ATTRIBUTE,
                 ErrorSeverity.ERROR);
index 6264c624a24693802db96d0ce212918b081918b0..94a7bfb2477d954bbcc20cf8bc26e9b7d7033598 100644 (file)
@@ -16,7 +16,6 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.dom.DOMResult;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
@@ -24,6 +23,7 @@ import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.netconf.mdsal.connector.ops.Datastore;
 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -219,7 +219,5 @@ public abstract class AbstractGet extends AbstractSingletonNetconfOperation {
         public Optional<Datastore> getDatastore() {
             return datastore;
         }
-
     }
-
 }
index c4ae3d989990de45d0b0ca04f3ccad547e949d54..a86080cc0ec4a08bb2bf76a51312074c79a417c7 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.base.MoreObjects;
 import com.google.common.base.Preconditions;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Deque;
 import java.util.HashMap;
 import java.util.List;
@@ -25,6 +24,7 @@ import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.xml.MissingNameSpaceException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -85,7 +85,7 @@ public class FilterContentValidator {
             throw new DocumentedException("Validation failed. Cause: " + e.getMessage(), e,
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.UNKNOWN_NAMESPACE,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
     }
 
@@ -110,7 +110,7 @@ public class FilterContentValidator {
                     + "in schema context: " + schemaContext.getCurrentContext().toString(),
                 DocumentedException.ErrorType.APPLICATION,
                 DocumentedException.ErrorTag.UNKNOWN_NAMESPACE,
-                DocumentedException.ErrorSeverity.ERROR);
+                ErrorSeverity.ERROR);
     }
 
     /**
@@ -197,7 +197,7 @@ public class FilterContentValidator {
             final List<XmlElement> childElements = current.getChildElements(pathElement);
             // if there are multiple list entries present in the filter, we can't use any keys and must read whole list
             if (childElements.size() != 1) {
-                return Collections.emptyMap();
+                return Map.of();
             }
             current = childElements.get(0);
         }
@@ -207,7 +207,7 @@ public class FilterContentValidator {
             final Optional<XmlElement> childElements =
                     current.getOnlyChildElementOptionally(qualifiedName.getLocalName());
             if (childElements.isEmpty()) {
-                return Collections.emptyMap();
+                return Map.of();
             }
             final Optional<String> keyValue = childElements.get().getOnlyTextContentOptionally();
             if (keyValue.isPresent()) {
@@ -306,5 +306,4 @@ public class FilterContentValidator {
             super("Element " + child + " can't be child of " + parent);
         }
     }
-
 }
index ffdb56261f1f76f8e97cd5cdedc1969eaa733971..54f7366b31c4a6d0b157223aa51147705c0600a2 100644 (file)
@@ -12,7 +12,6 @@ import java.util.concurrent.ExecutionException;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
@@ -20,6 +19,7 @@ import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
 import org.opendaylight.netconf.mdsal.connector.ops.Datastore;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
index 59006806e772387fdee75dfdce38d1b03a05b482..cc2ec31c0be40c22ae8b769da4b85196ddf9ecbf 100644 (file)
@@ -13,7 +13,6 @@ import java.util.concurrent.ExecutionException;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
@@ -21,6 +20,7 @@ import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
 import org.opendaylight.netconf.mdsal.connector.ops.Datastore;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
index 0b336adc1860f6332e877e6057fd70c5599b4d08..8d491b596da486cb2a3b2e287ade56f3dcf40688 100644 (file)
@@ -18,11 +18,11 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
 
@@ -36,6 +36,7 @@ public class CopyConfigTest extends AbstractNetconfOperationTest {
             copyConfig("messages/mapping/copyConfigs/copyConfig_no_target.xml");
             fail("Should have failed - <target> element is missing");
         } catch (final DocumentedException e) {
+            // FIXME: use assertThrows() and assertEquals()
             assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
             assertTrue(e.getErrorTag() == ErrorTag.MISSING_ATTRIBUTE);
             assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
index 9b97ab6273f5b395f16a85beec0c32d672fcc0cc..1af28ba83058d5197d8096e12443e754d6dde9bb 100644 (file)
@@ -14,7 +14,6 @@ import static org.junit.Assert.assertTrue;
 import java.net.URI;
 import org.junit.Test;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlElement;
@@ -23,6 +22,7 @@ import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
 import org.opendaylight.netconf.mdsal.connector.ops.get.GetConfig;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.w3c.dom.Document;
index 684e2e995a77cabab6beacdbb6838bb1c70ce25c..2e858e5a5aeb22420edb145199b7343ca7f70101 100644 (file)
@@ -41,7 +41,6 @@ import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlUtil;
@@ -51,6 +50,7 @@ import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.NoOpListenerRegistration;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
index 49af75c0c8b4d8a4e135df1e8648b24391218830..80d1e4e7fa69f1c4b705eb81e1a44fc80d0faa3b 100644 (file)
@@ -32,6 +32,7 @@ import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator;
 import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator.ValidationFailedException;
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.w3c.dom.Document;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
@@ -59,7 +60,7 @@ public class ValidateTest {
         whenValidatorIsNotDefined();
         final DocumentedException e = assertThrows(DocumentedException.class,
             () -> validate("messages/mapping/validate/validate.xml"));
-        assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+        assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
         assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
     }
@@ -69,7 +70,7 @@ public class ValidateTest {
         whenUsingValidator(noopValidator);
         final DocumentedException e = assertThrows(DocumentedException.class,
             () -> validate("messages/mapping/validate/validate_no_source.xml"));
-        assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+        assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.MISSING_ELEMENT, e.getErrorTag());
         assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
     }
@@ -79,7 +80,7 @@ public class ValidateTest {
         whenUsingValidator(noopValidator);
         final DocumentedException e = assertThrows(DocumentedException.class,
             () -> validate("messages/mapping/validate/validate_running.xml"));
-        assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+        assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
         assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
     }
@@ -105,7 +106,7 @@ public class ValidateTest {
         final TransactionProvider transactionProvider = initCandidateTransaction();
         final DocumentedException e = assertThrows(DocumentedException.class,
             () -> validate("messages/mapping/validate/validate.xml", transactionProvider));
-        assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+        assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, e.getErrorTag());
         assertEquals(DocumentedException.ErrorType.APPLICATION, e.getErrorType());
     }
index 6f71559ede86e2565800566c08ce29b0b7d1a5e6..63d228c41656590cd8a84c27abbbf83269dc2ba8 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.config.yang.netconf.mdsal.monitoring;
 
 import java.util.HashMap;
@@ -17,6 +16,7 @@ import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -60,8 +60,7 @@ public final class GetSchema extends AbstractSingletonNetconfOperation {
             errorInfo.put(DocumentedException.ErrorTag.OPERATION_FAILED.toString(), e.getMessage());
             LOG.warn("Rpc error: {}", DocumentedException.ErrorTag.OPERATION_FAILED, e);
             throw new DocumentedException(e.getMessage(), e, DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.OPERATION_FAILED,
-                    DocumentedException.ErrorSeverity.ERROR, errorInfo);
+                    DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, errorInfo);
         }
 
         final Element getSchemaResult;
index 18a1a2642c162ea2b5172c07eb8fd8a7e5f07c0e..07636246bb20848c41ab3a0e15445a3b637aa532 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -126,30 +127,6 @@ public class DocumentedException extends Exception {
         }
     }
 
-    public enum ErrorSeverity {
-        ERROR("error"), WARNING("warning");
-
-        private final String severityValue;
-
-        ErrorSeverity(final String severityValue) {
-            this.severityValue = requireNonNull(severityValue);
-        }
-
-        public String getSeverityValue() {
-            return this.severityValue;
-        }
-
-        public static ErrorSeverity from(final String text) {
-            for (ErrorSeverity e : values()) {
-                if (e.getSeverityValue().equalsIgnoreCase(text)) {
-                    return e;
-                }
-            }
-
-            return ERROR;
-        }
-    }
-
     private final ErrorType errorType;
     private final ErrorTag errorTag;
     private final ErrorSeverity errorSeverity;
@@ -222,12 +199,16 @@ public class DocumentedException extends Exception {
                 NodeList rpcErrorChildren = replyChild.getChildNodes();
                 for (int j = 0; j < rpcErrorChildren.getLength(); j++) {
                     Node rpcErrorChild = rpcErrorChildren.item(j);
+
+                    // FIXME: use a switch expression here
                     if (ERROR_TYPE.equals(rpcErrorChild.getLocalName())) {
                         errorType = ErrorType.from(rpcErrorChild.getTextContent());
                     } else if (ERROR_TAG.equals(rpcErrorChild.getLocalName())) {
                         errorTag = ErrorTag.from(rpcErrorChild.getTextContent());
                     } else if (ERROR_SEVERITY.equals(rpcErrorChild.getLocalName())) {
-                        errorSeverity = ErrorSeverity.from(rpcErrorChild.getTextContent());
+                        final ErrorSeverity sev = ErrorSeverity.forElementBody(rpcErrorChild.getTextContent());
+                        // FIXME: this should be a hard error
+                        errorSeverity = sev != null ? sev : ErrorSeverity.ERROR;
                     } else if (ERROR_MESSAGE.equals(rpcErrorChild.getLocalName())) {
                         errorMessage = rpcErrorChild.getTextContent();
                         allErrorMessages = allErrorMessages + errorMessage;
@@ -290,7 +271,7 @@ public class DocumentedException extends Exception {
 
             rpcError.appendChild(createTextNode(doc, ERROR_TYPE, getErrorType().getTypeValue()));
             rpcError.appendChild(createTextNode(doc, ERROR_TAG, getErrorTag().getTagValue()));
-            rpcError.appendChild(createTextNode(doc, ERROR_SEVERITY, getErrorSeverity().getSeverityValue()));
+            rpcError.appendChild(createTextNode(doc, ERROR_SEVERITY, getErrorSeverity().elementBody()));
             rpcError.appendChild(createTextNode(doc, ERROR_MESSAGE, getLocalizedMessage()));
 
             Map<String, String> errorInfoMap = getErrorInfo();
index 87b2ac729883ed9fa0527c4ac1d8893bcacdf393..6f7ccfef946eaba5549c8ca849272f3db8e55a9f 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.api;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Map;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.w3c.dom.Document;
 
 /**
index 6f4b34694d281f00624e478242f2971affc1c66b..9701428e420baf29833de59fddffa79775f4cddd 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netconf.api.xml;
 
 import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 
 public class MissingNameSpaceException extends DocumentedException {
     private static final long serialVersionUID = 1L;
index ebc3a85ad313d4dbaf8a30df6a77aa3564d1ed77..ed5e9c89292ab323913dab268c127257dc01c7d0 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netconf.api.xml;
 
 import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 
 public class UnexpectedElementException extends DocumentedException {
     private static final long serialVersionUID = 1L;
index 823fa30837530898d0a87908833cfcf4dab8b978..001107f7a719645baf8f7c66440adc3a8898ed87 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netconf.api.xml;
 
 import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 
 public class UnexpectedNamespaceException extends DocumentedException {
     private static final long serialVersionUID = 1L;
index a07a785f1dcd1c0753a8162a0a0cc18a1356658e..d19ce378b8016a060b9b489483f27c13e2d8e0c8 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.Optional;
 import javax.xml.XMLConstants;
 import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Attr;
@@ -87,7 +88,7 @@ public final class XmlElement {
                         throw new DocumentedException("Attribute doesn't start with :",
                                 DocumentedException.ErrorType.APPLICATION,
                                 DocumentedException.ErrorTag.INVALID_VALUE,
-                                DocumentedException.ErrorSeverity.ERROR);
+                                ErrorSeverity.ERROR);
                     }
                     prefix = attribKey.substring(XMLConstants.XMLNS_ATTRIBUTE.length() + 1);
                 }
@@ -112,7 +113,7 @@ public final class XmlElement {
                     getName()),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.OPERATION_FAILED,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
     }
 
@@ -124,7 +125,7 @@ public final class XmlElement {
                     expectedNamespace),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.OPERATION_FAILED,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
     }
 
@@ -136,7 +137,7 @@ public final class XmlElement {
                     expectedNamespace),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.OPERATION_FAILED,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
     }
 
@@ -211,10 +212,7 @@ public final class XmlElement {
      * @return List of child elements
      */
     public List<XmlElement> getChildElements(final String tagName) {
-        return getChildElementsInternal(e -> {
-            // localName returns pure localName without prefix
-            return e.getLocalName().equals(tagName);
-        });
+        return getChildElementsInternal(e -> e.getLocalName().equals(tagName));
     }
 
     public List<XmlElement> getChildElementsWithinNamespace(final String childName, final String namespace) {
@@ -302,7 +300,7 @@ public final class XmlElement {
                     childName, toString(), children.size()),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.INVALID_VALUE,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
 
         return children.get(0);
@@ -314,7 +312,7 @@ public final class XmlElement {
             throw new DocumentedException("One element " + childName + " expected in " + toString(),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.INVALID_VALUE,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
         return nameElements.get(0);
     }
@@ -326,7 +324,7 @@ public final class XmlElement {
                     children.size()),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.INVALID_VALUE,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
         return children.get(0);
     }
@@ -346,7 +344,7 @@ public final class XmlElement {
         throw new DocumentedException(getName() + " should contain text.",
                 DocumentedException.ErrorType.APPLICATION,
                 DocumentedException.ErrorTag.INVALID_VALUE,
-                DocumentedException.ErrorSeverity.ERROR
+                ErrorSeverity.ERROR
         );
     }
 
@@ -368,7 +366,7 @@ public final class XmlElement {
                     toString()),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.OPERATION_FAILED,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
         return attribute;
     }
@@ -396,7 +394,7 @@ public final class XmlElement {
             throw new MissingNameSpaceException(String.format("No namespace defined for %s", this),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.OPERATION_FAILED,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
         return namespaceURI.get();
     }
@@ -465,7 +463,7 @@ public final class XmlElement {
             throw new DocumentedException(String.format("Unrecognised elements %s in %s", childElements, this),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.INVALID_VALUE,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
     }
 
index 1e79339cf6b9d1d27ea1c14ffc844e154e318122..b21ffbdb7f680973b56b55c5edd49198a8e508ac 100644 (file)
@@ -5,15 +5,14 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.api;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import com.google.common.collect.ImmutableMap;
-import java.util.Collections;
+import com.google.common.collect.Iterators;
 import java.util.Iterator;
+import java.util.Map;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
@@ -22,6 +21,7 @@ import javax.xml.xpath.XPathFactory;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
@@ -42,7 +42,7 @@ public class NetconfDocumentedExceptionTest {
         xpath.setNamespaceContext(new NamespaceContext() {
             @Override
             public Iterator<String> getPrefixes(final String namespaceURI) {
-                return Collections.singletonList("netconf").iterator();
+                return Iterators.singletonIterator("netconf");
             }
 
             @Override
@@ -63,8 +63,8 @@ public class NetconfDocumentedExceptionTest {
         DocumentedException ex = new NetconfDocumentedException(errorMessage, null,
                 DocumentedException.ErrorType.PROTOCOL,
                 DocumentedException.ErrorTag.DATA_EXISTS,
-                DocumentedException.ErrorSeverity.WARNING,
-                ImmutableMap.of("foo", "bar"));
+                ErrorSeverity.WARNING,
+                Map.of("foo", "bar"));
 
         final Document doc = ex.toXMLDocument();
         assertNotNull("Document is null", doc);
@@ -89,8 +89,7 @@ public class NetconfDocumentedExceptionTest {
 
         final Node errorSeverityNode = getNode("netconf:error-severity", rpcErrorNode);
         assertNotNull("error-severity not found", errorSeverityNode);
-        assertEquals("error-severity", DocumentedException.ErrorSeverity.WARNING.getSeverityValue(),
-                errorSeverityNode.getTextContent());
+        assertEquals("error-severity", ErrorSeverity.WARNING.elementBody(), errorSeverityNode.getTextContent());
 
         final Node errorInfoNode = getNode("netconf:error-info/netconf:foo", rpcErrorNode);
         assertNotNull("foo not found", errorInfoNode);
@@ -105,11 +104,11 @@ public class NetconfDocumentedExceptionTest {
         ex = DocumentedException.fromXMLDocument(doc);
 
         assertNotNull("NetconfDocumentedException is null", ex);
-        assertEquals("getErrorSeverity", DocumentedException.ErrorSeverity.WARNING, ex.getErrorSeverity());
+        assertEquals("getErrorSeverity", ErrorSeverity.WARNING, ex.getErrorSeverity());
         assertEquals("getErrorTag", DocumentedException.ErrorTag.DATA_EXISTS, ex.getErrorTag());
         assertEquals("getErrorType", DocumentedException.ErrorType.PROTOCOL, ex.getErrorType());
         assertEquals("getLocalizedMessage", errorMessage, ex.getLocalizedMessage());
-        assertEquals("getErrorInfo", ImmutableMap.of("foo", "bar"), ex.getErrorInfo());
+        assertEquals("getErrorInfo", Map.of("foo", "bar"), ex.getErrorInfo());
     }
 
     @SuppressWarnings("unchecked")
index 026a481ae0985107aff6d9a3ff90c3bc863daf5f..cdf9ee3f05e61cbfc5d65faede18ff6cdc7fe00d 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.impl;
 
 import com.google.common.base.Preconditions;
@@ -23,6 +22,7 @@ import org.opendaylight.netconf.impl.osgi.NetconfOperationRouter;
 import org.opendaylight.netconf.notifications.NetconfNotification;
 import org.opendaylight.netconf.util.messages.SendErrorExceptionUtil;
 import org.opendaylight.netconf.util.messages.SubtreeFilter;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -138,8 +138,7 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
              */
             throw new DocumentedException("Unknown tag " + rootNode.getNodeName() + " in message:\n" + netconfMessage,
                     DocumentedException.ErrorType.PROTOCOL, DocumentedException.ErrorTag.UNKNOWN_ELEMENT,
-                    DocumentedException.ErrorSeverity.ERROR, ImmutableMap.of("bad-element",
-                    rootNode.getNodeName()));
+                    ErrorSeverity.ERROR, ImmutableMap.of("bad-element", rootNode.getNodeName()));
         }
     }
 
@@ -158,7 +157,7 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
 
         throw new DocumentedException("Missing attribute " + rootNode.getNodeName(),
                 DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.MISSING_ATTRIBUTE,
-                DocumentedException.ErrorSeverity.ERROR,
+                ErrorSeverity.ERROR,
                 ImmutableMap.of("bad-attribute", XmlNetconfConstants.MESSAGE_ID,
                         "bad-element", XmlNetconfConstants.RPC_KEY));
     }
index 2b30c0951b09fb4a85cf8bb189dd681476fc7789..ff08feb10f7f635c714425ffa6d113f85b551a8f 100644 (file)
@@ -9,12 +9,13 @@ package org.opendaylight.netconf.impl.mapping.operations;
 
 import static java.util.Objects.requireNonNull;
 
-import java.util.Collections;
+import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.impl.NetconfServerSession;
 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -55,8 +56,7 @@ public class DefaultCloseSession extends AbstractSingletonNetconfOperation imple
             throw new DocumentedException("Unable to properly close session "
                     + getNetconfSessionIdForReporting(), e, DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.OPERATION_FAILED,
-                    DocumentedException.ErrorSeverity.ERROR, Collections.singletonMap(
-                    DocumentedException.ErrorSeverity.ERROR.toString(), e.getMessage()));
+                    ErrorSeverity.ERROR, Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
         }
         return document.createElement(XmlNetconfConstants.OK);
     }
index 3b4a5604649b329f4cf46ed7a9e7615991956f35..dbc8e906c3a275f12fc8eec31c858774fffc76b9 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netconf.impl.mapping.operations;
 
 import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.NetconfMessage;
@@ -18,6 +17,7 @@ import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.impl.NetconfServerSession;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
 import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
index 9defc2e8346be5febc99db95b5385f6a5d4e2760..8a9acf07ee2fe98c406f857beb031a19090e5d56 100644 (file)
@@ -12,8 +12,8 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.ImmutableSet;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.NavigableMap;
 import java.util.Set;
 import java.util.TreeMap;
@@ -30,6 +30,7 @@ import org.opendaylight.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.netconf.mapping.api.SessionAwareNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -76,9 +77,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
 
             throw new DocumentedException(
                     String.format("Unable to handle rpc %s on session %s", messageAsString, session),
-                    e, DocumentedException.ErrorType.APPLICATION,
-                    tag, DocumentedException.ErrorSeverity.ERROR,
-                    Collections.singletonMap(tag.toString(), e.getMessage()));
+                    e, DocumentedException.ErrorType.APPLICATION, tag, ErrorSeverity.ERROR,
+                    Map.of(tag.toString(), e.getMessage()));
         } catch (final RuntimeException e) {
             throw handleUnexpectedEx("sort", e);
         }
@@ -100,8 +100,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
         return new DocumentedException("Unexpected error",
                 DocumentedException.ErrorType.APPLICATION,
                 DocumentedException.ErrorTag.OPERATION_FAILED,
-                DocumentedException.ErrorSeverity.ERROR,
-                Collections.singletonMap(DocumentedException.ErrorSeverity.ERROR.toString(), exception.toString()));
+                ErrorSeverity.ERROR,
+                Map.of(ErrorSeverity.ERROR.toString(), exception.toString()));
     }
 
     private static Document executeOperationWithHighestPriority(final Document message,
index 4973d255a94038be9f79cc75b1168c0d10fad6dc..f137dd1f5b3539525b2c04c177c4ab28f8ab8726 100644 (file)
@@ -13,6 +13,7 @@ import java.util.HashMap;
 import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.util.messages.SendErrorExceptionUtil;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,7 +42,7 @@ public final class DeserializerExceptionHandler implements ChannelHandler {
         info.put("cause", cause.getMessage());
         final DocumentedException ex = new DocumentedException(cause.getMessage(),
                 DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.MALFORMED_MESSAGE,
-                DocumentedException.ErrorSeverity.ERROR, info);
+                ErrorSeverity.ERROR, info);
 
         SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), ex);
     }
index dcc768374e10e84efc3deeb2f0a006a72f21c670..44ecfc76e3b7c2674c0ab9d11c4ccaa54649bd9f 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.netconf.impl.mapping.operations;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
@@ -38,7 +41,7 @@ public class DefaultCloseSessionTest {
         final EventLoop eventLoop = mock(EventLoop.class);
         doReturn(eventLoop).when(channel).eventLoop();
         doAnswer(invocation -> {
-            invocation.<Runnable>getArgument(0).run();
+            invocation.getArgument(0, Runnable.class).run();
             return null;
         }).when(eventLoop).execute(any(Runnable.class));
         doReturn(true).when(eventLoop).inEventLoop();
@@ -83,12 +86,17 @@ public class DefaultCloseSessionTest {
         verify(listener).onSessionTerminated(any(NetconfServerSession.class), any(NetconfTerminationReason.class));
     }
 
-    @Test(expected = DocumentedException.class)
+    @Test
     public void testDefaultCloseSession2() throws Exception {
-        AutoCloseable res = mock(AutoCloseable.class);
-        doThrow(NetconfDocumentedException.class).when(res).close();
-        DefaultCloseSession session = new DefaultCloseSession("", res);
+        final NetconfDocumentedException expectedCause = new NetconfDocumentedException("testMessage");
+        final AutoCloseable res = mock(AutoCloseable.class);
+        doThrow(expectedCause).when(res).close();
+        final DefaultCloseSession session = new DefaultCloseSession("testSession", res);
         XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
-        session.handleWithNoSubsequentOperations(XmlUtil.newDocument(), elem);
+
+        final DocumentedException ex = assertThrows(DocumentedException.class,
+            () -> session.handleWithNoSubsequentOperations(XmlUtil.newDocument(), elem));
+        assertEquals("Unable to properly close session testSession", ex.getMessage());
+        assertSame(expectedCause, ex.getCause());
     }
 }
index aa8ed9bd665c25207a820dbd96bd88961b731865..56884d35311f132f9c3b0d5ae21c0520f58b5534 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yangtools.yang.binding.Identifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 
 public final class NetconfTopologyUtils {
     public static final long DEFAULT_REQUEST_TIMEOUT_MILLIS = 60000L;
@@ -82,6 +83,6 @@ public final class NetconfTopologyUtils {
     public static DocumentedException createMasterIsDownException(final RemoteDeviceId id, final Exception cause) {
         return new DocumentedException(id + ":Master is down. Please try again.", cause,
                 DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED,
-                DocumentedException.ErrorSeverity.WARNING);
+                ErrorSeverity.WARNING);
     }
 }
index 688ff462665c7e8ec2924b43591997fbad87356e..aa3bc71964637388db516a78d5b86e1134696229 100644 (file)
@@ -46,6 +46,7 @@ import org.opendaylight.netconf.topology.singleton.messages.netconf.ReplaceEditC
 import org.opendaylight.netconf.topology.singleton.messages.netconf.UnlockRequest;
 import org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyReadResponse;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -300,7 +301,7 @@ public class ProxyNetconfServiceTest {
     private static void verifyDocumentedException(final Throwable cause) {
         assertTrue("Unexpected cause " + cause, cause instanceof DocumentedException);
         final DocumentedException de = (DocumentedException) cause;
-        assertEquals(DocumentedException.ErrorSeverity.WARNING, de.getErrorSeverity());
+        assertEquals(ErrorSeverity.WARNING, de.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, de.getErrorTag());
         assertEquals(DocumentedException.ErrorType.APPLICATION, de.getErrorType());
     }
index 8cbfb26268c576d9f42bb423df6d34211b033d9c..3ec6f891163ee2b7f87bbf0b3f8c35198010f8a3 100644 (file)
@@ -43,6 +43,7 @@ import org.opendaylight.netconf.topology.singleton.messages.transactions.MergeRe
 import org.opendaylight.netconf.topology.singleton.messages.transactions.PutRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitRequest;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -400,7 +401,7 @@ public class ProxyReadWriteTransactionTest {
     private static void verifyDocumentedException(final Throwable cause) {
         assertTrue("Unexpected cause " + cause, cause instanceof DocumentedException);
         final DocumentedException de = (DocumentedException) cause;
-        assertEquals(DocumentedException.ErrorSeverity.WARNING, de.getErrorSeverity());
+        assertEquals(ErrorSeverity.WARNING, de.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, de.getErrorTag());
         assertEquals(DocumentedException.ErrorType.APPLICATION, de.getErrorType());
     }
index ef78be50cc0aaee85ad195181cd185ca9a63f09f..b99f75d346545301d6c03c93fb44c283bba67882 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -28,7 +29,7 @@ public abstract class AbstractLastNetconfOperation extends AbstractNetconfOperat
                     "No netconf operation expected to be subsequent to %s, but is %s", this, subsequentOperation),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.MALFORMED_MESSAGE,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
 
         return handleWithNoSubsequentOperations(document, operationElement);
index 595f536593d722f4674c64b6d8f928ba84564607..98fb17d8563f1156c3481e007df15ad7946ef3c7 100644 (file)
@@ -32,6 +32,7 @@ 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.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -231,7 +232,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
                                 new Exception(throwable),
                                 DocumentedException.ErrorType.APPLICATION,
                                 DocumentedException.ErrorTag.OPERATION_FAILED,
-                                DocumentedException.ErrorSeverity.ERROR);
+                                ErrorSeverity.ERROR);
                 transformed.setException(exception);
             }
         }, MoreExecutors.directExecutor());
@@ -244,7 +245,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
     private void extractResult(final List<DOMRpcResult> domRpcResults,
                                final SettableFuture<RpcResult<Void>> transformed) {
         DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
-        DocumentedException.ErrorSeverity errSeverity = DocumentedException.ErrorSeverity.ERROR;
+        ErrorSeverity errSeverity = ErrorSeverity.ERROR;
         StringBuilder msgBuilder = new StringBuilder();
         boolean errorsEncouneterd = false;
         String errorTag = "operation-failed";
@@ -271,18 +272,8 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
                         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;
-                }
+
+                errSeverity = error.getSeverity().toNetconf();
                 msgBuilder.append(error.getMessage());
                 msgBuilder.append(error.getInfo());
                 errorTag = error.getTag();
index 1753029fb676553f6f1ff6bab440ad74a22e36a8..a3d53d268f188825a5bce0d6c49d53d13e55f430 100644 (file)
@@ -51,9 +51,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.not
 import org.opendaylight.yangtools.rfc7952.data.api.NormalizedMetadata;
 import org.opendaylight.yangtools.rfc7952.data.util.ImmutableNormalizedMetadata;
 import org.opendaylight.yangtools.rfc7952.data.util.ImmutableNormalizedMetadata.Builder;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
@@ -295,7 +295,7 @@ public final class NetconfMessageTransformUtil {
             throw new NetconfDocumentedException("Response message contained unknown \"message-id\"",
                     null, NetconfDocumentedException.ErrorType.PROTOCOL,
                     NetconfDocumentedException.ErrorTag.BAD_ATTRIBUTE,
-                    NetconfDocumentedException.ErrorSeverity.ERROR, errorInfo);
+                    ErrorSeverity.ERROR, errorInfo);
         }
     }
 
@@ -316,8 +316,7 @@ public final class NetconfMessageTransformUtil {
             }
         }
 
-        final ErrorSeverity severity = toRpcErrorSeverity(ex.getErrorSeverity());
-        return severity == ErrorSeverity.ERROR
+        return ex.getErrorSeverity() == ErrorSeverity.ERROR
                 ? RpcResultBuilder.newError(toRpcErrorType(ex.getErrorType()), ex.getErrorTag().getTagValue(),
                         ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause())
                 : RpcResultBuilder.newWarning(
@@ -325,15 +324,6 @@ public final class NetconfMessageTransformUtil {
                         ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause());
     }
 
-    private static ErrorSeverity toRpcErrorSeverity(final NetconfDocumentedException.ErrorSeverity severity) {
-        switch (severity) {
-            case WARNING:
-                return RpcError.ErrorSeverity.WARNING;
-            default:
-                return RpcError.ErrorSeverity.ERROR;
-        }
-    }
-
     private static RpcError.ErrorType toRpcErrorType(final NetconfDocumentedException.ErrorType type) {
         switch (type) {
             case PROTOCOL:
@@ -570,13 +560,10 @@ public final class NetconfMessageTransformUtil {
 
     public static RpcResult<NetconfMessage> toRpcResult(final FailedNetconfMessage message) {
         return RpcResultBuilder.<NetconfMessage>failed()
-                .withRpcError(
-                        toRpcError(
-                                new NetconfDocumentedException(
-                                        message.getException().getMessage(),
-                                        DocumentedException.ErrorType.APPLICATION,
-                                        DocumentedException.ErrorTag.MALFORMED_MESSAGE,
-                                        DocumentedException.ErrorSeverity.ERROR)))
+                .withRpcError(toRpcError(new NetconfDocumentedException(message.getException().getMessage(),
+                    DocumentedException.ErrorType.APPLICATION,
+                    DocumentedException.ErrorTag.MALFORMED_MESSAGE,
+                    ErrorSeverity.ERROR)))
                 .build();
     }
 }
index ed43703e3ec413c6e961162e9ec076bcd336768a..b7c35e0fbd34c19fbe3dc6ce32994f0762f3267d 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.test.tool.customrpc;
 
 import java.io.File;
@@ -17,6 +16,7 @@ import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.w3c.dom.Document;
 
 /**
@@ -52,7 +52,7 @@ class SettableRpc implements NetconfOperation {
         } else if (subsequentOperation.isExecutionTermination()) {
             throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage),
                     DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         } else {
             return subsequentOperation.execute(requestMessage);
         }
index b8605d432484241f8c7baaa80e0038e424b50237..a51f4712e1499e2aaba0725df39e526977424b3b 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.netconf.test.tool.monitoring;
 
-import java.util.Collections;
+import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
 import org.opendaylight.netconf.api.xml.XmlElement;
@@ -15,6 +15,7 @@ import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
 import org.opendaylight.netconf.util.mapping.AbstractNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -56,7 +57,7 @@ public class Get extends AbstractNetconfOperation {
             throw new DocumentedException(String.format("Subsequent netconf operation expected by %s", this),
                     DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.OPERATION_FAILED,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         }
 
         try {
@@ -76,8 +77,8 @@ public class Get extends AbstractNetconfOperation {
 
             throw new DocumentedException(errorMessage, e, DocumentedException.ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.OPERATION_FAILED,
-                    DocumentedException.ErrorSeverity.ERROR,
-                    Collections.singletonMap(DocumentedException.ErrorSeverity.ERROR.toString(), e.getMessage()));
+                    ErrorSeverity.ERROR,
+                    Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
         }
     }
 
index a6e0f07773dbadc6a6810fcec128903ab8ae9cd6..75f1b71adb836d571bc95d627f87e94285333d68 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.test.tool.rpchandler;
 
 import java.util.Optional;
@@ -16,6 +15,7 @@ import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.w3c.dom.Document;
 
 /**
@@ -51,7 +51,7 @@ class SettableRpc implements NetconfOperation {
         } else if (subsequentOperation.isExecutionTermination()) {
             throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage),
                     DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
-                    DocumentedException.ErrorSeverity.ERROR);
+                    ErrorSeverity.ERROR);
         } else {
             return subsequentOperation.execute(requestMessage);
         }
index f5c48882d7072ce5856a4223491e09ca19f68d08..de7c9c02a916bdca84cc2dbd885ca21abe1713e5 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
@@ -212,7 +213,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
                         } else {
                             return Futures.immediateFailedFuture(new NetconfDocumentedException("Lock operation failed",
                                 DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.LOCK_DENIED,
-                                DocumentedException.ErrorSeverity.ERROR));
+                                ErrorSeverity.ERROR));
                         }
                     },
                     MoreExecutors.directExecutor());
@@ -249,7 +250,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
     private static TransactionCommitFailedException toCommitFailedException(
             final Collection<? extends RpcError> errors) {
         DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
-        DocumentedException.ErrorSeverity errSeverity = DocumentedException.ErrorSeverity.ERROR;
+        ErrorSeverity errSeverity = ErrorSeverity.ERROR;
         StringJoiner msgBuilder = new StringJoiner(" ");
         String errorTag = "operation-failed";
         for (final RpcError error : errors) {
@@ -268,15 +269,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
                     errType = DocumentedException.ErrorType.APPLICATION;
                     break;
             }
-            switch (error.getSeverity()) {
-                case WARNING:
-                    errSeverity = DocumentedException.ErrorSeverity.WARNING;
-                    break;
-                case ERROR:
-                default:
-                    errSeverity = DocumentedException.ErrorSeverity.ERROR;
-                    break;
-            }
+            errSeverity = error.getSeverity().toNetconf();
             msgBuilder.add(error.getMessage());
             msgBuilder.add(error.getInfo());
             errorTag = error.getTag();
index 4d6230bd174b161e7472cf0c07d2ef8ba76e940b..35f4d18b4e5096add9ed83f04cec5f44759b7f8d 100644 (file)
@@ -39,6 +39,7 @@ import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
@@ -88,7 +89,7 @@ public class DeleteDataTransactionUtilTest {
             .thenReturn(immediateFalseFluentFuture());
         final NetconfDocumentedException exception = new NetconfDocumentedException("id",
             DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"),
-            DocumentedException.ErrorSeverity.ERROR);
+            ErrorSeverity.ERROR);
         final SettableFuture<? extends CommitInfo> ret = SettableFuture.create();
         ret.setException(new TransactionCommitFailedException(
             String.format("Commit of transaction %s failed", this), exception));
index 4129d7f87cd96e39743dedf434993fc28f962b66..5af6b45e5fa4e354da4ce12b9f348dfeb795e3f5 100644 (file)
@@ -50,6 +50,7 @@ import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -233,7 +234,7 @@ public class PatchDataTransactionUtilTest {
             this.targetNodeForCreateAndDelete);
         final NetconfDocumentedException exception = new NetconfDocumentedException("id",
             DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"),
-            DocumentedException.ErrorSeverity.ERROR);
+            ErrorSeverity.ERROR);
         final SettableFuture<? extends DOMRpcResult> ret = SettableFuture.create();
         ret.setException(new TransactionCommitFailedException(
             String.format("Commit of transaction %s failed", this), exception));