Remove DocumentedException.ErrorType 27/97027/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Jul 2021 14:06:43 +0000 (16:06 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Jul 2021 19:30:38 +0000 (21:30 +0200)
Use ErrorType from yang-common instead of defining our own. This allows
us to reuse some mapping code as well.

JIRA: NETCONF-793
Change-Id: I00c3344f15f5e052784e9f439a025678b093655e
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-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/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.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 1a7c42d699cd108bfeb0097e5d5ceb8ae32efcc7..345a5e5287d7a3d34c4ea9f2265e5eb451015caa 100644 (file)
@@ -19,8 +19,8 @@ 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.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index 5201ec112e2148736d2c3ee3f7d65d606c16cf46..81899f208d63fd066d75ff21e7caf27a377507fa 100644 (file)
@@ -24,6 +24,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -61,9 +62,7 @@ abstract class AbstractConfigOperation extends AbstractSingletonNetconfOperation
         final Optional<XmlElement> urlElement = parent.getOnlyChildElementOptionally(URL_KEY);
         if (urlElement.isEmpty()) {
             throw new DocumentedException("Invalid RPC, neither <config> not <url> element is present",
-                DocumentedException.ErrorType.PROTOCOL,
-                DocumentedException.ErrorTag.MISSING_ELEMENT,
-                ErrorSeverity.ERROR);
+                ErrorType.PROTOCOL, DocumentedException.ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
         }
 
         final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
@@ -85,19 +84,13 @@ abstract class AbstractConfigOperation extends AbstractSingletonNetconfOperation
             return XmlUtil.readXmlToDocument(input);
         } catch (MalformedURLException e) {
             throw new DocumentedException(url + " URL is invalid or unsupported", e,
-                DocumentedException.ErrorType.APPLICATION,
-                DocumentedException.ErrorTag.INVALID_VALUE,
-                ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         } catch (IOException e) {
             throw new DocumentedException("Could not open URL " + url, e,
-                DocumentedException.ErrorType.APPLICATION,
-                DocumentedException.ErrorTag.OPERATION_FAILED,
-                ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         } catch (SAXException e) {
             throw new DocumentedException("Could not parse XML at" + url, e,
-                DocumentedException.ErrorType.APPLICATION,
-                DocumentedException.ErrorTag.OPERATION_FAILED,
-                ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
     }
 
index f5126387b1ce4eb66829ce539414aeba92959334..c64eec08eeaff09895517903811a706fdaec606e 100644 (file)
@@ -16,11 +16,11 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.netconf.api.DocumentedException;
 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.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
@@ -90,11 +90,8 @@ abstract class AbstractEdit extends AbstractConfigOperation {
                     element.getName()));
         if (schemaNode.isEmpty()) {
             throw new DocumentedException(
-                "Unable to find node " + elementName + " with namespace: " + namespace + "in module: "
-                    + module.toString(),
-                ErrorType.APPLICATION,
-                ErrorTag.UNKNOWN_NAMESPACE,
-                ErrorSeverity.ERROR);
+                "Unable to find node " + elementName + " with namespace: " + namespace + " in module: " + module,
+                ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
         }
 
         return schemaNode.get();
index cebf3e5590dc8ec1ca3bbf6bbfe5b8232c5d3c15..2989e27aec57139ae3b1143fd2d703e3c2c51a80 100644 (file)
@@ -27,13 +27,13 @@ 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.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.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.common.ErrorType;
 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;
@@ -80,18 +80,14 @@ public final class CopyConfig extends AbstractEdit {
         final String target = targetElement.getName();
         if (Datastore.running.toString().equals(target)) {
             throw new DocumentedException("edit-config on running datastore is not supported",
-                ErrorType.PROTOCOL,
-                ErrorTag.OPERATION_NOT_SUPPORTED,
-                ErrorSeverity.ERROR);
+                ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
         } else if (Datastore.candidate.toString().equals(target)) {
             copyToCandidate(operationElement);
         } else if (URL_KEY.equals(target)) {
             copyToUrl(targetElement, operationElement);
         } else {
             throw new DocumentedException("Unsupported target: " + target,
-                ErrorType.PROTOCOL,
-                ErrorTag.BAD_ELEMENT,
-                ErrorSeverity.ERROR);
+                ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT, ErrorSeverity.ERROR);
         }
         return document.createElement(XmlNetconfConstants.OK);
     }
@@ -123,9 +119,7 @@ public final class CopyConfig extends AbstractEdit {
         final Optional<XmlElement> sourceElement = parent.getOnlyChildElementOptionally(SOURCE_KEY);
         if (sourceElement.isEmpty()) {
             throw new DocumentedException("<source> element is missing",
-                DocumentedException.ErrorType.PROTOCOL,
-                DocumentedException.ErrorTag.MISSING_ELEMENT,
-                ErrorSeverity.ERROR);
+                ErrorType.PROTOCOL, DocumentedException.ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
         }
 
         return sourceElement.get();
@@ -135,9 +129,7 @@ public final class CopyConfig extends AbstractEdit {
         final String url = urlElement.getTextContent();
         if (!url.startsWith("file:")) {
             throw new DocumentedException("Unsupported <url> protocol: " + url,
-                ErrorType.PROTOCOL,
-                ErrorTag.OPERATION_NOT_SUPPORTED,
-                ErrorSeverity.ERROR);
+                ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
         }
 
         // Read data from datastore:
@@ -155,14 +147,10 @@ public final class CopyConfig extends AbstractEdit {
             Files.write(file, xml.getBytes(StandardCharsets.UTF_8));
         } catch (URISyntaxException | IllegalArgumentException e) {
             throw new DocumentedException("Invalid URI: " + url, e,
-                ErrorType.RPC,
-                ErrorTag.INVALID_VALUE,
-                ErrorSeverity.ERROR);
+                ErrorType.RPC, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         } catch (IOException e) {
             throw new DocumentedException("Failed to write : " + url, e,
-                ErrorType.APPLICATION,
-                ErrorTag.OPERATION_FAILED,
-                ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
     }
 
@@ -187,9 +175,7 @@ public final class CopyConfig extends AbstractEdit {
             return Datastore.valueOf(source.getName());
         } catch (IllegalArgumentException e) {
             throw new DocumentedException("Unsupported source for <url> target", e,
-                ErrorType.PROTOCOL,
-                ErrorTag.OPERATION_NOT_SUPPORTED,
-                ErrorSeverity.ERROR);
+                ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
         }
     }
 
index ea9ad094fa7f741bfcf08010f008cb21a16907ff..bb3f97a585f9a8bb8dcd8b6fae723f80347222dd 100644 (file)
@@ -11,21 +11,19 @@ import java.util.HashMap;
 import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 public class DiscardChanges extends AbstractSingletonNetconfOperation {
-
     private static final Logger LOG = LoggerFactory.getLogger(DiscardChanges.class);
-
     private static final String OPERATION_NAME = "discard-changes";
 
     private final TransactionProvider transactionProvider;
index 6b5f080499383283816dd6a1d99338f0ac6abeb7..bc568e77e16e0a627f0ba262b3a4533bab933a4d 100644 (file)
@@ -16,13 +16,13 @@ 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.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.ModifyAction;
 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.common.ErrorType;
 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;
@@ -59,9 +59,7 @@ public final class EditConfig extends AbstractEdit {
         final Datastore targetDatastore = Datastore.valueOf(targetElement.getName());
         if (targetDatastore == Datastore.running) {
             throw new DocumentedException("edit-config on running datastore is not supported",
-                    ErrorType.PROTOCOL,
-                    ErrorTag.OPERATION_NOT_SUPPORTED,
-                    ErrorSeverity.ERROR);
+                    ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
         }
 
         final ModifyAction defaultAction = getDefaultOperation(operationElement);
index 6518fa4d5df11f98410b106a6d29c8456161d42a..ffbb548d1722998ad8859ef9cd25c0635d2ff06b 100644 (file)
@@ -12,6 +12,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -42,8 +43,7 @@ public class Lock extends AbstractSingletonNetconfOperation {
         }
 
         throw new DocumentedException("Unable to lock " + targetDatastore + " datastore",
-                DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
-                ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
     }
 
     static Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException {
index 97f852ce9428086a7dc16c3eecc4f3e2d3d90589..efc34d0a1573017e42148d9c977acdc6f94f41e8 100644 (file)
@@ -22,7 +22,6 @@ 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.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.api.xml.XmlNetconfConstants;
@@ -32,6 +31,7 @@ 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.ErrorType;
 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 5145cc2bda0ae5f0ff741906cad7d6bcc0f59420..b3fe4a56c9a24938862bfd1694033e3f02ee81b0 100644 (file)
@@ -12,6 +12,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -39,8 +40,7 @@ public class Unlock extends AbstractSingletonNetconfOperation {
         }
 
         throw new DocumentedException("Unable to unlock " + targetDatastore + " datastore",
-                DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
-                ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
     }
 
     @Override
index a7f224832fa89dadf7ccf9b32a964b5c4c4c7990..a8229f10f51c8bbbea7daf3d5328abb5649fbd4a 100644 (file)
@@ -10,11 +10,11 @@ package org.opendaylight.netconf.mdsal.connector.ops;
 import com.google.common.collect.ImmutableMap;
 import org.opendaylight.netconf.api.DocumentedException;
 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -39,9 +39,7 @@ public final class Validate extends AbstractConfigOperation {
         final Datastore targetDatastore = extractSourceParameter(operationElement, OPERATION_NAME);
         if (targetDatastore != Datastore.candidate) {
             throw new DocumentedException("<validate> is only supported on candidate datastore",
-                DocumentedException.ErrorType.PROTOCOL,
-                ErrorTag.OPERATION_NOT_SUPPORTED,
-                ErrorSeverity.ERROR);
+                ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
         }
 
         transactionProvider.validateTransaction();
index 94a7bfb2477d954bbcc20cf8bc26e9b7d7033598..e4fd8d6ad4fe3d358539c767300a1a26ca65209f 100644 (file)
@@ -17,13 +17,13 @@ import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.dom.DOMResult;
 import org.opendaylight.netconf.api.DocumentedException;
 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.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.common.ErrorType;
 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;
index a86080cc0ec4a08bb2bf76a51312074c79a417c7..0be3023f9f502e10971cbc0c24052b2715ba20b9 100644 (file)
@@ -25,6 +25,7 @@ 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.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -83,9 +84,7 @@ public class FilterContentValidator {
         } catch (final ValidationException e) {
             LOG.debug("Filter content isn't valid", e);
             throw new DocumentedException("Validation failed. Cause: " + e.getMessage(), e,
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.UNKNOWN_NAMESPACE,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
         }
     }
 
@@ -106,11 +105,9 @@ public class FilterContentValidator {
                 return childNode;
             }
         }
-        throw new DocumentedException("Unable to find node with namespace: " + nameSpace
-                    + "in schema context: " + schemaContext.getCurrentContext().toString(),
-                DocumentedException.ErrorType.APPLICATION,
-                DocumentedException.ErrorTag.UNKNOWN_NAMESPACE,
-                ErrorSeverity.ERROR);
+        throw new DocumentedException("Unable to find node with namespace: " + nameSpace + " in schema context: "
+                + schemaContext.getCurrentContext(),
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
     }
 
     /**
index 54f7366b31c4a6d0b157223aa51147705c0600a2..438af75491953ba10af04f55906ab833b99a2505 100644 (file)
@@ -13,13 +13,13 @@ 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.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.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.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
index cc2ec31c0be40c22ae8b769da4b85196ddf9ecbf..dbca36746ec827c2cff295ac1e6834cec1a53e17 100644 (file)
@@ -14,13 +14,13 @@ 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.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.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.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
@@ -96,5 +96,4 @@ public class GetConfig extends AbstractGet {
     protected String getOperationName() {
         return OPERATION_NAME;
     }
-
 }
index 8d491b596da486cb2a3b2e287ade56f3dcf40688..a9c951d7bc7823f0edcb3073a814f5b7d334bce0 100644 (file)
@@ -19,10 +19,10 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.opendaylight.netconf.api.DocumentedException;
 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
 
index 1af28ba83058d5197d8096e12443e754d6dde9bb..619f009fa207cc23375233363923f8c6c60334f9 100644 (file)
@@ -15,7 +15,6 @@ import java.net.URI;
 import org.junit.Test;
 import org.opendaylight.netconf.api.DocumentedException;
 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.XmlUtil;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
@@ -23,6 +22,7 @@ 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.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.w3c.dom.Document;
index 2e858e5a5aeb22420edb145199b7343ca7f70101..85d6d02962c4696ba35fe35728e50d6a9716d858 100644 (file)
@@ -42,7 +42,6 @@ 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.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
@@ -51,6 +50,7 @@ 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.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -263,6 +263,7 @@ public class RuntimeRpcTest {
             rpc.handle(rpcDocument, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT);
             fail("Should have failed, rpc has bad namespace");
         } catch (final DocumentedException e) {
+            // FIXME: use assertThrows() and assertEquals()
             assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
             assertTrue(e.getErrorTag() == ErrorTag.BAD_ELEMENT);
             assertTrue(e.getErrorType() == ErrorType.APPLICATION);
index 80d1e4e7fa69f1c4b705eb81e1a44fc80d0faa3b..37a7ba81750ed2a20e9886e606df6d7fe3139c95 100644 (file)
@@ -33,6 +33,7 @@ import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator.Vali
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
@@ -62,7 +63,7 @@ public class ValidateTest {
             () -> validate("messages/mapping/validate/validate.xml"));
         assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
-        assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
+        assertEquals(ErrorType.PROTOCOL, e.getErrorType());
     }
 
     @Test
@@ -72,7 +73,7 @@ public class ValidateTest {
             () -> validate("messages/mapping/validate/validate_no_source.xml"));
         assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.MISSING_ELEMENT, e.getErrorTag());
-        assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
+        assertEquals(ErrorType.PROTOCOL, e.getErrorType());
     }
 
     @Test
@@ -82,7 +83,7 @@ public class ValidateTest {
             () -> validate("messages/mapping/validate/validate_running.xml"));
         assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
-        assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
+        assertEquals(ErrorType.PROTOCOL, e.getErrorType());
     }
 
     @Test
@@ -108,7 +109,7 @@ public class ValidateTest {
             () -> validate("messages/mapping/validate/validate.xml", transactionProvider));
         assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, e.getErrorTag());
-        assertEquals(DocumentedException.ErrorType.APPLICATION, e.getErrorType());
+        assertEquals(ErrorType.APPLICATION, e.getErrorType());
     }
 
     private void whenValidatorIsNotDefined() {
index 63d228c41656590cd8a84c27abbbf83269dc2ba8..dfabde4eeccd9e8a1b4b4c9da7337d3a06a0df10 100644 (file)
@@ -17,6 +17,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -59,7 +60,7 @@ public final class GetSchema extends AbstractSingletonNetconfOperation {
             final Map<String, String> errorInfo = new HashMap<>();
             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,
+            throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION,
                     DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, errorInfo);
         }
 
index 07636246bb20848c41ab3a0e15445a3b637aa532..669218d5d0698f20b27dca2292026eff5268c29c 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.netconf.api;
 
-import static java.util.Objects.requireNonNull;
 import static org.opendaylight.netconf.api.xml.XmlNetconfConstants.RPC_REPLY_KEY;
 import static org.opendaylight.netconf.api.xml.XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
 
@@ -17,6 +16,7 @@ import java.util.Map.Entry;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -61,30 +61,6 @@ public class DocumentedException extends Exception {
         BUILDER_FACTORY.setIgnoringComments(true);
     }
 
-    public enum ErrorType {
-        TRANSPORT("transport"), RPC("rpc"), PROTOCOL("protocol"), APPLICATION("application");
-
-        private final String typeValue;
-
-        ErrorType(final String typeValue) {
-            this.typeValue = requireNonNull(typeValue);
-        }
-
-        public String getTypeValue() {
-            return this.typeValue;
-        }
-
-        public static ErrorType from(final String text) {
-            for (ErrorType e : values()) {
-                if (e.getTypeValue().equalsIgnoreCase(text)) {
-                    return e;
-                }
-            }
-
-            return APPLICATION;
-        }
-    }
-
     public enum ErrorTag {
         ACCESS_DENIED("access-denied"),
         BAD_ATTRIBUTE("bad-attribute"),
@@ -202,7 +178,9 @@ public class DocumentedException extends Exception {
 
                     // FIXME: use a switch expression here
                     if (ERROR_TYPE.equals(rpcErrorChild.getLocalName())) {
-                        errorType = ErrorType.from(rpcErrorChild.getTextContent());
+                        final ErrorType type = ErrorType.forElementBody(rpcErrorChild.getTextContent());
+                        // FIXME: this should be a hard error
+                        errorType = type != null ? type : ErrorType.APPLICATION;
                     } else if (ERROR_TAG.equals(rpcErrorChild.getLocalName())) {
                         errorTag = ErrorTag.from(rpcErrorChild.getTextContent());
                     } else if (ERROR_SEVERITY.equals(rpcErrorChild.getLocalName())) {
@@ -269,7 +247,7 @@ public class DocumentedException extends Exception {
             Node rpcError = doc.createElementNS(URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, RPC_ERROR);
             rpcReply.appendChild(rpcError);
 
-            rpcError.appendChild(createTextNode(doc, ERROR_TYPE, getErrorType().getTypeValue()));
+            rpcError.appendChild(createTextNode(doc, ERROR_TYPE, getErrorType().elementBody()));
             rpcError.appendChild(createTextNode(doc, ERROR_TAG, getErrorTag().getTagValue()));
             rpcError.appendChild(createTextNode(doc, ERROR_SEVERITY, getErrorSeverity().elementBody()));
             rpcError.appendChild(createTextNode(doc, ERROR_MESSAGE, getLocalizedMessage()));
index 6f7ccfef946eaba5549c8ca849272f3db8e55a9f..d13a5e1e97849f7eb1546fe30896d79ec650e14e 100644 (file)
@@ -5,12 +5,12 @@
  * 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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Map;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 
 /**
index 9701428e420baf29833de59fddffa79775f4cddd..092e9c5946fbe1bca784b2d7f26471b35dbefb79 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.api.xml;
 import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 
 public class MissingNameSpaceException extends DocumentedException {
     private static final long serialVersionUID = 1L;
index ed5e9c89292ab323913dab268c127257dc01c7d0..148fb109846f9a043f2eb0d767dbe3e45bed5e13 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.api.xml;
 import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 
 public class UnexpectedElementException extends DocumentedException {
     private static final long serialVersionUID = 1L;
index 001107f7a719645baf8f7c66440adc3a8898ed87..f727704a67bf7841110ebd51b37b5a99a42634d1 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.api.xml;
 import java.util.Map;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 
 public class UnexpectedNamespaceException extends DocumentedException {
     private static final long serialVersionUID = 1L;
index d19ce378b8016a060b9b489483f27c13e2d8e0c8..d65f4de0aeb9147ea5d6f7f717d5eeb195ce82c1 100644 (file)
@@ -21,6 +21,7 @@ import java.util.Optional;
 import javax.xml.XMLConstants;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Attr;
@@ -86,9 +87,7 @@ public final class XmlElement {
                 } else {
                     if (!attribKey.startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")) {
                         throw new DocumentedException("Attribute doesn't start with :",
-                                DocumentedException.ErrorType.APPLICATION,
-                                DocumentedException.ErrorTag.INVALID_VALUE,
-                                ErrorSeverity.ERROR);
+                                ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
                     }
                     prefix = attribKey.substring(XMLConstants.XMLNS_ATTRIBUTE.length() + 1);
                 }
@@ -111,33 +110,25 @@ public final class XmlElement {
         if (!getName().equals(expectedName)) {
             throw new UnexpectedElementException(String.format("Expected %s xml element but was %s", expectedName,
                     getName()),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.OPERATION_FAILED,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
     }
 
     public void checkNamespaceAttribute(final String expectedNamespace)
             throws UnexpectedNamespaceException, MissingNameSpaceException {
         if (!getNamespaceAttribute().equals(expectedNamespace)) {
-            throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s should be %s",
-                    getNamespaceAttribute(),
-                    expectedNamespace),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.OPERATION_FAILED,
-                    ErrorSeverity.ERROR);
+            throw new UnexpectedNamespaceException(
+                    String.format("Unexpected namespace %s should be %s", getNamespaceAttribute(), expectedNamespace),
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
     }
 
     public void checkNamespace(final String expectedNamespace)
             throws UnexpectedNamespaceException, MissingNameSpaceException {
         if (!getNamespace().equals(expectedNamespace)) {
-            throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s should be %s",
-                    getNamespace(),
-                    expectedNamespace),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.OPERATION_FAILED,
-                    ErrorSeverity.ERROR);
+            throw new UnexpectedNamespaceException(
+                    String.format("Unexpected namespace %s should be %s", getNamespace(), expectedNamespace),
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
     }
 
@@ -298,9 +289,7 @@ public final class XmlElement {
         if (children.size() != 1) {
             throw new DocumentedException(String.format("One element %s:%s expected in %s but was %s", namespace,
                     childName, toString(), children.size()),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.INVALID_VALUE,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         }
 
         return children.get(0);
@@ -310,9 +299,7 @@ public final class XmlElement {
         List<XmlElement> nameElements = getChildElements(childName);
         if (nameElements.size() != 1) {
             throw new DocumentedException("One element " + childName + " expected in " + toString(),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.INVALID_VALUE,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         }
         return nameElements.get(0);
     }
@@ -322,9 +309,7 @@ public final class XmlElement {
         if (children.size() != 1) {
             throw new DocumentedException(String.format("One element expected in %s but was %s", toString(),
                     children.size()),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.INVALID_VALUE,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         }
         return children.get(0);
     }
@@ -342,10 +327,7 @@ public final class XmlElement {
             }
         }
         throw new DocumentedException(getName() + " should contain text.",
-                DocumentedException.ErrorType.APPLICATION,
-                DocumentedException.ErrorTag.INVALID_VALUE,
-                ErrorSeverity.ERROR
-        );
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
     }
 
     public Optional<String> getOnlyTextContentOptionally() {
@@ -362,11 +344,8 @@ public final class XmlElement {
     public String getNamespaceAttribute() throws MissingNameSpaceException {
         String attribute = element.getAttribute(XMLConstants.XMLNS_ATTRIBUTE);
         if (attribute.isEmpty() || attribute.equals(DEFAULT_NAMESPACE_PREFIX)) {
-            throw new MissingNameSpaceException(String.format("Element %s must specify namespace",
-                    toString()),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.OPERATION_FAILED,
-                    ErrorSeverity.ERROR);
+            throw new MissingNameSpaceException(String.format("Element %s must specify namespace", toString()),
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
         return attribute;
     }
@@ -392,9 +371,7 @@ public final class XmlElement {
         Optional<String> namespaceURI = getNamespaceOptionally();
         if (namespaceURI.isEmpty()) {
             throw new MissingNameSpaceException(String.format("No namespace defined for %s", this),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.OPERATION_FAILED,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
         return namespaceURI.get();
     }
@@ -461,9 +438,7 @@ public final class XmlElement {
         }
         if (!childElements.isEmpty()) {
             throw new DocumentedException(String.format("Unrecognised elements %s in %s", childElements, this),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.INVALID_VALUE,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         }
     }
 
index b21ffbdb7f680973b56b55c5edd49198a8e508ac..87cf0686dd77cf8c5b26870d8a567ac6179458c4 100644 (file)
@@ -22,6 +22,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
@@ -60,11 +61,8 @@ public class NetconfDocumentedExceptionTest {
     @Test
     public void testToAndFromXMLDocument() throws XPathExpressionException {
         final String errorMessage = "mock error message";
-        DocumentedException ex = new NetconfDocumentedException(errorMessage, null,
-                DocumentedException.ErrorType.PROTOCOL,
-                DocumentedException.ErrorTag.DATA_EXISTS,
-                ErrorSeverity.WARNING,
-                Map.of("foo", "bar"));
+        DocumentedException ex = new NetconfDocumentedException(errorMessage, null, ErrorType.PROTOCOL,
+                DocumentedException.ErrorTag.DATA_EXISTS, ErrorSeverity.WARNING, Map.of("foo", "bar"));
 
         final Document doc = ex.toXMLDocument();
         assertNotNull("Document is null", doc);
@@ -79,8 +77,7 @@ public class NetconfDocumentedExceptionTest {
 
         final Node errorTypeNode = getNode("netconf:error-type", rpcErrorNode);
         assertNotNull("error-type not found", errorTypeNode);
-        assertEquals("error-type", DocumentedException.ErrorType.PROTOCOL.getTypeValue(),
-                errorTypeNode.getTextContent());
+        assertEquals("error-type", ErrorType.PROTOCOL.elementBody(), errorTypeNode.getTextContent());
 
         final Node errorTagNode = getNode("netconf:error-tag", rpcErrorNode);
         assertNotNull("error-tag not found", errorTagNode);
@@ -106,7 +103,7 @@ public class NetconfDocumentedExceptionTest {
         assertNotNull("NetconfDocumentedException is null", ex);
         assertEquals("getErrorSeverity", ErrorSeverity.WARNING, ex.getErrorSeverity());
         assertEquals("getErrorTag", DocumentedException.ErrorTag.DATA_EXISTS, ex.getErrorTag());
-        assertEquals("getErrorType", DocumentedException.ErrorType.PROTOCOL, ex.getErrorType());
+        assertEquals("getErrorType", ErrorType.PROTOCOL, ex.getErrorType());
         assertEquals("getLocalizedMessage", errorMessage, ex.getLocalizedMessage());
         assertEquals("getErrorInfo", Map.of("foo", "bar"), ex.getErrorInfo());
     }
index cdf9ee3f05e61cbfc5d65faede18ff6cdc7fe00d..0d4a84c86f3a122a559611e3945f3e866ba2dc66 100644 (file)
@@ -23,6 +23,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -137,8 +138,8 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
              * unexpected element Description: An unexpected element is present.
              */
             throw new DocumentedException("Unknown tag " + rootNode.getNodeName() + " in message:\n" + netconfMessage,
-                    DocumentedException.ErrorType.PROTOCOL, DocumentedException.ErrorTag.UNKNOWN_ELEMENT,
-                    ErrorSeverity.ERROR, ImmutableMap.of("bad-element", rootNode.getNodeName()));
+                    ErrorType.PROTOCOL, DocumentedException.ErrorTag.UNKNOWN_ELEMENT, ErrorSeverity.ERROR,
+                    ImmutableMap.of("bad-element", rootNode.getNodeName()));
         }
     }
 
@@ -156,9 +157,8 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
         }
 
         throw new DocumentedException("Missing attribute " + rootNode.getNodeName(),
-                DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.MISSING_ATTRIBUTE,
-                ErrorSeverity.ERROR,
-                ImmutableMap.of("bad-attribute", XmlNetconfConstants.MESSAGE_ID,
-                        "bad-element", XmlNetconfConstants.RPC_KEY));
+                ErrorType.RPC, DocumentedException.ErrorTag.MISSING_ATTRIBUTE, ErrorSeverity.ERROR, ImmutableMap.of(
+                    "bad-attribute", XmlNetconfConstants.MESSAGE_ID,
+                    "bad-element", XmlNetconfConstants.RPC_KEY));
     }
 }
