import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
@VisibleForTesting
Set<ActionDefinition> getActions() {
- Builder<ActionDefinition> builder = ImmutableSet.builder();
+ final Builder<ActionDefinition> builder = ImmutableSet.builder();
for (DataSchemaNode dataSchemaNode : schemaContext.getChildNodes()) {
if (dataSchemaNode instanceof ActionNodeContainer) {
findAction(dataSchemaNode, builder);
// If the schema context for netconf device does not contain model for base netconf operations,
// use default pre build context with just the base model
// This way operations like lock/unlock are supported even if the source for base model was not provided
- SchemaContext ctx = needToUseBaseCtx ? baseSchema.getSchemaContext() : schemaContext;
+ final SchemaContext ctx = needToUseBaseCtx ? baseSchema.getSchemaContext() : schemaContext;
NetconfMessageTransformUtil.writeNormalizedRpc((ContainerNode) payload, result, rpcInput, ctx);
} catch (final XMLStreamException | IOException | IllegalStateException e) {
throw new IllegalStateException("Unable to serialize " + rpcInput, e);
}
@Override
- public NetconfMessage toActionRequest(SchemaPath action, final DOMDataTreeIdentifier domDataTreeIdentifier,
+ public NetconfMessage toActionRequest(final SchemaPath action, final DOMDataTreeIdentifier domDataTreeIdentifier,
final NormalizedNode<?, ?> payload) {
ActionDefinition actionDefinition = null;
- SchemaPath schemaPath = action;
for (ActionDefinition actionDef : actions) {
if (actionDef.getPath().getLastComponent().equals(action.getLastComponent())) {
actionDefinition = actionDef;
- schemaPath = actionDef.getPath();
}
}
Preconditions.checkNotNull(actionDefinition, "Action does not exist: %s", action.getLastComponent());
- if (actionDefinition.getInput().getChildNodes().isEmpty()) {
+ final ContainerSchemaNode inputDef = actionDefinition.getInput();
+ if (inputDef.getChildNodes().isEmpty()) {
return new NetconfMessage(NetconfMessageTransformUtil.prepareDomResultForActionRequest(
DataSchemaContextTree.from(schemaContext), domDataTreeIdentifier, action, counter,
- actionDefinition.getQName().getLocalName())
- .getNode().getOwnerDocument());
+ actionDefinition.getQName().getLocalName()).getNode().getOwnerDocument());
}
Preconditions.checkNotNull(payload, "Transforming an action with input: %s, payload cannot be null",
Preconditions.checkArgument(payload instanceof ContainerNode,
"Transforming an rpc with input: %s, payload has to be a container, but was: %s",
action.getLastComponent(), payload);
- // Set the path to the input of rpc for the node stream writer
- action = action.createChild(QName.create(action.getLastComponent(), "input").intern());
+
+ // Set the path to the input of action for the node stream writer
final DOMResult result = NetconfMessageTransformUtil.prepareDomResultForActionRequest(
- DataSchemaContextTree.from(schemaContext), domDataTreeIdentifier, action, counter,
+ DataSchemaContextTree.from(schemaContext), domDataTreeIdentifier, inputDef.getPath(), counter,
actionDefinition.getQName().getLocalName());
try {
- NetconfMessageTransformUtil.writeNormalizedRpc((ContainerNode) payload, result,
- schemaPath.createChild(QName.create(action.getLastComponent(), "input").intern()), schemaContext);
+ NetconfMessageTransformUtil.writeNormalizedRpc((ContainerNode) payload, result, inputDef.getPath(),
+ schemaContext);
} catch (final XMLStreamException | IOException | IllegalStateException e) {
throw new IllegalStateException("Unable to serialize " + action, e);
}
final QName rpcQName = rpc.getLastComponent();
if (NetconfMessageTransformUtil.isDataRetrievalOperation(rpcQName)) {
final Element xmlData = NetconfMessageTransformUtil.getDataSubtree(message.getDocument());
- final ContainerSchemaNode schemaForDataRead =
- NetconfMessageTransformUtil.createSchemaForDataRead(schemaContext);
- final ContainerNode dataNode;
-
- try {
- final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
- final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
- final XmlParserStream xmlParser = XmlParserStream.create(writer, schemaContext, schemaForDataRead,
- strictParsing);
- xmlParser.traverse(new DOMSource(xmlData));
- dataNode = (ContainerNode) resultHolder.getResult();
- } catch (XMLStreamException | URISyntaxException | IOException | ParserConfigurationException
- | SAXException e) {
- throw new IllegalArgumentException(String.format("Failed to parse data response %s", xmlData), e);
- }
-
- normalizedNode = Builders.containerBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier
- .NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_QNAME))
- .withChild(dataNode).build();
+ final AnyXmlNode anyXmlNode = Builders.anyXmlBuilder()
+ .withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_DATA_NODEID)
+ .withValue(new DOMSource(xmlData)).build();
+ normalizedNode = Builders.containerBuilder().withNodeIdentifier(
+ new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_QNAME))
+ .withChild(anyXmlNode).build();
} else {
Map<QName, RpcDefinition> currentMappedRpcs = mappedRpcs;
}
}
Preconditions.checkNotNull(actionDefinition, "Action does not exist: %s", action);
- ContainerNode normalizedNode = (ContainerNode) parseResult(message, actionDefinition);
+ final ContainerNode normalizedNode = (ContainerNode) parseResult(message, actionDefinition);
if (normalizedNode == null) {
return new SimpleDOMActionResult(Collections.<RpcError>emptyList());