Search in sources :

Example 6 with DocumentedException

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

the class DefaultCloseSession method handleWithNoSubsequentOperations.

/**
 * Close netconf operation router associated to this session, which in turn
 * closes NetconfOperationServiceSnapshot with all NetconfOperationService
 * instances.
 */
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
    try {
        sessionResources.close();
        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, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, // FIXME: i.e. <error>exception.toString()</error>? That looks wrong on a few levels.
        Map.of(ErrorSeverity.ERROR.elementBody(), e.getMessage()));
    }
    return document.createElement(XmlNetconfConstants.OK);
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) DocumentedException(org.opendaylight.netconf.api.DocumentedException)

Example 7 with DocumentedException

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

the class ProxyNetconfServiceTest method verifyDocumentedException.

private static void verifyDocumentedException(final Throwable cause) {
    assertTrue("Unexpected cause " + cause, cause instanceof DocumentedException);
    final DocumentedException de = (DocumentedException) cause;
    assertEquals(ErrorSeverity.WARNING, de.getErrorSeverity());
    assertEquals(ErrorTag.OPERATION_FAILED, de.getErrorTag());
    assertEquals(ErrorType.APPLICATION, de.getErrorType());
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException)

Example 8 with DocumentedException

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

the class GetConfig method handleWithNoSubsequentOperations.

@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
    GetConfigExecution getConfigExecution = null;
    try {
        getConfigExecution = GetConfigExecution.fromXml(operationElement, OPERATION_NAME);
    } catch (final DocumentedException e) {
        LOG.warn("Get request processing failed on session: {}", getNetconfSessionIdForReporting(), e);
        throw e;
    }
    final Optional<YangInstanceIdentifier> dataRootOptional = getDataRootFromFilter(operationElement);
    if (dataRootOptional.isEmpty()) {
        return document.createElement(XmlNetconfConstants.DATA_KEY);
    }
    final YangInstanceIdentifier dataRoot = dataRootOptional.get();
    // Proper exception should be thrown
    Preconditions.checkState(getConfigExecution.getDatastore().isPresent(), "Source element missing from request");
    final DOMDataTreeReadWriteTransaction rwTx = getTransaction(getConfigExecution.getDatastore().get());
    try {
        final Optional<NormalizedNode> normalizedNodeOptional = rwTx.read(LogicalDatastoreType.CONFIGURATION, dataRoot).get();
        if (getConfigExecution.getDatastore().get() == Datastore.running) {
            transactionProvider.abortRunningTransaction(rwTx);
        }
        if (normalizedNodeOptional.isEmpty()) {
            return document.createElement(XmlNetconfConstants.DATA_KEY);
        }
        return serializeNodeWithParentStructure(document, dataRoot, normalizedNodeOptional.get());
    } catch (final InterruptedException | ExecutionException e) {
        LOG.warn("Unable to read data: {}", dataRoot, e);
        throw new IllegalStateException("Unable to read data " + dataRoot, e);
    }
}
Also used : DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) DocumentedException(org.opendaylight.netconf.api.DocumentedException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ExecutionException(java.util.concurrent.ExecutionException) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 9 with DocumentedException

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

the class CopyConfigTest method testRemoteToRemoteOperationIsNotSupported.

@Test
public void testRemoteToRemoteOperationIsNotSupported() {
    final DocumentedException e = assertThrows(DocumentedException.class, () -> copyConfig("messages/mapping/copyConfigs/copyConfig_url_remote_to_remote.xml"));
    assertEquals(e.getErrorSeverity(), ErrorSeverity.ERROR);
    assertEquals(e.getErrorTag(), ErrorTag.OPERATION_NOT_SUPPORTED);
    assertEquals(e.getErrorType(), ErrorType.PROTOCOL);
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) Test(org.junit.Test)

Example 10 with DocumentedException

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

the class NetconfMDSalMappingTest method testEditRunning.

@Test
public void testEditRunning() throws Exception {
    final DocumentedException ex = assertThrows(DocumentedException.class, () -> edit("messages/mapping/editConfigs/editConfig_running.xml"));
    assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
    assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
    assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) Test(org.junit.Test)

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