use of org.opendaylight.netconf.api.ModifyAction in project netconf by opendaylight.
the class NetconfMessageTransformUtil method createEditConfigAnyxml.
/**
* Create edit-config structure to invoke {@code operation} with {@code lastChildOverride} data on {@code dataPath}.
*
* @param ctx {@link EffectiveModelContext} device's model context
* @param dataPath {@link YangInstanceIdentifier} path to data in device's data-store
* @param operation Optional of {@link ModifyAction} action to be invoked
* @param lastChildOverride Optional of {@code NormalizedNode} data on which action will be invoked
* @return {@link DOMSourceAnyxmlNode} containing edit-config structure
*/
public static DOMSourceAnyxmlNode createEditConfigAnyxml(final EffectiveModelContext ctx, final YangInstanceIdentifier dataPath, final Optional<ModifyAction> operation, final Optional<NormalizedNode> lastChildOverride) {
if (dataPath.isEmpty()) {
Preconditions.checkArgument(lastChildOverride.isPresent(), "Data has to be present when creating structure for top level element");
Preconditions.checkArgument(lastChildOverride.get() instanceof DataContainerChild, "Data has to be either container or a list node when creating structure for top level element, " + "but was: %s", lastChildOverride.get());
}
final var element = XmlUtil.createElement(BLANK_DOCUMENT, NETCONF_CONFIG_QNAME.getLocalName(), Optional.of(NETCONF_CONFIG_QNAME.getNamespace().toString()));
final var metadata = operation.map(o -> leafMetadata(dataPath, o)).orElse(null);
try {
if (lastChildOverride.isPresent()) {
// FIXME remove ImmutableNodes.fromInstanceId usage
final var configContent = ImmutableNodes.fromInstanceId(ctx, dataPath, lastChildOverride.get());
NetconfUtil.writeNormalizedNode(configContent, metadata, new DOMResult(element), SchemaPath.ROOT, ctx);
} else {
NetconfUtil.writeNormalizedNode(dataPath, metadata, new DOMResult(element), SchemaPath.ROOT, ctx);
}
} catch (final IOException | XMLStreamException e) {
throw new IllegalStateException("Unable to serialize edit config content element for path " + dataPath, e);
}
return Builders.anyXmlBuilder().withNodeIdentifier(NETCONF_CONFIG_NODEID).withValue(new DOMSource(element)).build();
}
use of org.opendaylight.netconf.api.ModifyAction in project netconf by opendaylight.
the class SplittingNormalizedNodeMetadataStreamWriter method metadata.
@Override
public void metadata(final ImmutableMap<QName, Object> metadata) throws IOException {
final Object operation = metadata.get(OPERATION_ATTRIBUTE);
if (operation != null) {
checkState(operation instanceof String, "Unexpected operation attribute value %s", operation);
final ModifyAction newAction = ModifyAction.fromXmlValue((String) operation);
currentAction = newAction;
}
writer.metadata(filterMeta(metadata));
}
use of org.opendaylight.netconf.api.ModifyAction in project netconf by opendaylight.
the class SplittingNormalizedNodeMetadataStreamWriter method endNode.
@Override
public void endNode() throws IOException {
final ModifyAction prevAction = actions.peek();
if (prevAction != null) {
// a remove/delete operation
if (prevAction != currentAction && deleteDepth == 0) {
dataTreeChanges.add(new DataTreeChange(writer.build(), currentAction, currentPath));
} else {
writer.endNode();
}
popPath();
} else {
// All done, special-cased
LOG.debug("All done ... writer {}", writer);
writer.endNode();
dataTreeChanges.add(new DataTreeChange(result.getResult(), currentAction, currentPath));
}
}
use of org.opendaylight.netconf.api.ModifyAction in project netconf by opendaylight.
the class EditConfig method handleWithNoSubsequentOperations.
@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws DocumentedException {
final XmlElement targetElement = extractTargetElement(operationElement, OPERATION_NAME);
final Datastore targetDatastore = Datastore.valueOf(targetElement.getName());
if (targetDatastore == Datastore.running) {
throw new DocumentedException("edit-config on running datastore is not supported", ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
}
final ModifyAction defaultAction = getDefaultOperation(operationElement);
final XmlElement configElement = getConfigElement(operationElement);
for (final XmlElement element : configElement.getChildElements()) {
final SplittingNormalizedNodeMetadataStreamWriter writer = new SplittingNormalizedNodeMetadataStreamWriter(defaultAction);
parseIntoNormalizedNode(getSchemaNodeFromNamespace(element.getNamespace(), element), element, writer);
executeOperations(writer.getDataTreeChanges());
}
return document.createElement(XmlNetconfConstants.OK);
}
Aggregations