index ff08feb10f7f635c714425ffa6d113f85b551a8f..b0092519d875f3d6580b02b58d76f7e910b534d6 100644 (file)
@@ -16,6 +16,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -53,10 +54,9 @@ public class DefaultCloseSession extends AbstractSingletonNetconfOperation imple
             requireNonNull(session, "Session was not set").delayedClose();
             LOG.info("Session {} closing", session.getSessionId());
         } catch (final Exception e) {
-            throw new DocumentedException("Unable to properly close session "
-                    + getNetconfSessionIdForReporting(), e, DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.OPERATION_FAILED,
-                    ErrorSeverity.ERROR, Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
+            throw new DocumentedException("Unable to properly close session " + getNetconfSessionIdForReporting(), e,
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
+                    Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
         }
         return document.createElement(XmlNetconfConstants.OK);
     }
index dbc8e906c3a275f12fc8eec31c858774fffc76b9..844250c0974cf0366c4270f87ca97144af602b6a 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.netconf.impl.mapping.operations;
 
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
@@ -18,6 +17,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
index 8a9acf07ee2fe98c406f857beb031a19090e5d56..7dd0c2ad6b74d336732d7fb964b8edd4ae324f9a 100644 (file)
@@ -31,6 +31,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -77,8 +78,7 @@ 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, ErrorSeverity.ERROR,
-                    Map.of(tag.toString(), e.getMessage()));
+                    e, ErrorType.APPLICATION, tag, ErrorSeverity.ERROR, Map.of(tag.toString(), e.getMessage()));
         } catch (final RuntimeException e) {
             throw handleUnexpectedEx("sort", e);
         }
