Use NodeIdentifier to identify datastores
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / util / NetconfBaseOps.java
index b39da28c067f0f8514dca3d0ff4c6c6f41ae9a65..26165f799755874a9c2e58930218dcc7198d0112 100644 (file)
@@ -12,7 +12,7 @@ import static java.util.Objects.requireNonNull;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.COMMIT_RPC_CONTENT;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.EDIT_CONTENT_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.GET_RPC_CONTENT;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME;
@@ -27,7 +27,7 @@ import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTr
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_LOCK_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_LOCK_QNAME;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_SOURCE_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_TARGET_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_UNLOCK_NODEID;
@@ -36,7 +36,6 @@ import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTr
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.ROLLBACK_ON_ERROR_OPTION;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toFilterStructure;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
 
 import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.FutureCallback;
@@ -59,7 +58,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.re
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.get.config.input.source.ConfigSource;
 import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
 import org.opendaylight.yangtools.yang.common.Empty;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
@@ -74,7 +72,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
  * Provides base operations for NETCONF e.g. {@code get}, {@code get-config}, {@code edit-config}, {@code commit} etc.
  * as per <a href="https://www.rfc-editor.org/rfc/rfc6241#section-7">RFC6241 Protocol Operations</a>.
  */
-// FIXME: datastore etc. should require NodeIdentifier instead of QName to reduce GC pressure
 // FIXME: turn Optional arguments to @Nullable
 public final class NetconfBaseOps {
     private static final NodeIdentifier CONFIG_SOURCE_NODEID = NodeIdentifier.create(ConfigSource.QNAME);
@@ -99,7 +96,7 @@ public final class NetconfBaseOps {
     }
 
     public ListenableFuture<? extends DOMRpcResult> lock(final FutureCallback<DOMRpcResult> callback,
-            final QName datastore) {
+            final NodeIdentifier datastore) {
         return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_LOCK_QNAME, getLockContent(datastore)));
     }
 
@@ -111,28 +108,28 @@ public final class NetconfBaseOps {
 
     public ListenableFuture<? extends DOMRpcResult> lockCandidate(final FutureCallback<DOMRpcResult> callback) {
         return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_LOCK_QNAME,
-            getLockContent(NETCONF_CANDIDATE_QNAME)));
+            getLockContent(NETCONF_CANDIDATE_NODEID)));
     }
 
     public ListenableFuture<? extends DOMRpcResult> lockRunning(final FutureCallback<DOMRpcResult> callback) {
         return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_LOCK_QNAME,
-            getLockContent(NETCONF_RUNNING_QNAME)));
+            getLockContent(NETCONF_RUNNING_NODEID)));
     }
 
     public ListenableFuture<? extends DOMRpcResult> unlock(final FutureCallback<DOMRpcResult> callback,
-            final QName datastore) {
+            final NodeIdentifier datastore) {
         return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_UNLOCK_QNAME,
             getUnLockContent(datastore)));
     }
 
     public ListenableFuture<? extends DOMRpcResult> unlockRunning(final FutureCallback<DOMRpcResult> callback) {
         return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_UNLOCK_QNAME,
-            getUnLockContent(NETCONF_RUNNING_QNAME)));
+            getUnLockContent(NETCONF_RUNNING_NODEID)));
     }
 
     public ListenableFuture<? extends DOMRpcResult> unlockCandidate(final FutureCallback<DOMRpcResult> callback) {
         return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_UNLOCK_QNAME,
-            getUnLockContent(NETCONF_CANDIDATE_QNAME)));
+            getUnLockContent(NETCONF_CANDIDATE_NODEID)));
     }
 
     public ListenableFuture<? extends DOMRpcResult> discardChanges(final FutureCallback<DOMRpcResult> callback) {
@@ -145,32 +142,32 @@ public final class NetconfBaseOps {
     }
 
     public ListenableFuture<? extends DOMRpcResult> validate(final FutureCallback<DOMRpcResult> callback,
-            final QName datastore) {
+            final NodeIdentifier datastore) {
         return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_VALIDATE_QNAME,
             getValidateContent(requireNonNull(datastore))));
     }
 
     public ListenableFuture<? extends DOMRpcResult> validateCandidate(final FutureCallback<DOMRpcResult> callback) {
-        return validate(callback, NETCONF_CANDIDATE_QNAME);
+        return validate(callback, NETCONF_CANDIDATE_NODEID);
     }
 
     public ListenableFuture<? extends DOMRpcResult> validateRunning(final FutureCallback<DOMRpcResult> callback) {
-        return validate(callback, NETCONF_RUNNING_QNAME);
+        return validate(callback, NETCONF_RUNNING_NODEID);
     }
 
     public ListenableFuture<? extends DOMRpcResult> copyConfig(final FutureCallback<DOMRpcResult> callback,
-            final QName source, final QName target) {
+            final NodeIdentifier sourceDatastore, final NodeIdentifier targetDatastore) {
         return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_COPY_CONFIG_QNAME,
-            getCopyConfigContent(source, target)));
+            getCopyConfigContent(sourceDatastore, targetDatastore)));
     }
 
     public ListenableFuture<? extends DOMRpcResult> copyRunningToCandidate(
             final FutureCallback<DOMRpcResult> callback) {
-        return copyConfig(callback, NETCONF_RUNNING_QNAME, NETCONF_CANDIDATE_QNAME);
+        return copyConfig(callback, NETCONF_RUNNING_NODEID, NETCONF_CANDIDATE_NODEID);
     }
 
     public ListenableFuture<? extends DOMRpcResult> getConfig(final FutureCallback<DOMRpcResult> callback,
-            final QName datastore, final Optional<YangInstanceIdentifier> filterPath) {
+            final NodeIdentifier datastore, final Optional<YangInstanceIdentifier> filterPath) {
         return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_GET_CONFIG_QNAME, nonEmptyFilter(filterPath)
             .map(path -> NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_NODEID,
                 getSourceNode(datastore), transformer.toFilterStructure(path)))
