Convert mdsal-netconf-notification to OSGi DS 43/104343/5
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 9 Feb 2023 13:07:42 +0000 (14:07 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 13 Feb 2023 11:47:00 +0000 (11:47 +0000)
The blueprint here is quite simple, even if a bit confusing. At the end
of the day we have only two components with services and a few plugins.

JIRA: NETCONF-963
Change-Id: I8d715d1db2ac66972c432e2b2808ad02cba7a463
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
12 files changed:
netconf/mdsal-netconf-notification/pom.xml
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/CapabilityChangeNotificationProducer.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManager.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationOperationServiceFactory.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NotificationToMdsalWriter.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/SessionNotificationProducer.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/YangLibraryNotificationProducer.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/YangLibraryNotificationProducerRFC8525.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/NotificationsTransformUtil.java
netconf/mdsal-netconf-notification/src/main/resources/OSGI-INF/blueprint/mdsal-netconf-notification.xml [deleted file]
netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManagerTest.java
netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/NotificationToMdsalWriterTest.java

index 6a2b595e23777394dc97c5c9a2a3b8a37bfca3e8..5aa2d62964e0ad1fac2a906f7c84e50e1cb4bd23 100644 (file)
             <artifactId>mdsal-binding-runtime-spi</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.opendaylight.netconf.model</groupId>
-            <artifactId>rfc5277</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${project.groupId}</groupId>
+            <groupId>org.opendaylight.netconf</groupId>
             <artifactId>netconf-api</artifactId>
         </dependency>
         <dependency>
-            <groupId>${project.groupId}</groupId>
+            <groupId>org.opendaylight.netconf</groupId>
             <artifactId>netconf-notifications-api</artifactId>
         </dependency>
         <dependency>
-            <groupId>${project.groupId}</groupId>
+            <groupId>org.opendaylight.netconf</groupId>
             <artifactId>netconf-mapping-api</artifactId>
         </dependency>
         <dependency>
-            <groupId>${project.groupId}</groupId>
+            <groupId>org.opendaylight.netconf</groupId>
             <artifactId>netconf-util</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.netconf.model</groupId>
+            <artifactId>rfc5277</artifactId>
+        </dependency>
         <dependency>
             <groupId>com.guicedee.services</groupId>
             <artifactId>javax.inject</artifactId>
             <optional>true</optional>
         </dependency>
+        <dependency>
+            <groupId>jakarta.annotation</groupId>
+            <artifactId>jakarta.annotation-api</artifactId>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>org.xmlunit</groupId>
@@ -78,5 +88,4 @@
             <scope>test</scope>
         </dependency>
     </dependencies>
-
 </project>
index 51c05b2e878655713c2d495bad598665bfc1bce6..9fe607e43e12170ace1a877af5f208a2fe7cd3f8 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.netconf.mdsal.notification.impl;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Set;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataObjectModification;
@@ -26,6 +25,10 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.not
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.Empty;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -33,23 +36,36 @@ import org.slf4j.LoggerFactory;
  * Listens on capabilities changes in data store and publishes them to base
  * netconf notification stream listener.
  */
+@Component(service = { })
 public final class CapabilityChangeNotificationProducer extends OperationalDatastoreListener<Capabilities>
-    implements AutoCloseable {
-
-    private static final InstanceIdentifier<Capabilities> CAPABILITIES_INSTANCE_IDENTIFIER =
-            InstanceIdentifier.create(NetconfState.class).child(Capabilities.class);
+        implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(CapabilityChangeNotificationProducer.class);
+    private static final InstanceIdentifier<Capabilities> CAPABILITIES_INSTANCE_IDENTIFIER =
+            InstanceIdentifier.builder(NetconfState.class).child(Capabilities.class).build();
 
     private final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration;
     private final ListenerRegistration<?> capabilityChangeListenerRegistration;
 
-    public CapabilityChangeNotificationProducer(final NetconfNotificationCollector netconfNotificationCollector,
-                                                final DataBroker dataBroker) {
+    @Activate
+    public CapabilityChangeNotificationProducer(
+            @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
+            @Reference final DataBroker dataBroker) {
         super(CAPABILITIES_INSTANCE_IDENTIFIER);
-        baseNotificationPublisherRegistration = netconfNotificationCollector.registerBaseNotificationPublisher();
+        baseNotificationPublisherRegistration = notifManager.registerBaseNotificationPublisher();
         capabilityChangeListenerRegistration = registerOnChanges(dataBroker);
     }
 
+    @Deactivate
+    @Override
+    public void close() {
+        if (baseNotificationPublisherRegistration != null) {
+            baseNotificationPublisherRegistration.close();
+        }
+        if (capabilityChangeListenerRegistration != null) {
+            capabilityChangeListenerRegistration.close();
+        }
+    }
+
     @Override
     public void onDataTreeChanged(final Collection<DataTreeModification<Capabilities>> changes) {
         for (DataTreeModification<Capabilities> change : changes) {
@@ -59,10 +75,10 @@ public final class CapabilityChangeNotificationProducer extends OperationalDatas
                 case WRITE: {
                     final Capabilities dataAfter = rootNode.getDataAfter();
                     final Capabilities dataBefore = rootNode.getDataBefore();
-                    final Set<Uri> before = dataBefore != null ? ImmutableSet.copyOf(dataBefore.getCapability()) :
-                            Collections.emptySet();
-                    final Set<Uri> after = dataAfter != null ? ImmutableSet.copyOf(dataAfter.getCapability()) :
-                            Collections.emptySet();
+                    final Set<Uri> before = dataBefore != null ? ImmutableSet.copyOf(dataBefore.getCapability())
+                        : Set.of();
+                    final Set<Uri> after = dataAfter != null ? ImmutableSet.copyOf(dataAfter.getCapability())
+                        : Set.of();
                     final Set<Uri> added = Sets.difference(after, before);
                     final Set<Uri> removed = Sets.difference(before, after);
                     publishNotification(added, removed);
@@ -72,7 +88,7 @@ public final class CapabilityChangeNotificationProducer extends OperationalDatas
                     final Capabilities dataBeforeDelete = rootNode.getDataBefore();
                     if (dataBeforeDelete != null) {
                         final Set<Uri> removed = ImmutableSet.copyOf(dataBeforeDelete.getCapability());
-                        publishNotification(Collections.emptySet(), removed);
+                        publishNotification(Set.of(), removed);
                     }
                     break;
                 }
@@ -80,7 +96,6 @@ public final class CapabilityChangeNotificationProducer extends OperationalDatas
                     LOG.debug("Received intentionally unhandled type: {}.", modificationType);
             }
         }
-
     }
 
     private void publishNotification(final Set<Uri> added, final Set<Uri> removed) {
@@ -94,17 +109,4 @@ public final class CapabilityChangeNotificationProducer extends OperationalDatas
             .setModifiedCapability(Set.of())
             .build());
     }
-
-    /**
-     * Invoked by blueprint.
-     */
-    @Override
-    public void close() {
-        if (baseNotificationPublisherRegistration != null) {
-            baseNotificationPublisherRegistration.close();
-        }
-        if (capabilityChangeListenerRegistration != null) {
-            capabilityChangeListenerRegistration.close();
-        }
-    }
 }
