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