import org.opendaylight.netconf.api.xml.XmlElement;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.netconf.mapping.api.HandlingPriority;
-import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
-import org.opendaylight.netconf.util.mapping.AbstractSingletonNetconfOperation;
+import org.opendaylight.netconf.server.api.operations.AbstractSingletonNetconfOperation;
+import org.opendaylight.netconf.server.api.operations.HandlingPriority;
+import org.opendaylight.netconf.server.api.operations.NetconfOperationChainedExecution;
import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.data.impl.schema.SchemaOrderedNormalizedNodeWriter;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
import org.slf4j.Logger;
import org.xml.sax.SAXException;
public class RuntimeRpc extends AbstractSingletonNetconfOperation {
-
private static final Logger LOG = LoggerFactory.getLogger(RuntimeRpc.class);
-
private static final XMLOutputFactory XML_OUTPUT_FACTORY;
static {
return HandlingPriority.CANNOT_HANDLE;
}
- getRpcDefinitionFromModule(module.get(), namespaceURI, netconfOperationName);
+ getRpcDefinitionFromModule(module.orElseThrow(), namespaceURI, netconfOperationName);
return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;
-
}
@Override
ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, ErrorSeverity.ERROR);
}
- final Optional<RpcDefinition> rpcDefinitionOptional = getRpcDefinitionFromModule(moduleOptional.get(),
+ final Optional<RpcDefinition> rpcDefinitionOptional = getRpcDefinitionFromModule(moduleOptional.orElseThrow(),
namespaceURI, netconfOperationName);
if (rpcDefinitionOptional.isEmpty()) {
ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, ErrorSeverity.ERROR);
}
- final RpcDefinition rpcDefinition = rpcDefinitionOptional.get();
+ final RpcDefinition rpcDefinition = rpcDefinitionOptional.orElseThrow();
final ContainerNode inputNode = rpcToNNode(operationElement, rpcDefinition);
final DOMRpcResult result;
} catch (final InterruptedException | ExecutionException e) {
throw DocumentedException.wrap(e);
}
- if (result.getResult() == null) {
+ if (result.value() == null) {
return XmlUtil.createElement(document, XmlNetconfConstants.OK,
Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
}
- return transformNormalizedNode(document, result.getResult(), rpcDefinition.getOutput().getPath());
+ return transformNormalizedNode(document, result.value(),
+ Absolute.of(rpcDefinition.getQName(), rpcDefinition.getOutput().getQName()));
}
@Override
- public Document handle(final Document requestMessage,
- final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
-
+ public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation)
+ throws DocumentedException {
final XmlElement requestElement = getRequestElementWithCheck(requestMessage);
-
final Document document = XmlUtil.newDocument();
-
final XmlElement operationElement = requestElement.getOnlyChildElement();
final Map<String, Attr> attributes = requestElement.getAttributes();
}
private Element transformNormalizedNode(final Document document, final NormalizedNode data,
- final SchemaPath rpcOutputPath) {
+ final Absolute rpcOutputPath) {
final DOMResult result = new DOMResult(document.createElement(XmlNetconfConstants.RPC_REPLY_KEY));
final XMLStreamWriter xmlWriter = getXmlStreamWriter(result);
final NormalizedNodeStreamWriter nnStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter,
schemaContext.getCurrentContext(), rpcOutputPath);
- final SchemaOrderedNormalizedNodeWriter nnWriter =
- new SchemaOrderedNormalizedNodeWriter(nnStreamWriter, schemaContext.getCurrentContext(), rpcOutputPath);
+ final SchemaOrderedNormalizedNodeWriter nnWriter = new SchemaOrderedNormalizedNodeWriter(nnStreamWriter,
+ schemaContext.getCurrentContext(), rpcOutputPath);
writeRootElement(xmlWriter, nnWriter, (ContainerNode) data);
try {
nnStreamWriter.close();
xmlWriter.close();
} catch (IOException | XMLStreamException e) {
+ // FIXME: throw DocumentedException
LOG.warn("Error while closing streams", e);
}
try {
return XML_OUTPUT_FACTORY.createXMLStreamWriter(result);
} catch (final XMLStreamException e) {
- throw new RuntimeException(e);
+ throw new IllegalStateException(e);
}
}
nnWriter.flush();
xmlWriter.flush();
} catch (XMLStreamException | IOException e) {
- throw new RuntimeException(e);
+ // FIXME: throw DocumentedException
+ throw new IllegalStateException(e);
}
}
try {
xmlParser.traverse(new DOMSource(element.getDomElement()));
} catch (final XMLStreamException | URISyntaxException | IOException | SAXException ex) {
- throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex, ErrorType.PROTOCOL,
- DocumentedException.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
+ throw new NetconfDocumentedException("Error parsing input: " + ex.getMessage(), ex,
+ ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR);
}
return (ContainerNode) resultHolder.getResult();