index f25724efb87e485113b96953abadf402ebebe524..0a1bac8a2ada4ff47e883c313137845121189e6e 100644 (file)
@@ -21,9 +21,12 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.checkerframework.checker.lock.qual.GuardedBy;
+import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecFactory;
+import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeGenerator;
 import org.opendaylight.netconf.mdsal.notification.impl.ops.NotificationsTransformUtil;
 import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration;
 import org.opendaylight.netconf.notifications.NetconfNotification;
@@ -47,6 +50,12 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.librar
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdate;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
+import org.opendaylight.yangtools.yang.parser.api.YangParserException;
+import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,9 +63,10 @@ import org.slf4j.LoggerFactory;
  *  A thread-safe implementation NetconfNotificationRegistry.
  */
 @Singleton
-public class NetconfNotificationManager implements NetconfNotificationCollector, NetconfNotificationRegistry,
+@Component(service = { NetconfNotificationCollector.class, NetconfNotificationRegistry.class }, immediate = true,
+           property = "type=netconf-notification-manager")
+public final class NetconfNotificationManager implements NetconfNotificationCollector, NetconfNotificationRegistry,
         NetconfNotificationListener, AutoCloseable {
-
     public static final StreamNameType BASE_STREAM_NAME = new StreamNameType("NETCONF");
     public static final Stream BASE_NETCONF_STREAM = new StreamBuilder()
                 .setName(BASE_STREAM_NAME)
@@ -90,8 +100,33 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
     private final NotificationsTransformUtil transformUtil;
 
     @Inject
-    public NetconfNotificationManager(final NotificationsTransformUtil transformUtil) {
-        this.transformUtil = requireNonNull(transformUtil);
+    @Activate
+    public NetconfNotificationManager(@Reference final YangParserFactory parserFactory,
+            @Reference final BindingRuntimeGenerator generator, @Reference final BindingDOMCodecFactory codecFactory)
+                throws YangParserException {
+        transformUtil = new NotificationsTransformUtil(parserFactory, generator, codecFactory);
+    }
+
+    @PreDestroy
+    @Deactivate
+    @Override
+    public synchronized void close() {
+        // Unregister all listeners
+        // Use new list to avoid ConcurrentModificationException
+        for (final GenericNotificationListenerReg listenerReg : new ArrayList<>(notificationListeners.values())) {
+            listenerReg.close();
+        }
+        notificationListeners.clear();
+
+        // Unregister all publishers
+        // Use new list to avoid ConcurrentModificationException
+        for (final GenericNotificationPublisherReg notificationPublisher : new ArrayList<>(notificationPublishers)) {
+            notificationPublisher.close();
+        }
+        notificationPublishers.clear();
+
+        // Clear stream Listeners
+        streamListeners.clear();
     }
 
     @Override
@@ -156,26 +191,6 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
         };
     }
 
