Uploaded image for project: 'netconf'
  1. netconf
  2. NETCONF-472

ReadDataTransactionUtil creates two NotificationListenerAdapters for JSON stream

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Resolution: Done
    • None
    • None
    • restconf-nb
    • None
    • Operating System: All
      Platform: All

    • 9160

    Description

      when you get http://localhost:8181/restconf/18/data/ietf-restconf-monitoring:restconf-state/streams, ReadDataTransactionUtil
      will read notification data from yang modules and create NotificationListenerAdapters for each NotificationDefinition.
      the Code snippet as below:
      public static NormalizedNode<?, ?> readData(final String identifier, final String content,
      final TransactionVarsWrapper transactionNode, final String withDefa,
      final SchemaContextRef schemaContextRef, final UriInfo uriInfo) {
      if (identifier.contains(STREAMS_PATH) && !identifier.contains(STREAM_PATH_PART)) {
      final DOMDataReadWriteTransaction wTx = transactionNode.getTransactionChain().newReadWriteTransaction();
      final SchemaContext schemaContext = schemaContextRef.get();
      final boolean exist = SubscribeToStreamUtil.checkExist(schemaContext, wTx);

      for (final NotificationDefinition notificationDefinition : schemaContextRef.get().getNotifications()) {
      final List<NotificationListenerAdapter> notifiStreamXML =
      CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContextRef,
      NotificationOutputType.XML.getName());
      final List<NotificationListenerAdapter> notifiStreamJSON =
      CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContextRef,
      NotificationOutputType.JSON.getName());
      notifiStreamJSON.addAll(notifiStreamXML);

      for (final NotificationListenerAdapter listener : notifiStreamJSON)

      { final URI uri = SubscribeToStreamUtil.prepareUriByStreamName(uriInfo, listener.getStreamName()); final NormalizedNode mapToStreams = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring( listener.getSchemaPath().getLastComponent(), schemaContext.getNotifications(), null, listener.getOutputType(), uri, SubscribeToStreamUtil.getMonitoringModule(schemaContext), exist); SubscribeToStreamUtil.writeDataToDS(schemaContext, listener.getSchemaPath().getLastComponent().getLocalName(), wTx, exist, mapToStreams); }

      }
      SubscribeToStreamUtil.submitData(wTx);
      }
      return readData(content, transactionNode, withDefa);
      }

      Obviously, it's wrong to add the notifiStreamXML object to notifiStreamJSON. It leads that two NotificationListenerAdapter will exist in Notifcator for JSON streamName: one is for XML, one if for JSON. It's not what we want. So I change it to like this below:

      public static NormalizedNode<?, ?> readData(final String identifier, final String content,
      final TransactionVarsWrapper transactionNode, final String withDefa,
      final SchemaContextRef schemaContextRef, final UriInfo uriInfo) {
      if (identifier.contains(STREAMS_PATH) && !identifier.contains(STREAM_PATH_PART)) {
      final DOMDataReadWriteTransaction wTx = transactionNode.getTransactionChain().newReadWriteTransaction();
      final SchemaContext schemaContext = schemaContextRef.get();
      final boolean exist = SubscribeToStreamUtil.checkExist(schemaContext, wTx);

      for (final NotificationDefinition notificationDefinition : schemaContextRef.get().getNotifications()) {
      final List<NotificationListenerAdapter> notifiStreamXML =
      CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContextRef,
      NotificationOutputType.XML.getName());
      final List<NotificationListenerAdapter> notifiStreamJSON =
      CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContextRef,
      NotificationOutputType.JSON.getName());

      List<NotificationListenerAdapter> notifiStream = Lists.newArrayList();
      notifiStream.addAll(notifiStreamXML);
      notifiStream.addAll(notifiStreamJSON);
      for (final NotificationListenerAdapter listener : notifiStream)

      { final URI uri = SubscribeToStreamUtil.prepareUriByStreamName(uriInfo, listener.getStreamName()); final NormalizedNode mapToStreams = RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring( listener.getSchemaPath().getLastComponent(), schemaContext.getNotifications(), null, listener.getOutputType(), uri, SubscribeToStreamUtil.getMonitoringModule(schemaContext), exist); SubscribeToStreamUtil.writeDataToDS(schemaContext, listener.getSchemaPath().getLastComponent().getLocalName(), wTx, exist, mapToStreams); }

      }
      SubscribeToStreamUtil.submitData(wTx);
      }
      return readData(content, transactionNode, withDefa);
      }
      If doing so, there will only one NotificationListenerAdapter for JSON stream and one for XML stream.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            wusandi@163.com wu sandi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: