Remove DocumentedException.ErrorTag 29/97029/5
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Jul 2021 20:08:47 +0000 (22:08 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 28 Jul 2021 08:30:45 +0000 (10:30 +0200)
We have an openly-extensible ErrorTag concept in yang-common. Remove
the hard-coded enum we have in DocumentedException.

JIRA: NETCONF-793
Change-Id: Ic4e1bebff549c5fd09a78995b8e76e37905241ef
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
48 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/main/java/org/opendaylight/netconf/api/xml/XmlUtil.java
netconf/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java
netconf/netconf-api/src/test/java/org/opendaylight/netconf/api/xml/XmlElementTest.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/osgi/NetconfOperationRouterImplTest.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/listener/NetconfDeviceCommunicator.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 345a5e5287d7a3d34c4ea9f2265e5eb451015caa..ecf344a93cd24e0fb7e72fdc9a50fe46dab5e9d4 100644 (file)
@@ -18,8 +18,8 @@ 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index 81899f208d63fd066d75ff21e7caf27a377507fa..321a7a0d6fce74caba91c6b0debcff722adb57c7 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -62,7 +63,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",
-                ErrorType.PROTOCOL, DocumentedException.ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
+                ErrorType.PROTOCOL, ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
         }
 
         final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
@@ -84,13 +85,13 @@ abstract class AbstractConfigOperation extends AbstractSingletonNetconfOperation
             return XmlUtil.readXmlToDocument(input);
         } catch (MalformedURLException e) {
             throw new DocumentedException(url + " URL is invalid or unsupported", e,
-                ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         } catch (IOException e) {
             throw new DocumentedException("Could not open URL " + url, e,
-                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         } catch (SAXException e) {
             throw new DocumentedException("Could not parse XML at" + url, e,
-                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
     }
 
index c64eec08eeaff09895517903811a706fdaec606e..41ac93f9fd82c3a6d843afb933e23c2da8ff2fee 100644 (file)
@@ -15,11 +15,11 @@ 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.ErrorTag;
 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
@@ -62,7 +62,7 @@ abstract class AbstractEdit extends AbstractConfigOperation {
             xmlParser.traverse(new DOMSource(element.getDomElement()));
         } catch (final XMLStreamException | URISyntaxException | IOException | SAXException ex) {
             throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex, ErrorType.PROTOCOL,
-                ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
+                DocumentedException.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
         }
     }
 
index 2989e27aec57139ae3b1143fd2d703e3c2c51a80..9ba2a1499b2a1f4f51aedb7f80cb859f30c333c4 100644 (file)
@@ -26,13 +26,13 @@ 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.ErrorTag;
 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -119,7 +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",
-                ErrorType.PROTOCOL, DocumentedException.ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
+                ErrorType.PROTOCOL, ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
         }
 
         return sourceElement.get();
index bb3f97a585f9a8bb8dcd8b6fae723f80347222dd..eed436c38e286ae038557c2c334c7f716df0962a 100644 (file)
@@ -10,12 +10,12 @@ 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.ErrorTag;
 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,7 +42,7 @@ public class DiscardChanges extends AbstractSingletonNetconfOperation {
         } catch (final IllegalStateException e) {
             LOG.warn("Abort failed ", e);
             final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.OPERATION_FAILED.name(),
+            errorInfo.put(ErrorTag.OPERATION_FAILED.elementBody(),
                     "Operation failed. Use 'get-config' or 'edit-config' before triggering "
                             + OPERATION_NAME + " operation");
             throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED,
index bc568e77e16e0a627f0ba262b3a4533bab933a4d..66020c8dad9253a0f40f46b11c36f0197d38856d 100644 (file)
@@ -15,13 +15,13 @@ 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.ErrorTag;
 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
index ffbb548d1722998ad8859ef9cd25c0635d2ff06b..ab9076e2a49d7763af01a34845a8d6c812934cc4 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,7 +44,7 @@ public class Lock extends AbstractSingletonNetconfOperation {
         }
 
         throw new DocumentedException("Unable to lock " + targetDatastore + " datastore",
-                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
     }
 
     static Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException {
index efc34d0a1573017e42148d9c977acdc6f94f41e8..8159382c36b04eaeae6fc1718906e76727e608f1 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.ErrorTag;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
@@ -31,6 +30,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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -260,7 +260,7 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation {
             xmlParser.traverse(new DOMSource(element.getDomElement()));
         } catch (final XMLStreamException | URISyntaxException | IOException | SAXException ex) {
             throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex, ErrorType.PROTOCOL,
-                    ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
+                    DocumentedException.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
         }
 
         return (ContainerNode) resultHolder.getResult();
index b3fe4a56c9a24938862bfd1694033e3f02ee81b0..4fd8f22feece27d84910fc89154fe3ef9a2f109b 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,7 +41,7 @@ public class Unlock extends AbstractSingletonNetconfOperation {
         }
 
         throw new DocumentedException("Unable to unlock " + targetDatastore + " datastore",
-                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
     }
 
     @Override
index a8229f10f51c8bbbea7daf3d5328abb5649fbd4a..c9620176aa8013390f980fcb832cefe5d5b03952 100644 (file)
@@ -9,11 +9,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.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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index e4fd8d6ad4fe3d358539c767300a1a26ca65209f..1366fc4e7c9cd601f8998f5b783a781e1b7120d6 100644 (file)
@@ -16,13 +16,13 @@ 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.ErrorTag;
 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
index 0be3023f9f502e10971cbc0c24052b2715ba20b9..27c0c71064a322141ce201633f548df572c61673 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
@@ -84,7 +85,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,
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
         }
     }
 
@@ -107,7 +108,7 @@ public class FilterContentValidator {
         }
         throw new DocumentedException("Unable to find node with namespace: " + nameSpace + " in schema context: "
                 + schemaContext.getCurrentContext(),
-                ErrorType.APPLICATION, DocumentedException.ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
     }
 
     /**
index 438af75491953ba10af04f55906ab833b99a2505..8c28dc8fd65f9c3a18a839b31116595cdbb966a1 100644 (file)
@@ -12,13 +12,13 @@ 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.ErrorTag;
 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
index dbca36746ec827c2cff295ac1e6834cec1a53e17..7de5b223bc6b46fc58db86d151ba12bda3935826 100644 (file)
@@ -13,13 +13,13 @@ 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.ErrorTag;
 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
index a9c951d7bc7823f0edcb3073a814f5b7d334bce0..1044a8773c12e11a34b2bb3bbf3f71e758313c35 100644 (file)
@@ -18,10 +18,10 @@ 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.ErrorTag;
 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
index 619f009fa207cc23375233363923f8c6c60334f9..d111a5d8a07961b816d8656ff2de9def93c4abf9 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.ErrorTag;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
@@ -22,6 +21,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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
index 85d6d02962c4696ba35fe35728e50d6a9716d858..79142fda2a2479813f6388a4e412e611e94967ef 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.ErrorTag;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
@@ -50,6 +49,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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
index 37a7ba81750ed2a20e9886e606df6d7fe3139c95..891254bef1eac36ceb04cafdcf5fe67872dec701 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 
@@ -62,7 +63,7 @@ public class ValidateTest {
         final DocumentedException e = assertThrows(DocumentedException.class,
             () -> validate("messages/mapping/validate/validate.xml"));
         assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
-        assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
+        assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
         assertEquals(ErrorType.PROTOCOL, e.getErrorType());
     }
 
@@ -72,7 +73,7 @@ public class ValidateTest {
         final DocumentedException e = assertThrows(DocumentedException.class,
             () -> validate("messages/mapping/validate/validate_no_source.xml"));
         assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
-        assertEquals(DocumentedException.ErrorTag.MISSING_ELEMENT, e.getErrorTag());
+        assertEquals(ErrorTag.MISSING_ELEMENT, e.getErrorTag());
         assertEquals(ErrorType.PROTOCOL, e.getErrorType());
     }
 
@@ -82,7 +83,7 @@ public class ValidateTest {
         final DocumentedException e = assertThrows(DocumentedException.class,
             () -> validate("messages/mapping/validate/validate_running.xml"));
         assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
-        assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
+        assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
         assertEquals(ErrorType.PROTOCOL, e.getErrorType());
     }
 
@@ -108,7 +109,7 @@ public class ValidateTest {
         final DocumentedException e = assertThrows(DocumentedException.class,
             () -> validate("messages/mapping/validate/validate.xml", transactionProvider));
         assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
-        assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, e.getErrorTag());
+        assertEquals(ErrorTag.OPERATION_FAILED, e.getErrorTag());
         assertEquals(ErrorType.APPLICATION, e.getErrorType());
     }
 
index dfabde4eeccd9e8a1b4b4c9da7337d3a06a0df10..2152d184f6ecaec57b761ca4c92ddd196b32badf 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,10 +59,11 @@ public final class GetSchema extends AbstractSingletonNetconfOperation {
             schema = cap.getSchemaForCapability(entry.identifier, entry.version);
         } catch (final IllegalStateException e) {
             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);
+            // FIXME: so we have an <operation-failed>e.getMessage()</operation-failed> ??? In which namespace? Why?
+            errorInfo.put(ErrorTag.OPERATION_FAILED.elementBody(), e.getMessage());
+            LOG.warn("Rpc error: {}", ErrorTag.OPERATION_FAILED, e);
             throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION,
-                    DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, errorInfo);
+                    ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, errorInfo);
         }
 
         final Element getSchemaResult;
index 669218d5d0698f20b27dca2292026eff5268c29c..4007d0aa9f91a52d6643770bb908dd6d16cac0a3 100644 (file)
@@ -10,12 +10,14 @@ package org.opendaylight.netconf.api;
 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;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.HashMap;
 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.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -27,6 +29,7 @@ import org.w3c.dom.NodeList;
  * Checked exception to communicate an error that needs to be sent to the
  * netconf client.
  */
+// FIXME: NETCONF-793: implement YangNetconfErrorAware
 public class DocumentedException extends Exception {
 
     public static final String RPC_ERROR = "rpc-error";
@@ -38,10 +41,12 @@ public class DocumentedException extends Exception {
     public static final String ERROR_MESSAGE = "error-message";
     public static final String ERROR_INFO = "error-info";
 
-    private static final long serialVersionUID = 1L;
+    // FIXME: This is an RFC6241 definition, remove it once we have yangtools-7.0.5
+    @Deprecated(forRemoval = true)
+    public static final ErrorTag MALFORMED_MESSAGE = new ErrorTag("malformed-message");
 
+    private static final long serialVersionUID = 1L;
     private static final Logger LOG = LoggerFactory.getLogger(DocumentedException.class);
-
     private static final DocumentBuilderFactory BUILDER_FACTORY;
 
     static {
@@ -61,49 +66,8 @@ public class DocumentedException extends Exception {
         BUILDER_FACTORY.setIgnoringComments(true);
     }
 
-    public enum ErrorTag {
-        ACCESS_DENIED("access-denied"),
-        BAD_ATTRIBUTE("bad-attribute"),
-        BAD_ELEMENT("bad-element"),
-        DATA_EXISTS("data-exists"),
-        DATA_MISSING("data-missing"),
-        IN_USE("in-use"),
-        INVALID_VALUE("invalid-value"),
-        LOCK_DENIED("lock-denied"),
-        MALFORMED_MESSAGE("malformed-message"),
-        MISSING_ATTRIBUTE("missing-attribute"),
-        MISSING_ELEMENT("missing-element"),
-        OPERATION_FAILED("operation-failed"),
-        OPERATION_NOT_SUPPORTED("operation-not-supported"),
-        RESOURCE_DENIED("resource-denied"),
-        ROLLBCK_FAILED("rollback-failed"),
-        TOO_BIG("too-big"),
-        UNKNOWN_ATTRIBUTE("unknown-attribute"),
-        UNKNOWN_ELEMENT("unknown-element"),
-        UNKNOWN_NAMESPACE("unknown-namespace");
-
-        private final String tagValue;
-
-        ErrorTag(final String tagValue) {
-            this.tagValue = tagValue;
-        }
-
-        public String getTagValue() {
-            return this.tagValue;
-        }
-
-        public static ErrorTag from(final String text) {
-            for (ErrorTag e : values()) {
-                if (e.getTagValue().equals(text)) {
-                    return e;
-                }
-            }
-
-            return OPERATION_FAILED;
-        }
-    }
-
     private final ErrorType errorType;
+    @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "FIXME: should not be necessary with yangtools-7.0.5")
     private final ErrorTag errorTag;
     private final ErrorSeverity errorSeverity;
     private final Map<String, String> errorInfo;
@@ -141,14 +105,16 @@ public class DocumentedException extends Exception {
         this.errorType = errorType;
         this.errorTag = errorTag;
         this.errorSeverity = errorSeverity;
+        // FIXME: this contract (based on what fromXMLDocument does) is quite wrong. It ignores the XML realities of
+        //        what constitutes a tag and especially tag value when faced with encoding XML-namespaced entities --
+        //        such as 'identity' arguments -- represented as QNames.
         this.errorInfo = errorInfo;
     }
 
-    public static <E extends Exception> DocumentedException wrap(final E exception) throws DocumentedException {
-        final Map<String, String> errorInfo = new HashMap<>();
-        errorInfo.put(ErrorTag.OPERATION_FAILED.name(), "Exception thrown");
+    public static DocumentedException wrap(final Exception exception) throws DocumentedException {
         throw new DocumentedException(exception.getMessage(), exception, ErrorType.APPLICATION,
-                ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, errorInfo);
+                ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
+                Map.of(ErrorTag.OPERATION_FAILED.elementBody(), "Exception thrown"));
     }
 
     public static DocumentedException fromXMLDocument(final Document fromDoc) {
@@ -162,9 +128,10 @@ public class DocumentedException extends Exception {
 
         Node rpcReply = fromDoc.getDocumentElement();
 
-        // FIXME: BUG? - we only handle one rpc-error. For now, shove extra errorMessages
-        // found in multiple rpc-error in the errorInfo Map to at least let them propagate
-        // back to caller.
+        // FIXME: we only handle one rpc-error. For now, shove extra errorMessages found in multiple rpc-error in the
+        //        errorInfo Map to at least let them propagate back to caller.
+        //        this will be solved through migration to YangNetconfErrorAware, as that allows reporting multipl
+        //        error events
         int rpcErrorCount = 0;
 
         NodeList replyChildren = rpcReply.getChildNodes();
@@ -182,7 +149,7 @@ public class DocumentedException extends Exception {
                         // 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());
+                        errorTag = new ErrorTag(rpcErrorChild.getTextContent());
                     } else if (ERROR_SEVERITY.equals(rpcErrorChild.getLocalName())) {
                         final ErrorSeverity sev = ErrorSeverity.forElementBody(rpcErrorChild.getTextContent());
                         // FIXME: this should be a hard error
@@ -213,6 +180,22 @@ public class DocumentedException extends Exception {
         for (int i = 0; i < children.getLength(); i++) {
             Node child = children.item(i);
             if (child.getNodeType() == Node.ELEMENT_NODE) {
+                // FIXME: Holy namespace ignorance, Batman!
+                //
+                // So this is just not enough to decode things in the general sense. getTextContenxt() may easily be a
+                // qualified QName, such as an identity name or an instance-identifier. What the entire 'infoMap' needs
+                // to contain is each child's XML context, so that the string literal can be interpreted as needed.
+                //
+                // yang.common.YangNamespaceContext represents the minimal API surface that needs to be exposed. That
+                // effectively means:
+                //
+                // final class ElementValue implements YangNamespaceContext {
+                //   public final String elementContenxt();
+                // }
+                //
+                // Map<QName, ElementValue> infoMap;
+                //
+                // except... what do we use for revision?
                 infoMap.put(child.getNodeName(), child.getTextContent());
             }
         }
@@ -220,6 +203,7 @@ public class DocumentedException extends Exception {
         return infoMap;
     }
 
+    // FIXME: NETCONF-793: remove all of these in favor of YangNetconfErrorAware
     public ErrorType getErrorType() {
         return this.errorType;
     }
@@ -236,6 +220,8 @@ public class DocumentedException extends Exception {
         return this.errorInfo;
     }
 
+    // FIXME: this really should be an spi/util method (or even netconf-util-w3c-dom?) as this certainly is not the
+    //        primary interface we want to expose -- it is inherently mutable and its API is a pure nightmare.
     public Document toXMLDocument() {
         Document doc = null;
         try {
@@ -248,7 +234,7 @@ public class DocumentedException extends Exception {
             rpcReply.appendChild(rpcError);
 
             rpcError.appendChild(createTextNode(doc, ERROR_TYPE, getErrorType().elementBody()));
-            rpcError.appendChild(createTextNode(doc, ERROR_TAG, getErrorTag().getTagValue()));
+            rpcError.appendChild(createTextNode(doc, ERROR_TAG, getErrorTag().elementBody()));
             rpcError.appendChild(createTextNode(doc, ERROR_SEVERITY, getErrorSeverity().elementBody()));
             rpcError.appendChild(createTextNode(doc, ERROR_MESSAGE, getLocalizedMessage()));
 
@@ -275,7 +261,7 @@ public class DocumentedException extends Exception {
         return doc;
     }
 
-    private Node createTextNode(final Document doc, final String tag, final String textContent) {
+    private static Node createTextNode(final Document doc, final String tag, final String textContent) {
         Node node = doc.createElementNS(URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, tag);
         node.setTextContent(textContent);
         return node;
index d13a5e1e97849f7eb1546fe30896d79ec650e14e..ed623cd7f10693c408bc524482e198300da26486 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.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 
index 092e9c5946fbe1bca784b2d7f26471b35dbefb79..6908d07c46bcd7c5528f7a53e741094394822afc 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 
 public class MissingNameSpaceException extends DocumentedException {
index 148fb109846f9a043f2eb0d767dbe3e45bed5e13..95a036d8a235dd6722ccaaf91d66f1de0331b983 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 
 public class UnexpectedElementException extends DocumentedException {
index f727704a67bf7841110ebd51b37b5a99a42634d1..825f1ad8e6e7fac6141557eb418680a4949b133e 100644 (file)
@@ -10,11 +10,16 @@ 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 
 public class UnexpectedNamespaceException extends DocumentedException {
     private static final long serialVersionUID = 1L;
 
+    public UnexpectedNamespaceException(final String format, final Object... args) {
+        this(String.format(format, args), ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
+    }
+
     public UnexpectedNamespaceException(final String message, final ErrorType errorType, final ErrorTag errorTag,
             final ErrorSeverity errorSeverity) {
         this(message, errorType, errorTag, errorSeverity, Map.of());
index d65f4de0aeb9147ea5d6f7f717d5eeb195ce82c1..c4346ee7e1d59f990e2a95fca3d23dee39cdeee3 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -87,7 +88,7 @@ public final class XmlElement {
                 } else {
                     if (!attribKey.startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")) {
                         throw new DocumentedException("Attribute doesn't start with :",
-                                ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
+                                ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
                     }
                     prefix = attribKey.substring(XMLConstants.XMLNS_ATTRIBUTE.length() + 1);
                 }
@@ -108,9 +109,9 @@ public final class XmlElement {
 
     public void checkName(final String expectedName) throws UnexpectedElementException {
         if (!getName().equals(expectedName)) {
-            throw new UnexpectedElementException(String.format("Expected %s xml element but was %s", expectedName,
-                    getName()),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
+            throw new UnexpectedElementException(
+                    String.format("Expected %s xml element but was %s", expectedName, getName()),
+                    ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
     }
 
@@ -119,7 +120,7 @@ public final class XmlElement {
         if (!getNamespaceAttribute().equals(expectedNamespace)) {
             throw new UnexpectedNamespaceException(
                     String.format("Unexpected namespace %s should be %s", getNamespaceAttribute(), expectedNamespace),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
     }
 
@@ -128,7 +129,7 @@ public final class XmlElement {
         if (!getNamespace().equals(expectedNamespace)) {
             throw new UnexpectedNamespaceException(
                     String.format("Unexpected namespace %s should be %s", getNamespace(), expectedNamespace),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
     }
 
@@ -289,7 +290,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()),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         }
 
         return children.get(0);
@@ -299,7 +300,7 @@ public final class XmlElement {
         List<XmlElement> nameElements = getChildElements(childName);
         if (nameElements.size() != 1) {
             throw new DocumentedException("One element " + childName + " expected in " + toString(),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         }
         return nameElements.get(0);
     }
@@ -307,9 +308,9 @@ public final class XmlElement {
     public XmlElement getOnlyChildElement() throws DocumentedException {
         List<XmlElement> children = getChildElements();
         if (children.size() != 1) {
-            throw new DocumentedException(String.format("One element expected in %s but was %s", toString(),
-                    children.size()),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
+            throw new DocumentedException(
+                    String.format("One element expected in %s but was %s", toString(), children.size()),
+                    ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         }
         return children.get(0);
     }
@@ -327,7 +328,7 @@ public final class XmlElement {
             }
         }
         throw new DocumentedException(getName() + " should contain text.",
-                ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
+                ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
     }
 
     public Optional<String> getOnlyTextContentOptionally() {
@@ -345,7 +346,7 @@ public final class XmlElement {
         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()),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
         return attribute;
     }
@@ -371,7 +372,7 @@ public final class XmlElement {
         Optional<String> namespaceURI = getNamespaceOptionally();
         if (namespaceURI.isEmpty()) {
             throw new MissingNameSpaceException(String.format("No namespace defined for %s", this),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
         return namespaceURI.get();
     }
@@ -438,7 +439,7 @@ public final class XmlElement {
         }
         if (!childElements.isEmpty()) {
             throw new DocumentedException(String.format("Unrecognised elements %s in %s", childElements, this),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
         }
     }
 
index 84548313176f326ed6fb071c7347a86f1ec75508..aa3f5b434d49a586377122bfa9f7b739a9901e11 100644 (file)
@@ -68,7 +68,7 @@ public final class XmlUtil {
         BUILDER_FACTORY = factory;
     }
 
-    private static final ThreadLocal<DocumentBuilder> DEFAULT_DOM_BUILDER = new ThreadLocal<DocumentBuilder>() {
+    private static final ThreadLocal<DocumentBuilder> DEFAULT_DOM_BUILDER = new ThreadLocal<>() {
         @Override
         protected DocumentBuilder initialValue() {
             try {
index 87cf0686dd77cf8c5b26870d8a567ac6179458c4..f4261f0a7fc0bda515fa0bf8d8fb213382b4b6b9 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -62,7 +63,7 @@ public class NetconfDocumentedExceptionTest {
     public void testToAndFromXMLDocument() throws XPathExpressionException {
         final String errorMessage = "mock error message";
         DocumentedException ex = new NetconfDocumentedException(errorMessage, null, ErrorType.PROTOCOL,
-                DocumentedException.ErrorTag.DATA_EXISTS, ErrorSeverity.WARNING, Map.of("foo", "bar"));
+                ErrorTag.DATA_EXISTS, ErrorSeverity.WARNING, Map.of("foo", "bar"));
 
         final Document doc = ex.toXMLDocument();
         assertNotNull("Document is null", doc);
@@ -81,8 +82,7 @@ public class NetconfDocumentedExceptionTest {
 
         final Node errorTagNode = getNode("netconf:error-tag", rpcErrorNode);
         assertNotNull("error-tag not found", errorTagNode);
-        assertEquals("error-tag", DocumentedException.ErrorTag.DATA_EXISTS.getTagValue(),
-                errorTagNode.getTextContent());
+        assertEquals("error-tag", ErrorTag.DATA_EXISTS.elementBody(), errorTagNode.getTextContent());
 
         final Node errorSeverityNode = getNode("netconf:error-severity", rpcErrorNode);
         assertNotNull("error-severity not found", errorSeverityNode);
@@ -102,7 +102,7 @@ public class NetconfDocumentedExceptionTest {
 
         assertNotNull("NetconfDocumentedException is null", ex);
         assertEquals("getErrorSeverity", ErrorSeverity.WARNING, ex.getErrorSeverity());
-        assertEquals("getErrorTag", DocumentedException.ErrorTag.DATA_EXISTS, ex.getErrorTag());
+        assertEquals("getErrorTag", ErrorTag.DATA_EXISTS, ex.getErrorTag());
         assertEquals("getErrorType", ErrorType.PROTOCOL, ex.getErrorType());
         assertEquals("getLocalizedMessage", errorMessage, ex.getLocalizedMessage());
         assertEquals("getErrorInfo", Map.of("foo", "bar"), ex.getErrorInfo());
index 04c73da365986035aca402c6b299a129826324bd..478098eafe6827c5c181f087df549fd174d95dbf 100644 (file)
@@ -121,6 +121,8 @@ public class XmlElementTest {
 
         final DocumentedException e = assertThrows(DocumentedException.class,
             () -> xmlElement.checkUnrecognisedElements(xmlElement.getOnlyChildElement("inner")));
-        assertThat(e.getMessage(), both(containsString("innerNamespace")).and(containsString("innerNamespace")));
+        assertThat(e.getMessage(),
+            // FIXME: this looks very suspect
+            both(containsString("innerNamespace")).and(containsString("innerNamespace")));
     }
 }
index 0d4a84c86f3a122a559611e3945f3e866ba2dc66..c641d4158dd22ff93dcc2fd100d4ff3ebc51a797 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -138,7 +139,7 @@ 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,
-                    ErrorType.PROTOCOL, DocumentedException.ErrorTag.UNKNOWN_ELEMENT, ErrorSeverity.ERROR,
+                    ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT, ErrorSeverity.ERROR,
                     ImmutableMap.of("bad-element", rootNode.getNodeName()));
         }
     }
@@ -157,7 +158,7 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
         }
 
         throw new DocumentedException("Missing attribute " + rootNode.getNodeName(),
-                ErrorType.RPC, DocumentedException.ErrorTag.MISSING_ATTRIBUTE, ErrorSeverity.ERROR, ImmutableMap.of(
+                ErrorType.RPC, ErrorTag.MISSING_ATTRIBUTE, ErrorSeverity.ERROR, ImmutableMap.of(
                     "bad-attribute", XmlNetconfConstants.MESSAGE_ID,
                     "bad-element", XmlNetconfConstants.RPC_KEY));
     }
index b0092519d875f3d6580b02b58d76f7e910b534d6..7fe49959e89f035e606695df86a21d0fa0d10371 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -55,8 +56,9 @@ public class DefaultCloseSession extends AbstractSingletonNetconfOperation imple
             LOG.info("Session {} closing", session.getSessionId());
         } catch (final Exception e) {
             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()));
+                    ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
+                    // FIXME: i.e. <error>exception.toString()</error>? That looks wrong on a few levels.
+                    Map.of(ErrorSeverity.ERROR.elementBody(), e.getMessage()));
         }
         return document.createElement(XmlNetconfConstants.OK);
     }
index 844250c0974cf0366c4270f87ca97144af602b6a..65c2168ff68517e77b5f55a3b4bd83b2bc3eb947 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.ErrorTag;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlElement;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
@@ -17,6 +16,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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index 7dd0c2ad6b74d336732d7fb964b8edd4ae324f9a..3aa1c7107243a89c3a1a92ff3e15131eb2ec3a09 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -69,16 +70,31 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
             final String messageAsString = XmlUtil.toString(message);
             LOG.warn("Unable to handle rpc {} on session {}", messageAsString, session, e);
 
-            final DocumentedException.ErrorTag tag;
-            if (e instanceof IllegalArgumentException) {
-                tag = DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED;
-            } else {
-                tag = DocumentedException.ErrorTag.OPERATION_FAILED;
-            }
+            final ErrorTag tag = e instanceof IllegalArgumentException ? ErrorTag.OPERATION_NOT_SUPPORTED
+                : ErrorTag.OPERATION_FAILED;
 
             throw new DocumentedException(
-                    String.format("Unable to handle rpc %s on session %s", messageAsString, session),
-                    e, ErrorType.APPLICATION, tag, ErrorSeverity.ERROR, Map.of(tag.toString(), e.getMessage()));
+                    String.format("Unable to handle rpc %s on session %s", messageAsString, session), e,
+                    ErrorType.APPLICATION, tag, ErrorSeverity.ERROR,
+                    // FIXME: i.e. in what namespace are we providing these tags? why is this not just:
+                    //
+                    // <java-throwable xmlns="org.opendaylight.something">
+                    //   <message>e.getMessage()</message>
+                    // </java-throwable>
+                    //
+                    // for each place where we are mapping Exception.getMessage() ? We probably do not want to propagate
+                    // stack traces out, but suppressed exceptions and causal list might be interesting:
+                    //
+                    // <java-throwable xmlns="org.opendaylight.something">
+                    //   <message>reported exception</message>
+                    // </java-throwable>
+                    // <java-throwable xmlns="org.opendaylight.something">
+                    //   <message>cause of reported exception</message>
+                    // </java-throwable>
+                    // <java-throwable xmlns="org.opendaylight.something">
+                    //   <message>cause of cause of reported exception</message>
+                    // </java-throwable>
+                    Map.of(tag.elementBody(), e.getMessage()));
         } catch (final RuntimeException e) {
             throw handleUnexpectedEx("sort", e);
         }
@@ -98,8 +114,9 @@ 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",
-                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
-                Map.of(ErrorSeverity.ERROR.toString(), exception.toString()));
+                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
+                // FIXME: i.e. <error>exception.toString()</error>? That looks wrong on a few levels.
+                Map.of(ErrorSeverity.ERROR.elementBody(), exception.toString()));
     }
 
     private static Document executeOperationWithHighestPriority(final Document message,
index 49817193738a271e4893d8b20063cc90d011c7ea..55631ef0eb6dfba066c15f18b8f49f417e2bbcb6 100644 (file)
@@ -19,7 +19,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class DeserializerExceptionHandler implements ChannelHandler {
-
     private static final Logger LOG = LoggerFactory.getLogger(DeserializerExceptionHandler.class);
 
     @Override
@@ -42,7 +41,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(),
-                ErrorType.RPC, DocumentedException.ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR, info);
+                ErrorType.RPC, DocumentedException.MALFORMED_MESSAGE, ErrorSeverity.ERROR, info);
 
         SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), ex);
     }
index 5abcd7512b357dceceb06297d16b1e394c5e17f1..b9b2f28e125815b98f79a3cc7026468819fcfc5f 100644 (file)
@@ -33,6 +33,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.netconf.mapping.api.NetconfOperationService;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
 
@@ -113,7 +114,7 @@ public class NetconfOperationRouterImplTest {
     public void testOnNetconfMessageFail() throws Exception {
         final DocumentedException ex =  assertThrows(DocumentedException.class,
             () -> emptyOperationRouter.onNetconfMessage(TEST_RPC_DOC, null));
-        assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
+        assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
     }
 
     @Test
index 56ee80fa73ae068e17378f800bb5addb173ce9d2..6d44d74174fb9f937f94faa1770e08863b54e05c 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 
 public final class NetconfTopologyUtils {
@@ -83,6 +84,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,
-                ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.WARNING);
+                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.WARNING);
     }
 }
index 877c9e2b4c0c728130a78e6e23898eccf06fd334..33fe1a5f47e8d8118eedcae5cc2965629a34d206 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -303,7 +304,7 @@ public class ProxyNetconfServiceTest {
         assertTrue("Unexpected cause " + cause, cause instanceof DocumentedException);
         final DocumentedException de = (DocumentedException) cause;
         assertEquals(ErrorSeverity.WARNING, de.getErrorSeverity());
-        assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, de.getErrorTag());
+        assertEquals(ErrorTag.OPERATION_FAILED, de.getErrorTag());
         assertEquals(ErrorType.APPLICATION, de.getErrorType());
     }
 }
\ No newline at end of file
index 83f1dd9ae980d88941398f655abee0538037e284..5f46010daa972744f199044f8e21d14284a28bef 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -403,7 +404,7 @@ public class ProxyReadWriteTransactionTest {
         assertTrue("Unexpected cause " + cause, cause instanceof DocumentedException);
         final DocumentedException de = (DocumentedException) cause;
         assertEquals(ErrorSeverity.WARNING, de.getErrorSeverity());
-        assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, de.getErrorTag());
+        assertEquals(ErrorTag.OPERATION_FAILED, de.getErrorTag());
         assertEquals(ErrorType.APPLICATION, de.getErrorType());
     }
 }
index 7595a86ea5f09278cd82fee05211b33f56cbdb1d..f4414fb29540cc108cd03a62a9b804fc7d66af07 100644 (file)
@@ -17,7 +17,6 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 public abstract class AbstractLastNetconfOperation extends AbstractNetconfOperation {
-
     protected AbstractLastNetconfOperation(final String netconfSessionIdForReporting) {
         super(netconfSessionIdForReporting);
     }
@@ -28,7 +27,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),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, DocumentedException.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
         }
 
         return handleWithNoSubsequentOperations(document, operationElement);
index de840e27d09ac143fbb88af6370a821240e1c994..b6725d6231c3c6290deef4b37f0f66fee05daa0e 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -227,7 +228,7 @@ public class NetconfDeviceCommunicator
     private static RpcResult<NetconfMessage> createErrorRpcResult(final RpcError.ErrorType errorType,
             final String message) {
         return RpcResultBuilder.<NetconfMessage>failed()
-            .withError(errorType, NetconfDocumentedException.ErrorTag.OPERATION_FAILED.getTagValue(), message).build();
+            .withError(errorType, ErrorTag.OPERATION_FAILED.elementBody(), message).build();
     }
 
     @Override
index 896485b70b8563f6806ff9437539b260ba78628f..3e6201df86c692ae605c7a35e312768c52c207e1 100644 (file)
@@ -27,12 +27,12 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.ModifyAction;
 import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -230,10 +230,9 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
                 final NetconfDocumentedException exception =
                         new NetconfDocumentedException(
                                 id + ":RPC during tx returned an exception" + throwable.getMessage(),
+                                // FIXME: add proper unmask/wrap to ExecutionException
                                 new Exception(throwable),
-                                ErrorType.APPLICATION,
-                                DocumentedException.ErrorTag.OPERATION_FAILED,
-                                ErrorSeverity.ERROR);
+                                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
                 transformed.setException(exception);
             }
         }, MoreExecutors.directExecutor());
@@ -264,11 +263,8 @@ public abstract class AbstractWriteTx implements DOMDataTreeWriteTransaction {
             }
         }
         if (errorsEncouneterd) {
-            final NetconfDocumentedException exception = new NetconfDocumentedException(id
-                    + ":RPC during tx failed. " + msgBuilder.toString(),
-                    errType,
-                    DocumentedException.ErrorTag.from(errorTag),
-                    errSeverity);
+            final NetconfDocumentedException exception = new NetconfDocumentedException(
+                    id + ":RPC during tx failed. " + msgBuilder, errType, new ErrorTag(errorTag), errSeverity);
             transformed.setException(exception);
             return;
         }
index 865a2a62c7827cc50cb6cd68256a9c919ad95e5f..6e4d1f8c2daa6c44b2220c985a77048f9b144db8 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
@@ -289,7 +290,7 @@ public final class NetconfMessageTransformUtil {
 
         if (!inputMsgId.equals(outputMsgId)) {
             throw new NetconfDocumentedException("Response message contained unknown \"message-id\"", null,
-                    ErrorType.PROTOCOL, NetconfDocumentedException.ErrorTag.BAD_ATTRIBUTE, ErrorSeverity.ERROR,
+                    ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE, ErrorSeverity.ERROR,
                     ImmutableMap.of("actual-message-id", outputMsgId, "expected-message-id", inputMsgId));
         }
     }
@@ -312,10 +313,10 @@ public final class NetconfMessageTransformUtil {
         }
 
         return ex.getErrorSeverity() == ErrorSeverity.ERROR
-                ? RpcResultBuilder.newError(ex.getErrorType().toLegacy(), ex.getErrorTag().getTagValue(),
+                ? RpcResultBuilder.newError(ex.getErrorType().toLegacy(), ex.getErrorTag().elementBody(),
                         ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause())
                 : RpcResultBuilder.newWarning(
-                        ex.getErrorType().toLegacy(), ex.getErrorTag().getTagValue(),
+                        ex.getErrorType().toLegacy(), ex.getErrorTag().elementBody(),
                         ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause());
     }
 
@@ -543,7 +544,7 @@ public final class NetconfMessageTransformUtil {
     public static RpcResult<NetconfMessage> toRpcResult(final FailedNetconfMessage message) {
         return RpcResultBuilder.<NetconfMessage>failed()
                 .withRpcError(toRpcError(new NetconfDocumentedException(message.getException().getMessage(),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR)))
+                    ErrorType.APPLICATION, DocumentedException.MALFORMED_MESSAGE, ErrorSeverity.ERROR)))
                 .build();
     }
 }
index 422cb573b1f46d9b60b9c7c3ecce1922902cfea0..54f9101d4e25448baaf01aaa49c06fd343c1f3e8 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 
@@ -52,7 +53,7 @@ class SettableRpc implements NetconfOperation {
             return document;
         } else if (subsequentOperation.isExecutionTermination()) {
             throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
         } else {
             return subsequentOperation.execute(requestMessage);
         }
index 1af952b64765b8f05430e676ca06be4967a216e0..b47b9e74443b9cd1a4916a161ece1af723b9778b 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -56,7 +57,7 @@ public class Get extends AbstractNetconfOperation {
             throws DocumentedException {
         if (subsequentOperation.isExecutionTermination()) {
             throw new DocumentedException(String.format("Subsequent netconf operation expected by %s", this),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
         }
 
         try {
@@ -75,8 +76,9 @@ public class Get extends AbstractNetconfOperation {
             LOG.warn(errorMessage, e);
 
             throw new DocumentedException(errorMessage, e,
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
-                    Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
+                    ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
+                    // FIXME: i.e. <error>e.getMessage()</error> ?
+                    Map.of(ErrorSeverity.ERROR.elementBody(), e.getMessage()));
         }
     }
 
index 9a1d499b39fe710272fc99b7c2c2838b1d123829..d0097a3a70361af0b970295d8f4bccd44fa74fca 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.w3c.dom.Document;
 
@@ -51,7 +52,7 @@ class SettableRpc implements NetconfOperation {
             return document;
         } else if (subsequentOperation.isExecutionTermination()) {
             throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage),
-                    ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
+                    ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
         } else {
             return subsequentOperation.execute(requestMessage);
         }
index 635042114a77ccca546d226175dc2dd13e68da67..5c03c7c082d6e69be8b51f9868eca90a7d057335 100644 (file)
@@ -31,10 +31,10 @@ import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -213,7 +213,7 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
                             return operation.get();
                         } else {
                             return Futures.immediateFailedFuture(new NetconfDocumentedException("Lock operation failed",
-                                ErrorType.APPLICATION, DocumentedException.ErrorTag.LOCK_DENIED, ErrorSeverity.ERROR));
+                                ErrorType.APPLICATION, ErrorTag.LOCK_DENIED, ErrorSeverity.ERROR));
                         }
                     },
                     MoreExecutors.directExecutor());
@@ -252,18 +252,18 @@ final class NetconfRestconfTransaction extends RestconfTransaction {
         ErrorType errType = ErrorType.APPLICATION;
         ErrorSeverity errSeverity = ErrorSeverity.ERROR;
         StringJoiner msgBuilder = new StringJoiner(" ");
-        String errorTag = "operation-failed";
+        ErrorTag errorTag = ErrorTag.OPERATION_FAILED;
         for (final RpcError error : errors) {
             errType = error.getErrorType().toNetconf();
             errSeverity = error.getSeverity().toNetconf();
             msgBuilder.add(error.getMessage());
             msgBuilder.add(error.getInfo());
-            errorTag = error.getTag();
+            errorTag = new ErrorTag(error.getTag());
         }
 
         return new TransactionCommitFailedException("Netconf transaction commit failed",
-            new NetconfDocumentedException("RPC during tx failed. " + msgBuilder.toString(), errType,
-                DocumentedException.ErrorTag.from(errorTag), errSeverity));
+            new NetconfDocumentedException("RPC during tx failed. " + msgBuilder.toString(), errType, errorTag,
+                errSeverity));
     }
 
     private static void executeWithLogging(final Supplier<ListenableFuture<? extends DOMRpcResult>> operation) {
index f73e9f1713f4d715ca98a23fd855ff10933ba671..07b1e1c33214ed4d6b2844bb4dfdb35ff774031f 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -105,13 +106,13 @@ final class FutureCallbackTx {
                 final List<Throwable> causalChain = Throwables.getCausalChain(cause);
                 for (Throwable error : causalChain) {
                     if (error instanceof DocumentedException) {
-                        final DocumentedException.ErrorTag errorTag = ((DocumentedException) error).getErrorTag();
-                        if (errorTag.equals(DocumentedException.ErrorTag.DATA_EXISTS)) {
+                        final ErrorTag errorTag = ((DocumentedException) error).getErrorTag();
+                        if (errorTag.equals(ErrorTag.DATA_EXISTS)) {
                             LOG.trace("Operation via Restconf was not executed because data at {} already exists",
                                 path);
                             throw new RestconfDocumentedException(e, new RestconfError(ErrorType.PROTOCOL,
                                 RestconfError.ErrorTag.DATA_EXISTS, "Data already exists", path));
-                        } else if (errorTag.equals(DocumentedException.ErrorTag.DATA_MISSING)) {
+                        } else if (errorTag.equals(ErrorTag.DATA_MISSING)) {
                             LOG.trace("Operation via Restconf was not executed because data at {} does not exist",
                                 path);
                             throw new RestconfDocumentedException(e, new RestconfError(ErrorType.PROTOCOL,
@@ -122,7 +123,7 @@ final class FutureCallbackTx {
                         throw new RestconfDocumentedException(error.getMessage(),
                                 ((NetconfDocumentedException) error).getErrorType(),
                                 RestconfError.ErrorTag.valueOfCaseInsensitive(
-                                        ((NetconfDocumentedException) error).getErrorTag().getTagValue()), e);
+                                        ((NetconfDocumentedException) error).getErrorTag().elementBody()), e);
                     }
                 }
 
index 3186cc5111028dbdc7262b2b568e814bfe356570..419853552d4f60249d67ddba3b17bdaa4b19f8a7 100644 (file)
@@ -29,16 +29,16 @@ import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 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.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.restconf.common.errors.RestconfError;
 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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
@@ -88,7 +88,7 @@ public class DeleteDataTransactionUtilTest {
         when(readWrite.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty()))
             .thenReturn(immediateFalseFluentFuture());
         final NetconfDocumentedException exception = new NetconfDocumentedException("id",
-            ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"), ErrorSeverity.ERROR);
+            ErrorType.RPC, ErrorTag.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 {
             fail("Delete operation should fail due to missing data");
         } catch (final RestconfDocumentedException e) {
             assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
-            assertEquals(ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
+            assertEquals(RestconfError.ErrorTag.DATA_MISSING, e.getErrors().get(0).getErrorTag());
         }
     }
 }
index f14edee6fb15ddfef573fc424ec0dd0e122a086a..03e661895385588616e45b8ad77afd2d0f150c43 100644 (file)
@@ -37,7 +37,6 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 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.restconf.common.context.InstanceIdentifierContext;
@@ -51,6 +50,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.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -234,7 +234,7 @@ public class PatchDataTransactionUtilTest {
         doReturn(immediateFalseFluentFuture()).when(this.rwTransaction).exists(LogicalDatastoreType.CONFIGURATION,
             this.targetNodeForCreateAndDelete);
         final NetconfDocumentedException exception = new NetconfDocumentedException("id",
-            ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"), ErrorSeverity.ERROR);
+            ErrorType.RPC, ErrorTag.DATA_MISSING, ErrorSeverity.ERROR);
         final SettableFuture<? extends DOMRpcResult> ret = SettableFuture.create();
         ret.setException(new TransactionCommitFailedException(
             String.format("Commit of transaction %s failed", this), exception));