-    @Override
-    public synchronized void close() {
-        // Unregister all listeners
-        // Use new list to avoid ConcurrentModificationException
-        for (final GenericNotificationListenerReg listenerReg : new ArrayList<>(notificationListeners.values())) {
-            listenerReg.close();
-        }
-        notificationListeners.clear();
-
-        // Unregister all publishers
-        // Use new list to avoid ConcurrentModificationException
-        for (final GenericNotificationPublisherReg notificationPublisher : new ArrayList<>(notificationPublishers)) {
-            notificationPublisher.close();
-        }
-        notificationPublishers.clear();
-
-        // Clear stream Listeners
-        streamListeners.clear();
-    }
-
     @Override
     public synchronized NotificationPublisherRegistration registerNotificationPublisher(final Stream stream) {
         final StreamNameType streamName = requireNonNull(stream).getName();
index 1f37ccf5c36288e0fbe078c312fc8b344112040f..1c554d76e6e36d8306d4b8115b2f3301cf8fd132 100644 (file)
@@ -5,10 +5,10 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.mdsal.notification.impl;
 
-import java.util.Collections;
+import static java.util.Objects.requireNonNull;
+
 import java.util.Set;
 import org.opendaylight.netconf.api.capability.Capability;
 import org.opendaylight.netconf.api.monitoring.CapabilityListener;
@@ -17,18 +17,31 @@ import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener;
 import org.opendaylight.netconf.notifications.NetconfNotificationRegistry;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 
+@Component(service = NetconfOperationServiceFactory.class, immediate = true,
+           property = "type=mdsal-netconf-notification")
 public final class NetconfNotificationOperationServiceFactory implements NetconfOperationServiceFactory, AutoCloseable {
-    private final NetconfNotificationRegistry netconfNotificationRegistry;
-    private final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener;
+    private final NetconfNotificationRegistry notifManager;
+    private final NetconfOperationServiceFactoryListener aggregatorRegistry;
 
+    @Activate
     public NetconfNotificationOperationServiceFactory(
-            final NetconfNotificationRegistry netconfNotificationRegistry,
-            final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener) {
-        this.netconfNotificationRegistry = netconfNotificationRegistry;
-        this.netconfOperationServiceFactoryListener = netconfOperationServiceFactoryListener;
+            @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationRegistry notifManager,
+            @Reference(target = "(type=mapper-aggregator-registry)")
+            final NetconfOperationServiceFactoryListener aggregatorRegistry) {
+        this.notifManager = requireNonNull(notifManager);
+        this.aggregatorRegistry = requireNonNull(aggregatorRegistry);
+        this.aggregatorRegistry.onAddNetconfOperationServiceFactory(this);
+    }
 
-        this.netconfOperationServiceFactoryListener.onAddNetconfOperationServiceFactory(this);
+    @Deactivate
+    @Override
+    public void close() {
+        aggregatorRegistry.onRemoveNetconfOperationServiceFactory(this);
     }
 
     @Override
@@ -38,21 +51,16 @@ public final class NetconfNotificationOperationServiceFactory implements Netconf
         // config-netconf-connector (it exposes all the schemas)
         // If the schemas exposed by config-netconf-connector are filtered,
         // this class would expose monitoring related models
-        return Collections.emptySet();
+        return Set.of();
     }
 
     @Override
     public NetconfOperationService createService(final String netconfSessionIdForReporting) {
-        return new NetconfNotificationOperationService(netconfSessionIdForReporting, netconfNotificationRegistry);
+        return new NetconfNotificationOperationService(netconfSessionIdForReporting, notifManager);
     }
 
     @Override
     public Registration registerCapabilityListener(final CapabilityListener listener) {
         return () -> { };
     }
-
-    @Override
-    public void close() {
-        netconfOperationServiceFactoryListener.onRemoveNetconfOperationServiceFactory(this);
-    }
 }
