Do not use YIID parser for writing 33/97133/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 31 May 2021 11:43:14 +0000 (13:43 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 11 Aug 2021 11:19:18 +0000 (13:19 +0200)
We are using instance identifier parser in contexts which have
a fixed structure. Use a simple YangInstanceIdentifier factory
instead.

JIRA: NETCONF-726
JIRA: NETCONF-800
Change-Id: Idff625265f5240e8331a7eb289b3098916d10c98
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 4eba0cde9be1d0767679bd365a8de27844c50554)

restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractNotificationsData.java

index c736e0de9c85b868e9995b2e898e17c89a5edfb1..d871c8d0e3eed8002089452aff61f82cf83382df 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.restconf.nb.rfc8040;
 
+import com.google.common.annotations.Beta;
 import java.net.URI;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.$YangModuleInfoImpl;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.Module;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.module.Deviation;
@@ -15,6 +17,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.librar
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 
 /**
  * Base Draft for Restconf project.
@@ -210,6 +215,23 @@ public final class Rfc8040 {
         public static final QName LEAF_LOCATION_ACCESS_QNAME = QName.create(MODULE_QNAME, LEAF_LOCATION_ACCESS_NAME)
                 .intern();
 
+        private static final YangInstanceIdentifier RESTCONF_STATE_STREAMS = YangInstanceIdentifier.create(
+            NodeIdentifier.create(CONT_RESTCONF_STATE_QNAME), NodeIdentifier.create(CONT_STREAMS_QNAME),
+            NodeIdentifier.create(LIST_STREAM_QNAME));
+
+        @Beta
+        // FIXME: move this method somewhere else
+        public static @NonNull YangInstanceIdentifier restconfStateStreamPath(final String streamName) {
+            return restconfStateStreamPath(NodeIdentifierWithPredicates.of(LIST_STREAM_QNAME, LEAF_NAME_STREAM_QNAME,
+                streamName));
+        }
+
+        @Beta
+        // FIXME: move this method somewhere else
+        public static @NonNull YangInstanceIdentifier restconfStateStreamPath(final NodeIdentifierWithPredicates arg) {
+            return RESTCONF_STATE_STREAMS.node(arg);
+        }
+
         /**
          * Constants for capabilities.
          */
index eeff1134026f366fdadbe07be4d18f6ea8ddec6f..46d54f8e8a8408316a5cf18789545332e2d61149 100644 (file)
@@ -66,7 +66,6 @@ import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfInvokeOperations
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter;
 import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil;
-import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.concepts.Immutable;
@@ -242,10 +241,8 @@ public class RestconfDataServiceImpl implements RestconfDataService {
                 listener.getSchemaPath().lastNodeIdentifier(), schemaContext.getNotifications(), null,
                 listener.getOutputType(), uri);
 
-        final String name = listener.getSchemaPath().lastNodeIdentifier().getLocalName();
         transaction.merge(LogicalDatastoreType.OPERATIONAL,
-            IdentifierCodec.deserialize(Rfc8040.MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + name, schemaContext),
-            mapToStreams);
+            Rfc8040.MonitoringModule.restconfStateStreamPath(mapToStreams.getIdentifier()), mapToStreams);
     }
 
     @Override
index 5886aeb13c140a8000fa712070405ecf540ba9ca..3da9f2669a2949f522685bc0c879c68db51eb345 100644 (file)
@@ -158,9 +158,7 @@ abstract class SubscribeToStreamUtil {
                     notificationListenerAdapter.get().getSchemaPath().lastNodeIdentifier(),
                     schemaContext.getNotifications(), notificationQueryParams.getStart(),
                     notificationListenerAdapter.get().getOutputType(), uri);
-        writeDataToDS(schemaContext,
-            notificationListenerAdapter.get().getSchemaPath().lastNodeIdentifier().getLocalName(), writeTransaction,
-            mapToStreams);
+        writeDataToDS(writeTransaction, mapToStreams);
         submitData(writeTransaction);
         transactionChain.close();
         return uri;
@@ -213,23 +211,21 @@ abstract class SubscribeToStreamUtil {
         final DOMTransactionChain transactionChain = handlersHolder.getTransactionChainHandler().get();
         final DOMDataTreeReadWriteTransaction writeTransaction = transactionChain.newReadWriteTransaction();
         final EffectiveModelContext schemaContext = handlersHolder.getSchemaHandler().get();
-        final String serializedPath = IdentifierCodec.serialize(listener.get().getPath(), schemaContext);
 
         final MapEntryNode mapToStreams =
             RestconfMappingNodeUtil.mapDataChangeNotificationStreamByIetfRestconfMonitoring(listener.get().getPath(),
-                notificationQueryParams.getStart(), listener.get().getOutputType(), uri, schemaContext, serializedPath);
-        writeDataToDS(schemaContext, serializedPath, writeTransaction, mapToStreams);
+                notificationQueryParams.getStart(), listener.get().getOutputType(), uri, schemaContext,
+                IdentifierCodec.serialize(listener.get().getPath(), schemaContext));
+        writeDataToDS(writeTransaction, mapToStreams);
         submitData(writeTransaction);
         transactionChain.close();
         return uri;
     }
 
-    private static void writeDataToDS(final EffectiveModelContext schemaContext, final String name,
-            final DOMDataTreeReadWriteTransaction readWriteTransaction, final MapEntryNode mapToStreams) {
+    private static void writeDataToDS(final DOMDataTreeReadWriteTransaction readWriteTransaction,
+            final MapEntryNode mapToStreams) {
         readWriteTransaction.merge(LogicalDatastoreType.OPERATIONAL,
-            // FIXME: do not use IdentifierCodec here
-            IdentifierCodec.deserialize(MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + name, schemaContext),
-            mapToStreams);
+            MonitoringModule.restconfStateStreamPath(mapToStreams.getIdentifier()), mapToStreams);
     }
 
     private static void submitData(final DOMDataTreeReadWriteTransaction readWriteTransaction) {
index 1518bdd0127845314741bba47794d0bab811c5ab..46a6286c5b2dad2bda529d20281a497a4e3f2396 100644 (file)
@@ -30,7 +30,6 @@ import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -80,8 +79,7 @@ abstract class AbstractNotificationsData {
     protected void deleteDataInDS() throws Exception {
         try (DOMTransactionChain transactionChain = this.transactionChainHandler.get()) {
             final DOMDataTreeWriteTransaction wTx = transactionChain.newWriteOnlyTransaction();
-            wTx.delete(LogicalDatastoreType.OPERATIONAL, IdentifierCodec
-                .deserialize(MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + this.localName, this.schemaHandler.get()));
+            wTx.delete(LogicalDatastoreType.OPERATIONAL, MonitoringModule.restconfStateStreamPath(this.localName));
             wTx.commit().get();
         }
     }