@@ -98,9 +98,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
     private static DocumentedException handleUnexpectedEx(final String op, final Exception exception) {
         LOG.error("Unexpected exception during netconf operation {}", op, exception);
         return new DocumentedException("Unexpected error",
-                DocumentedException.ErrorType.APPLICATION,
-                DocumentedException.ErrorTag.OPERATION_FAILED,
-                ErrorSeverity.ERROR,
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
                 Map.of(ErrorSeverity.ERROR.toString(), exception.toString()));
     }
 
index f137dd1f5b3539525b2c04c177c4ab28f8ab8726..49817193738a271e4893d8b20063cc90d011c7ea 100644 (file)
@@ -14,6 +14,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,8 +42,7 @@ public final class DeserializerExceptionHandler implements ChannelHandler {
         final Map<String, String> info = new HashMap<>();
         info.put("cause", cause.getMessage());
         final DocumentedException ex = new DocumentedException(cause.getMessage(),
-                DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.MALFORMED_MESSAGE,
-                ErrorSeverity.ERROR, info);
+                ErrorType.RPC, DocumentedException.ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR, info);
 
         SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), ex);
     }
index 56884d35311f132f9c3b0d5ae21c0520f58b5534..56ee80fa73ae068e17378f800bb5addb173ce9d2 100644 (file)
@@ -24,6 +24,7 @@ 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;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 
 public final class NetconfTopologyUtils {
     public static final long DEFAULT_REQUEST_TIMEOUT_MILLIS = 60000L;
@@ -82,7 +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,
-                ErrorSeverity.WARNING);
+                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.WARNING);
     }
 }
