import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
throw new DocumentedException("Invalid RPC, neither <config> not <url> element is present",
DocumentedException.ErrorType.PROTOCOL,
DocumentedException.ErrorTag.MISSING_ELEMENT,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
throw new DocumentedException(url + " URL is invalid or unsupported", e,
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.INVALID_VALUE,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
} catch (IOException e) {
- throw new DocumentedException("Could not open URL:" + url, e,
+ throw new DocumentedException("Could not open URL " + url, e,
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
} catch (SAXException e) {
throw new DocumentedException("Could not parse XML at" + url, e,
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
}
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Iterator;
-import java.util.Map;
import java.util.Optional;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.dom.DOMSource;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
final NodeList elementsByTagName = getElementsByTagName(operationElement, TARGET_KEY);
// Direct lookup instead of using XmlElement class due to performance
if (elementsByTagName.getLength() == 0) {
- final Map<String, String> errorInfo = ImmutableMap.of("bad-attribute", TARGET_KEY, "bad-element",
- operationName);
throw new DocumentedException("Missing target element", ErrorType.PROTOCOL, ErrorTag.MISSING_ATTRIBUTE,
- ErrorSeverity.ERROR, errorInfo);
+ ErrorSeverity.ERROR, ImmutableMap.of("bad-attribute", TARGET_KEY, "bad-element", operationName));
} else if (elementsByTagName.getLength() > 1) {
throw new DocumentedException("Multiple target elements", ErrorType.RPC, ErrorTag.UNKNOWN_ATTRIBUTE,
ErrorSeverity.ERROR);
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
throw new DocumentedException("<source> element is missing",
DocumentedException.ErrorType.PROTOCOL,
DocumentedException.ErrorTag.MISSING_ELEMENT,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
return sourceElement.get();
import java.util.HashMap;
import java.util.Map;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
protected String getOperationName() {
return OPERATION_NAME;
}
-
}
*/
package org.opendaylight.netconf.mdsal.connector.ops;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.ExecutionException;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.ModifyAction;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
.getDataSchemaNode();
// we should have the schema node that points to the parent list now, enforce it
- Preconditions.checkState(schemaNode instanceof ListSchemaNode, "Schema node is not pointing to a list.");
+ checkState(schemaNode instanceof ListSchemaNode, "Schema node is not pointing to a list.");
//merge empty ordered or unordered map
if (((ListSchemaNode) schemaNode).isUserOrdered()) {
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
throw new DocumentedException("Unable to lock " + targetDatastore + " datastore",
DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
static Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException {
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
operations/UnLock.java
*/
public class Unlock extends AbstractSingletonNetconfOperation {
-
private static final Logger LOG = LoggerFactory.getLogger(Unlock.class);
-
private static final String OPERATION_NAME = "unlock";
public Unlock(final String netconfSessionIdForReporting) {
throw new DocumentedException("Unable to unlock " + targetDatastore + " datastore",
DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
@Override
protected String getOperationName() {
return OPERATION_NAME;
}
-
}
package org.opendaylight.netconf.mdsal.connector.ops;
import com.google.common.collect.ImmutableMap;
-import java.util.Map;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
final NodeList elementsByTagName = getElementsByTagName(operationElement, SOURCE_KEY);
// Direct lookup instead of using XmlElement class due to performance
if (elementsByTagName.getLength() == 0) {
- final Map<String, String> errorInfo = ImmutableMap.of("bad-attribute", SOURCE_KEY, "bad-element",
- operationName);
throw new DocumentedException("Missing source element", ErrorType.PROTOCOL, ErrorTag.MISSING_ELEMENT,
- ErrorSeverity.ERROR, errorInfo);
+ ErrorSeverity.ERROR, ImmutableMap.of("bad-attribute", SOURCE_KEY, "bad-element", operationName));
} else if (elementsByTagName.getLength() > 1) {
throw new DocumentedException("Multiple source elements", ErrorType.RPC, ErrorTag.UNKNOWN_ATTRIBUTE,
ErrorSeverity.ERROR);
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.dom.DOMResult;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
import org.opendaylight.netconf.mdsal.connector.ops.Datastore;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
public Optional<Datastore> getDatastore() {
return datastore;
}
-
}
-
}
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import org.opendaylight.netconf.api.xml.MissingNameSpaceException;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
throw new DocumentedException("Validation failed. Cause: " + e.getMessage(), e,
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.UNKNOWN_NAMESPACE,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
}
+ "in schema context: " + schemaContext.getCurrentContext().toString(),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.UNKNOWN_NAMESPACE,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
/**
final List<XmlElement> childElements = current.getChildElements(pathElement);
// if there are multiple list entries present in the filter, we can't use any keys and must read whole list
if (childElements.size() != 1) {
- return Collections.emptyMap();
+ return Map.of();
}
current = childElements.get(0);
}
final Optional<XmlElement> childElements =
current.getOnlyChildElementOptionally(qualifiedName.getLocalName());
if (childElements.isEmpty()) {
- return Collections.emptyMap();
+ return Map.of();
}
final Optional<String> keyValue = childElements.get().getOnlyTextContentOptionally();
if (keyValue.isPresent()) {
super("Element " + child + " can't be child of " + parent);
}
}
-
}
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
import org.opendaylight.netconf.mdsal.connector.ops.Datastore;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
import org.opendaylight.netconf.mdsal.connector.ops.Datastore;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.util.test.XmlFileLoader;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
copyConfig("messages/mapping/copyConfigs/copyConfig_no_target.xml");
fail("Should have failed - <target> element is missing");
} catch (final DocumentedException e) {
+ // FIXME: use assertThrows() and assertEquals()
assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
assertTrue(e.getErrorTag() == ErrorTag.MISSING_ATTRIBUTE);
assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
import java.net.URI;
import org.junit.Test;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
import org.opendaylight.netconf.mdsal.connector.ops.get.GetConfig;
import org.opendaylight.netconf.util.test.XmlFileLoader;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.w3c.dom.Document;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.util.test.XmlFileLoader;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.NoOpListenerRegistration;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator.ValidationFailedException;
import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.w3c.dom.Document;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
whenValidatorIsNotDefined();
final DocumentedException e = assertThrows(DocumentedException.class,
() -> validate("messages/mapping/validate/validate.xml"));
- assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+ assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
}
whenUsingValidator(noopValidator);
final DocumentedException e = assertThrows(DocumentedException.class,
() -> validate("messages/mapping/validate/validate_no_source.xml"));
- assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+ assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
assertEquals(DocumentedException.ErrorTag.MISSING_ELEMENT, e.getErrorTag());
assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
}
whenUsingValidator(noopValidator);
final DocumentedException e = assertThrows(DocumentedException.class,
() -> validate("messages/mapping/validate/validate_running.xml"));
- assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+ assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
assertEquals(DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
assertEquals(DocumentedException.ErrorType.PROTOCOL, e.getErrorType());
}
final TransactionProvider transactionProvider = initCandidateTransaction();
final DocumentedException e = assertThrows(DocumentedException.class,
() -> validate("messages/mapping/validate/validate.xml", transactionProvider));
- assertEquals(DocumentedException.ErrorSeverity.ERROR, e.getErrorSeverity());
+ assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, e.getErrorTag());
assertEquals(DocumentedException.ErrorType.APPLICATION, e.getErrorType());
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.config.yang.netconf.mdsal.monitoring;
import java.util.HashMap;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
errorInfo.put(DocumentedException.ErrorTag.OPERATION_FAILED.toString(), e.getMessage());
LOG.warn("Rpc error: {}", DocumentedException.ErrorTag.OPERATION_FAILED, e);
throw new DocumentedException(e.getMessage(), e, DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR, errorInfo);
+ DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, errorInfo);
}
final Element getSchemaResult;
import java.util.Map.Entry;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
}
}
- public enum ErrorSeverity {
- ERROR("error"), WARNING("warning");
-
- private final String severityValue;
-
- ErrorSeverity(final String severityValue) {
- this.severityValue = requireNonNull(severityValue);
- }
-
- public String getSeverityValue() {
- return this.severityValue;
- }
-
- public static ErrorSeverity from(final String text) {
- for (ErrorSeverity e : values()) {
- if (e.getSeverityValue().equalsIgnoreCase(text)) {
- return e;
- }
- }
-
- return ERROR;
- }
- }
-
private final ErrorType errorType;
private final ErrorTag errorTag;
private final ErrorSeverity errorSeverity;
NodeList rpcErrorChildren = replyChild.getChildNodes();
for (int j = 0; j < rpcErrorChildren.getLength(); j++) {
Node rpcErrorChild = rpcErrorChildren.item(j);
+
+ // FIXME: use a switch expression here
if (ERROR_TYPE.equals(rpcErrorChild.getLocalName())) {
errorType = ErrorType.from(rpcErrorChild.getTextContent());
} else if (ERROR_TAG.equals(rpcErrorChild.getLocalName())) {
errorTag = ErrorTag.from(rpcErrorChild.getTextContent());
} else if (ERROR_SEVERITY.equals(rpcErrorChild.getLocalName())) {
- errorSeverity = ErrorSeverity.from(rpcErrorChild.getTextContent());
+ final ErrorSeverity sev = ErrorSeverity.forElementBody(rpcErrorChild.getTextContent());
+ // FIXME: this should be a hard error
+ errorSeverity = sev != null ? sev : ErrorSeverity.ERROR;
} else if (ERROR_MESSAGE.equals(rpcErrorChild.getLocalName())) {
errorMessage = rpcErrorChild.getTextContent();
allErrorMessages = allErrorMessages + errorMessage;
rpcError.appendChild(createTextNode(doc, ERROR_TYPE, getErrorType().getTypeValue()));
rpcError.appendChild(createTextNode(doc, ERROR_TAG, getErrorTag().getTagValue()));
- rpcError.appendChild(createTextNode(doc, ERROR_SEVERITY, getErrorSeverity().getSeverityValue()));
+ rpcError.appendChild(createTextNode(doc, ERROR_SEVERITY, getErrorSeverity().elementBody()));
rpcError.appendChild(createTextNode(doc, ERROR_MESSAGE, getLocalizedMessage()));
Map<String, String> errorInfoMap = getErrorInfo();
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Map;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.w3c.dom.Document;
/**
import java.util.Map;
import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
public class MissingNameSpaceException extends DocumentedException {
private static final long serialVersionUID = 1L;
import java.util.Map;
import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
public class UnexpectedElementException extends DocumentedException {
private static final long serialVersionUID = 1L;
import java.util.Map;
import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
public class UnexpectedNamespaceException extends DocumentedException {
private static final long serialVersionUID = 1L;
import java.util.Optional;
import javax.xml.XMLConstants;
import org.opendaylight.netconf.api.DocumentedException;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Attr;
throw new DocumentedException("Attribute doesn't start with :",
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.INVALID_VALUE,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
prefix = attribKey.substring(XMLConstants.XMLNS_ATTRIBUTE.length() + 1);
}
getName()),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
}
expectedNamespace),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
}
expectedNamespace),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
}
* @return List of child elements
*/
public List<XmlElement> getChildElements(final String tagName) {
- return getChildElementsInternal(e -> {
- // localName returns pure localName without prefix
- return e.getLocalName().equals(tagName);
- });
+ return getChildElementsInternal(e -> e.getLocalName().equals(tagName));
}
public List<XmlElement> getChildElementsWithinNamespace(final String childName, final String namespace) {
childName, toString(), children.size()),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.INVALID_VALUE,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
return children.get(0);
throw new DocumentedException("One element " + childName + " expected in " + toString(),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.INVALID_VALUE,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
return nameElements.get(0);
}
children.size()),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.INVALID_VALUE,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
return children.get(0);
}
throw new DocumentedException(getName() + " should contain text.",
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.INVALID_VALUE,
- DocumentedException.ErrorSeverity.ERROR
+ ErrorSeverity.ERROR
);
}
toString()),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
return attribute;
}
throw new MissingNameSpaceException(String.format("No namespace defined for %s", this),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
return namespaceURI.get();
}
throw new DocumentedException(String.format("Unrecognised elements %s in %s", childElements, this),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.INVALID_VALUE,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import com.google.common.collect.ImmutableMap;
-import java.util.Collections;
+import com.google.common.collect.Iterators;
import java.util.Iterator;
+import java.util.Map;
import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
xpath.setNamespaceContext(new NamespaceContext() {
@Override
public Iterator<String> getPrefixes(final String namespaceURI) {
- return Collections.singletonList("netconf").iterator();
+ return Iterators.singletonIterator("netconf");
}
@Override
DocumentedException ex = new NetconfDocumentedException(errorMessage, null,
DocumentedException.ErrorType.PROTOCOL,
DocumentedException.ErrorTag.DATA_EXISTS,
- DocumentedException.ErrorSeverity.WARNING,
- ImmutableMap.of("foo", "bar"));
+ ErrorSeverity.WARNING,
+ Map.of("foo", "bar"));
final Document doc = ex.toXMLDocument();
assertNotNull("Document is null", doc);
final Node errorSeverityNode = getNode("netconf:error-severity", rpcErrorNode);
assertNotNull("error-severity not found", errorSeverityNode);
- assertEquals("error-severity", DocumentedException.ErrorSeverity.WARNING.getSeverityValue(),
- errorSeverityNode.getTextContent());
+ assertEquals("error-severity", ErrorSeverity.WARNING.elementBody(), errorSeverityNode.getTextContent());
final Node errorInfoNode = getNode("netconf:error-info/netconf:foo", rpcErrorNode);
assertNotNull("foo not found", errorInfoNode);
ex = DocumentedException.fromXMLDocument(doc);
assertNotNull("NetconfDocumentedException is null", ex);
- assertEquals("getErrorSeverity", DocumentedException.ErrorSeverity.WARNING, ex.getErrorSeverity());
+ assertEquals("getErrorSeverity", ErrorSeverity.WARNING, ex.getErrorSeverity());
assertEquals("getErrorTag", DocumentedException.ErrorTag.DATA_EXISTS, ex.getErrorTag());
assertEquals("getErrorType", DocumentedException.ErrorType.PROTOCOL, ex.getErrorType());
assertEquals("getLocalizedMessage", errorMessage, ex.getLocalizedMessage());
- assertEquals("getErrorInfo", ImmutableMap.of("foo", "bar"), ex.getErrorInfo());
+ assertEquals("getErrorInfo", Map.of("foo", "bar"), ex.getErrorInfo());
}
@SuppressWarnings("unchecked")
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.impl;
import com.google.common.base.Preconditions;
import org.opendaylight.netconf.notifications.NetconfNotification;
import org.opendaylight.netconf.util.messages.SendErrorExceptionUtil;
import org.opendaylight.netconf.util.messages.SubtreeFilter;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
*/
throw new DocumentedException("Unknown tag " + rootNode.getNodeName() + " in message:\n" + netconfMessage,
DocumentedException.ErrorType.PROTOCOL, DocumentedException.ErrorTag.UNKNOWN_ELEMENT,
- DocumentedException.ErrorSeverity.ERROR, ImmutableMap.of("bad-element",
- rootNode.getNodeName()));
+ ErrorSeverity.ERROR, ImmutableMap.of("bad-element", rootNode.getNodeName()));
}
}
throw new DocumentedException("Missing attribute " + rootNode.getNodeName(),
DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.MISSING_ATTRIBUTE,
- DocumentedException.ErrorSeverity.ERROR,
+ ErrorSeverity.ERROR,
ImmutableMap.of("bad-attribute", XmlNetconfConstants.MESSAGE_ID,
"bad-element", XmlNetconfConstants.RPC_KEY));
}
import static java.util.Objects.requireNonNull;
-import java.util.Collections;
+import java.util.Map;
import org.opendaylight.netconf.api.DocumentedException;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.impl.NetconfServerSession;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
throw new DocumentedException("Unable to properly close session "
+ getNetconfSessionIdForReporting(), e, DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR, Collections.singletonMap(
- DocumentedException.ErrorSeverity.ERROR.toString(), e.getMessage()));
+ ErrorSeverity.ERROR, Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
}
return document.createElement(XmlNetconfConstants.OK);
}
package org.opendaylight.netconf.impl.mapping.operations;
import org.opendaylight.netconf.api.DocumentedException;
-import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
import org.opendaylight.netconf.api.DocumentedException.ErrorType;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.impl.NetconfServerSession;
import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import com.google.common.collect.ImmutableSet;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
+import java.util.Map;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
import org.opendaylight.netconf.mapping.api.NetconfOperationService;
import org.opendaylight.netconf.mapping.api.SessionAwareNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
throw new DocumentedException(
String.format("Unable to handle rpc %s on session %s", messageAsString, session),
- e, DocumentedException.ErrorType.APPLICATION,
- tag, DocumentedException.ErrorSeverity.ERROR,
- Collections.singletonMap(tag.toString(), e.getMessage()));
+ e, DocumentedException.ErrorType.APPLICATION, tag, ErrorSeverity.ERROR,
+ Map.of(tag.toString(), e.getMessage()));
} catch (final RuntimeException e) {
throw handleUnexpectedEx("sort", e);
}
return new DocumentedException("Unexpected error",
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR,
- Collections.singletonMap(DocumentedException.ErrorSeverity.ERROR.toString(), exception.toString()));
+ ErrorSeverity.ERROR,
+ Map.of(ErrorSeverity.ERROR.toString(), exception.toString()));
}
private static Document executeOperationWithHighestPriority(final Document message,
import java.util.Map;
import org.opendaylight.netconf.api.DocumentedException;
import org.opendaylight.netconf.util.messages.SendErrorExceptionUtil;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
info.put("cause", cause.getMessage());
final DocumentedException ex = new DocumentedException(cause.getMessage(),
DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.MALFORMED_MESSAGE,
- DocumentedException.ErrorSeverity.ERROR, info);
+ ErrorSeverity.ERROR, info);
SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), ex);
}
*/
package org.opendaylight.netconf.impl.mapping.operations;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
final EventLoop eventLoop = mock(EventLoop.class);
doReturn(eventLoop).when(channel).eventLoop();
doAnswer(invocation -> {
- invocation.<Runnable>getArgument(0).run();
+ invocation.getArgument(0, Runnable.class).run();
return null;
}).when(eventLoop).execute(any(Runnable.class));
doReturn(true).when(eventLoop).inEventLoop();
verify(listener).onSessionTerminated(any(NetconfServerSession.class), any(NetconfTerminationReason.class));
}
- @Test(expected = DocumentedException.class)
+ @Test
public void testDefaultCloseSession2() throws Exception {
- AutoCloseable res = mock(AutoCloseable.class);
- doThrow(NetconfDocumentedException.class).when(res).close();
- DefaultCloseSession session = new DefaultCloseSession("", res);
+ final NetconfDocumentedException expectedCause = new NetconfDocumentedException("testMessage");
+ final AutoCloseable res = mock(AutoCloseable.class);
+ doThrow(expectedCause).when(res).close();
+ final DefaultCloseSession session = new DefaultCloseSession("testSession", res);
XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
- session.handleWithNoSubsequentOperations(XmlUtil.newDocument(), elem);
+
+ final DocumentedException ex = assertThrows(DocumentedException.class,
+ () -> session.handleWithNoSubsequentOperations(XmlUtil.newDocument(), elem));
+ assertEquals("Unable to properly close session testSession", ex.getMessage());
+ assertSame(expectedCause, ex.getCause());
}
}
import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
public final class NetconfTopologyUtils {
public static final long DEFAULT_REQUEST_TIMEOUT_MILLIS = 60000L;
public static DocumentedException createMasterIsDownException(final RemoteDeviceId id, final Exception cause) {
return new DocumentedException(id + ":Master is down. Please try again.", cause,
DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.WARNING);
+ ErrorSeverity.WARNING);
}
}
import org.opendaylight.netconf.topology.singleton.messages.netconf.UnlockRequest;
import org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply;
import org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyReadResponse;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
private static void verifyDocumentedException(final Throwable cause) {
assertTrue("Unexpected cause " + cause, cause instanceof DocumentedException);
final DocumentedException de = (DocumentedException) cause;
- assertEquals(DocumentedException.ErrorSeverity.WARNING, de.getErrorSeverity());
+ assertEquals(ErrorSeverity.WARNING, de.getErrorSeverity());
assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, de.getErrorTag());
assertEquals(DocumentedException.ErrorType.APPLICATION, de.getErrorType());
}
import org.opendaylight.netconf.topology.singleton.messages.transactions.PutRequest;
import org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest;
import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitRequest;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
private static void verifyDocumentedException(final Throwable cause) {
assertTrue("Unexpected cause " + cause, cause instanceof DocumentedException);
final DocumentedException de = (DocumentedException) cause;
- assertEquals(DocumentedException.ErrorSeverity.WARNING, de.getErrorSeverity());
+ assertEquals(ErrorSeverity.WARNING, de.getErrorSeverity());
assertEquals(DocumentedException.ErrorTag.OPERATION_FAILED, de.getErrorTag());
assertEquals(DocumentedException.ErrorType.APPLICATION, de.getErrorType());
}
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mapping.api.HandlingPriority;
import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
"No netconf operation expected to be subsequent to %s, but is %s", this, subsequentOperation),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.MALFORMED_MESSAGE,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
return handleWithNoSubsequentOperations(document, operationElement);
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
new Exception(throwable),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
transformed.setException(exception);
}
}, MoreExecutors.directExecutor());
private void extractResult(final List<DOMRpcResult> domRpcResults,
final SettableFuture<RpcResult<Void>> transformed) {
DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
- DocumentedException.ErrorSeverity errSeverity = DocumentedException.ErrorSeverity.ERROR;
+ ErrorSeverity errSeverity = ErrorSeverity.ERROR;
StringBuilder msgBuilder = new StringBuilder();
boolean errorsEncouneterd = false;
String errorTag = "operation-failed";
errType = DocumentedException.ErrorType.APPLICATION;
break;
}
- final RpcError.ErrorSeverity severity = error.getSeverity();
- switch (severity) {
- case ERROR:
- errSeverity = DocumentedException.ErrorSeverity.ERROR;
- break;
- case WARNING:
- errSeverity = DocumentedException.ErrorSeverity.WARNING;
- break;
- default:
- errSeverity = DocumentedException.ErrorSeverity.ERROR;
- break;
- }
+
+ errSeverity = error.getSeverity().toNetconf();
msgBuilder.append(error.getMessage());
msgBuilder.append(error.getInfo());
errorTag = error.getTag();
import org.opendaylight.yangtools.rfc7952.data.api.NormalizedMetadata;
import org.opendaylight.yangtools.rfc7952.data.util.ImmutableNormalizedMetadata;
import org.opendaylight.yangtools.rfc7952.data.util.ImmutableNormalizedMetadata.Builder;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
throw new NetconfDocumentedException("Response message contained unknown \"message-id\"",
null, NetconfDocumentedException.ErrorType.PROTOCOL,
NetconfDocumentedException.ErrorTag.BAD_ATTRIBUTE,
- NetconfDocumentedException.ErrorSeverity.ERROR, errorInfo);
+ ErrorSeverity.ERROR, errorInfo);
}
}
}
}
- final ErrorSeverity severity = toRpcErrorSeverity(ex.getErrorSeverity());
- return severity == ErrorSeverity.ERROR
+ return ex.getErrorSeverity() == ErrorSeverity.ERROR
? RpcResultBuilder.newError(toRpcErrorType(ex.getErrorType()), ex.getErrorTag().getTagValue(),
ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause())
: RpcResultBuilder.newWarning(
ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause());
}
- private static ErrorSeverity toRpcErrorSeverity(final NetconfDocumentedException.ErrorSeverity severity) {
- switch (severity) {
- case WARNING:
- return RpcError.ErrorSeverity.WARNING;
- default:
- return RpcError.ErrorSeverity.ERROR;
- }
- }
-
private static RpcError.ErrorType toRpcErrorType(final NetconfDocumentedException.ErrorType type) {
switch (type) {
case PROTOCOL:
public static RpcResult<NetconfMessage> toRpcResult(final FailedNetconfMessage message) {
return RpcResultBuilder.<NetconfMessage>failed()
- .withRpcError(
- toRpcError(
- new NetconfDocumentedException(
- message.getException().getMessage(),
- DocumentedException.ErrorType.APPLICATION,
- DocumentedException.ErrorTag.MALFORMED_MESSAGE,
- DocumentedException.ErrorSeverity.ERROR)))
+ .withRpcError(toRpcError(new NetconfDocumentedException(message.getException().getMessage(),
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.MALFORMED_MESSAGE,
+ ErrorSeverity.ERROR)))
.build();
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.test.tool.customrpc;
import java.io.File;
import org.opendaylight.netconf.mapping.api.HandlingPriority;
import org.opendaylight.netconf.mapping.api.NetconfOperation;
import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.w3c.dom.Document;
/**
} else if (subsequentOperation.isExecutionTermination()) {
throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage),
DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
} else {
return subsequentOperation.execute(requestMessage);
}
*/
package org.opendaylight.netconf.test.tool.monitoring;
-import java.util.Collections;
+import java.util.Map;
import org.opendaylight.netconf.api.DocumentedException;
import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.mapping.api.HandlingPriority;
import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
import org.opendaylight.netconf.util.mapping.AbstractNetconfOperation;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
throw new DocumentedException(String.format("Subsequent netconf operation expected by %s", this),
DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
}
try {
throw new DocumentedException(errorMessage, e, DocumentedException.ErrorType.APPLICATION,
DocumentedException.ErrorTag.OPERATION_FAILED,
- DocumentedException.ErrorSeverity.ERROR,
- Collections.singletonMap(DocumentedException.ErrorSeverity.ERROR.toString(), e.getMessage()));
+ ErrorSeverity.ERROR,
+ Map.of(ErrorSeverity.ERROR.toString(), e.getMessage()));
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.test.tool.rpchandler;
import java.util.Optional;
import org.opendaylight.netconf.mapping.api.HandlingPriority;
import org.opendaylight.netconf.mapping.api.NetconfOperation;
import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.w3c.dom.Document;
/**
} else if (subsequentOperation.isExecutionTermination()) {
throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage),
DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
} else {
return subsequentOperation.execute(requestMessage);
}
import org.opendaylight.netconf.api.DocumentedException;
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
} else {
return Futures.immediateFailedFuture(new NetconfDocumentedException("Lock operation failed",
DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.LOCK_DENIED,
- DocumentedException.ErrorSeverity.ERROR));
+ ErrorSeverity.ERROR));
}
},
MoreExecutors.directExecutor());
private static TransactionCommitFailedException toCommitFailedException(
final Collection<? extends RpcError> errors) {
DocumentedException.ErrorType errType = DocumentedException.ErrorType.APPLICATION;
- DocumentedException.ErrorSeverity errSeverity = DocumentedException.ErrorSeverity.ERROR;
+ ErrorSeverity errSeverity = ErrorSeverity.ERROR;
StringJoiner msgBuilder = new StringJoiner(" ");
String errorTag = "operation-failed";
for (final RpcError error : errors) {
errType = DocumentedException.ErrorType.APPLICATION;
break;
}
- switch (error.getSeverity()) {
- case WARNING:
- errSeverity = DocumentedException.ErrorSeverity.WARNING;
- break;
- case ERROR:
- default:
- errSeverity = DocumentedException.ErrorSeverity.ERROR;
- break;
- }
+ errSeverity = error.getSeverity().toNetconf();
msgBuilder.add(error.getMessage());
msgBuilder.add(error.getInfo());
errorTag = error.getTag();
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
.thenReturn(immediateFalseFluentFuture());
final NetconfDocumentedException exception = new NetconfDocumentedException("id",
DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"),
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
final SettableFuture<? extends CommitInfo> ret = SettableFuture.create();
ret.setException(new TransactionCommitFailedException(
String.format("Commit of transaction %s failed", this), exception));
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
this.targetNodeForCreateAndDelete);
final NetconfDocumentedException exception = new NetconfDocumentedException("id",
DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.from("data-missing"),
- DocumentedException.ErrorSeverity.ERROR);
+ ErrorSeverity.ERROR);
final SettableFuture<? extends DOMRpcResult> ret = SettableFuture.create();
ret.setException(new TransactionCommitFailedException(
String.format("Commit of transaction %s failed", this), exception));