Added full YIID to ietf-restconf-monitoring DS 84/83284/23
authorJaroslav Tóth <jtoth@frinx.io>
Tue, 16 Jul 2019 11:14:31 +0000 (13:14 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 12 May 2021 22:39:46 +0000 (22:39 +0000)
- Currently local-name of the QName is used as key to the list
  of created streams - that is a bug because local-name doesn't
  have to be unique in scope of one module or whole schema context.
- This fix puts the whole serialized YIID to DS as stream name.

JIRA: NETCONF-726
Change-Id: I28012a478b958b933af993c2ede5f91c2eb8e211
Signed-off-by: Jaroslav Tóth <jtoth@frinx.io>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
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/utils/mapping/RestconfMappingNodeUtil.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtilTest.java

index ee96e3e36f6152c1773a657d436e1b1b80c6b37f..dd75c2bf2c276eafda3dfe268345e7f34f6bb7ae 100644 (file)
@@ -53,7 +53,7 @@ import org.slf4j.LoggerFactory;
  */
 abstract class SubscribeToStreamUtil {
     /**
-     * Implementation of {@link UrlResolver} for Server-sent events.
+     * Implementation of SubscribeToStreamUtil for Server-sent events.
      */
     private static final class ServerSentEvents extends SubscribeToStreamUtil {
         static final ServerSentEvents INSTANCE = new ServerSentEvents();
@@ -67,7 +67,7 @@ abstract class SubscribeToStreamUtil {
     }
 
     /**
-     * Implementation of {@link UrlResolver} for Web sockets.
+     * Implementation of SubscribeToStreamUtil for Web sockets.
      */
     private static final class WebSockets extends SubscribeToStreamUtil {
         static final WebSockets INSTANCE = new WebSockets();
@@ -122,7 +122,6 @@ abstract class SubscribeToStreamUtil {
      * @param uriInfo                 URI information.
      * @param notificationQueryParams Query parameters of notification.
      * @param handlersHolder          Holder of handlers for notifications.
-     * @param urlResolver             Resolver for proper implementation. Possibilities is WS or SSE.
      * @return Stream location for listening.
      */
     final @NonNull URI subscribeToYangStream(final String identifier, final UriInfo uriInfo,
@@ -134,7 +133,7 @@ abstract class SubscribeToStreamUtil {
         final Optional<NotificationListenerAdapter> notificationListenerAdapter =
                 ListenersBroker.getInstance().getNotificationListenerFor(streamName);
 
-        if (!notificationListenerAdapter.isPresent()) {
+        if (notificationListenerAdapter.isEmpty()) {
             throw new RestconfDocumentedException(String.format(
                     "Stream with name %s was not found.", streamName),
                     ErrorType.PROTOCOL,
@@ -214,13 +213,13 @@ 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,
-                getMonitoringModule(schemaContext), schemaContext);
-        writeDataToDS(schemaContext, listener.get().getPath().getLastPathArgument().getNodeType().getLocalName(),
-                writeTransaction, mapToStreams);
+                getMonitoringModule(schemaContext), schemaContext, serializedPath);
+        writeDataToDS(schemaContext, serializedPath, writeTransaction, mapToStreams);
         submitData(writeTransaction);
         transactionChain.close();
         return uri;
index fe29f1f9f68ca46c3b05993fcbdbd6d1b6efc782..1b58884d440e418215f3ba34733ae983d07e3d4a 100644 (file)
@@ -409,7 +409,7 @@ public final class RestconfMappingNodeUtil {
      */
     public static MapEntryNode mapDataChangeNotificationStreamByIetfRestconfMonitoring(
             final YangInstanceIdentifier path, final Instant start, final String outputType, final URI uri,
-            final Module monitoringModule, final EffectiveModelContext schemaContext) {
+            final Module monitoringModule, final EffectiveModelContext schemaContext, final String streamName) {
         final SchemaNode schemaNode = ParserIdentifier
                 .toInstanceIdentifier(ParserIdentifier.stringFromYangInstanceIdentifier(path, schemaContext),
                         schemaContext, Optional.empty())
@@ -423,8 +423,7 @@ public final class RestconfMappingNodeUtil {
 
         final ListSchemaNode listSchema = (ListSchemaNode) streamListSchema;
         prepareLeafAndFillEntryBuilder(streamEntry,
-                listSchema.getDataChildByName(MonitoringModule.LEAF_NAME_STREAM_QNAME),
-                schemaNode.getQName().getLocalName());
+                listSchema.getDataChildByName(MonitoringModule.LEAF_NAME_STREAM_QNAME), streamName);
 
         final Optional<String> optDesc = schemaNode.getDescription();
         if (optDesc.isPresent()) {
index 6b273d2a34b3ae6d6acadb2804c1e280069931c1..70d855f565256c2100f270e8fe3e80603408d1af 100644 (file)
@@ -57,7 +57,6 @@ import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
@@ -137,12 +136,8 @@ public class RestconfStreamsSubscriptionServiceImplTest {
         final Map<String, ListenerAdapter> listenersByStreamNameSetter = new HashMap<>();
         final ListenerAdapter adapter = mock(ListenerAdapter.class);
         final YangInstanceIdentifier yiid = mock(YangInstanceIdentifier.class);
-        final YangInstanceIdentifier.PathArgument lastPathArgument = mock(YangInstanceIdentifier.PathArgument.class);
-        final QName qname = QName.create("toaster", "2009-11-20", "toasterStatus");
         Mockito.when(adapter.getPath()).thenReturn(yiid);
         Mockito.when(adapter.getOutputType()).thenReturn("JSON");
-        Mockito.when(yiid.getLastPathArgument()).thenReturn(lastPathArgument);
-        Mockito.when(lastPathArgument.getNodeType()).thenReturn(qname);
         listenersByStreamNameSetter.put(
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 adapter);
index d14e396038c9a8ecea572b718c7e7bbf4fd8280a..4ea6d79469184f2267a2b169052353f3cb8cced4 100644 (file)
@@ -115,12 +115,11 @@ public class RestconfMappingNodeUtilTest {
         final String outputType = "XML";
         final URI uri = new URI("uri");
         final Module monitoringModule = schemaContextMonitoring.findModule(MonitoringModule.MODULE_QNAME).orElse(null);
+        final String streamName = "/nested-module:depth1-cont/depth2-leaf1";
 
-        final Map<QName, Object> map = prepareMap(path.getLastPathArgument().getNodeType().getLocalName(), uri, start,
-            outputType);
-
+        final Map<QName, Object> map = prepareMap(streamName, uri, start, outputType);
         final MapEntryNode mappedData = RestconfMappingNodeUtil.mapDataChangeNotificationStreamByIetfRestconfMonitoring(
-            path, start, outputType, uri, monitoringModule, schemaContextMonitoring);
+            path, start, outputType, uri, monitoringModule, schemaContextMonitoring, streamName);
         assertMappedData(map, mappedData);
     }