From: Jaroslav Tóth Date: Tue, 16 Jul 2019 11:14:31 +0000 (+0200) Subject: Added full YIID to ietf-restconf-monitoring DS X-Git-Tag: v1.13.2~1 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=5e5b43df99680cb11a838b3d899616a0e7b08720;p=netconf.git Added full YIID to ietf-restconf-monitoring DS - 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 Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java index ee96e3e36f..dd75c2bf2c 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java @@ -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 = 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; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtil.java index fe29f1f9f6..1b58884d44 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtil.java @@ -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 optDesc = schemaNode.getDescription(); if (optDesc.isPresent()) { diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java index 6b273d2a34..70d855f565 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java @@ -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 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); diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtilTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtilTest.java index d14e396038..4ea6d79469 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtilTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/utils/mapping/RestconfMappingNodeUtilTest.java @@ -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 map = prepareMap(path.getLastPathArgument().getNodeType().getLocalName(), uri, start, - outputType); - + final Map 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); }