index aa3bc71964637388db516a78d5b86e1134696229..877c9e2b4c0c728130a78e6e23898eccf06fd334 100644 (file)
@@ -47,6 +47,7 @@ import org.opendaylight.netconf.topology.singleton.messages.netconf.UnlockReques
 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.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -303,6 +304,6 @@ public class ProxyNetconfServiceTest {
         final DocumentedException de = (DocumentedException) cause;
         assertEquals(ErrorSeverity.WARNING, de.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, de.getErrorTag());
-        assertEquals(DocumentedException.ErrorType.APPLICATION, de.getErrorType());
+        assertEquals(ErrorType.APPLICATION, de.getErrorType());
     }
 }
\ No newline at end of file
index 3ec6f891163ee2b7f87bbf0b3f8c35198010f8a3..83f1dd9ae980d88941398f655abee0538037e284 100644 (file)
@@ -44,6 +44,7 @@ import org.opendaylight.netconf.topology.singleton.messages.transactions.PutRequ
 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.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -403,6 +404,6 @@ public class ProxyReadWriteTransactionTest {
         final DocumentedException de = (DocumentedException) cause;
         assertEquals(ErrorSeverity.WARNING, de.getErrorSeverity());
         assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, de.getErrorTag());
-        assertEquals(DocumentedException.ErrorType.APPLICATION, de.getErrorType());
+        assertEquals(ErrorType.APPLICATION, de.getErrorType());
     }
 }
