<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>
<scope>test</scope>
</dependency>
</dependencies>
-
</project>
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;
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;
* 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) {
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);
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;
}
LOG.debug("Received intentionally unhandled type: {}.", modificationType);
}
}
-
}
private void publishNotification(final Set<Uri> added, final Set<Uri> removed) {
.setModifiedCapability(Set.of())
.build());
}
-
- /**
- * Invoked by blueprint.
- */
- @Override
- public void close() {
- if (baseNotificationPublisherRegistration != null) {
- baseNotificationPublisherRegistration.close();
- }
- if (capabilityChangeListenerRegistration != null) {
- capabilityChangeListenerRegistration.close();
- }
- }
}
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;
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;
* 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)
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
};
}
- @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();
* 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;
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
// 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);
- }
}
*/
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;
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;
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));
LOG.warn("Unable to clear streams", throwable);
}
}, MoreExecutors.directExecutor());
-
- notificationRegistration.close();
- }
-
- /**
- * Invoked by blueprint.
- */
- public void start() {
- notificationRegistration = netconfNotificationCollector.registerStreamListener(this);
}
@Override
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();
*/
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;
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
}
}
- 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());
}
}
* 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
* @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) {
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());
+ }
+ }
+ }
}
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) {
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());
+ }
+ }
+ }
}
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;
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;
+++ /dev/null
-<?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>
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;
}
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
doReturn(tx).when(dataBroker).newWriteOnlyTransaction();
writer = new NotificationToMdsalWriter(notificationCollector, dataBroker);
- writer.start();
}
@Test