@@ -178,7 +175,7 @@ public final class NetconfBaseOps {
     }
 
     private ListenableFuture<? extends DOMRpcResult> getConfig(final FutureCallback<DOMRpcResult> callback,
-            final QName datastore, final Optional<YangInstanceIdentifier> filterPath,
+            final NodeIdentifier datastore, final Optional<YangInstanceIdentifier> filterPath,
             final List<YangInstanceIdentifier> fields) {
         final ContainerNode rpcInput;
         if (nonEmptyFilter(filterPath).isPresent()) {
@@ -268,17 +265,17 @@ public final class NetconfBaseOps {
 
     public ListenableFuture<? extends DOMRpcResult> getConfigRunning(final FutureCallback<DOMRpcResult> callback,
             final Optional<YangInstanceIdentifier> filterPath) {
-        return getConfig(callback, NETCONF_RUNNING_QNAME, filterPath);
+        return getConfig(callback, NETCONF_RUNNING_NODEID, filterPath);
     }
 
     private ListenableFuture<? extends DOMRpcResult> getConfigRunning(final FutureCallback<DOMRpcResult> callback,
             final Optional<YangInstanceIdentifier> filterPath, final List<YangInstanceIdentifier> fields) {
-        return getConfig(callback, NETCONF_RUNNING_QNAME, filterPath, fields);
+        return getConfig(callback, NETCONF_RUNNING_NODEID, filterPath, fields);
     }
 
     public ListenableFuture<? extends DOMRpcResult> getConfigCandidate(final FutureCallback<DOMRpcResult> callback,
             final Optional<YangInstanceIdentifier> filterPath) {
-        return getConfig(callback, NETCONF_CANDIDATE_QNAME, filterPath);
+        return getConfig(callback, NETCONF_CANDIDATE_NODEID, filterPath);
     }
 
     public ListenableFuture<? extends DOMRpcResult> get(final FutureCallback<DOMRpcResult> callback,
@@ -327,29 +324,29 @@ public final class NetconfBaseOps {
     public ListenableFuture<? extends DOMRpcResult> editConfigCandidate(
             final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
             final ModifyAction modifyAction, final boolean rollback) {
-        return editConfig(callback, NETCONF_CANDIDATE_QNAME, editStructure, Optional.of(modifyAction), rollback);
+        return editConfig(callback, NETCONF_CANDIDATE_NODEID, editStructure, Optional.of(modifyAction), rollback);
     }
 
     public ListenableFuture<? extends DOMRpcResult> editConfigCandidate(
             final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
             final boolean rollback) {
-        return editConfig(callback, NETCONF_CANDIDATE_QNAME, editStructure, Optional.empty(), rollback);
+        return editConfig(callback, NETCONF_CANDIDATE_NODEID, editStructure, Optional.empty(), rollback);
     }
 
     public ListenableFuture<? extends DOMRpcResult> editConfigRunning(
             final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
             final ModifyAction modifyAction, final boolean rollback) {
-        return editConfig(callback, NETCONF_RUNNING_QNAME, editStructure, Optional.of(modifyAction), rollback);
+        return editConfig(callback, NETCONF_RUNNING_NODEID, editStructure, Optional.of(modifyAction), rollback);
     }
 
     public ListenableFuture<? extends DOMRpcResult> editConfigRunning(
             final FutureCallback<? super DOMRpcResult> callback, final DataContainerChild editStructure,
             final boolean rollback) {
-        return editConfig(callback, NETCONF_RUNNING_QNAME, editStructure, Optional.empty(), rollback);
+        return editConfig(callback, NETCONF_RUNNING_NODEID, editStructure, Optional.empty(), rollback);
     }
 
     public ListenableFuture<? extends DOMRpcResult> editConfig(
-            final FutureCallback<? super DOMRpcResult> callback, final QName datastore,
+            final FutureCallback<? super DOMRpcResult> callback, final NodeIdentifier datastore,
             final DataContainerChild editStructure, final Optional<ModifyAction> modifyAction,
             final boolean rollback) {
         return addCallback(requireNonNull(callback), rpc.invokeRpc(NETCONF_EDIT_CONFIG_QNAME,
@@ -364,8 +361,9 @@ public final class NetconfBaseOps {
             .build();
     }
 
-    private static ContainerNode getEditConfigContent(final QName datastore, final DataContainerChild editStructure,
-            final Optional<ModifyAction> defaultOperation, final boolean rollback) {
+    private static ContainerNode getEditConfigContent(final NodeIdentifier datastore,
+            final DataContainerChild editStructure, final Optional<ModifyAction> defaultOperation,
+            final boolean rollback) {
         final var editBuilder = Builders.containerBuilder()
             .withNodeIdentifier(NETCONF_EDIT_CONFIG_NODEID)
             // Target
@@ -385,7 +383,7 @@ public final class NetconfBaseOps {
         return editBuilder.withChild(editStructure).build();
     }
 
-    public static @NonNull ContainerNode getSourceNode(final QName datastore) {
+    public static @NonNull ContainerNode getSourceNode(final NodeIdentifier datastore) {
         return Builders.containerBuilder()
             .withNodeIdentifier(NETCONF_SOURCE_NODEID)
             .withChild(Builders.choiceBuilder()
@@ -395,39 +393,40 @@ public final class NetconfBaseOps {
             .build();
     }
 
-    public static @NonNull ContainerNode getLockContent(final QName datastore) {
+    public static @NonNull ContainerNode getLockContent(final NodeIdentifier datastore) {
         return Builders.containerBuilder()
             .withNodeIdentifier(NETCONF_LOCK_NODEID)
             .withChild(getTargetNode(datastore))
             .build();
     }
 
-    public static @NonNull ContainerNode getTargetNode(final QName datastore) {
+    public static @NonNull ContainerNode getTargetNode(final NodeIdentifier datastore) {
         return Builders.containerBuilder()
             .withNodeIdentifier(NETCONF_TARGET_NODEID)
             .withChild(Builders.choiceBuilder()
                 .withNodeIdentifier(CONFIG_TARGET_NODEID)
-                .withChild(ImmutableNodes.leafNode(toId(datastore), Empty.value()))
+                .withChild(ImmutableNodes.leafNode(datastore, Empty.value()))
                 .build())
             .build();
     }
 
-    public static @NonNull ContainerNode getCopyConfigContent(final QName source, final QName target) {
+    public static @NonNull ContainerNode getCopyConfigContent(final NodeIdentifier sourceDatastore,
+            final NodeIdentifier targetDatastore) {
         return Builders.containerBuilder()
             .withNodeIdentifier(NETCONF_COPY_CONFIG_NODEID)
-            .withChild(getTargetNode(target))
-            .withChild(getSourceNode(source))
+            .withChild(getTargetNode(targetDatastore))
+            .withChild(getSourceNode(sourceDatastore))
             .build();
     }
 
-    public static @NonNull ContainerNode getValidateContent(final QName source) {
+    public static @NonNull ContainerNode getValidateContent(final NodeIdentifier sourceDatastore) {
         return Builders.containerBuilder()
             .withNodeIdentifier(NETCONF_VALIDATE_NODEID)
-            .withChild(getSourceNode(source))
+            .withChild(getSourceNode(sourceDatastore))
             .build();
     }
 
-    public static @NonNull ContainerNode getUnLockContent(final QName datastore) {
+    public static @NonNull ContainerNode getUnLockContent(final NodeIdentifier datastore) {
         return Builders.containerBuilder()
             .withNodeIdentifier(NETCONF_UNLOCK_NODEID)
             .withChild(getTargetNode(datastore))