From: Robert Varga Date: Mon, 26 Jul 2021 14:06:43 +0000 (+0200) Subject: Remove DocumentedException.ErrorType X-Git-Tag: v2.0.2~8 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F27%2F97027%2F4;p=netconf.git Remove DocumentedException.ErrorType 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 --- diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java index 1a7c42d699..345a5e5287 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/TransactionProvider.java @@ -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; diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractConfigOperation.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractConfigOperation.java index 5201ec112e..81899f208d 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractConfigOperation.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractConfigOperation.java @@ -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 urlElement = parent.getOnlyChildElementOptionally(URL_KEY); if (urlElement.isEmpty()) { throw new DocumentedException("Invalid RPC, neither not 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); } } diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java index f5126387b1..c64eec08ee 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/AbstractEdit.java @@ -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(); diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfig.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfig.java index cebf3e5590..2989e27aec 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfig.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfig.java @@ -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 sourceElement = parent.getOnlyChildElementOptionally(SOURCE_KEY); if (sourceElement.isEmpty()) { throw new DocumentedException(" 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 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 target", e, - ErrorType.PROTOCOL, - ErrorTag.OPERATION_NOT_SUPPORTED, - ErrorSeverity.ERROR); + ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR); } } diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/DiscardChanges.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/DiscardChanges.java index ea9ad094fa..bb3f97a585 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/DiscardChanges.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/DiscardChanges.java @@ -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; diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java index 6b5f080499..bc568e77e1 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java @@ -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); diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Lock.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Lock.java index 6518fa4d5d..ffbb548d17 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Lock.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Lock.java @@ -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 { diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java index 97f852ce94..efc34d0a15 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java @@ -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; diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Unlock.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Unlock.java index 5145cc2bda..b3fe4a56c9 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Unlock.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Unlock.java @@ -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 diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Validate.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Validate.java index a7f224832f..a8229f10f5 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Validate.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/Validate.java @@ -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(" 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(); diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/AbstractGet.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/AbstractGet.java index 94a7bfb247..e4fd8d6ad4 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/AbstractGet.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/AbstractGet.java @@ -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; diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java index a86080cc0e..0be3023f9f 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidator.java @@ -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); } /** diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/Get.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/Get.java index 54f7366b31..438af75491 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/Get.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/Get.java @@ -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; diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/GetConfig.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/GetConfig.java index cc2ec31c0b..dbca36746e 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/GetConfig.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/GetConfig.java @@ -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; } - } diff --git a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfigTest.java b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfigTest.java index 8d491b596d..a9c951d7bc 100644 --- a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfigTest.java +++ b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/CopyConfigTest.java @@ -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; diff --git a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java index 1af28ba830..619f009fa2 100644 --- a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java +++ b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java @@ -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; diff --git a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpcTest.java b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpcTest.java index 2e858e5a5a..85d6d02962 100644 --- a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpcTest.java +++ b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpcTest.java @@ -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); diff --git a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/ValidateTest.java b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/ValidateTest.java index 80d1e4e7fa..37a7ba8175 100644 --- a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/ValidateTest.java +++ b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/ValidateTest.java @@ -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() { diff --git a/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/GetSchema.java b/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/GetSchema.java index 63d228c416..dfabde4eec 100644 --- a/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/GetSchema.java +++ b/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/GetSchema.java @@ -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 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); } diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java index 07636246bb..669218d5d0 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java @@ -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())); diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfDocumentedException.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfDocumentedException.java index 6f7ccfef94..d13a5e1e97 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfDocumentedException.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfDocumentedException.java @@ -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; /** diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/MissingNameSpaceException.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/MissingNameSpaceException.java index 9701428e42..092e9c5946 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/MissingNameSpaceException.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/MissingNameSpaceException.java @@ -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; diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/UnexpectedElementException.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/UnexpectedElementException.java index ed5e9c8929..148fb10984 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/UnexpectedElementException.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/UnexpectedElementException.java @@ -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; diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/UnexpectedNamespaceException.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/UnexpectedNamespaceException.java index 001107f7a7..f727704a67 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/UnexpectedNamespaceException.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/UnexpectedNamespaceException.java @@ -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; diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlElement.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlElement.java index d19ce378b8..d65f4de0ae 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlElement.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/xml/XmlElement.java @@ -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 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 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 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); } } diff --git a/netconf/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java b/netconf/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java index b21ffbdb7f..87cf0686dd 100644 --- a/netconf/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java +++ b/netconf/netconf-api/src/test/java/org/opendaylight/netconf/api/NetconfDocumentedExceptionTest.java @@ -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()); } diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionListener.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionListener.java index cdf9ee3f05..0d4a84c86f 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionListener.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionListener.java @@ -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 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); } diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java index 56884d3531..56ee80fa73 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java @@ -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); } } diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/netconf/ProxyNetconfServiceTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/netconf/ProxyNetconfServiceTest.java index aa3bc71964..877c9e2b4c 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/netconf/ProxyNetconfServiceTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/netconf/ProxyNetconfServiceTest.java @@ -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 diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/ProxyReadWriteTransactionTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/ProxyReadWriteTransactionTest.java index 3ec6f89116..83f1dd9ae9 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/ProxyReadWriteTransactionTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/tx/ProxyReadWriteTransactionTest.java @@ -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()); } } diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperation.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperation.java index b99f75d346..7595a86ea5 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperation.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/mapping/AbstractLastNetconfOperation.java @@ -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); diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/AbstractWriteTx.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/AbstractWriteTx.java index 98fb17d856..896485b70b 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/AbstractWriteTx.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/AbstractWriteTx.java @@ -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 domRpcResults, final SettableFuture> 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()); diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfMessageTransformUtil.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfMessageTransformUtil.java index a3d53d268f..865a2a62c7 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfMessageTransformUtil.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfMessageTransformUtil.java @@ -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 errorInfo = ImmutableMap.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 toRpcResult(final FailedNetconfMessage message) { return RpcResultBuilder.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(); } } diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/customrpc/SettableRpc.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/customrpc/SettableRpc.java index b7c35e0fbd..422cb573b1 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/customrpc/SettableRpc.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/customrpc/SettableRpc.java @@ -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); } diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/Get.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/Get.java index a51f4712e1..1af952b647 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/Get.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/monitoring/Get.java @@ -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())); } } diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableRpc.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableRpc.java index 75f1b71adb..9a1d499b39 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableRpc.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableRpc.java @@ -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); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java index de7c9c02a9..635042114a 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfTransaction.java @@ -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 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()); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.java index fddf1a78eb..1e0697b46f 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/FutureCallbackTx.java @@ -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); } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java index 35f4d18b4e..ba2af37eb3 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java @@ -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 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()); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java index 5af6b45e5f..785bae0dda 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java @@ -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 ret = SettableFuture.create(); ret.setException(new TransactionCommitFailedException( String.format("Commit of transaction %s failed", this), exception));