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