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;
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;
final Optional<XmlElement> urlElement = parent.getOnlyChildElementOptionally(URL_KEY);
if (urlElement.isEmpty()) {
throw new DocumentedException("Invalid RPC, neither <config> not <url> element is present",
- DocumentedException.ErrorType.PROTOCOL,
- DocumentedException.ErrorTag.MISSING_ELEMENT,
- ErrorSeverity.ERROR);
+ ErrorType.PROTOCOL, DocumentedException.ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
}
final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
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);
}
}
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;
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();
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;
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);
}
final Optional<XmlElement> sourceElement = parent.getOnlyChildElementOptionally(SOURCE_KEY);
if (sourceElement.isEmpty()) {
throw new DocumentedException("<source> element is missing",
- DocumentedException.ErrorType.PROTOCOL,
- DocumentedException.ErrorTag.MISSING_ELEMENT,
- ErrorSeverity.ERROR);
+ ErrorType.PROTOCOL, DocumentedException.ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
}
return sourceElement.get();
final String url = urlElement.getTextContent();
if (!url.startsWith("file:")) {
throw new DocumentedException("Unsupported <url> protocol: " + url,
- ErrorType.PROTOCOL,
- ErrorTag.OPERATION_NOT_SUPPORTED,
- ErrorSeverity.ERROR);
+ ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
}
// Read data from datastore:
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);
}
}
return Datastore.valueOf(source.getName());
} catch (IllegalArgumentException e) {
throw new DocumentedException("Unsupported source for <url> target", e,
- ErrorType.PROTOCOL,
- ErrorTag.OPERATION_NOT_SUPPORTED,
- ErrorSeverity.ERROR);
+ ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
}
}
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;
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;
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);
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;
}
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 {
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;
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;
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;
}
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
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;
final Datastore targetDatastore = extractSourceParameter(operationElement, OPERATION_NAME);
if (targetDatastore != Datastore.candidate) {
throw new DocumentedException("<validate> is only supported on candidate datastore",
- DocumentedException.ErrorType.PROTOCOL,
- ErrorTag.OPERATION_NOT_SUPPORTED,
- ErrorSeverity.ERROR);
+ ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
}
transactionProvider.validateTransaction();
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;
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;
} 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);
}
}
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);
}
/**
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;
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;
protected String getOperationName() {
return OPERATION_NAME;
}
-
}
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;
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;
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;
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;
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;
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);
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)
() -> 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
() -> 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
() -> 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
() -> 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() {
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;
final Map<String, String> errorInfo = new HashMap<>();
errorInfo.put(DocumentedException.ErrorTag.OPERATION_FAILED.toString(), e.getMessage());
LOG.warn("Rpc error: {}", DocumentedException.ErrorTag.OPERATION_FAILED, e);
- throw new DocumentedException(e.getMessage(), e, DocumentedException.ErrorType.APPLICATION,
+ throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, errorInfo);
}
*/
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;
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;
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"),
// 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())) {
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()));
* 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;
/**
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;
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;
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;
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;
} 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);
}
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);
}
}
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);
List<XmlElement> nameElements = getChildElements(childName);
if (nameElements.size() != 1) {
throw new DocumentedException("One element " + childName + " expected in " + toString(),
- DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.INVALID_VALUE,
- ErrorSeverity.ERROR);
+ ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
}
return nameElements.get(0);
}
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);
}
}
}
throw new DocumentedException(getName() + " should contain text.",
- DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.INVALID_VALUE,
- ErrorSeverity.ERROR
- );
+ ErrorType.APPLICATION, DocumentedException.ErrorTag.INVALID_VALUE, ErrorSeverity.ERROR);
}
public Optional<String> getOnlyTextContentOptionally() {
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;
}
Optional<String> namespaceURI = getNamespaceOptionally();
if (namespaceURI.isEmpty()) {
throw new MissingNameSpaceException(String.format("No namespace defined for %s", this),
- DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.OPERATION_FAILED,
- ErrorSeverity.ERROR);
+ ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
}
return namespaceURI.get();
}
}
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);
}
}
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;
@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);
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);
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());
}
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;
* unexpected element Description: An unexpected element is present.
*/
throw new DocumentedException("Unknown tag " + rootNode.getNodeName() + " in message:\n" + netconfMessage,
- DocumentedException.ErrorType.PROTOCOL, DocumentedException.ErrorTag.UNKNOWN_ELEMENT,
- ErrorSeverity.ERROR, ImmutableMap.of("bad-element", rootNode.getNodeName()));
+ ErrorType.PROTOCOL, DocumentedException.ErrorTag.UNKNOWN_ELEMENT, ErrorSeverity.ERROR,
+ ImmutableMap.of("bad-element", rootNode.getNodeName()));
}
}
}
throw new DocumentedException("Missing attribute " + rootNode.getNodeName(),
- DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.MISSING_ATTRIBUTE,
- ErrorSeverity.ERROR,
- ImmutableMap.of("bad-attribute", XmlNetconfConstants.MESSAGE_ID,
- "bad-element", XmlNetconfConstants.RPC_KEY));
+ ErrorType.RPC, DocumentedException.ErrorTag.MISSING_ATTRIBUTE, ErrorSeverity.ERROR, ImmutableMap.of(
+ "bad-attribute", XmlNetconfConstants.MESSAGE_ID,
+ "bad-element", XmlNetconfConstants.RPC_KEY));
}
}
import org.opendaylight.netconf.impl.NetconfServerSession;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
requireNonNull(session, "Session was not set").delayedClose();
LOG.info("Session {} closing", session.getSessionId());
} catch (final Exception e) {
- throw new DocumentedException("Unable to properly close session "
- + getNetconfSessionIdForReporting(), e, DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.OPERATION_FAILED,
- ErrorSeverity.ERROR, Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
+ throw new DocumentedException("Unable to properly close session " + getNetconfSessionIdForReporting(), e,
+ ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
+ Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
}
return document.createElement(XmlNetconfConstants.OK);
}
import org.opendaylight.netconf.api.DocumentedException;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
-import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.opendaylight.netconf.mapping.api.NetconfOperationService;
import org.opendaylight.netconf.mapping.api.SessionAwareNetconfOperation;
import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
throw new DocumentedException(
String.format("Unable to handle rpc %s on session %s", messageAsString, session),
- e, DocumentedException.ErrorType.APPLICATION, tag, ErrorSeverity.ERROR,
- Map.of(tag.toString(), e.getMessage()));
+ e, ErrorType.APPLICATION, tag, ErrorSeverity.ERROR, Map.of(tag.toString(), e.getMessage()));
} catch (final RuntimeException e) {
throw handleUnexpectedEx("sort", e);
}
private static DocumentedException handleUnexpectedEx(final String op, final Exception exception) {
LOG.error("Unexpected exception during netconf operation {}", op, exception);
return new DocumentedException("Unexpected error",
- DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.OPERATION_FAILED,
- ErrorSeverity.ERROR,
+ ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR,
Map.of(ErrorSeverity.ERROR.toString(), exception.toString()));
}
import org.opendaylight.netconf.api.DocumentedException;
import org.opendaylight.netconf.util.messages.SendErrorExceptionUtil;
import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final Map<String, String> info = new HashMap<>();
info.put("cause", cause.getMessage());
final DocumentedException ex = new DocumentedException(cause.getMessage(),
- DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.MALFORMED_MESSAGE,
- ErrorSeverity.ERROR, info);
+ ErrorType.RPC, DocumentedException.ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR, info);
SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), ex);
}
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;
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);
}
}
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;
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
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;
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());
}
}
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;
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);
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;
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);
justification = "https://github.com/spotbugs/spotbugs/issues/811")
private void extractResult(final List<DOMRpcResult> domRpcResults,
final SettableFuture<RpcResult<Void>> transformed) {
- DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
+ ErrorType errType = ErrorType.APPLICATION;
ErrorSeverity errSeverity = ErrorSeverity.ERROR;
StringBuilder msgBuilder = new StringBuilder();
boolean errorsEncouneterd = false;
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());
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;
final String outputMsgId = output.getDocument().getDocumentElement().getAttribute(MESSAGE_ID_ATTR);
if (!inputMsgId.equals(outputMsgId)) {
- final Map<String, String> errorInfo = ImmutableMap.<String, String>builder()
- .put("actual-message-id", outputMsgId)
- .put("expected-message-id", inputMsgId)
- .build();
-
- throw new NetconfDocumentedException("Response message contained unknown \"message-id\"",
- null, NetconfDocumentedException.ErrorType.PROTOCOL,
- NetconfDocumentedException.ErrorTag.BAD_ATTRIBUTE,
- ErrorSeverity.ERROR, errorInfo);
+ throw new NetconfDocumentedException("Response message contained unknown \"message-id\"", null,
+ ErrorType.PROTOCOL, NetconfDocumentedException.ErrorTag.BAD_ATTRIBUTE, ErrorSeverity.ERROR,
+ ImmutableMap.of("actual-message-id", outputMsgId, "expected-message-id", inputMsgId));
}
}
}
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());
}
public static RpcResult<NetconfMessage> toRpcResult(final FailedNetconfMessage message) {
return RpcResultBuilder.<NetconfMessage>failed()
.withRpcError(toRpcError(new NetconfDocumentedException(message.getException().getMessage(),
- DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.MALFORMED_MESSAGE,
- ErrorSeverity.ERROR)))
+ ErrorType.APPLICATION, DocumentedException.ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR)))
.build();
}
}
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;
/**
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);
}
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;
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 {
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()));
}
}
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;
/**
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);
}
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;
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());
justification = "https://github.com/spotbugs/spotbugs/issues/811")
private static TransactionCommitFailedException toCommitFailedException(
final Collection<? extends RpcError> errors) {
- DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
+ ErrorType errType = ErrorType.APPLICATION;
ErrorSeverity errSeverity = ErrorSeverity.ERROR;
StringJoiner msgBuilder = new StringJoiner(" ");
String errorTag = "operation-failed";
for (final RpcError error : errors) {
- switch (error.getErrorType()) {
- case RPC:
- errType = DocumentedException.ErrorType.RPC;
- break;
- case PROTOCOL:
- errType = DocumentedException.ErrorType.PROTOCOL;
- break;
- case TRANSPORT:
- errType = DocumentedException.ErrorType.TRANSPORT;
- break;
- case APPLICATION:
- default:
- errType = DocumentedException.ErrorType.APPLICATION;
- break;
- }
+ errType = error.getErrorType().toNetconf();
errSeverity = error.getSeverity().toNetconf();
msgBuilder.add(error.getMessage());
msgBuilder.add(error.getInfo());
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);
}
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)
when(readWrite.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty()))
.thenReturn(immediateFalseFluentFuture());
final NetconfDocumentedException exception = new NetconfDocumentedException("id",
- DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"),
- ErrorSeverity.ERROR);
+ ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"), ErrorSeverity.ERROR);
final SettableFuture<? extends CommitInfo> ret = SettableFuture.create();
ret.setException(new TransactionCommitFailedException(
String.format("Commit of transaction %s failed", this), exception));
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());
}
}
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;
doReturn(immediateFalseFluentFuture()).when(this.rwTransaction).exists(LogicalDatastoreType.CONFIGURATION,
this.targetNodeForCreateAndDelete);
final NetconfDocumentedException exception = new NetconfDocumentedException("id",
- DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"),
- ErrorSeverity.ERROR);
+ ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"), ErrorSeverity.ERROR);
final SettableFuture<? extends DOMRpcResult> ret = SettableFuture.create();
ret.setException(new TransactionCommitFailedException(
String.format("Commit of transaction %s failed", this), exception));