index 5e17e09555637ff755ebe7bcab5edf3f1db1bbd4..a78e08c44aae949eed414601e2727bf242415619 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.mdsal.notification.impl;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.concurrent.ExecutionException;
@@ -15,6 +17,7 @@ import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
+import org.opendaylight.netconf.notifications.NetconfNotificationCollector.NetconfNotificationStreamListener;
 import org.opendaylight.netconf.notifications.NotificationRegistration;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf;
@@ -22,32 +25,38 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Listens on changes in netconf notification stream availability and writes
- * changes to the data store.
+ * Listens on changes in netconf notification stream availability and writes changes to the data store.
  */
-public final class NotificationToMdsalWriter implements AutoCloseable, NetconfNotificationCollector
-        .NetconfNotificationStreamListener {
-
+@Component(service = { })
+public final class NotificationToMdsalWriter implements NetconfNotificationStreamListener, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(NotificationToMdsalWriter.class);
-    private static final InstanceIdentifier<Streams> STREAMS = InstanceIdentifier.builder(Netconf.class)
-            .child(Streams.class).build();
+    private static final InstanceIdentifier<Streams> STREAMS =
+        InstanceIdentifier.builder(Netconf.class).child(Streams.class).build();
 
-    private final NetconfNotificationCollector netconfNotificationCollector;
     private final DataBroker dataBroker;
-    private NotificationRegistration notificationRegistration;
-
-    public NotificationToMdsalWriter(final NetconfNotificationCollector netconfNotificationCollector,
-                                     final DataBroker dataBroker) {
-        this.netconfNotificationCollector = netconfNotificationCollector;
-        this.dataBroker = dataBroker;
+    private final NotificationRegistration notificationRegistration;
+
+    @Activate
+    public NotificationToMdsalWriter(
+            @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
+            @Reference final DataBroker dataBroker) {
+        this.dataBroker = requireNonNull(dataBroker);
+        notificationRegistration = notifManager.registerStreamListener(this);
     }
 
+    @Deactivate
     @Override
     public void close() {
+        notificationRegistration.close();
+
         final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
         tx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Netconf.class));
 
@@ -62,15 +71,6 @@ public final class NotificationToMdsalWriter implements AutoCloseable, NetconfNo
                 LOG.warn("Unable to clear streams", throwable);
             }
         }, MoreExecutors.directExecutor());
-
-        notificationRegistration.close();
-    }
-
-    /**
-     * Invoked by blueprint.
-     */
-    public void start() {
-        notificationRegistration = netconfNotificationCollector.registerStreamListener(this);
     }
 
     @Override