index b99f75d346545301d6c03c93fb44c283bba67882..7595a86ea5f09278cd82fee05211b33f56cbdb1d 100644 (file)
@@ -12,6 +12,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -27,9 +28,7 @@ public abstract class AbstractLastNetconfOperation extends AbstractNetconfOperat
         if (!subsequentOperation.isExecutionTermination()) {
             throw new DocumentedException(String.format(
                     "No netconf operation expected to be subsequent to %s, but is %s", this, subsequentOperation),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.MALFORMED_MESSAGE,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
         }
 
         return handleWithNoSubsequentOperations(document, operationElement);
index 98fb17d8563f1156c3481e007df15ad7946ef3c7..896485b70b8563f6806ff9437539b260ba78628f 100644 (file)
@@ -33,6 +33,7 @@ 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.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -230,7 +231,7 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
                         new NetconfDocumentedException(
                                 id + ":RPC during tx returned an exception" + throwable.getMessage(),
                                 new Exception(throwable),
-                                DocumentedException.ErrorType.APPLICATION,
+                                ErrorType.APPLICATION,
                                 DocumentedException.ErrorTag.OPERATION_FAILED,
                                 ErrorSeverity.ERROR);
                 transformed.setException(exception);
@@ -244,7 +245,7 @@ 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;
+        ErrorType errType = ErrorType.APPLICATION;
         ErrorSeverity errSeverity = ErrorSeverity.ERROR;
         StringBuilder msgBuilder = new StringBuilder();
         boolean errorsEncouneterd = false;
@@ -254,25 +255,8 @@ 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;
-                }
 
