Bump upstreams
[netconf.git] / plugins / netconf-client-mdsal / src / main / java / org / opendaylight / netconf / client / mdsal / impl / NetconfBaseOps.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.client.mdsal.impl;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
12 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.COMMIT_RPC_CONTENT;
13 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.DISCARD_CHANGES_RPC_CONTENT;
14 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.EDIT_CONTENT_NODEID;
15 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.GET_RPC_CONTENT;
16 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID;
17 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_NODEID;
18 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_DEFAULT_OPERATION_NODEID;
19 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_NODEID;
20 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_ERROR_OPTION_NODEID;
21 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_NODEID;
22 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_GET_NODEID;
23 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_LOCK_NODEID;
24 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID;
25 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_SOURCE_NODEID;
26 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_TARGET_NODEID;
27 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_UNLOCK_NODEID;
28 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.NETCONF_VALIDATE_NODEID;
29 import static org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil.toFilterStructure;
30
31 import com.google.common.collect.Iterables;
32 import com.google.common.util.concurrent.FutureCallback;
33 import com.google.common.util.concurrent.Futures;
34 import com.google.common.util.concurrent.ListenableFuture;
35 import com.google.common.util.concurrent.MoreExecutors;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.Map.Entry;
39 import java.util.Optional;
40 import java.util.stream.Collectors;
41 import org.eclipse.jdt.annotation.NonNull;
42 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
43 import org.opendaylight.netconf.api.EffectiveOperation;
44 import org.opendaylight.netconf.client.mdsal.api.NetconfRpcService;
45 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices.Rpcs;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.Commit;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.CopyConfig;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.DiscardChanges;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditConfig;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.Get;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.GetConfig;
52 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.Lock;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.Unlock;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.Validate;
55 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.copy.config.input.target.ConfigTarget;
56 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.get.config.input.source.ConfigSource;
57 import org.opendaylight.yangtools.yang.common.Empty;
58 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
59 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
60 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
61 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
62 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
63 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
64 import org.opendaylight.yangtools.yang.data.api.schema.MountPointContext;
65 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
66 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
67 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
68
69 /**
70  * Provides base operations for NETCONF e.g. {@code get}, {@code get-config}, {@code edit-config}, {@code commit} etc.
71  * as per <a href="https://www.rfc-editor.org/rfc/rfc6241#section-7">RFC6241 Protocol Operations</a>.
72  */
73 // FIXME: turn Optional arguments to @Nullable
74 public final class NetconfBaseOps {
75     private static final NodeIdentifier CONFIG_SOURCE_NODEID = NodeIdentifier.create(ConfigSource.QNAME);
76     private static final NodeIdentifier CONFIG_TARGET_NODEID = NodeIdentifier.create(ConfigTarget.QNAME);
77     private static final LeafNode<String> NETCONF_ERROR_OPTION_ROLLBACK =
78         ImmutableNodes.leafNode(NETCONF_ERROR_OPTION_NODEID, "rollback-on-error");
79
80     private final NetconfRpcService rpc;
81     private final MountPointContext mountContext;
82     private final RpcStructureTransformer transformer;
83
84     public NetconfBaseOps(final Rpcs rpc, final MountPointContext mountContext) {
85         this.rpc = requireNonNull(rpc);
86         this.mountContext = requireNonNull(mountContext);
87
88         if (rpc instanceof Rpcs.Schemaless) {
89             transformer = new SchemalessRpcStructureTransformer();
90         } else if (rpc instanceof Rpcs.Normalized) {
91             transformer = new NetconfRpcStructureTransformer(mountContext);
92         } else {
93             throw new IllegalStateException("Unhandled rpcs " + rpc);
94         }
95     }
96
97     public ListenableFuture<? extends DOMRpcResult> lock(final FutureCallback<DOMRpcResult> callback,
98             final NodeIdentifier datastore) {
99         return addCallback(requireNonNull(callback), rpc.invokeNetconf(Lock.QNAME, getLockContent(datastore)));
100     }
101
102     private static <T> ListenableFuture<T> addCallback(final FutureCallback<? super T> callback,
103             final ListenableFuture<T> future) {
104         Futures.addCallback(future, callback, MoreExecutors.directExecutor());
105         return future;
106     }
107
108     public ListenableFuture<? extends DOMRpcResult> lockCandidate(final FutureCallback<DOMRpcResult> callback) {
109         return addCallback(requireNonNull(callback), rpc.invokeNetconf(Lock.QNAME,
110             getLockContent(NETCONF_CANDIDATE_NODEID)));
111     }
112
113     public ListenableFuture<? extends DOMRpcResult> lockRunning(final FutureCallback<DOMRpcResult> callback) {
114         return addCallback(requireNonNull(callback), rpc.invokeNetconf(Lock.QNAME,
115             getLockContent(NETCONF_RUNNING_NODEID)));
116     }
117
118     public ListenableFuture<? extends DOMRpcResult> unlock(final FutureCallback<DOMRpcResult> callback,
119             final NodeIdentifier datastore) {
120         return addCallback(requireNonNull(callback), rpc.invokeNetconf(Unlock.QNAME, getUnLockContent(datastore)));
121     }
122
123     public ListenableFuture<? extends DOMRpcResult> unlockRunning(final FutureCallback<DOMRpcResult> callback) {
124         return addCallback(requireNonNull(callback), rpc.invokeNetconf(Unlock.QNAME,
125             getUnLockContent(NETCONF_RUNNING_NODEID)));
126     }
127
128     public ListenableFuture<? extends DOMRpcResult> unlockCandidate(final FutureCallback<DOMRpcResult> callback) {
129         return addCallback(requireNonNull(callback), rpc.invokeNetconf(Unlock.QNAME,
130             getUnLockContent(NETCONF_CANDIDATE_NODEID)));
131     }
132
133     public ListenableFuture<? extends DOMRpcResult> discardChanges(final FutureCallback<DOMRpcResult> callback) {
134         return addCallback(requireNonNull(callback), rpc.invokeNetconf(DiscardChanges.QNAME,
135             DISCARD_CHANGES_RPC_CONTENT));
136     }
137
138     public ListenableFuture<? extends DOMRpcResult> commit(final FutureCallback<DOMRpcResult> callback) {
139         return addCallback(requireNonNull(callback), rpc.invokeNetconf(Commit.QNAME, COMMIT_RPC_CONTENT));
140     }
141
142     public ListenableFuture<? extends DOMRpcResult> validate(final FutureCallback<DOMRpcResult> callback,
143             final NodeIdentifier datastore) {
144         return addCallback(requireNonNull(callback), rpc.invokeNetconf(Validate.QNAME,
145             getValidateContent(requireNonNull(datastore))));
146     }
147
148     public ListenableFuture<? extends DOMRpcResult> validateCandidate(final FutureCallback<DOMRpcResult> callback) {
149         return validate(callback, NETCONF_CANDIDATE_NODEID);
150     }
151
152     public ListenableFuture<? extends DOMRpcResult> validateRunning(final FutureCallback<DOMRpcResult> callback) {
153         return validate(callback, NETCONF_RUNNING_NODEID);
154     }
155
156     public ListenableFuture<? extends DOMRpcResult> copyConfig(final FutureCallback<DOMRpcResult> callback,
157             final NodeIdentifier sourceDatastore, final NodeIdentifier targetDatastore) {
158         return addCallback(requireNonNull(callback), rpc.invokeNetconf(CopyConfig.QNAME,
159             getCopyConfigContent(sourceDatastore, targetDatastore)));
160     }
161
162     public ListenableFuture<? extends DOMRpcResult> copyRunningToCandidate(
163             final FutureCallback<DOMRpcResult> callback) {
164         return copyConfig(callback, NETCONF_RUNNING_NODEID, NETCONF_CANDIDATE_NODEID);
165     }
166
167     public ListenableFuture<? extends DOMRpcResult> getConfig(final FutureCallback<DOMRpcResult> callback,
168             final NodeIdentifier datastore, final Optional<YangInstanceIdentifier> filterPath) {
169         final var source = getSourceNode(datastore);
170         return addCallback(requireNonNull(callback), rpc.invokeNetconf(GetConfig.QNAME,
171             nonEmptyFilter(filterPath)
172                 .map(path -> NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID, source,
173                     transformer.toFilterStructure(path)))
174                 .orElseGet(() -> NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID, source))));
175     }
176
177     private ListenableFuture<? extends DOMRpcResult> getConfig(final FutureCallback<DOMRpcResult> callback,
178             final NodeIdentifier datastore, final Optional<YangInstanceIdentifier> filterPath,
179             final List<YangInstanceIdentifier> fields) {
180         final ContainerNode rpcInput;
181         if (nonEmptyFilter(filterPath).isPresent()) {
182             rpcInput = NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID, getSourceNode(datastore),
183                 transformer.toFilterStructure(List.of(FieldsFilter.of(filterPath.orElseThrow(), fields))));
184         } else if (containsEmptyPath(fields)) {
185             rpcInput = NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID, getSourceNode(datastore));
186         } else {
187             rpcInput = NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID,
188                     getSourceNode(datastore), getSubtreeFilterFromRootFields(fields));
189         }
190         return addCallback(requireNonNull(callback), rpc.invokeNetconf(GetConfig.QNAME, rpcInput));
191     }
192
193     /**
194      * Calling GET-CONFIG RPC with subtree filter that is specified by {@link YangInstanceIdentifier}.
195      *
196      * @param callback   RPC response callback
197      * @param filterPath path to requested data
198      * @return asynchronous completion token with read {@link NormalizedNode} wrapped in {@link Optional} instance
199      */
200     public ListenableFuture<Optional<NormalizedNode>> getConfigRunningData(final FutureCallback<DOMRpcResult> callback,
201             final Optional<YangInstanceIdentifier> filterPath) {
202         return extractData(filterPath, getConfigRunning(callback, filterPath));
203     }
204
205     /**
206      * Calling GET-CONFIG RPC with subtree filter tha tis specified by parent {@link YangInstanceIdentifier} and list
207      * of specific fields that caller would like to read. Field paths are relative to parent path.
208      *
209      * @param callback   RPC response callback
210      * @param filterPath parent path to requested data
211      * @param fields     paths to specific fields that are selected under parent path
212      * @return asynchronous completion token with read {@link NormalizedNode} wrapped in {@link Optional} instance
213      */
214     public ListenableFuture<Optional<NormalizedNode>> getConfigRunningData(final FutureCallback<DOMRpcResult> callback,
215             final Optional<YangInstanceIdentifier> filterPath, final List<YangInstanceIdentifier> fields) {
216         if (fields.isEmpty()) {
217             // RFC doesn't allow to build subtree filter that would expect just empty element in response
218             return Futures.immediateFailedFuture(new IllegalArgumentException(
219                 "Failed to build NETCONF GET-CONFIG RPC: provided list of fields is empty; filter path: "
220                     + filterPath));
221         }
222         return extractData(filterPath, getConfigRunning(callback, filterPath, fields));
223     }
224
225     /**
226      * Calling GET RPC with subtree filter that is specified by {@link YangInstanceIdentifier}.
227      *
228      * @param callback   RPC response callback
229      * @param filterPath path to requested data
230      * @return asynchronous completion token with read {@link NormalizedNode} wrapped in {@link Optional} instance
231      */
232     public ListenableFuture<Optional<NormalizedNode>> getData(final FutureCallback<DOMRpcResult> callback,
233             final Optional<YangInstanceIdentifier> filterPath) {
234         return extractData(filterPath, get(callback, filterPath));
235     }
236
237     /**
238      * Calling GET RPC with subtree filter tha tis specified by parent {@link YangInstanceIdentifier} and list
239      * of specific fields that caller would like to read. Field paths are relative to parent path.
240      *
241      * @param callback   RPC response callback
242      * @param filterPath parent path to requested data
243      * @param fields     paths to specific fields that are selected under parent path
244      * @return asynchronous completion token with read {@link NormalizedNode} wrapped in {@link Optional} instance
245      */
246     public ListenableFuture<Optional<NormalizedNode>> getData(final FutureCallback<DOMRpcResult> callback,
247             final Optional<YangInstanceIdentifier> filterPath, final List<YangInstanceIdentifier> fields) {
248         if (fields.isEmpty()) {
249             // RFC doesn't allow to build subtree filter that would expect just empty element in response
250             return Futures.immediateFailedFuture(new IllegalArgumentException(
251                     "Failed to build NETCONF GET RPC: provided list of fields is empty; filter path: " + filterPath));
252         }
253         return extractData(filterPath, get(callback, filterPath, fields));
254     }
255
256     private ListenableFuture<Optional<NormalizedNode>> extractData(final Optional<YangInstanceIdentifier> path,
257             final ListenableFuture<? extends DOMRpcResult> configRunning) {
258         return Futures.transform(configRunning, result -> {
259             final var errors = result.errors();
260             checkArgument(errors.isEmpty(), "Unable to read data: %s, errors: %s", path, errors);
261             return transformer.selectFromDataStructure(result.value()
262                 .getChildByArg(NetconfMessageTransformUtil.NETCONF_DATA_NODEID), path.orElseThrow());
263         }, MoreExecutors.directExecutor());
264     }
265
266     public ListenableFuture<? extends DOMRpcResult> getConfigRunning(final FutureCallback<DOMRpcResult> callback,
267             final Optional<YangInstanceIdentifier> filterPath) {
268         return getConfig(callback, NETCONF_RUNNING_NODEID, filterPath);
269     }
270
271     private ListenableFuture<? extends DOMRpcResult> getConfigRunning(final FutureCallback<DOMRpcResult> callback,
272             final Optional<YangInstanceIdentifier> filterPath, final List<YangInstanceIdentifier> fields) {
273         return getConfig(callback, NETCONF_RUNNING_NODEID, filterPath, fields);
274     }
275
276     public ListenableFuture<? extends DOMRpcResult> getConfigCandidate(final FutureCallback<DOMRpcResult> callback,
277             final Optional<YangInstanceIdentifier> filterPath) {
278         return getConfig(callback, NETCONF_CANDIDATE_NODEID, filterPath);
279     }
280
281     public ListenableFuture<? extends DOMRpcResult> get(final FutureCallback<DOMRpcResult> callback,
282             final Optional<YangInstanceIdentifier> filterPath) {
283         return addCallback(requireNonNull(callback), rpc.invokeNetconf(Get.QNAME,
284             nonEmptyFilter(filterPath)
285                 .map(path -> NetconfMessageTransformUtil.wrap(NETCONF_GET_NODEID,
286                     toFilterStructure(path, mountContext.modelContext())))
287                 .orElse(NetconfMessageTransformUtil.GET_RPC_CONTENT)));
288     }
289
290     private ListenableFuture<? extends DOMRpcResult> get(final FutureCallback<DOMRpcResult> callback,
291             final Optional<YangInstanceIdentifier> filterPath, final List<YangInstanceIdentifier> fields) {
292         final ContainerNode rpcInput;
293         if (nonEmptyFilter(filterPath).isPresent()) {
294             rpcInput = NetconfMessageTransformUtil.wrap(NETCONF_GET_NODEID, transformer.toFilterStructure(
295                     List.of(FieldsFilter.of(filterPath.orElseThrow(), fields))));
296         } else if (containsEmptyPath(fields)) {
297             rpcInput = GET_RPC_CONTENT;
298         } else {
299             rpcInput = NetconfMessageTransformUtil.wrap(NETCONF_GET_NODEID, getSubtreeFilterFromRootFields(fields));
300         }
301         return addCallback(requireNonNull(callback), rpc.invokeNetconf(Get.QNAME, rpcInput));
302     }
303
304     private static boolean containsEmptyPath(final List<YangInstanceIdentifier> fields) {
305         return fields.stream().anyMatch(YangInstanceIdentifier::isEmpty);
306     }
307
308     private DataContainerChild getSubtreeFilterFromRootFields(final List<YangInstanceIdentifier> fields) {
309         return transformer.toFilterStructure(fields.stream()
310             .map(fieldPath -> Map.entry(
311                 YangInstanceIdentifier.of(Iterables.limit(fieldPath.getPathArguments(), 1)),
312                 YangInstanceIdentifier.of(Iterables.skip(fieldPath.getPathArguments(), 1))))
313             .collect(Collectors.groupingBy(Entry::getKey,
314                 Collectors.mapping(Entry::getValue, Collectors.toUnmodifiableList())))
315             .entrySet().stream()
316             .map(entry -> FieldsFilter.of(entry.getKey(), entry.getValue()))
317             .collect(Collectors.toUnmodifiableList()));
318     }
319
320     private static Optional<YangInstanceIdentifier> nonEmptyFilter(final Optional<YangInstanceIdentifier> filterPath) {
321         return filterPath.filter(path -> !path.isEmpty());
322     }
323
324     public ListenableFuture<? extends DOMRpcResult> editConfigCandidate(
325             final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
326             final EffectiveOperation modifyAction, final boolean rollback) {
327         return editConfig(callback, NETCONF_CANDIDATE_NODEID, editStructure, Optional.of(modifyAction), rollback);
328     }
329
330     public ListenableFuture<? extends DOMRpcResult> editConfigCandidate(
331             final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
332             final boolean rollback) {
333         return editConfig(callback, NETCONF_CANDIDATE_NODEID, editStructure, Optional.empty(), rollback);
334     }
335
336     public ListenableFuture<? extends DOMRpcResult> editConfigRunning(
337             final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
338             final EffectiveOperation modifyAction, final boolean rollback) {
339         return editConfig(callback, NETCONF_RUNNING_NODEID, editStructure, Optional.of(modifyAction), rollback);
340     }
341
342     public ListenableFuture<? extends DOMRpcResult> editConfigRunning(
343             final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
344             final boolean rollback) {
345         return editConfig(callback, NETCONF_RUNNING_NODEID, editStructure, Optional.empty(), rollback);
346     }
347
348     public ListenableFuture<? extends DOMRpcResult> editConfig(
349             final FutureCallback<? super DOMRpcResult> callback, final NodeIdentifier datastore,
350             final DataContainerChild editStructure, final Optional<EffectiveOperation> modifyAction,
351             final boolean rollback) {
352         return addCallback(requireNonNull(callback), rpc.invokeNetconf(EditConfig.QNAME,
353             getEditConfigContent(requireNonNull(datastore), requireNonNull(editStructure), modifyAction, rollback)));
354     }
355
356     public ChoiceNode createEditConfigStructure(final Optional<NormalizedNode> lastChild,
357             final Optional<EffectiveOperation> operation, final YangInstanceIdentifier dataPath) {
358         return Builders.choiceBuilder()
359             .withNodeIdentifier(EDIT_CONTENT_NODEID)
360             .withChild(transformer.createEditConfigStructure(lastChild, dataPath, operation))
361             .build();
362     }
363
364     private static ContainerNode getEditConfigContent(final NodeIdentifier datastore,
365             final DataContainerChild editStructure, final Optional<EffectiveOperation> defaultOperation,
366             final boolean rollback) {
367         final var editBuilder = Builders.containerBuilder()
368             .withNodeIdentifier(NETCONF_EDIT_CONFIG_NODEID)
369             // Target
370             .withChild(getTargetNode(datastore));
371
372         // Default operation
373         defaultOperation.ifPresent(op -> {
374             editBuilder.withChild(ImmutableNodes.leafNode(NETCONF_DEFAULT_OPERATION_NODEID, op.xmlValue()));
375         });
376
377         // Error option
378         if (rollback) {
379             editBuilder.withChild(NETCONF_ERROR_OPTION_ROLLBACK);
380         }
381
382         // Edit content
383         return editBuilder.withChild(editStructure).build();
384     }
385
386     public static @NonNull ContainerNode getSourceNode(final NodeIdentifier datastore) {
387         return Builders.containerBuilder()
388             .withNodeIdentifier(NETCONF_SOURCE_NODEID)
389             .withChild(Builders.choiceBuilder()
390                 .withNodeIdentifier(CONFIG_SOURCE_NODEID)
391                 .withChild(ImmutableNodes.leafNode(datastore, Empty.value()))
392                 .build())
393             .build();
394     }
395
396     public static @NonNull ContainerNode getLockContent(final NodeIdentifier datastore) {
397         return Builders.containerBuilder()
398             .withNodeIdentifier(NETCONF_LOCK_NODEID)
399             .withChild(getTargetNode(datastore))
400             .build();
401     }
402
403     public static @NonNull ContainerNode getTargetNode(final NodeIdentifier datastore) {
404         return Builders.containerBuilder()
405             .withNodeIdentifier(NETCONF_TARGET_NODEID)
406             .withChild(Builders.choiceBuilder()
407                 .withNodeIdentifier(CONFIG_TARGET_NODEID)
408                 .withChild(ImmutableNodes.leafNode(datastore, Empty.value()))
409                 .build())
410             .build();
411     }
412
413     public static @NonNull ContainerNode getCopyConfigContent(final NodeIdentifier sourceDatastore,
414             final NodeIdentifier targetDatastore) {
415         return Builders.containerBuilder()
416             .withNodeIdentifier(NETCONF_COPY_CONFIG_NODEID)
417             .withChild(getTargetNode(targetDatastore))
418             .withChild(getSourceNode(sourceDatastore))
419             .build();
420     }
421
422     public static @NonNull ContainerNode getValidateContent(final NodeIdentifier sourceDatastore) {
423         return Builders.containerBuilder()
424             .withNodeIdentifier(NETCONF_VALIDATE_NODEID)
425             .withChild(getSourceNode(sourceDatastore))
426             .build();
427     }
428
429     public static @NonNull ContainerNode getUnLockContent(final NodeIdentifier datastore) {
430         return Builders.containerBuilder()
431             .withNodeIdentifier(NETCONF_UNLOCK_NODEID)
432             .withChild(getTargetNode(datastore))
433             .build();
434     }
435 }