[NETCONF-472] ReadDataTransactionUtil creates two NotificationListenerAdapters for JSON stream Created: 14/Sep/17  Updated: 15/Mar/19  Resolved: 28/May/18

Status: Resolved
Project: netconf
Component/s: restconf-nb
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: wu sandi Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


External issue ID: 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.



 Comments   
Comment by wu sandi [ 14/Sep/17 ]

I have fix this bug by commit https://git.opendaylight.org/gerrit/#/c/63122/.

Comment by OpenDaylight Release [ 03/May/18 ]

Andrew, moving it to you for now.

Please decide to who this should be assigned.  

Comment by Andrew Grimberg [ 03/May/18 ]

You must have meant some other Andrew. I have no knowledge of how to do anything related to this!

Generated at Wed Feb 07 20:15:07 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.