+                errType = error.getErrorType().toNetconf();
                 errSeverity = error.getSeverity().toNetconf();
                 msgBuilder.append(error.getMessage());
                 msgBuilder.append(error.getInfo());
index a3d53d268f188825a5bce0d6c49d53d13e55f430..865a2a62c7827cc50cb6cd68256a9c919ad95e5f 100644 (file)
@@ -52,6 +52,7 @@ 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.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -287,15 +288,9 @@ public final class NetconfMessageTransformUtil {
         final String outputMsgId = output.getDocument().getDocumentElement().getAttribute(MESSAGE_ID_ATTR);
 
         if (!inputMsgId.equals(outputMsgId)) {
-            final Map<String, String> errorInfo = ImmutableMap.<String, String>builder()
-                    .put("actual-message-id", outputMsgId)
-                    .put("expected-message-id", inputMsgId)
-                    .build();
-
-            throw new NetconfDocumentedException("Response message contained unknown \"message-id\"",
-                    null, NetconfDocumentedException.ErrorType.PROTOCOL,
-                    NetconfDocumentedException.ErrorTag.BAD_ATTRIBUTE,
-                    ErrorSeverity.ERROR, errorInfo);
+            throw new NetconfDocumentedException("Response message contained unknown \"message-id\"", null,
+                    ErrorType.PROTOCOL, NetconfDocumentedException.ErrorTag.BAD_ATTRIBUTE, ErrorSeverity.ERROR,
+                    ImmutableMap.of("actual-message-id", outputMsgId, "expected-message-id", inputMsgId));
         }
     }
 
@@ -317,26 +312,13 @@ public final class NetconfMessageTransformUtil {
         }
 
         return ex.getErrorSeverity() == ErrorSeverity.ERROR
-                ? RpcResultBuilder.newError(toRpcErrorType(ex.getErrorType()), ex.getErrorTag().getTagValue(),
+                ? RpcResultBuilder.newError(ex.getErrorType().toLegacy(), ex.getErrorTag().getTagValue(),
                         ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause())
                 : RpcResultBuilder.newWarning(
-                        toRpcErrorType(ex.getErrorType()), ex.getErrorTag().getTagValue(),
+                        ex.getErrorType().toLegacy(), ex.getErrorTag().getTagValue(),
                         ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause());
     }
 
-    private static RpcError.ErrorType toRpcErrorType(final NetconfDocumentedException.ErrorType type) {
-        switch (type) {
-            case PROTOCOL:
-                return RpcError.ErrorType.PROTOCOL;
-            case RPC:
-                return RpcError.ErrorType.RPC;
-            case TRANSPORT:
-                return RpcError.ErrorType.TRANSPORT;
-            default:
-                return RpcError.ErrorType.APPLICATION;
-        }
-    }
-
     public static NodeIdentifier toId(final PathArgument qname) {
         return qname instanceof NodeIdentifier ? (NodeIdentifier) qname : toId(qname.getNodeType());
     }
@@ -561,9 +543,7 @@ 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,
-                    ErrorSeverity.ERROR)))
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR)))
                 .build();
     }
 }