@@ -91,9 +91,7 @@ public final class NotificationToMdsalWriter implements AutoCloseable, NetconfNo
     public void onStreamUnregistered(final StreamNameType stream) {
         final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
 
-        final InstanceIdentifier<Stream> streamIdentifier = STREAMS.child(Stream.class, new StreamKey(stream));
-
-        tx.delete(LogicalDatastoreType.OPERATIONAL, streamIdentifier);
+        tx.delete(LogicalDatastoreType.OPERATIONAL, STREAMS.child(Stream.class, new StreamKey(stream)));
 
         try {
             tx.commit().get();
index c05cb18e874f4cea60756436ed99339dd0228cf8..778f0ff43f21b731b1615261e78aae9082bfa7a7 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.netconf.mdsal.notification.impl;
 
-import static com.google.common.base.Preconditions.checkArgument;
-
 import java.util.Collection;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataObjectModification;
@@ -19,33 +17,47 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.re
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEndBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStartBuilder;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Listens on changes in NetconfState/Sessions/Session datastore and publishes them.
  */
+@Component(service = { })
 public class SessionNotificationProducer extends OperationalDatastoreListener<Session> {
-    private static final InstanceIdentifier<Session> SESSION_INSTANCE_IDENTIFIER =
-            InstanceIdentifier.create(NetconfState.class).child(Sessions.class).child(Session.class);
     private static final Logger LOG = LoggerFactory.getLogger(SessionNotificationProducer.class);
+    private static final InstanceIdentifier<Session> SESSION_INSTANCE_IDENTIFIER =
+            InstanceIdentifier.builder(NetconfState.class).child(Sessions.class).child(Session.class).build();
 
     private final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration;
     private final ListenerRegistration<?> sessionListenerRegistration;
 
-    public SessionNotificationProducer(final NetconfNotificationCollector netconfNotificationCollector,
-                                       final DataBroker dataBroker) {
+    @Activate
+    public SessionNotificationProducer(
+            @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
+            @Reference final DataBroker dataBroker) {
         super(SESSION_INSTANCE_IDENTIFIER);
 
-        this.baseNotificationPublisherRegistration = netconfNotificationCollector.registerBaseNotificationPublisher();
-        this.sessionListenerRegistration = registerOnChanges(dataBroker);
+        baseNotificationPublisherRegistration = notifManager.registerBaseNotificationPublisher();
+        sessionListenerRegistration = registerOnChanges(dataBroker);
+    }
+
+    @Deactivate
+    public void close() {
+        if (baseNotificationPublisherRegistration != null) {
+            baseNotificationPublisherRegistration.close();
+        }
+        if (sessionListenerRegistration != null) {
+            sessionListenerRegistration.close();
+        }
     }
 
     @Override
@@ -72,37 +84,19 @@ public class SessionNotificationProducer extends OperationalDatastoreListener<Se
         }
     }
 
-    private void publishStartedSession(final DataObject dataObject) {
-        checkArgument(dataObject instanceof Session);
-        Session session = (Session) dataObject;
-        final NetconfSessionStart sessionStart = new NetconfSessionStartBuilder()
-                .setSessionId(new SessionIdOrZeroType(session.getSessionId()))
-                .setSourceHost(session.getSourceHost().getIpAddress())
-                .setUsername(session.getUsername())
-                .build();
-        baseNotificationPublisherRegistration.onSessionStarted(sessionStart);
-    }
-
-    private void publishEndedSession(final DataObject dataObject) {
-        checkArgument(dataObject instanceof Session);
-        Session session = (Session) dataObject;
-        final NetconfSessionEnd sessionEnd = new NetconfSessionEndBuilder()
-                .setSessionId(new SessionIdOrZeroType(session.getSessionId()))
-                .setSourceHost(session.getSourceHost().getIpAddress())
-                .setUsername(session.getUsername())
-                .build();
-        baseNotificationPublisherRegistration.onSessionEnded(sessionEnd);
+    private void publishStartedSession(final Session session) {
+        baseNotificationPublisherRegistration.onSessionStarted(new NetconfSessionStartBuilder()
+            .setSessionId(new SessionIdOrZeroType(session.getSessionId()))
+            .setSourceHost(session.getSourceHost().getIpAddress())
+            .setUsername(session.getUsername())
+            .build());
     }
 
-    /**
-     * Invoked by blueprint.
-     */
-    public void close() {
-        if (baseNotificationPublisherRegistration != null) {
-            baseNotificationPublisherRegistration.close();
-        }
-        if (sessionListenerRegistration != null) {
-            sessionListenerRegistration.close();
-        }
+    private void publishEndedSession(final Session session) {
+        baseNotificationPublisherRegistration.onSessionEnded(new NetconfSessionEndBuilder()
+            .setSessionId(new SessionIdOrZeroType(session.getSessionId()))
+            .setSourceHost(session.getSourceHost().getIpAddress())
+            .setUsername(session.getUsername())
+            .build());
     }
 }
index bf5dce34220078a243c39fecd76dd253dd2e78ac..6deedd191604b33fae90184aada21808b872c254 100644 (file)
@@ -5,20 +5,21 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.mdsal.notification.impl;
 
 import java.util.Collection;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataObjectModification;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
 import org.opendaylight.netconf.notifications.YangLibraryPublisherRegistration;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryChange;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryChangeBuilder;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 
 /**
  * Listens on the set of modules and submodules changes in data store and publishes
@@ -28,40 +29,26 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
  * @deprecated ietf-yang-library:yang-library-change was deprecated in the new RFC8525.
  *             Use {@link YangLibraryNotificationProducerRFC8525}.
  */
+@Component(service = { })
 @Deprecated(forRemoval = true)
 public final class YangLibraryNotificationProducer extends OperationalDatastoreListener<ModulesState>
-    implements AutoCloseable {
-
+        implements AutoCloseable {
     private static final InstanceIdentifier<ModulesState> MODULES_STATE_INSTANCE_IDENTIFIER =
             InstanceIdentifier.create(ModulesState.class);
 
     private final ListenerRegistration<?> yangLibraryChangeListenerRegistration;
     private final YangLibraryPublisherRegistration yangLibraryPublisherRegistration;
 
-    public YangLibraryNotificationProducer(final NetconfNotificationCollector netconfNotificationCollector,
-                                           final DataBroker dataBroker) {
+    @Activate
+    public YangLibraryNotificationProducer(
+            @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
+            @Reference final DataBroker dataBroker) {
         super(MODULES_STATE_INSTANCE_IDENTIFIER);
-        this.yangLibraryPublisherRegistration = netconfNotificationCollector.registerYangLibraryPublisher();
-        this.yangLibraryChangeListenerRegistration = registerOnChanges(dataBroker);
-    }
-
-    @Override
-    public void onDataTreeChanged(final Collection<DataTreeModification<ModulesState>> changes) {
-        for (DataTreeModification<ModulesState> change : changes) {
-            final DataObjectModification<ModulesState> rootNode = change.getRootNode();
-            final ModulesState dataAfter = rootNode.getDataAfter();
-            if (dataAfter != null) {
-                final YangLibraryChange yangLibraryChange = new YangLibraryChangeBuilder()
-                        .setModuleSetId(dataAfter.getModuleSetId())
-                        .build();
-                yangLibraryPublisherRegistration.onYangLibraryChange(yangLibraryChange);
-            }
-        }
+        yangLibraryPublisherRegistration = notifManager.registerYangLibraryPublisher();
+        yangLibraryChangeListenerRegistration = registerOnChanges(dataBroker);
     }
 
-    /**
-     * Invoked by blueprint.
-     */
+    @Deactivate
     @Override
     public void close() {
         if (yangLibraryPublisherRegistration != null) {
@@ -71,4 +58,16 @@ public final class YangLibraryNotificationProducer extends OperationalDatastoreL
             yangLibraryChangeListenerRegistration.close();
         }
     }
+
+    @Override
+    public void onDataTreeChanged(final Collection<DataTreeModification<ModulesState>> changes) {
+        for (DataTreeModification<ModulesState> change : changes) {
+            final ModulesState dataAfter = change.getRootNode().getDataAfter();
+            if (dataAfter != null) {
+                yangLibraryPublisherRegistration.onYangLibraryChange(new YangLibraryChangeBuilder()
+                    .setModuleSetId(dataAfter.getModuleSetId())
+                    .build());
+            }
+        }
+    }
 }
index ddfb8b0a02bc2c6c85608fd21145fee0c2ea368a..3e45f86763d2e7e073a32de92ab270de768c96b0 100644 (file)
@@ -9,56 +9,43 @@
 package org.opendaylight.netconf.mdsal.notification.impl;
 
 import java.util.Collection;
-import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataObjectModification;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
 import org.opendaylight.netconf.notifications.YangLibraryPublisherRegistration;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdate;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdateBuilder;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 
 /**
  * Listens on the modules, submodules, datastores, and datastore schemas changes in data store and publishes
  * to base netconf notification stream listener a server-specific identifier representing
  * the current set of modules, submodules, datastores, and datastore schemas.
  */
+@Component(service = { })
 public final class YangLibraryNotificationProducerRFC8525 extends OperationalDatastoreListener<YangLibrary>
         implements AutoCloseable {
-
     private static final InstanceIdentifier<YangLibrary> YANG_LIBRARY_INSTANCE_IDENTIFIER =
             InstanceIdentifier.create(YangLibrary.class);
 
     private final ListenerRegistration<?> yangLibraryChangeListenerRegistration;
     private final YangLibraryPublisherRegistration yangLibraryPublisherRegistration;
 
-    public YangLibraryNotificationProducerRFC8525(final NetconfNotificationCollector netconfNotificationCollector,
-                                           final DataBroker dataBroker) {
+    @Activate
+    public YangLibraryNotificationProducerRFC8525(
+            @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager,
+            @Reference final DataBroker dataBroker) {
         super(YANG_LIBRARY_INSTANCE_IDENTIFIER);
-        this.yangLibraryPublisherRegistration = netconfNotificationCollector.registerYangLibraryPublisher();
-        this.yangLibraryChangeListenerRegistration = registerOnChanges(dataBroker);
-    }
-
-    @Override
-    public void onDataTreeChanged(@NonNull Collection<DataTreeModification<YangLibrary>> changes) {
-        for (DataTreeModification<YangLibrary> change : changes) {
-            final DataObjectModification<YangLibrary> rootNode = change.getRootNode();
-            final YangLibrary dataAfter = rootNode.getDataAfter();
-            if (dataAfter != null) {
-                final YangLibraryUpdate yangLibraryUpdate = new YangLibraryUpdateBuilder()
-                        .setContentId(dataAfter.getContentId())
-                        .build();
-                yangLibraryPublisherRegistration.onYangLibraryUpdate(yangLibraryUpdate);
-            }
-        }
+        yangLibraryPublisherRegistration = notifManager.registerYangLibraryPublisher();
+        yangLibraryChangeListenerRegistration = registerOnChanges(dataBroker);
     }
 
-    /**
-     * Invoked by blueprint.
-     */
+    @Deactivate
     @Override
     public void close() {
         if (yangLibraryPublisherRegistration != null) {
@@ -68,4 +55,16 @@ public final class YangLibraryNotificationProducerRFC8525 extends OperationalDat
             yangLibraryChangeListenerRegistration.close();
         }
     }
+
+    @Override
+    public void onDataTreeChanged(final Collection<DataTreeModification<YangLibrary>> changes) {
+        for (DataTreeModification<YangLibrary> change : changes) {
+            final YangLibrary dataAfter = change.getRootNode().getDataAfter();
+            if (dataAfter != null) {
+                yangLibraryPublisherRegistration.onYangLibraryUpdate(new YangLibraryUpdateBuilder()
+                    .setContentId(dataAfter.getContentId())
+                    .build());
+            }
+        }
+    }
 }
index f6ae762330f5a94dd58c985a92148b13693fef7c..28f04fdee7c1cc20d75f5a4cf7716c622b31914f 100644 (file)
@@ -12,7 +12,6 @@ import static com.google.common.base.Verify.verify;
 import java.io.IOException;
 import java.util.Date;
 import java.util.Optional;
-import javax.inject.Singleton;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMResult;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
@@ -35,7 +34,6 @@ import org.opendaylight.yangtools.yang.parser.api.YangParserException;
 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
 import org.w3c.dom.Document;
 
-@Singleton
 public final class NotificationsTransformUtil {
     private final EffectiveModelContext schemaContext;
     private final BindingNormalizedNodeSerializer serializer;
diff --git a/netconf/mdsal-netconf-notification/src/main/resources/OSGI-INF/blueprint/mdsal-netconf-notification.xml b/netconf/mdsal-netconf-notification/src/main/resources/OSGI-INF/blueprint/mdsal-netconf-notification.xml
deleted file mode 100644 (file)
index 477eb6b..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2016 Inocybe Technologies Inc. and others.  All rights reserved.
-
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v1.0 which accompanies this distribution,
- and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           odl:restart-dependents-on-updates="true">
-
-    <reference id="dataBroker"
-               interface="org.opendaylight.mdsal.binding.api.DataBroker"
-               odl:type="default"/>
-    <reference id="netconfOperationServiceFactoryListener"
-               interface="org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener"
-               odl:type="mapper-aggregator-registry"/>
-    <reference id="bindingGenerator"
-               interface="org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeGenerator"/>
-    <reference id="codecFactory"
-               interface="org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecFactory"/>
-    <reference id="parserFactory"
-               interface="org.opendaylight.yangtools.yang.parser.api.YangParserFactory"/>
-
-    <!--This is the MD-SAL netconf server notification blueprint xml file-->
-    <bean id="transformUtil"
-          class="org.opendaylight.netconf.mdsal.notification.impl.ops.NotificationsTransformUtil">
-        <argument ref="parserFactory"/>
-        <argument ref="bindingGenerator"/>
-        <argument ref="codecFactory"/>
-    </bean>
-
-    <bean id="netconfNotificationManager"
-          class="org.opendaylight.netconf.mdsal.notification.impl.NetconfNotificationManager"
-          destroy-method="close">
-               <argument ref="transformUtil"/>
-    </bean>
-    <service ref="netconfNotificationManager"
-             interface="org.opendaylight.netconf.notifications.NetconfNotificationRegistry"
-             odl:type="netconf-notification-manager">
-    </service>
-    <service ref="netconfNotificationManager"
-             interface="org.opendaylight.netconf.notifications.NetconfNotificationCollector"
-             odl:type="netconf-notification-manager">
-    </service>
-
-    <bean id="notificationToMdsalWriter"
-          class="org.opendaylight.netconf.mdsal.notification.impl.NotificationToMdsalWriter"
-          init-method="start"
-          destroy-method="close">
-        <argument ref="netconfNotificationManager"/>
-        <argument ref="dataBroker"/>
-    </bean>
-
-    <bean id="capabilityChangeNotificationProducer"
-          class="org.opendaylight.netconf.mdsal.notification.impl.CapabilityChangeNotificationProducer"
-          destroy-method="close">
-        <argument ref="netconfNotificationManager"/>
-        <argument ref="dataBroker"/>
-    </bean>
-
-    <bean id="yangLibraryNotificationProducer"
-          class="org.opendaylight.netconf.mdsal.notification.impl.YangLibraryNotificationProducer"
-          destroy-method="close">
-        <argument ref="netconfNotificationManager"/>
-        <argument ref="dataBroker"/>
-    </bean>
-
-    <bean id="yangLibraryNotificationProducerRFC8525"
-          class="org.opendaylight.netconf.mdsal.notification.impl.YangLibraryNotificationProducerRFC8525"
-          destroy-method="close">
-        <argument ref="netconfNotificationManager"/>
-        <argument ref="dataBroker"/>
-    </bean>
-
-    <bean id="sessionNotificationProducer"
-          class="org.opendaylight.netconf.mdsal.notification.impl.SessionNotificationProducer"
-          destroy-method="close">
-        <argument ref="netconfNotificationManager"/>
-        <argument ref="dataBroker"/>
-    </bean>
-
-    <bean id="netconfNotificationOperationServiceFactory"
-          class="org.opendaylight.netconf.mdsal.notification.impl.NetconfNotificationOperationServiceFactory"
-          destroy-method="close">
-        <argument ref="netconfNotificationManager"/>
-        <argument ref="netconfOperationServiceFactoryListener"/>
-    </bean>
-    <service ref="netconfNotificationOperationServiceFactory"
-             interface="org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory"
-             odl:type="mdsal-netconf-notification"/>
-</blueprint>
index 0b93fd944c6ae8bb69d0ae74ed7e3037ea30a90f..34bbcf3f1f47e6329167cd97865ff041dd47224e 100644 (file)
@@ -31,7 +31,6 @@ import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.binding.dom.codec.impl.di.DefaultBindingDOMCodecFactory;
 import org.opendaylight.mdsal.binding.generator.impl.DefaultBindingRuntimeGenerator;
 import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.netconf.mdsal.notification.impl.ops.NotificationsTransformUtil;
 import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration;
 import org.opendaylight.netconf.notifications.NetconfNotification;
 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
@@ -246,7 +245,7 @@ public class NetconfNotificationManagerTest {
     }
 
     private static NetconfNotificationManager createManager() throws YangParserException {
-        return new NetconfNotificationManager(new NotificationsTransformUtil(new DefaultYangParserFactory(),
-            new DefaultBindingRuntimeGenerator(), new DefaultBindingDOMCodecFactory()));
+        return new NetconfNotificationManager(new DefaultYangParserFactory(),
+            new DefaultBindingRuntimeGenerator(), new DefaultBindingDOMCodecFactory());
     }
 }
\ No newline at end of file
index 3274cfd2d3c9942061e5e4e7d0b960382bd86c8e..5d43bb4e519f323bdd3718ce6e3c3f286db4b39c 100644 (file)
@@ -58,7 +58,6 @@ public class NotificationToMdsalWriterTest {
         doReturn(tx).when(dataBroker).newWriteOnlyTransaction();
 
         writer = new NotificationToMdsalWriter(notificationCollector, dataBroker);
-        writer.start();
     }
 
     @Test