2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.client.mdsal.impl;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static com.google.common.base.Preconditions.checkNotNull;
12 import static java.util.Objects.requireNonNull;
14 import com.google.common.annotations.Beta;
15 import com.google.common.annotations.VisibleForTesting;
16 import com.google.common.collect.ImmutableList;
17 import com.google.common.collect.ImmutableMap;
18 import com.google.common.collect.ImmutableSet;
19 import com.google.common.collect.Iterables;
20 import com.google.common.collect.Maps;
21 import com.google.common.collect.Multimap;
22 import com.google.common.collect.Multimaps;
23 import com.google.common.collect.Streams;
24 import java.io.IOException;
25 import java.time.Instant;
26 import java.util.AbstractMap;
27 import java.util.ArrayDeque;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.Collections;
31 import java.util.Deque;
32 import java.util.HashMap;
33 import java.util.List;
35 import java.util.Map.Entry;
36 import java.util.Optional;
38 import java.util.function.Function;
39 import java.util.stream.Collectors;
40 import javax.xml.stream.XMLStreamException;
41 import javax.xml.transform.dom.DOMResult;
42 import javax.xml.transform.dom.DOMSource;
43 import org.checkerframework.checker.lock.qual.GuardedBy;
44 import org.eclipse.jdt.annotation.NonNull;
45 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
46 import org.opendaylight.mdsal.dom.api.DOMActionResult;
47 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
48 import org.opendaylight.mdsal.dom.api.DOMEvent;
49 import org.opendaylight.mdsal.dom.api.DOMNotification;
50 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
51 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
52 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
53 import org.opendaylight.netconf.api.messages.NetconfMessage;
54 import org.opendaylight.netconf.api.xml.MissingNameSpaceException;
55 import org.opendaylight.netconf.api.xml.XmlElement;
56 import org.opendaylight.netconf.client.mdsal.api.ActionTransformer;
57 import org.opendaylight.netconf.client.mdsal.api.BaseNetconfSchema;
58 import org.opendaylight.netconf.client.mdsal.api.NotificationTransformer;
59 import org.opendaylight.netconf.client.mdsal.api.RpcTransformer;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.GetConfig;
61 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscription;
62 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
63 import org.opendaylight.yangtools.yang.common.QName;
64 import org.opendaylight.yangtools.yang.common.Revision;
65 import org.opendaylight.yangtools.yang.common.RpcResult;
66 import org.opendaylight.yangtools.yang.common.XMLNamespace;
67 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
68 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
69 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
70 import org.opendaylight.yangtools.yang.data.api.schema.MountPointContext;
71 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
72 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
73 import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
74 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
75 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizationResultHolder;
76 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
77 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
78 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
79 import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
80 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
81 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
82 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
83 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
84 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
85 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
86 import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
87 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
88 import org.opendaylight.yangtools.yang.model.api.Module;
89 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
90 import org.opendaylight.yangtools.yang.model.api.OperationDefinition;
91 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
92 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
93 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
94 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
95 import org.slf4j.Logger;
96 import org.slf4j.LoggerFactory;
97 import org.w3c.dom.Document;
98 import org.w3c.dom.Element;
99 import org.w3c.dom.Node;
100 import org.w3c.dom.NodeList;
102 public class NetconfMessageTransformer
103 implements ActionTransformer, NotificationTransformer, RpcTransformer<ContainerNode, DOMRpcResult> {
104 private static final Logger LOG = LoggerFactory.getLogger(NetconfMessageTransformer.class);
106 private static final ImmutableSet<XMLNamespace> BASE_OR_NOTIFICATION_NS = ImmutableSet.of(
107 GetConfig.QNAME.getNamespace(),
108 NetconfCapabilityChange.QNAME.getNamespace(),
109 CreateSubscription.QNAME.getNamespace());
111 private final MountPointContext mountContext;
112 private final DataSchemaContextTree contextTree;
113 private final BaseNetconfSchema baseSchema;
114 private final MessageCounter counter;
115 private final ImmutableMap<QName, ? extends RpcDefinition> mappedRpcs;
116 private final Multimap<QName, ? extends NotificationDefinition> mappedNotifications;
117 private final boolean strictParsing;
118 private final ImmutableMap<Absolute, ActionDefinition> actions;
120 public NetconfMessageTransformer(final MountPointContext mountContext, final boolean strictParsing,
121 final BaseNetconfSchema baseSchema) {
122 counter = new MessageCounter();
123 this.mountContext = requireNonNull(mountContext);
125 final EffectiveModelContext modelContext = mountContext.modelContext();
126 contextTree = DataSchemaContextTree.from(modelContext);
128 mappedRpcs = Maps.uniqueIndex(modelContext.getOperations(), SchemaNode::getQName);
129 actions = getActions(modelContext);
131 // RFC6020 normal notifications
132 mappedNotifications = Multimaps.index(modelContext.getNotifications(),
133 node -> node.getQName().withoutRevision());
134 this.baseSchema = baseSchema;
135 this.strictParsing = strictParsing;
139 static ImmutableMap<Absolute, ActionDefinition> getActions(final EffectiveModelContext schemaContext) {
140 final var builder = ImmutableMap.<Absolute, ActionDefinition>builder();
141 findAction(schemaContext, new ArrayDeque<>(), builder);
142 return builder.build();
145 private static void findAction(final DataSchemaNode dataSchemaNode, final Deque<QName> path,
146 final ImmutableMap.Builder<Absolute, ActionDefinition> builder) {
147 if (dataSchemaNode instanceof ActionNodeContainer) {
148 for (ActionDefinition actionDefinition : ((ActionNodeContainer) dataSchemaNode).getActions()) {
149 path.addLast(actionDefinition.getQName());
150 builder.put(Absolute.of(path), actionDefinition);
154 if (dataSchemaNode instanceof DataNodeContainer) {
155 for (DataSchemaNode innerDataSchemaNode : ((DataNodeContainer) dataSchemaNode).getChildNodes()) {
156 path.addLast(innerDataSchemaNode.getQName());
157 findAction(innerDataSchemaNode, path, builder);
160 } else if (dataSchemaNode instanceof ChoiceSchemaNode) {
161 for (CaseSchemaNode caze : ((ChoiceSchemaNode) dataSchemaNode).getCases()) {
162 path.addLast(caze.getQName());
163 findAction(caze, path, builder);
170 public synchronized DOMNotification toNotification(final NetconfMessage message) {
171 final Entry<Instant, XmlElement> stripped = NetconfMessageTransformUtil.stripNotification(message);
172 final QName notificationNoRev;
174 notificationNoRev = QName.create(
175 stripped.getValue().getNamespace(), stripped.getValue().getName()).withoutRevision();
176 } catch (final MissingNameSpaceException e) {
177 throw new IllegalArgumentException(
178 "Unable to parse notification " + message + ", cannot find namespace", e);
181 final var matchingTopLevel = mappedNotifications.get(notificationNoRev);
182 final var element = stripped.getValue().getDomElement();
183 if (!matchingTopLevel.isEmpty()) {
184 final var notification = getMostRecentNotification(matchingTopLevel);
185 // FIXME: we really should have a pre-constructed identifier here
186 return new NetconfDeviceNotification(toNotification(Absolute.of(notification.getQName()), element),
190 final var nestedInfo = findNestedNotification(message, element)
191 .orElseThrow(() -> new IllegalArgumentException("Unable to parse notification for " + element
192 + ". Available notifications: " + mappedNotifications.keySet()));
193 final var schemaPath = nestedInfo.schemaPath;
194 return new NetconfDeviceTreeNotification(toNotification(schemaPath, nestedInfo.element), schemaPath,
195 stripped.getKey(), nestedInfo.instancePath);
199 private ContainerNode toNotification(final Absolute notificationPath, final Element element) {
200 final NormalizationResultHolder resultHolder = new NormalizationResultHolder();
202 final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
203 final XmlParserStream xmlParser = XmlParserStream.create(writer, mountContext,
204 SchemaInferenceStack.of(mountContext.modelContext(), notificationPath).toInference(), strictParsing);
205 xmlParser.traverse(new DOMSource(element));
206 } catch (XMLStreamException | IOException | UnsupportedOperationException e) {
207 throw new IllegalArgumentException(String.format("Failed to parse notification %s", element), e);
209 return (ContainerNode) resultHolder.getResult().data();
212 private Optional<NestedNotificationInfo> findNestedNotification(final NetconfMessage message,
213 final Element element) {
214 final var modules = mountContext.modelContext().findModules(XMLNamespace.of(element.getNamespaceURI()))
216 if (!modules.hasNext()) {
217 throw new IllegalArgumentException(
218 "Unable to parse notification " + message + ", cannot find top level module");
220 final Module module = modules.next();
221 final QName topLevelNodeQName = QName.create(element.getNamespaceURI(), element.getLocalName());
222 for (DataSchemaNode childNode : module.getChildNodes()) {
223 if (topLevelNodeQName.isEqualWithoutRevision(childNode.getQName())) {
224 return Optional.of(traverseXmlNodeContainingNotification(element, childNode, new ArrayList<>(),
225 YangInstanceIdentifier.builder()));
228 return Optional.empty();
231 // FIXME: this method is using QNames which are not bound to a Revision. Why is that?
232 // FIXME: furthermore this does not handle the entirety of schema layout: notably missing a choice/case schema nodes
233 private NestedNotificationInfo traverseXmlNodeContainingNotification(final Node xmlNode,
234 final SchemaNode schemaNode, final List<QName> schemaBuilder,
235 final InstanceIdentifierBuilder instanceBuilder) {
236 if (schemaNode instanceof ContainerSchemaNode containerSchema) {
237 instanceBuilder.node(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName()));
238 schemaBuilder.add(containerSchema.getQName());
240 Entry<Node, SchemaNode> xmlContainerChildPair = findXmlContainerChildPair(xmlNode, containerSchema);
241 return traverseXmlNodeContainingNotification(xmlContainerChildPair.getKey(),
242 xmlContainerChildPair.getValue(), schemaBuilder, instanceBuilder);
243 } else if (schemaNode instanceof ListSchemaNode listSchema) {
244 instanceBuilder.node(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName()));
245 schemaBuilder.add(listSchema.getQName());
247 Map<QName, Object> listKeys = findXmlListKeys(xmlNode, listSchema);
248 instanceBuilder.nodeWithKey(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName()), listKeys);
250 Entry<Node, SchemaNode> xmlListChildPair = findXmlListChildPair(xmlNode, listSchema);
251 return traverseXmlNodeContainingNotification(xmlListChildPair.getKey(),
252 xmlListChildPair.getValue(), schemaBuilder, instanceBuilder);
253 } else if (schemaNode instanceof NotificationDefinition) {
254 // FIXME: this should not be here: it does not form a valid YangInstanceIdentifier
255 instanceBuilder.node(QName.create(xmlNode.getNamespaceURI(), xmlNode.getLocalName()));
256 schemaBuilder.add(schemaNode.getQName());
258 return new NestedNotificationInfo(Absolute.of(schemaBuilder),
259 DOMDataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION, instanceBuilder.build()), xmlNode);
261 throw new IllegalStateException("No notification found");
264 private static Entry<Node, SchemaNode> findXmlContainerChildPair(final Node xmlNode,
265 final ContainerSchemaNode container) {
266 final NodeList nodeList = xmlNode.getChildNodes();
267 final Map<QName, SchemaNode> childrenWithoutRevision =
268 Streams.concat(container.getChildNodes().stream(), container.getNotifications().stream())
269 .collect(Collectors.toMap(child -> child.getQName().withoutRevision(), Function.identity()));
271 for (int i = 0; i < nodeList.getLength(); i++) {
272 Node currentNode = nodeList.item(i);
273 if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
274 QName currentNodeQName = QName.create(currentNode.getNamespaceURI(), currentNode.getLocalName());
275 SchemaNode schemaChildNode = childrenWithoutRevision.get(currentNodeQName);
276 if (schemaChildNode != null) {
277 return Map.entry(currentNode, schemaChildNode);
281 throw new IllegalStateException("No container child found.");
284 private static Map<QName, Object> findXmlListKeys(final Node xmlNode, final ListSchemaNode listSchemaNode) {
285 Map<QName, Object> listKeys = new HashMap<>();
286 NodeList nodeList = xmlNode.getChildNodes();
287 Set<QName> keyDefinitionsWithoutRevision = listSchemaNode.getKeyDefinition().stream()
288 .map(QName::withoutRevision).collect(Collectors.toSet());
289 for (int i = 0; i < nodeList.getLength(); i++) {
290 Node currentNode = nodeList.item(i);
291 if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
292 QName currentNodeQName = QName.create(currentNode.getNamespaceURI(), currentNode.getLocalName());
293 if (keyDefinitionsWithoutRevision.contains(currentNodeQName)) {
294 listKeys.put(currentNodeQName, currentNode.getFirstChild().getNodeValue());
298 if (listKeys.isEmpty()) {
299 throw new IllegalStateException("Notification cannot be contained in list without key statement.");
304 private static Entry<Node, SchemaNode> findXmlListChildPair(final Node xmlNode, final ListSchemaNode list) {
305 final NodeList nodeList = xmlNode.getChildNodes();
306 for (int i = 0; i < nodeList.getLength(); i++) {
307 Node currentNode = nodeList.item(i);
308 if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
309 QName currentNodeQName = QName.create(currentNode.getNamespaceURI(), currentNode.getLocalName());
310 for (SchemaNode childNode : Iterables.concat(list.getChildNodes(), list.getNotifications())) {
311 if (!list.getKeyDefinition().contains(childNode.getQName())
312 && currentNodeQName.isEqualWithoutRevision(childNode.getQName())) {
313 return new AbstractMap.SimpleEntry<>(currentNode, childNode);
318 throw new IllegalStateException("No list child found.");
321 private static NotificationDefinition getMostRecentNotification(
322 final Collection<? extends NotificationDefinition> notificationDefinitions) {
323 return Collections.max(notificationDefinitions, (o1, o2) ->
324 Revision.compare(o1.getQName().getRevision(), o2.getQName().getRevision()));
328 public NetconfMessage toRpcRequest(final QName rpc, final ContainerNode payload) {
329 // In case no input for rpc is defined, we can simply construct the payload here
331 // Determine whether a base netconf operation is being invoked
332 // and also check if the device exposed model for base netconf.
333 // If no, use pre built base netconf operations model
334 final boolean needToUseBaseCtx = mappedRpcs.get(rpc) == null && isBaseOrNotificationRpc(rpc);
335 final ImmutableMap<QName, ? extends RpcDefinition> currentMappedRpcs;
336 if (needToUseBaseCtx) {
337 currentMappedRpcs = baseSchema.mappedRpcs();
339 currentMappedRpcs = mappedRpcs;
342 final RpcDefinition mappedRpc = checkNotNull(currentMappedRpcs.get(rpc),
343 "Unknown rpc %s, available rpcs: %s", rpc, currentMappedRpcs.keySet());
344 if (mappedRpc.getInput().getChildNodes().isEmpty()) {
345 return new NetconfMessage(NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpc, counter)
346 .getNode().getOwnerDocument());
349 checkNotNull(payload, "Transforming an rpc with input: %s, payload cannot be null", rpc);
351 final DOMResult result = NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpc, counter);
353 // If the schema context for netconf device does not contain model for base netconf operations,
354 // use default pre build context with just the base model
355 // This way operations like lock/unlock are supported even if the source for base model was not provided
356 final var modelContext = needToUseBaseCtx ? baseSchema.modelContext() : mountContext.modelContext();
357 NetconfMessageTransformUtil.writeNormalizedOperationInput(payload, result, Absolute.of(rpc), modelContext);
358 } catch (final XMLStreamException | IOException | IllegalStateException e) {
359 throw new IllegalStateException("Unable to serialize input of " + rpc, e);
362 final Document node = result.getNode().getOwnerDocument();
364 return new NetconfMessage(node);
368 public NetconfMessage toActionRequest(final Absolute action, final DOMDataTreeIdentifier domDataTreeIdentifier,
369 final NormalizedNode payload) {
370 final ActionDefinition actionDef = actions.get(action);
371 checkArgument(actionDef != null, "Action does not exist: %s", action);
373 final InputSchemaNode inputDef = actionDef.getInput();
374 if (inputDef.getChildNodes().isEmpty()) {
375 return new NetconfMessage(NetconfMessageTransformUtil.prepareDomResultForActionRequest(contextTree,
376 domDataTreeIdentifier, counter, actionDef.getQName()).getNode().getOwnerDocument());
379 checkNotNull(payload, "Transforming an action with input: %s, payload cannot be null", action);
380 checkArgument(payload instanceof ContainerNode,
381 "Transforming an action with input: %s, payload has to be a container, but was: %s", action, payload);
383 final DOMResult result = NetconfMessageTransformUtil.prepareDomResultForActionRequest(contextTree,
384 domDataTreeIdentifier, counter, actionDef.getQName());
386 NetconfMessageTransformUtil.writeNormalizedOperationInput((ContainerNode) payload, result, action,
387 mountContext.modelContext());
388 } catch (final XMLStreamException | IOException | IllegalStateException e) {
389 throw new IllegalStateException("Unable to serialize input of " + action, e);
392 return new NetconfMessage(result.getNode().getOwnerDocument());
395 private static boolean isBaseOrNotificationRpc(final QName rpc) {
396 return BASE_OR_NOTIFICATION_NS.contains(rpc.getNamespace());
400 public synchronized DOMRpcResult toRpcResult(final RpcResult<NetconfMessage> resultPayload, final QName rpc) {
401 if (!resultPayload.isSuccessful()) {
402 return new DefaultDOMRpcResult(resultPayload.getErrors());
405 final var message = resultPayload.getResult();
406 final ContainerNode normalizedNode;
407 if (NetconfMessageTransformUtil.isDataRetrievalOperation(rpc)) {
408 normalizedNode = ImmutableNodes.newContainerBuilder()
409 .withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_NODEID)
410 .withChild(ImmutableNodes.newAnyxmlBuilder(DOMSource.class)
411 .withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_DATA_NODEID)
412 .withValue(new DOMSource(NetconfMessageTransformUtil.getDataSubtree(message.getDocument())))
416 // Determine whether a base netconf operation is being invoked
417 // and also check if the device exposed model for base netconf.
418 // If no, use pre built base netconf operations model
419 final ImmutableMap<QName, ? extends RpcDefinition> currentMappedRpcs;
420 if (mappedRpcs.get(rpc) == null && isBaseOrNotificationRpc(rpc)) {
421 currentMappedRpcs = baseSchema.mappedRpcs();
423 currentMappedRpcs = mappedRpcs;
426 final RpcDefinition rpcDefinition = currentMappedRpcs.get(rpc);
427 checkArgument(rpcDefinition != null, "Unable to parse response of %s, the rpc is unknown", rpc);
429 // In case no input for rpc is defined, we can simply construct the payload here
430 normalizedNode = parseResult(message, Absolute.of(rpc), rpcDefinition);
432 return new DefaultDOMRpcResult(normalizedNode);
436 public DOMActionResult toActionResult(final Absolute action, final NetconfMessage message) {
437 final ActionDefinition actionDefinition = actions.get(action);
438 checkArgument(actionDefinition != null, "Action does not exist: %s", action);
439 final ContainerNode normalizedNode = parseResult(message, action, actionDefinition);
441 if (normalizedNode == null) {
442 return new SimpleDOMActionResult(List.of());
444 return new SimpleDOMActionResult(normalizedNode, List.of());
448 private ContainerNode parseResult(final NetconfMessage message, final Absolute operationPath,
449 final OperationDefinition operationDef) {
450 final Optional<XmlElement> okResponseElement = XmlElement.fromDomDocument(message.getDocument())
451 .getOnlyChildElementWithSameNamespaceOptionally("ok");
452 final var operOutput = operationDef.getOutput();
453 if (operOutput.getChildNodes().isEmpty()) {
454 checkArgument(okResponseElement.isPresent(), "Unexpected content in response of operation: %s, %s",
455 operationDef.getQName(), message);
458 if (okResponseElement.isPresent()) {
459 // FIXME: could be an action as well
460 LOG.debug("Received response <ok/> for RPC with defined Output");
464 final var operSteps = operationPath.getNodeIdentifiers();
465 final var outputPath = Absolute.of(ImmutableList.<QName>builderWithExpectedSize(operSteps.size() + 1)
467 .add(operOutput.getQName())
469 // FIXME: we should have a cached inference here, or XMLParserStream should accept Absolute instead
470 final var inference = SchemaInferenceStack.of(mountContext.modelContext(), outputPath).toInference();
472 final NormalizationResultHolder resultHolder = new NormalizationResultHolder();
473 final Element element = message.getDocument().getDocumentElement();
475 final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
476 final XmlParserStream xmlParser = XmlParserStream.create(writer, mountContext, inference, strictParsing);
477 xmlParser.traverse(new DOMSource(element));
478 } catch (XMLStreamException | IOException e) {
479 throw new IllegalArgumentException(String.format("Failed to parse RPC response %s", element), e);
481 return (ContainerNode) resultHolder.getResult().data();
485 public static class NetconfDeviceNotification implements DOMNotification, DOMEvent {
486 private final ContainerNode content;
487 private final Absolute schemaPath;
488 private final Instant eventTime;
490 NetconfDeviceNotification(final ContainerNode content, final Instant eventTime) {
491 this.content = content;
492 this.eventTime = eventTime;
493 schemaPath = Absolute.of(content.name().getNodeType());
496 NetconfDeviceNotification(final ContainerNode content, final Absolute schemaPath, final Instant eventTime) {
497 this.content = content;
498 this.eventTime = eventTime;
499 this.schemaPath = schemaPath;
503 public Absolute getType() {
508 public ContainerNode getBody() {
513 public Instant getEventInstant() {
519 public static class NetconfDeviceTreeNotification extends NetconfDeviceNotification {
520 private final DOMDataTreeIdentifier domDataTreeIdentifier;
522 NetconfDeviceTreeNotification(final ContainerNode content, final Absolute schemaPath, final Instant eventTime,
523 final DOMDataTreeIdentifier domDataTreeIdentifier) {
524 super(content, schemaPath, eventTime);
525 this.domDataTreeIdentifier = domDataTreeIdentifier;
528 public DOMDataTreeIdentifier getDomDataTreeIdentifier() {
529 return domDataTreeIdentifier;
533 private static final class NestedNotificationInfo {
534 final @NonNull DOMDataTreeIdentifier instancePath;
535 final @NonNull Absolute schemaPath;
536 final @NonNull Element element;
538 NestedNotificationInfo(final Absolute schemaPath, final DOMDataTreeIdentifier instancePath,
539 final Node documentNode) {
540 this.schemaPath = requireNonNull(schemaPath);
541 this.instancePath = requireNonNull(instancePath);
542 checkArgument(documentNode instanceof Element, "Unexpected document node %s", documentNode);
543 element = (Element) documentNode;