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);
}
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());
}
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);
}
}
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);
}
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());
}
Aggregations