use of org.opendaylight.netconf.api.xml.XmlElement 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.xml.XmlElement 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);
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class Lock method extractTargetParameter.
static Datastore extractTargetParameter(final XmlElement operationElement) throws DocumentedException {
final XmlElement targetElement = operationElement.getOnlyChildElementWithSameNamespace(TARGET_KEY);
final XmlElement targetChildNode = targetElement.getOnlyChildElementWithSameNamespace();
return Datastore.valueOf(targetChildNode.getName());
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class SettableRpc method handle.
@Override
public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
final XmlElement rpcElement = requestElement.getOnlyChildElement();
final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
final Optional<Document> response = rpcHandler.getResponse(rpcElement);
if (response.isPresent()) {
final Document document = response.get();
checkForError(document);
document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
return document;
} else if (subsequentOperation.isExecutionTermination()) {
throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage), ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
} else {
return subsequentOperation.execute(requestMessage);
}
}
use of org.opendaylight.netconf.api.xml.XmlElement in project netconf by opendaylight.
the class SimulatedGetConfig method handleWithNoSubsequentOperations.
@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) {
final Element element = document.createElement(XmlNetconfConstants.DATA_KEY);
for (final XmlElement e : storage.getConfigList()) {
final Element domElement = e.getDomElement();
element.appendChild(element.getOwnerDocument().importNode(domElement, true));
}
return element;
}
Aggregations