index b7c35e0fbd34c19fbe3dc6ce32994f0762f3267d..422cb573b1f46d9b60b9c7c3ecce1922902cfea0 100644 (file)
@@ -17,6 +17,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 
 /**
@@ -51,8 +52,7 @@ class SettableRpc implements NetconfOperation {
             return document;
         } else if (subsequentOperation.isExecutionTermination()) {
             throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage),
-                    DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
         } else {
             return subsequentOperation.execute(requestMessage);
         }
index a51f4712e1499e2aaba0725df39e526977424b3b..1af952b64765b8f05430e676ca06be4967a216e0 100644 (file)
@@ -16,6 +16,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -55,9 +56,7 @@ public class Get extends AbstractNetconfOperation {
             throws DocumentedException {
         if (subsequentOperation.isExecutionTermination()) {
             throw new DocumentedException(String.format("Subsequent netconf operation expected by %s", this),
-                    DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.OPERATION_FAILED,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
 
         try {
@@ -75,9 +74,8 @@ public class Get extends AbstractNetconfOperation {
             final String errorMessage = "Get operation for netconf-state subtree failed";
             LOG.warn(errorMessage, e);
 
-            throw new DocumentedException(errorMessage, e, DocumentedException.ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.OPERATION_FAILED,
-                    ErrorSeverity.ERROR,
+            throw new DocumentedException(errorMessage, e,
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
                     Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
         }
     }
index 75f1b71adb836d571bc95d627f87e94285333d68..9a1d499b39fe710272fc99b7c2c2838b1d123829 100644 (file)
@@ -16,6 +16,7 @@ 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.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 
 /**
@@ -50,8 +51,7 @@ class SettableRpc implements NetconfOperation {
             return document;
         } else if (subsequentOperation.isExecutionTermination()) {
             throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage),
-                    DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
-                    ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
         } else {
             return subsequentOperation.execute(requestMessage);
         }
index de7c9c02a916bdca84cc2dbd885ca21abe1713e5..635042114a77ccca546d226175dc2dd13e68da67 100644 (file)
@@ -35,6 +35,7 @@ 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.ErrorType;
 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,8 +213,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
                             return operation.get();
                         } else {
                             return Futures.immediateFailedFuture(new NetconfDocumentedException("Lock operation failed",
-                                DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.LOCK_DENIED,
-                                ErrorSeverity.ERROR));
+                                ErrorType.APPLICATION, DocumentedException.ErrorTag.LOCK_DENIED, ErrorSeverity.ERROR));
                         }
                     },
                     MoreExecutors.directExecutor());
@@ -249,26 +249,12 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
             justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static TransactionCommitFailedException toCommitFailedException(
             final Collection<? extends RpcError> errors) {
-        DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
+        ErrorType errType = ErrorType.APPLICATION;
         ErrorSeverity errSeverity = ErrorSeverity.ERROR;
         StringJoiner msgBuilder = new StringJoiner(" ");
         String errorTag = "operation-failed";
         for (final RpcError error : errors) {
-            switch (error.getErrorType()) {
-                case RPC:
-                    errType = DocumentedException.ErrorType.RPC;
-                    break;
-                case PROTOCOL:
-                    errType = DocumentedException.ErrorType.PROTOCOL;
-                    break;
-                case TRANSPORT:
-                    errType = DocumentedException.ErrorType.TRANSPORT;
-                    break;
-                case APPLICATION:
-                default:
-                    errType = DocumentedException.ErrorType.APPLICATION;
-                    break;
-            }
+            errType = error.getErrorType().toNetconf();
             errSeverity = error.getSeverity().toNetconf();
             msgBuilder.add(error.getMessage());
             msgBuilder.add(error.getInfo());
index fddf1a78eb2b8dc2ce16807151c6b48a7f98d8af..1e0697b46fd98508c64c385c5256b8c37874f6f7 100644 (file)
@@ -120,7 +120,7 @@ final class FutureCallbackTx {
                     if (error instanceof NetconfDocumentedException) {
                         throw new RestconfDocumentedException(error.getMessage(),
                                 RestconfError.ErrorType.valueOfCaseInsensitive(
-                                        ((NetconfDocumentedException) error).getErrorType().getTypeValue()),
+                                        ((NetconfDocumentedException) error).getErrorType().elementBody()),
                                 RestconfError.ErrorTag.valueOfCaseInsensitive(
                                         ((NetconfDocumentedException) error).getErrorTag().getTagValue()), e);
                     }
index 35f4d18b4e5096add9ed83f04cec5f44759b7f8d..ba2af37eb326befcd73a4b5882dc490fc73e383b 100644 (file)
@@ -34,12 +34,13 @@ import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
-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.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
@@ -88,8 +89,7 @@ public class DeleteDataTransactionUtilTest {
         when(readWrite.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty()))
             .thenReturn(immediateFalseFluentFuture());
         final NetconfDocumentedException exception = new NetconfDocumentedException("id",
-            DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"),
-            ErrorSeverity.ERROR);
+            ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"), ErrorSeverity.ERROR);
         final SettableFuture<? extends CommitInfo> ret = SettableFuture.create();
         ret.setException(new TransactionCommitFailedException(
             String.format("Commit of transaction %s failed", this), exception));
@@ -112,7 +112,7 @@ public class DeleteDataTransactionUtilTest {
             DeleteDataTransactionUtil.deleteData(strategy, context.getInstanceIdentifier());
             fail("Delete operation should fail due to missing data");
         } catch (final RestconfDocumentedException e) {
-            assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
+            assertEquals(RestconfError.ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
             assertEquals(ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
         }
     }
index 5af6b45e5fa4e354da4ce12b9f348dfeb795e3f5..785bae0dda98a716cb3c9baaf276dc7ffa2b3b0e 100644 (file)
@@ -51,6 +51,7 @@ import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStra
 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.ErrorType;
 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,8 +234,7 @@ public class PatchDataTransactionUtilTest {
         doReturn(immediateFalseFluentFuture()).when(this.rwTransaction).exists(LogicalDatastoreType.CONFIGURATION,
             this.targetNodeForCreateAndDelete);
         final NetconfDocumentedException exception = new NetconfDocumentedException("id",
-            DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"),
-            ErrorSeverity.ERROR);
+            ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"), ErrorSeverity.ERROR);
         final SettableFuture<? extends DOMRpcResult> ret = SettableFuture.create();
         ret.setException(new TransactionCommitFailedException(
             String.format("Commit of transaction %s failed", this), exception));