Search in sources :

Example 16 with DocumentedException

use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.

the class ValidateTest method testValidateFailed.

@Test
public void testValidateFailed() throws Exception {
    whenUsingValidator(failingValidator);
    final TransactionProvider transactionProvider = initCandidateTransaction();
    final DocumentedException e = assertThrows(DocumentedException.class, () -> validate("messages/mapping/validate/validate.xml", transactionProvider));
    assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
    assertEquals(ErrorTag.OPERATION_FAILED, e.getErrorTag());
    assertEquals(ErrorType.APPLICATION, e.getErrorType());
}
Also used : TransactionProvider(org.opendaylight.netconf.mdsal.connector.TransactionProvider) DocumentedException(org.opendaylight.netconf.api.DocumentedException) Test(org.junit.Test)

Example 17 with DocumentedException

use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.

the class RuntimeRpc method handleWithNoSubsequentOperations.

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
    final String netconfOperationName = operationElement.getName();
    final String netconfOperationNamespace;
    try {
        netconfOperationNamespace = operationElement.getNamespace();
    } catch (final DocumentedException e) {
        LOG.debug("Cannot retrieve netconf operation namespace from message due to ", e);
        throw new DocumentedException("Cannot retrieve netconf operation namespace from message", e, ErrorType.PROTOCOL, ErrorTag.UNKNOWN_NAMESPACE, ErrorSeverity.ERROR);
    }
    final XMLNamespace namespaceURI = createNsUri(netconfOperationNamespace);
    final Optional<? extends Module> moduleOptional = getModule(namespaceURI);
    if (moduleOptional.isEmpty()) {
        throw new DocumentedException("Unable to find module in Schema Context with namespace and name : " + namespaceURI + " " + netconfOperationName + schemaContext.getCurrentContext(), ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, ErrorSeverity.ERROR);
    }
    final Optional<RpcDefinition> rpcDefinitionOptional = getRpcDefinitionFromModule(moduleOptional.get(), namespaceURI, netconfOperationName);
    if (rpcDefinitionOptional.isEmpty()) {
        throw new DocumentedException("Unable to find RpcDefinition with namespace and name : " + namespaceURI + " " + netconfOperationName, ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, ErrorSeverity.ERROR);
    }
    final RpcDefinition rpcDefinition = rpcDefinitionOptional.get();
    final ContainerNode inputNode = rpcToNNode(operationElement, rpcDefinition);
    final DOMRpcResult result;
    try {
        result = rpcService.invokeRpc(rpcDefinition.getQName(), inputNode).get();
    } catch (final InterruptedException | ExecutionException e) {
        throw DocumentedException.wrap(e);
    }
    if (result.getResult() == null) {
        return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
    }
    return transformNormalizedNode(document, result.getResult(), Absolute.of(rpcDefinition.getQName(), rpcDefinition.getOutput().getQName()));
}
Also used : RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) DocumentedException(org.opendaylight.netconf.api.DocumentedException) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ExecutionException(java.util.concurrent.ExecutionException)

Example 18 with DocumentedException

use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.

the class TransactionProvider method commitTransaction.

public synchronized boolean commitTransaction() throws DocumentedException {
    if (getCandidateTransaction().isEmpty()) {
        // making empty commit without prior opened transaction, just return true
        LOG.debug("Making commit without open candidate transaction for session {}", netconfSessionIdForReporting);
        return true;
    }
    final FluentFuture<? extends CommitInfo> future = candidateTransaction.commit();
    try {
        future.get();
    } catch (final InterruptedException | ExecutionException e) {
        LOG.debug("Transaction {} failed on", candidateTransaction, e);
        final String cause = e.getCause() != null ? " Cause: " + e.getCause().getMessage() : "";
        throw new DocumentedException("Transaction commit failed on " + e.getMessage() + " " + netconfSessionIdForReporting + cause, e, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
    } finally {
        allOpenReadWriteTransactions.remove(candidateTransaction);
        candidateTransaction = null;
    }
    return true;
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) ExecutionException(java.util.concurrent.ExecutionException)

Example 19 with DocumentedException

use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.

the class AbstractConfigOperation method getConfigElement.

static XmlElement getConfigElement(final XmlElement parent) throws DocumentedException {
    final Optional<XmlElement> configElement = parent.getOnlyChildElementOptionally(CONFIG_KEY);
    if (configElement.isPresent()) {
        return configElement.get();
    }
    final Optional<XmlElement> urlElement = parent.getOnlyChildElementOptionally(URL_KEY);
    if (urlElement.isEmpty()) {
        throw new DocumentedException("Invalid RPC, neither <config> not <url> element is present", ErrorType.PROTOCOL, ErrorTag.MISSING_ELEMENT, ErrorSeverity.ERROR);
    }
    final Document document = getDocumentFromUrl(urlElement.get().getTextContent());
    return XmlElement.fromDomElementWithExpected(document.getDocumentElement(), CONFIG_KEY, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Document(org.w3c.dom.Document)

Example 20 with DocumentedException

use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.

the class CopyConfig method handleWithNoSubsequentOperations.

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
    final XmlElement targetElement = extractTargetElement(operationElement, OPERATION_NAME);
    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);
    } 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);
    }
    return document.createElement(XmlNetconfConstants.OK);
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) XmlElement(org.opendaylight.netconf.api.xml.XmlElement)

Aggregations

DocumentedException (org.opendaylight.netconf.api.DocumentedException)54 Test (org.junit.Test)25 XmlElement (org.opendaylight.netconf.api.xml.XmlElement)14 Document (org.w3c.dom.Document)9 NetconfDocumentedException (org.opendaylight.netconf.api.NetconfDocumentedException)6 ExecutionException (java.util.concurrent.ExecutionException)5 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 Element (org.w3c.dom.Element)5 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 List (java.util.List)3 XMLNamespace (org.opendaylight.yangtools.yang.common.XMLNamespace)3 XmlNodeConverter (io.lighty.codecs.util.XmlNodeConverter)2 DeserializationException (io.lighty.codecs.util.exception.DeserializationException)2 Response (io.lighty.netconf.device.response.Response)2 ResponseData (io.lighty.netconf.device.response.ResponseData)2 Reader (java.io.Reader)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CompletableFuture (java.util.concurrent.CompletableFuture)2