import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
import org.opendaylight.restconf.nb.rfc8040.streams.listeners.DeviceNotificationListenerAdaptor;
import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
-import org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.IdentifierCodec;
import org.opendaylight.yang.gen.v1.urn.opendaylight.device.notification.rev221106.SubscribeDeviceNotificationInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.device.notification.rev221106.SubscribeDeviceNotificationOutput;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
return data.childByArg(childName) instanceof LeafNode<?> leafNode && leafNode.body() instanceof String str
? str : null;
}
-
- /**
- * Create YANG notification stream using notification definition in YANG schema.
- *
- * @param notificationDefinition YANG notification definition.
- * @param refSchemaCtx Reference to {@link EffectiveModelContext}
- * @param outputType Output type (XML or JSON).
- * @return {@link NotificationListenerAdapter}
- */
- static NotificationListenerAdapter createYangNotifiStream(final NotificationDefinition notificationDefinition,
- final EffectiveModelContext refSchemaCtx, final NotificationOutputType outputType) {
- final var streamName = parseNotificationStreamName(requireNonNull(notificationDefinition),
- requireNonNull(refSchemaCtx), requireNonNull(outputType));
- final var listenersBroker = ListenersBroker.getInstance();
-
- final var existing = listenersBroker.notificationListenerFor(streamName);
- return existing != null ? existing
- : listenersBroker.registerNotificationListener(
- Absolute.of(notificationDefinition.getQName()), streamName, outputType);
- }
-
- private static String parseNotificationStreamName(final NotificationDefinition notificationDefinition,
- final EffectiveModelContext refSchemaCtx, final NotificationOutputType outputType) {
- final QName notificationDefinitionQName = notificationDefinition.getQName();
- final Module module = refSchemaCtx.findModule(
- notificationDefinitionQName.getModule().getNamespace(),
- notificationDefinitionQName.getModule().getRevision()).orElse(null);
- requireNonNull(module, String.format("Module for namespace %s does not exist.",
- notificationDefinitionQName.getModule().getNamespace()));
-
- final StringBuilder streamNameBuilder = new StringBuilder();
- streamNameBuilder.append(RestconfStreamsConstants.NOTIFICATION_STREAM)
- .append('/')
- .append(module.getName())
- .append(':')
- .append(notificationDefinitionQName.getLocalName());
- if (outputType != NotificationOutputType.XML) {
- streamNameBuilder.append('/').append(outputType.getName());
- }
- return streamNameBuilder.toString();
- }
}
import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteOperations;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.PostDataTransactionUtil;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.PutDataTransactionUtil;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.ReadDataTransactionUtil;
+import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
+import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenersBroker;
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.ParserIdentifier;
import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
private void createAllYangNotificationStreams(final EffectiveModelContext schemaContext, final UriInfo uriInfo) {
- final DOMDataTreeWriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
- for (final NotificationDefinition notificationDefinition : schemaContext.getNotifications()) {
- writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction,
- CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContext,
- NotificationOutputType.XML));
- writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction,
- CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContext,
- NotificationOutputType.JSON));
+ final var transaction = dataBroker.newWriteOnlyTransaction();
+
+ for (var module : schemaContext.getModuleStatements().values()) {
+ final var moduleName = module.argument().getLocalName();
+ // Note: this handles only RFC6020 notifications
+ module.streamEffectiveSubstatements(NotificationEffectiveStatement.class).forEach(notification -> {
+ final var notifName = notification.argument();
+
+ writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction,
+ createYangNotifiStream(moduleName, notifName, NotificationOutputType.XML));
+ writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction,
+ createYangNotifiStream(moduleName, notifName, NotificationOutputType.JSON));
+ });
}
+
try {
transaction.commit().get();
} catch (final InterruptedException | ExecutionException e) {
}
}
+ private static NotificationListenerAdapter createYangNotifiStream(final String moduleName, final QName notifName,
+ final NotificationOutputType outputType) {
+ final var streamName = createNotificationStreamName(moduleName, notifName.getLocalName(), outputType);
+ final var listenersBroker = ListenersBroker.getInstance();
+
+ final var existing = listenersBroker.notificationListenerFor(streamName);
+ return existing != null ? existing
+ : listenersBroker.registerNotificationListener(Absolute.of(notifName), streamName, outputType);
+ }
+
+ private static String createNotificationStreamName(final String moduleName, final String notifName,
+ final NotificationOutputType outputType) {
+ final var sb = new StringBuilder()
+ .append(RestconfStreamsConstants.NOTIFICATION_STREAM)
+ .append('/').append(moduleName).append(':').append(notifName);
+ if (outputType != NotificationOutputType.XML) {
+ sb.append('/').append(outputType.getName());
+ }
+ return sb.toString();
+ }
+
private void writeNotificationStreamToDatastore(final EffectiveModelContext schemaContext,
final UriInfo uriInfo, final DOMDataTreeWriteOperations tx, final NotificationListenerAdapter listener) {
final URI uri = streamUtils.prepareUriByStreamName(uriInfo, listener.getStreamName());