<artifactId>sal-netconf-connector</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>messagebus-netconf</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<type>xml</type>
<classifier>features</classifier>
</dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>odl-message-bus</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>odl-netconf-clustered-topology</artifactId>
</properties>
<dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>odl-message-bus</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>odl-netconf-clustered-topology</artifactId>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright © 2017 Red Hat, Inc. and others.
-
- 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
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>feature-parent</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- <relativePath>../../parent</relativePath>
- </parent>
-
- <artifactId>odl-message-bus</artifactId>
- <packaging>feature</packaging>
-
- <!-- messagebus endpoint for netconf connector-->
-
- <dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>odl-netconf-connector-all</artifactId>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>odl-controller-exp-messagebus</artifactId>
- <type>xml</type>
- <classifier>features</classifier>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>messagebus-netconf</artifactId>
- </dependency>
- </dependencies>
-</project>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Copyright © 2020 PANTHEON.tech, s.r.o. and others.
- ~
- ~ 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
- -->
-<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="odl-message-bus-${project.version}">
- <feature name="odl-message-bus" version="${project.version}">
- <feature version="[3,4)">odl-controller-exp-messagebus</feature>
- </feature>
-</features>
<modules>
<module>features-netconf-connector</module>
- <module>odl-message-bus</module>
<module>odl-netconf-clustered-topology</module>
<module>odl-netconf-connector</module>
<module>odl-netconf-connector-all</module>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Copyright (c) 2015 Cisco Systems, 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
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.opendaylight.netconf</groupId>
- <artifactId>netconf-parent</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- <relativePath>../../parent</relativePath>
- </parent>
-
- <artifactId>messagebus-netconf</artifactId>
- <name>${project.artifactId}</name>
- <packaging>bundle</packaging>
-
- <dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>ietf-netconf-notifications</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-impl</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>messagebus-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>messagebus-spi</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>messagebus-util</artifactId>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>sal-netconf-connector</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>mdsal-binding-dom-codec-api</artifactId>
- </dependency>
-
- <!-- Testing Dependencies -->
- <dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>mdsal-binding-test-utils</artifactId>
- </dependency>
- </dependencies>
-</project>
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-import javax.xml.transform.dom.DOMSource;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
-import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceStatus;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceStatusNotification;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceStatusNotificationBuilder;
-import org.opendaylight.yangtools.util.xml.UntrustedXML;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/**
- * Topic registration on event-source-status-notification.
- */
-@Deprecated(forRemoval = true)
-class ConnectionNotificationTopicRegistration extends NotificationTopicRegistration {
- private static final Logger LOG = LoggerFactory.getLogger(ConnectionNotificationTopicRegistration.class);
-
- public static final Absolute EVENT_SOURCE_STATUS_PATH =
- Absolute.of(QName.create(EventSourceStatusNotification.QNAME, "event-source-status"));
- private static final NodeIdentifier EVENT_SOURCE_STATUS_ARG = NodeIdentifier.create(
- EventSourceStatusNotification.QNAME);
-
- private final DOMNotificationListener domNotificationListener;
-
- ConnectionNotificationTopicRegistration(final String sourceName,
- final DOMNotificationListener domNotificationListener) {
- super(NotificationSourceType.ConnectionStatusChange, sourceName,
- EVENT_SOURCE_STATUS_PATH.lastNodeIdentifier().getNamespace().toString());
- this.domNotificationListener = requireNonNull(domNotificationListener);
- LOG.info("Connection notification source has been initialized.");
- setActive(true);
- setReplaySupported(false);
- }
-
- @Override
- public void close() {
- if (isActive()) {
- LOG.debug("Connection notification - publish Deactive");
- publishNotification(EventSourceStatus.Deactive);
- notificationTopicMap.clear();
- setActive(false);
- }
- }
-
- @Override
- void activateNotificationSource() {
- LOG.debug("Connection notification - publish Active");
- publishNotification(EventSourceStatus.Active);
- }
-
- @Override
- void deActivateNotificationSource() {
- LOG.debug("Connection notification - publish Inactive");
- publishNotification(EventSourceStatus.Inactive);
- }
-
- @Override
- void reActivateNotificationSource() {
- LOG.debug("Connection notification - reactivate - publish active");
- publishNotification(EventSourceStatus.Active);
- }
-
- @Override
- boolean registerNotificationTopic(final SchemaPath notificationPath, final TopicId topicId) {
- if (!checkNotificationPath(notificationPath)) {
- LOG.debug("Bad SchemaPath for notification try to register");
- return false;
- }
- Set<TopicId> topicIds = getTopicsForNotification(notificationPath);
- topicIds.add(topicId);
- notificationTopicMap.put(notificationPath, topicIds);
- return true;
- }
-
- @Override
- synchronized void unRegisterNotificationTopic(final TopicId topicId) {
- List<SchemaPath> notificationPathToRemove = new ArrayList<>();
- for (SchemaPath notifKey : notificationTopicMap.keySet()) {
- Set<TopicId> topicList = notificationTopicMap.get(notifKey);
- if (topicList != null) {
- topicList.remove(topicId);
- if (topicList.isEmpty()) {
- notificationPathToRemove.add(notifKey);
- }
- }
- }
- for (SchemaPath notifKey : notificationPathToRemove) {
- notificationTopicMap.remove(notifKey);
- }
- }
-
- private void publishNotification(final EventSourceStatus eventSourceStatus) {
-
- final EventSourceStatusNotification notification = new EventSourceStatusNotificationBuilder()
- .setStatus(eventSourceStatus).build();
- domNotificationListener.onNotification(createNotification(notification));
- }
-
- private static DOMNotification createNotification(final EventSourceStatusNotification notification) {
- final ContainerNode cn = Builders.containerBuilder().withNodeIdentifier(EVENT_SOURCE_STATUS_ARG)
- .withChild(encapsulate(notification)).build();
- DOMNotification dn = new DOMNotification() {
-
- @Override
- public Absolute getType() {
- return EVENT_SOURCE_STATUS_PATH;
- }
-
- @Override
- public ContainerNode getBody() {
- return cn;
- }
- };
- return dn;
- }
-
- private static DOMSourceAnyxmlNode encapsulate(final EventSourceStatusNotification notification) {
- Document doc = UntrustedXML.newDocumentBuilder().newDocument();
-
- final Element rootElement = XmlUtil.createElement(doc, "EventSourceStatusNotification",
- Optional.of(EVENT_SOURCE_STATUS_ARG.getNodeType().getNamespace().toString()));
-
- final Element sourceElement = doc.createElement("status");
- sourceElement.appendChild(doc.createTextNode(notification.getStatus().name()));
- rootElement.appendChild(sourceElement);
-
- return Builders.anyXmlBuilder().withNodeIdentifier(EVENT_SOURCE_STATUS_ARG)
- .withValue(new DOMSource(rootElement)).build();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import static com.google.common.util.concurrent.Futures.immediateFuture;
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Multimaps;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.io.IOException;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-import java.util.regex.Pattern;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.dom.DOMSource;
-import org.opendaylight.controller.messagebus.app.util.TopicDOMNotification;
-import org.opendaylight.controller.messagebus.app.util.Util;
-import org.opendaylight.controller.messagebus.spi.EventSource;
-import org.opendaylight.mdsal.dom.api.DOMEvent;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
-import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
-import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.netconf.util.NetconfUtil;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicNotification;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.DisJoinTopicInput;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.DisJoinTopicOutput;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.DisJoinTopicOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicInput;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicOutput;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicStatus;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
-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.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/**
- * NetconfEventSource serves as proxy between nodes and messagebus. Subscribers can join topic stream from this source.
- * Then they will receive notifications from device that matches pattern specified by topic.
- */
-@Deprecated(forRemoval = true)
-public class NetconfEventSource implements EventSource, DOMNotificationListener {
-
- private static final Logger LOG = LoggerFactory.getLogger(NetconfEventSource.class);
-
- private static final NodeIdentifier TOPIC_NOTIFICATION_ARG = NodeIdentifier.create(TopicNotification.QNAME);
- private static final NodeIdentifier EVENT_SOURCE_ARG = NodeIdentifier.create(
- QName.create(TopicNotification.QNAME, "node-id"));
- private static final NodeIdentifier TOPIC_ID_ARG = NodeIdentifier.create(
- QName.create(TopicNotification.QNAME, "topic-id"));
- private static final NodeIdentifier PAYLOAD_ARG = NodeIdentifier.create(
- QName.create(TopicNotification.QNAME, "payload"));
- private static final String CONNECTION_NOTIFICATION_SOURCE_NAME = "ConnectionNotificationSource";
-
- private final DOMNotificationPublishService domPublish;
-
- private final Map<String, String> urnPrefixToStreamMap; // key = urnPrefix, value = StreamName
-
- /**
- * Map notification uri -> registrations.
- */
- private final Multimap<String, NotificationTopicRegistration>
- notificationTopicRegistrations = Multimaps.synchronizedListMultimap(ArrayListMultimap.create());
- private final NetconfEventSourceMount mount;
-
- /**
- * Creates new NetconfEventSource for node. Topic notifications will be published via provided
- * {@link DOMNotificationPublishService}
- *
- * @param streamMap netconf streams from device
- * @param publishService publish service
- */
- public NetconfEventSource(final Map<String, String> streamMap,
- final NetconfEventSourceMount mount,
- final DOMNotificationPublishService publishService) {
- this.mount = mount;
- this.urnPrefixToStreamMap = requireNonNull(streamMap);
- this.domPublish = requireNonNull(publishService);
- this.initializeNotificationTopicRegistrationList();
-
- LOG.info("NetconfEventSource [{}] created.", mount.getNodeId());
- }
-
- /**
- * Creates {@link ConnectionNotificationTopicRegistration} for connection. Also creates
- * {@link StreamNotificationTopicRegistration} for every prefix and available stream as defined in config file.
- */
- private void initializeNotificationTopicRegistrationList() {
- final ConnectionNotificationTopicRegistration cntr =
- new ConnectionNotificationTopicRegistration(CONNECTION_NOTIFICATION_SOURCE_NAME, this);
- notificationTopicRegistrations
- .put(cntr.getNotificationUrnPrefix(), cntr);
- Map<String, Stream> availableStreams = getAvailableStreams();
- LOG.debug("Stream configuration compare...");
- for (Entry<String, String> entry : this.urnPrefixToStreamMap.entrySet()) {
- String urnPrefix = entry.getKey();
- final String streamName = entry.getValue();
- LOG.debug("urnPrefix: {} streamName: {}", urnPrefix, streamName);
- if (availableStreams.containsKey(streamName)) {
- LOG.debug("Stream containig on device");
- notificationTopicRegistrations
- .put(urnPrefix, new StreamNotificationTopicRegistration(availableStreams.get(streamName),
- urnPrefix, this));
- }
- }
- }
-
- private Map<String, Stream> getAvailableStreams() {
- final Collection<Stream> availableStreams;
- try {
- availableStreams = mount.getAvailableStreams();
- } catch (InterruptedException | ExecutionException e) {
- LOG.warn("Can not read streams for node {}", mount.getNodeId(), e);
- return ImmutableMap.of();
- }
-
- return Maps.uniqueIndex(availableStreams, input -> input.getName().getValue());
- }
-
- @Override
- public ListenableFuture<RpcResult<JoinTopicOutput>> joinTopic(final JoinTopicInput input) {
- LOG.debug("Join topic {} on {}", input.getTopicId().getValue(), mount.getNodeId());
- final NotificationPattern notificationPattern = input.getNotificationPattern();
- final List<SchemaPath> matchingNotifications = getMatchingNotifications(notificationPattern);
- return registerTopic(input.getTopicId(), matchingNotifications);
-
- }
-
- @Override
- public ListenableFuture<RpcResult<DisJoinTopicOutput>> disJoinTopic(final DisJoinTopicInput input) {
- for (NotificationTopicRegistration reg : notificationTopicRegistrations.values()) {
- reg.unRegisterNotificationTopic(input.getTopicId());
- }
- return Util.resultRpcSuccessFor(new DisJoinTopicOutputBuilder().build());
- }
-
- private synchronized ListenableFuture<RpcResult<JoinTopicOutput>> registerTopic(
- final TopicId topicId,
- final List<SchemaPath> notificationsToSubscribe) {
- requireNonNull(notificationsToSubscribe);
- LOG.debug("Join topic {} - register", topicId);
- JoinTopicStatus joinTopicStatus = JoinTopicStatus.Down;
-
- LOG.debug("Notifications to subscribe has found - count {}", notificationsToSubscribe.size());
- int registeredNotificationCount = 0;
- for (SchemaPath schemaPath : notificationsToSubscribe) {
- final Collection<NotificationTopicRegistration> topicRegistrations =
- notificationTopicRegistrations.get(schemaPath.getLastComponent().getNamespace().toString());
- for (NotificationTopicRegistration reg : topicRegistrations) {
- LOG.info("Source of notification {} is activating, TopicId {}", reg.getSourceName(),
- topicId.getValue());
- boolean regSuccess = reg.registerNotificationTopic(schemaPath, topicId);
- if (regSuccess) {
- registeredNotificationCount = registeredNotificationCount + 1;
- }
- }
- }
- if (registeredNotificationCount > 0) {
- joinTopicStatus = JoinTopicStatus.Up;
- }
- final JoinTopicOutput output = new JoinTopicOutputBuilder().setStatus(joinTopicStatus).build();
- return immediateFuture(RpcResultBuilder.success(output).build());
-
- }
-
- public void reActivateStreams() {
- for (NotificationTopicRegistration reg : notificationTopicRegistrations.values()) {
- LOG.info("Source of notification {} is reactivating on node {}", reg.getSourceName(), mount.getNodeId());
- reg.reActivateNotificationSource();
- }
- }
-
- public void deActivateStreams() {
- for (NotificationTopicRegistration reg : notificationTopicRegistrations.values()) {
- LOG.info("Source of notification {} is deactivating on node {}", reg.getSourceName(), mount.getNodeId());
- reg.deActivateNotificationSource();
- }
- }
-
- @Override
- public void onNotification(final DOMNotification notification) {
- Instant notificationEventTime = null;
- if (notification instanceof DOMEvent) {
- notificationEventTime = ((DOMEvent) notification).getEventInstant();
- }
- final String namespace = notification.getType().lastNodeIdentifier().getNamespace().toString();
- for (NotificationTopicRegistration notifReg : notificationTopicRegistrations.get(namespace)) {
- notifReg.setLastEventTime(notificationEventTime);
- for (TopicId topicId : notifReg.getTopicsForNotification(notification.getType().asSchemaPath())) {
- publishNotification(notification, topicId);
- LOG.debug("Notification {} has been published for TopicId {}", notification.getType(),
- topicId.getValue());
- }
- }
- }
-
- private void publishNotification(final DOMNotification notification, final TopicId topicId) {
- final ContainerNode topicNotification = Builders.containerBuilder().withNodeIdentifier(TOPIC_NOTIFICATION_ARG)
- .withChild(ImmutableNodes.leafNode(TOPIC_ID_ARG, topicId))
- .withChild(ImmutableNodes.leafNode(EVENT_SOURCE_ARG, mount.getNodeId()))
- .withChild(encapsulate(notification))
- .build();
- try {
- domPublish.putNotification(new TopicDOMNotification(topicNotification));
- } catch (final InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- private DOMSourceAnyxmlNode encapsulate(final DOMNotification body) {
- // FIXME: Introduce something like YangModeledAnyXmlNode in Yangtools
- final Document doc = XmlUtil.newDocument();
- final Optional<String> namespace = Optional.of(PAYLOAD_ARG.getNodeType().getNamespace().toString());
- final Element element = XmlUtil.createElement(doc, "payload", namespace);
-
- final DOMResult result = new DOMResult(element);
-
- try {
- NetconfUtil.writeNormalizedNode(body.getBody(), result, body.getType().asSchemaPath(),
- mount.getSchemaContext());
- return Builders.anyXmlBuilder().withNodeIdentifier(PAYLOAD_ARG).withValue(new DOMSource(element)).build();
- } catch (IOException | XMLStreamException e) {
- LOG.error("Unable to encapsulate notification.", e);
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Returns all available notification paths that matches given pattern.
- *
- * @param notificationPattern pattern
- * @return notification paths
- */
- private List<SchemaPath> getMatchingNotifications(final NotificationPattern notificationPattern) {
- final String regex = notificationPattern.getValue();
-
- final Pattern pattern = Pattern.compile(regex);
- List<SchemaPath> availableNotifications = getAvailableNotifications();
- return Util.expandQname(availableNotifications, pattern);
- }
-
- @Override
- public void close() throws Exception {
- for (NotificationTopicRegistration streamReg : notificationTopicRegistrations.values()) {
- streamReg.close();
- }
- }
-
- @Override
- public NodeKey getSourceNodeKey() {
- return mount.getNode().key();
- }
-
- @Override
- public List<SchemaPath> getAvailableNotifications() {
-
- final List<SchemaPath> availNotifList = new ArrayList<>();
- // add Event Source Connection status notification
- availNotifList.add(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath());
-
- // add all known notifications from netconf device
- for (final NotificationDefinition nd : mount.getSchemaContext().getNotifications()) {
- availNotifList.add(nd.getPath());
- }
- return availNotifList;
- }
-
- NetconfEventSourceMount getMount() {
- return mount;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import static com.google.common.base.Verify.verifyNotNull;
-import static java.util.Objects.requireNonNull;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import org.opendaylight.controller.messagebus.spi.EventSourceRegistry;
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataObjectModification;
-import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
-import org.opendaylight.mdsal.binding.api.DataTreeModification;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * NetconfEventSourceManager implements DataChangeListener. On topology changes, it manages creation,
- * updating and removing registrations of event sources.
- */
-@Deprecated(forRemoval = true)
-public final class NetconfEventSourceManager implements DataTreeChangeListener<Node>, AutoCloseable {
-
- private static final Logger LOG = LoggerFactory.getLogger(NetconfEventSourceManager.class);
- private static final TopologyKey NETCONF_TOPOLOGY_KEY = new TopologyKey(
- new TopologyId(TopologyNetconf.QNAME.getLocalName()));
- private static final InstanceIdentifier<Node> NETCONF_DEVICE_PATH = InstanceIdentifier.create(NetworkTopology.class)
- .child(Topology.class, NETCONF_TOPOLOGY_KEY).child(Node.class);
-
- private Map<String, String> streamMap;
- private final ConcurrentHashMap<InstanceIdentifier<?>, NetconfEventSourceRegistration> registrationMap =
- new ConcurrentHashMap<>();
- private final DOMNotificationPublishService publishService;
- private final DOMMountPointService domMounts;
- private ListenerRegistration<NetconfEventSourceManager> listenerRegistration;
- private final EventSourceRegistry eventSourceRegistry;
- private final DataBroker dataBroker;
- private final BindingNormalizedNodeSerializer serializer;
-
- public NetconfEventSourceManager(final DataBroker dataBroker,
- final BindingNormalizedNodeSerializer serializer,
- final DOMNotificationPublishService domPublish,
- final DOMMountPointService domMount,
- final EventSourceRegistry eventSourceRegistry) {
- this.dataBroker = requireNonNull(dataBroker);
- this.serializer = requireNonNull(serializer);
- this.domMounts = requireNonNull(domMount);
- this.publishService = requireNonNull(domPublish);
- this.eventSourceRegistry = requireNonNull(eventSourceRegistry);
- }
-
- /**
- * Invoked by blueprint.
- */
- public void initialize() {
- listenerRegistration = verifyNotNull(dataBroker).registerDataTreeChangeListener(DataTreeIdentifier.create(
- LogicalDatastoreType.OPERATIONAL, NETCONF_DEVICE_PATH), this);
- LOG.info("NetconfEventSourceManager initialized.");
- }
-
- @Override
- public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
- for (DataTreeModification<Node> change: changes) {
- LOG.debug("DataTreeModification: {}", change);
- final DataObjectModification<Node> rootNode = change.getRootNode();
- final InstanceIdentifier<Node> identifier = change.getRootPath().getRootIdentifier();
- switch (rootNode.getModificationType()) {
- case WRITE:
- case SUBTREE_MODIFIED:
- nodeCreated(identifier, rootNode.getDataAfter());
- break;
- case DELETE:
- nodeRemoved(identifier);
- break;
- default:
- break;
- }
- }
- }
-
- private void nodeCreated(final InstanceIdentifier<?> key, final Node node) {
- if (!validateNode(node)) {
- LOG.warn("NodeCreated event : Node [{}] is null or not valid.", key);
- return;
- }
- LOG.info("Netconf event source [{}] is creating...", key);
- NetconfEventSourceRegistration nesr = NetconfEventSourceRegistration.create(serializer, requireNonNull(key),
- node, this);
- if (nesr != null) {
- NetconfEventSourceRegistration nesrOld = registrationMap.put(key, nesr);
- if (nesrOld != null) {
- nesrOld.close();
- }
- }
- }
-
- private void nodeRemoved(final InstanceIdentifier<?> key) {
- LOG.info("Netconf event source [{}] is removing...", key);
- NetconfEventSourceRegistration nesr = registrationMap.remove(requireNonNull(key));
- if (nesr != null) {
- nesr.close();
- }
- }
-
- private static boolean validateNode(final Node node) {
- return node == null ? false : isNetconfNode(node);
- }
-
- Map<String, String> getStreamMap() {
- return streamMap;
- }
-
- DOMNotificationPublishService getPublishService() {
- return publishService;
- }
-
- DOMMountPointService getDomMounts() {
- return domMounts;
- }
-
- EventSourceRegistry getEventSourceRegistry() {
- return eventSourceRegistry;
- }
-
- /**
- * Invoked by blueprint.
- *
- * @param streamMap Stream map
- */
- public void setStreamMap(final Map<String, String> streamMap) {
- this.streamMap = streamMap;
- }
-
- private static boolean isNetconfNode(final Node node) {
- return node.augmentation(NetconfNode.class) != null;
- }
-
- @Override
- public void close() {
- listenerRegistration.close();
- for (final NetconfEventSourceRegistration reg : registrationMap.values()) {
- reg.close();
- }
- registrationMap.clear();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.time.Instant;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
-import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
-import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.mdsal.dom.api.DOMService;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInput;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInputBuilder;
-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;
-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.yang.ietf.yang.types.rev130715.DateAndTime;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-
-/**
- * Facade of mounted netconf device.
- */
-@Deprecated(forRemoval = true)
-class NetconfEventSourceMount {
- private static final YangInstanceIdentifier STREAMS_PATH = YangInstanceIdentifier.builder().node(Netconf.QNAME)
- .node(Streams.QNAME).build();
- private static final QName CREATE_SUBSCRIPTION = QName.create(CreateSubscriptionInput.QNAME, "create-subscription");
-
- private final DOMRpcService rpcService;
- private final DOMNotificationService notificationService;
- private final DOMDataBroker dataBroker;
- private final Node node;
- private final String nodeId;
- private final BindingNormalizedNodeSerializer serializer;
- private final DOMSchemaService schemaService;
-
- NetconfEventSourceMount(final BindingNormalizedNodeSerializer serializer, final Node node,
- final DOMMountPoint mountPoint) {
- this.serializer = requireNonNull(serializer);
- this.node = node;
- this.nodeId = node.getNodeId().getValue();
- this.rpcService = getService(mountPoint, DOMRpcService.class);
- this.notificationService = getService(mountPoint, DOMNotificationService.class);
- this.dataBroker = getService(mountPoint, DOMDataBroker.class);
- this.schemaService = getService(mountPoint, DOMSchemaService.class);
- }
-
- private static <T extends DOMService> T getService(final DOMMountPoint mountPoint, final Class<T> service) {
- final Optional<T> optional = mountPoint.getService(service);
- Preconditions.checkState(optional.isPresent(), "Service not present on mount point: %s", service.getName());
- return optional.get();
- }
-
- Node getNode() {
- return node;
- }
-
- String getNodeId() {
- return nodeId;
- }
-
- /**
- * Invokes create-subscription rpc on mounted device stream. If lastEventTime is provided and stream supports
- * replay,
- * rpc will be invoked with start time parameter.
- *
- * @param stream stream
- * @param lastEventTime last event time
- * @return rpc result
- */
- ListenableFuture<? extends DOMRpcResult> invokeCreateSubscription(final Stream stream,
- final Optional<Instant> lastEventTime) {
- final CreateSubscriptionInputBuilder inputBuilder = new CreateSubscriptionInputBuilder()
- .setStream(stream.getName());
- if (lastEventTime.isPresent() && stream.getReplaySupport()) {
- final ZonedDateTime dateTime = lastEventTime.get().atZone(ZoneId.systemDefault());
- final String formattedDate = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(dateTime);
- inputBuilder.setStartTime(new DateAndTime(formattedDate));
- }
- final CreateSubscriptionInput input = inputBuilder.build();
- final ContainerNode nnInput = serializer.toNormalizedNodeRpcData(input);
- return rpcService.invokeRpc(CREATE_SUBSCRIPTION, nnInput);
- }
-
- /**
- * Invokes create-subscription rpc on mounted device stream.
- *
- * @param stream stream
- * @return rpc result
- */
- ListenableFuture<? extends DOMRpcResult> invokeCreateSubscription(final Stream stream) {
- return invokeCreateSubscription(stream, Optional.empty());
- }
-
- /**
- * Returns list of streams available on device.
- *
- * @return list of streams
- * @throws ExecutionException if data read fails
- * @throws InterruptedException if data read fails
- */
- Collection<Stream> getAvailableStreams() throws InterruptedException, ExecutionException {
- final Optional<NormalizedNode<?, ?>> streams;
- try (DOMDataTreeReadTransaction tx = dataBroker.newReadOnlyTransaction()) {
- streams = tx.read(LogicalDatastoreType.OPERATIONAL, STREAMS_PATH).get();
- }
- if (streams.isPresent()) {
- Streams streams1 = (Streams) serializer.fromNormalizedNode(STREAMS_PATH, streams.get()).getValue();
- return streams1.nonnullStream().values();
- }
- return Collections.emptyList();
- }
-
- EffectiveModelContext getSchemaContext() {
- return schemaService.getGlobalContext();
- }
-
- /**
- * Registers notification listener to receive a set of notifications.
- *
- * @param listener listener
- * @param notificationPath notification path
- * @return ListenerRegistration
- * @see DOMNotificationService#registerNotificationListener(DOMNotificationListener, SchemaPath...)
- */
- ListenerRegistration<DOMNotificationListener> registerNotificationListener(final DOMNotificationListener listener,
- final SchemaPath notificationPath) {
- return notificationService.registerNotificationListener(listener, notificationPath.asAbsolute());
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import static com.google.common.base.Preconditions.checkState;
-import static java.util.Objects.requireNonNull;
-
-import java.util.List;
-import java.util.Optional;
-import org.opendaylight.controller.messagebus.spi.EventSourceRegistration;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
-import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Helper class to keep connection status of netconf node and event source registration object.
- */
-@Deprecated(forRemoval = true)
-final class NetconfEventSourceRegistration implements AutoCloseable {
-
- private static final Logger LOG = LoggerFactory.getLogger(NetconfEventSourceRegistration.class);
- private static final YangInstanceIdentifier NETCONF_DEVICE_DOM_PATH = YangInstanceIdentifier.builder()
- .node(NetworkTopology.QNAME).node(Topology.QNAME)
- .nodeWithKey(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), TopologyNetconf.QNAME
- .getLocalName())
- .node(Node.QNAME).build();
- private static final QName NODE_ID_QNAME = QName.create(Node.QNAME, "node-id");
- private static final String NOTIFICATION_CAPABILITY_PREFIX = "(urn:ietf:params:xml:ns:netconf:notification";
-
- private final Node node;
- private final NetconfEventSourceManager netconfEventSourceManager;
- private final BindingNormalizedNodeSerializer serializer;
-
- private ConnectionStatus currentNetconfConnStatus;
- private EventSourceRegistration<NetconfEventSource> eventSourceRegistration;
-
- private NetconfEventSourceRegistration(final BindingNormalizedNodeSerializer serializer, final Node node,
- final NetconfEventSourceManager netconfEventSourceManager) {
- this.serializer = requireNonNull(serializer);
- this.node = node;
- this.netconfEventSourceManager = netconfEventSourceManager;
- this.eventSourceRegistration = null;
- this.currentNetconfConnStatus = ConnectionStatus.Connecting;
- }
-
- static NetconfEventSourceRegistration create(final BindingNormalizedNodeSerializer serializer,
- final InstanceIdentifier<?> instanceIdent, final Node node,
- final NetconfEventSourceManager netconfEventSourceManager) {
- requireNonNull(instanceIdent);
- requireNonNull(netconfEventSourceManager);
- if (!isEventSource(node)) {
- return null;
- }
- NetconfEventSourceRegistration nesr = new NetconfEventSourceRegistration(serializer, node,
- netconfEventSourceManager);
- nesr.updateStatus();
- LOG.debug("NetconfEventSourceRegistration for node {} has been initialized...", node.getNodeId().getValue());
- return nesr;
- }
-
- private static boolean isEventSource(final Node node) {
- final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
- if (netconfNode == null) {
- return false;
- }
- if (netconfNode.getAvailableCapabilities() == null) {
- return false;
- }
- final List<AvailableCapability> capabilities = netconfNode.getAvailableCapabilities().getAvailableCapability();
- if (capabilities == null || capabilities.isEmpty()) {
- return false;
- }
- for (final AvailableCapability capability : netconfNode.getAvailableCapabilities().getAvailableCapability()) {
- if (capability.getCapability().startsWith(NOTIFICATION_CAPABILITY_PREFIX)) {
- return true;
- }
- }
-
- return false;
- }
-
- Optional<EventSourceRegistration<NetconfEventSource>> getEventSourceRegistration() {
- return Optional.ofNullable(eventSourceRegistration);
- }
-
- NetconfNode getNetconfNode() {
- return node.augmentation(NetconfNode.class);
- }
-
- void updateStatus() {
- ConnectionStatus netconfConnStatus = getNetconfNode().getConnectionStatus();
- LOG.info("Change status on node {}, new status is {}", this.node.getNodeId().getValue(), netconfConnStatus);
- if (netconfConnStatus.equals(currentNetconfConnStatus)) {
- return;
- }
- changeStatus(netconfConnStatus);
- }
-
- private static boolean checkConnectionStatusType(final ConnectionStatus status) {
- return status == ConnectionStatus.Connected || status == ConnectionStatus.Connecting
- || status == ConnectionStatus.UnableToConnect;
- }
-
- private void changeStatus(final ConnectionStatus newStatus) {
- requireNonNull(newStatus);
- checkState(this.currentNetconfConnStatus != null);
- if (!checkConnectionStatusType(newStatus)) {
- throw new IllegalStateException("Unknown new Netconf Connection Status");
- }
- switch (this.currentNetconfConnStatus) {
- case Connecting:
- case UnableToConnect:
- if (newStatus == ConnectionStatus.Connected) {
- if (this.eventSourceRegistration == null) {
- registrationEventSource();
- } else {
- // reactivate stream on registered event source (invoke publish notification about connection)
- this.eventSourceRegistration.getInstance().reActivateStreams();
- }
- }
- break;
- case Connected:
- if (newStatus == ConnectionStatus.Connecting || newStatus == ConnectionStatus.UnableToConnect) {
- // deactivate streams on registered event source (invoke publish notification about connection)
- this.eventSourceRegistration.getInstance().deActivateStreams();
- }
- break;
- default:
- throw new IllegalStateException("Unknown current Netconf Connection Status");
- }
- this.currentNetconfConnStatus = newStatus;
- }
-
- private void registrationEventSource() {
- final Optional<DOMMountPoint> domMountPoint = netconfEventSourceManager.getDomMounts()
- .getMountPoint(domMountPath(node.getNodeId()));
- EventSourceRegistration<NetconfEventSource> registration = null;
- if (domMountPoint.isPresent()/* && mountPoint.isPresent()*/) {
- NetconfEventSourceMount mount = new NetconfEventSourceMount(serializer, node, domMountPoint.get());
- final NetconfEventSource netconfEventSource = new NetconfEventSource(
- netconfEventSourceManager.getStreamMap(),
- mount,
- netconfEventSourceManager.getPublishService());
- registration = netconfEventSourceManager.getEventSourceRegistry().registerEventSource(netconfEventSource);
- LOG.info("Event source {} has been registered", node.getNodeId().getValue());
- }
- this.eventSourceRegistration = registration;
- }
-
- private static YangInstanceIdentifier domMountPath(final NodeId nodeId) {
- return YangInstanceIdentifier.builder(NETCONF_DEVICE_DOM_PATH)
- .nodeWithKey(Node.QNAME, NODE_ID_QNAME, nodeId.getValue()).build();
- }
-
- private void closeEventSourceRegistration() {
- if (getEventSourceRegistration().isPresent()) {
- getEventSourceRegistration().get().close();
- }
- }
-
- @Override
- public void close() {
- closeEventSourceRegistration();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import java.time.Instant;
-import java.util.HashSet;
-import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Notification topic registration.
- */
-@Deprecated(forRemoval = true)
-abstract class NotificationTopicRegistration implements AutoCloseable {
-
- private static final Logger LOG = LoggerFactory.getLogger(NotificationTopicRegistration.class);
-
- public enum NotificationSourceType {
- NetconfDeviceStream,
- ConnectionStatusChange
- }
-
- private boolean active;
- private final NotificationSourceType notificationSourceType;
- private final String sourceName;
- private final String notificationUrnPrefix;
- private boolean replaySupported;
- private Instant lastEventTime;
- protected final ConcurrentHashMap<SchemaPath, Set<TopicId>> notificationTopicMap = new ConcurrentHashMap<>();
-
- protected NotificationTopicRegistration(final NotificationSourceType notificationSourceType,
- final String sourceName, final String notificationUrnPrefix) {
- this.notificationSourceType = notificationSourceType;
- this.sourceName = sourceName;
- this.notificationUrnPrefix = notificationUrnPrefix;
- this.active = false;
- this.setReplaySupported(false);
- }
-
- public boolean isActive() {
- return active;
- }
-
- protected void setActive(final boolean active) {
- this.active = active;
- }
-
- public NotificationSourceType getNotificationSourceType() {
- return notificationSourceType;
- }
-
- public String getSourceName() {
- return sourceName;
- }
-
- public String getNotificationUrnPrefix() {
- return notificationUrnPrefix;
- }
-
- /**
- * Returns registered topics for given notification path.
- *
- * @param notificationPath path
- * @return topicIds
- */
- Set<TopicId> getTopicsForNotification(final SchemaPath notificationPath) {
- final Set<TopicId> topicIds = notificationTopicMap.get(notificationPath);
- return topicIds != null ? topicIds : new HashSet<>();
- }
-
- /**
- * Checks, if notification is from namespace belonging to this registration.
- *
- * @param notificationPath path
- * @return true, if notification belongs to registration namespace
- */
- boolean checkNotificationPath(final SchemaPath notificationPath) {
- if (notificationPath == null) {
- return false;
- }
- String nameSpace = notificationPath.getLastComponent().getNamespace().toString();
- LOG.debug("CheckNotification - name space {} - NotificationUrnPrefix {}", nameSpace,
- getNotificationUrnPrefix());
- return nameSpace.startsWith(getNotificationUrnPrefix());
- }
-
- Optional<Instant> getLastEventTime() {
- return Optional.ofNullable(lastEventTime);
- }
-
- void setLastEventTime(final Instant lastEventTime) {
- this.lastEventTime = lastEventTime;
- }
-
- abstract void activateNotificationSource();
-
- abstract void deActivateNotificationSource();
-
- abstract void reActivateNotificationSource();
-
- /**
- * Registers associated event source notification to topic.
- *
- * @param notificationPath notification path
- * @param topicId topic id
- * @return true, if successful
- */
- abstract boolean registerNotificationTopic(SchemaPath notificationPath, TopicId topicId);
-
- /**
- * Registers associated event source notification to topic.
- *
- * @param topicId topic id
- */
- abstract void unRegisterNotificationTopic(TopicId topicId);
-
- public boolean isReplaySupported() {
- return replaySupported;
- }
-
- protected void setReplaySupported(final boolean replaySupported) {
- this.replaySupported = replaySupported;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutionException;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
-import org.opendaylight.mdsal.dom.api.DOMRpcResult;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Topic registration for notification with specified namespace from stream.
- */
-@Deprecated(forRemoval = true)
-class StreamNotificationTopicRegistration extends NotificationTopicRegistration {
-
- private static final Logger LOG = LoggerFactory.getLogger(StreamNotificationTopicRegistration.class);
-
- private final String nodeId;
- private final NetconfEventSource netconfEventSource;
- private final NetconfEventSourceMount mountPoint;
- private final ConcurrentHashMap<SchemaPath, ListenerRegistration<DOMNotificationListener>>
- notificationRegistrationMap = new ConcurrentHashMap<>();
- private final Stream stream;
-
- /**
- * Creates registration to notification stream.
- *
- * @param stream stream
- * @param notificationPrefix notifications namespace
- * @param netconfEventSource event source
- */
- StreamNotificationTopicRegistration(final Stream stream, final String notificationPrefix,
- final NetconfEventSource netconfEventSource) {
- super(NotificationSourceType.NetconfDeviceStream, stream.getName().getValue(), notificationPrefix);
- this.netconfEventSource = netconfEventSource;
- this.mountPoint = netconfEventSource.getMount();
- this.nodeId = mountPoint.getNode().getNodeId().getValue();
- this.stream = stream;
- setReplaySupported(stream.getReplaySupport());
- setActive(false);
- LOG.info("StreamNotificationTopicRegistration initialized for {}", getStreamName());
- }
-
- /**
- * Subscribes to notification stream associated with this registration.
- */
- @Override
- void activateNotificationSource() {
- if (!isActive()) {
- LOG.info("Stream {} is not active on node {}. Will subscribe.", this.getStreamName(), this.nodeId);
- final ListenableFuture<? extends DOMRpcResult> result = mountPoint.invokeCreateSubscription(stream);
- try {
- result.get();
- setActive(true);
- } catch (InterruptedException | ExecutionException e) {
- LOG.warn("Can not subscribe stream {} on node {}", this.getSourceName(), this.nodeId, e);
- setActive(false);
- }
- } else {
- LOG.info("Stream {} is now active on node {}", this.getStreamName(), this.nodeId);
- }
- }
-
- /**
- * Subscribes to notification stream associated with this registration. If replay is supported, notifications
- * from last
- * received event time will be requested.
- */
- @Override
- void reActivateNotificationSource() {
- if (isActive()) {
- LOG.info("Stream {} is reactivating on node {}.", this.getStreamName(), this.nodeId);
- final ListenableFuture<? extends DOMRpcResult> result = mountPoint.invokeCreateSubscription(stream,
- getLastEventTime());
- try {
- result.get();
- setActive(true);
- } catch (InterruptedException | ExecutionException e) {
- LOG.warn("Can not resubscribe stream {} on node {}", this.getSourceName(), this.nodeId, e);
- setActive(false);
- }
- }
- }
-
- @Override
- void deActivateNotificationSource() {
- // no operations need
- }
-
- private void closeStream() {
- if (isActive()) {
- for (ListenerRegistration<DOMNotificationListener> reg : notificationRegistrationMap.values()) {
- reg.close();
- }
- notificationRegistrationMap.clear();
- notificationTopicMap.clear();
- setActive(false);
- }
- }
-
- private String getStreamName() {
- return getSourceName();
- }
-
- @Override
- boolean registerNotificationTopic(final SchemaPath notificationPath, final TopicId topicId) {
- if (!checkNotificationPath(notificationPath)) {
- LOG.debug("Bad SchemaPath for notification try to register");
- return false;
- }
-
- activateNotificationSource();
- if (!isActive()) {
- LOG.warn("Stream {} is not active, listener for notification {} is not registered.", getStreamName(),
- notificationPath);
- return false;
- }
-
- ListenerRegistration<DOMNotificationListener> registration =
- mountPoint.registerNotificationListener(netconfEventSource, notificationPath);
- notificationRegistrationMap.put(notificationPath, registration);
- Set<TopicId> topicIds = getTopicsForNotification(notificationPath);
- topicIds.add(topicId);
-
- notificationTopicMap.put(notificationPath, topicIds);
- return true;
- }
-
- @Override
- synchronized void unRegisterNotificationTopic(final TopicId topicId) {
- List<SchemaPath> notificationPathToRemove = new ArrayList<>();
- for (SchemaPath notifKey : notificationTopicMap.keySet()) {
- Set<TopicId> topicList = notificationTopicMap.get(notifKey);
- if (topicList != null) {
- topicList.remove(topicId);
- if (topicList.isEmpty()) {
- notificationPathToRemove.add(notifKey);
- }
- }
- }
- for (SchemaPath notifKey : notificationPathToRemove) {
- notificationTopicMap.remove(notifKey);
- ListenerRegistration<DOMNotificationListener> reg = notificationRegistrationMap.remove(notifKey);
- if (reg != null) {
- reg.close();
- }
- }
- }
-
- @Override
- public void close() {
- closeStream();
- }
-
-}
+++ /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:use-default-for-reference-types="true">
-
- <reference id="dataBroker"
- interface="org.opendaylight.mdsal.binding.api.DataBroker"
- odl:type="default"/>
- <reference id="domCodec"
- interface="org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer" />
- <reference id="domMountPointService"
- interface="org.opendaylight.mdsal.dom.api.DOMMountPointService" />
- <reference id="domNotificationPublishService"
- interface="org.opendaylight.mdsal.dom.api.DOMNotificationPublishService" />
- <reference id="eventSourceRegistry"
- interface="org.opendaylight.controller.messagebus.spi.EventSourceRegistry" />
-
- <bean id="netconfEventSourceManager"
- class="org.opendaylight.netconf.messagebus.eventsources.netconf.NetconfEventSourceManager"
- init-method="initialize"
- destroy-method="close">
- <argument ref="dataBroker" />
- <argument ref="domCodec" />
- <argument ref="domNotificationPublishService" />
- <argument ref="domMountPointService" />
- <argument ref="eventSourceRegistry" />
- <property name="streamMap">
- <map>
- <entry key="urn:ietf:params:xml:ns:yang:smiv2" value="SNMP"/>
- <entry key="urn:ietf:params:xml:ns:yang:ietf-syslog-notification" value="SYSLOG"/>
- </map>
- </property>
- </bean>
-
-</blueprint>
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.opendaylight.mdsal.binding.dom.codec.impl.BindingCodecContext;
-import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf;
-
-@Deprecated(forRemoval = true)
-public abstract class AbstractCodecTest {
- static BindingCodecContext SERIALIZER;
-
- @BeforeClass
- public static void beforeClass() {
- SERIALIZER = new BindingCodecContext(BindingRuntimeHelpers.createRuntimeContext(Netconf.class));
- }
-
- @AfterClass
- public static void afterClass() {
- SERIALIZER = null;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.verify;
-
-import java.util.Collection;
-import java.util.Set;
-import javax.xml.transform.dom.DOMSource;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceStatus;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-
-@Deprecated(forRemoval = true)
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class ConnectionNotificationTopicRegistrationTest {
-
- private ConnectionNotificationTopicRegistration registration;
-
- @Mock
- private DOMNotificationListener listener;
-
- @Before
- public void setUp() {
- registration = new ConnectionNotificationTopicRegistration("candidate", listener);
- }
-
- @Test
- public void testClose() throws Exception {
- registration.setActive(true);
- registration.close();
- assertFalse(registration.isActive());
- checkStatus(listener, EventSourceStatus.Deactive);
- }
-
- @Test
- public void testActivateNotificationSource() throws Exception {
- registration.activateNotificationSource();
- checkStatus(listener, EventSourceStatus.Active);
- }
-
- @Test
- public void testDeActivateNotificationSource() throws Exception {
- registration.deActivateNotificationSource();
- checkStatus(listener, EventSourceStatus.Inactive);
- }
-
- @Test
- public void testReActivateNotificationSource() throws Exception {
- registration.reActivateNotificationSource();
- checkStatus(listener, EventSourceStatus.Active);
- }
-
- @Test
- public void testRegisterAndUnregisterNotificationTopic() throws Exception {
- final TopicId topic1 = registerTopic("topic1");
- final TopicId topic2 = registerTopic("topic2");
- final TopicId topic3 = registerTopic("topic3");
- final Set<TopicId> notificationTopicIds = registration.getTopicsForNotification(
- ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath());
- assertNotNull(notificationTopicIds);
- assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3));
-
- registration.unRegisterNotificationTopic(topic3);
- final Set<TopicId> afterUnregister = registration.getTopicsForNotification(
- ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath());
- assertNotNull(afterUnregister);
- assertThat(afterUnregister, hasItems(topic1, topic2));
- assertFalse(afterUnregister.contains(topic3));
- }
-
- private TopicId registerTopic(final String value) {
- final TopicId topic = TopicId.getDefaultInstance(value);
- registration.registerNotificationTopic(
- ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath(), topic);
- return topic;
- }
-
-
- /**
- * Checks status node of notification received by listener.
- *
- * @param listener listener
- * @param status expected value
- */
- private static void checkStatus(final DOMNotificationListener listener, final EventSourceStatus status) {
- ArgumentCaptor<DOMNotification> notificationCaptor = ArgumentCaptor.forClass(DOMNotification.class);
- verify(listener).onNotification(notificationCaptor.capture());
- final DOMNotification value = notificationCaptor.getValue();
- assertEquals(ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH, value.getType());
- final Collection<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> body =
- value.getBody().getValue();
- assertEquals(1, body.size());
- final DOMSource source = (DOMSource) body.iterator().next().getValue();
- final String statusNodeValue = source.getNode().getFirstChild().getFirstChild().getNodeValue();
- assertEquals(status.toString(), statusNodeValue);
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.notNull;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import com.google.common.util.concurrent.FluentFuture;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Optional;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.controller.messagebus.spi.EventSource;
-import org.opendaylight.controller.messagebus.spi.EventSourceRegistry;
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataObjectModification;
-import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
-import org.opendaylight.mdsal.binding.api.DataTreeModification;
-import org.opendaylight.mdsal.binding.api.MountPointService;
-import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
-import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
-import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.util.concurrent.FluentFutures;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-@Deprecated(forRemoval = true)
-public class NetconfEventSourceManagerTest extends AbstractCodecTest {
- private NetconfEventSourceManager netconfEventSourceManager;
- private ListenerRegistration<?> listenerRegistrationMock;
- private DOMMountPointService domMountPointServiceMock;
- private MountPointService mountPointServiceMock;
- private EventSourceRegistry eventSourceTopologyMock;
- private DataTreeModification<Node> dataTreeModificationMock;
- private RpcProviderService rpcProviderRegistryMock;
- private EventSourceRegistry eventSourceRegistry;
-
- @SuppressWarnings("unchecked")
- @Before
- public void setUp() throws Exception {
- final DataBroker dataBrokerMock = mock(DataBroker.class);
- final DOMNotificationPublishService domNotificationPublishServiceMock =
- mock(DOMNotificationPublishService.class);
- domMountPointServiceMock = mock(DOMMountPointService.class);
- eventSourceTopologyMock = mock(EventSourceRegistry.class);
- rpcProviderRegistryMock = mock(RpcProviderService.class);
- eventSourceRegistry = mock(EventSourceRegistry.class);
-
- listenerRegistrationMock = mock(ListenerRegistration.class);
- doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataTreeChangeListener(
- any(DataTreeIdentifier.class), any(NetconfEventSourceManager.class));
-
- DOMMountPoint domMountPointMock = mock(DOMMountPoint.class);
- Optional<DOMMountPoint> optionalDomMountServiceMock = Optional.of(domMountPointMock);
- doReturn(optionalDomMountServiceMock).when(domMountPointServiceMock).getMountPoint((YangInstanceIdentifier)
- notNull());
- DOMDataBroker mpDataBroker = mock(DOMDataBroker.class);
- doReturn(Optional.of(mpDataBroker)).when(domMountPointMock).getService(DOMDataBroker.class);
- doReturn(Optional.of(mock(DOMRpcService.class))).when(domMountPointMock).getService(DOMRpcService.class);
- doReturn(Optional.of(mock(DOMNotificationService.class))).when(domMountPointMock)
- .getService(DOMNotificationService.class);
- doReturn(Optional.of(mock(DOMSchemaService.class))).when(domMountPointMock).getService(DOMSchemaService.class);
-
- DOMDataTreeReadTransaction rtx = mock(DOMDataTreeReadTransaction.class);
- doReturn(rtx).when(mpDataBroker).newReadOnlyTransaction();
- final FluentFuture<Optional<NormalizedNode<?, ?>>> readStreamFuture =
- FluentFutures.immediateFluentFuture(Optional.of(NetconfTestUtils.getStreamsNode("stream-1")));
-
- YangInstanceIdentifier pathStream = YangInstanceIdentifier.builder().node(Netconf.QNAME).node(Streams.QNAME)
- .build();
- doReturn(readStreamFuture).when(rtx).read(LogicalDatastoreType.OPERATIONAL, pathStream);
-
- netconfEventSourceManager = new NetconfEventSourceManager(dataBrokerMock, SERIALIZER,
- domNotificationPublishServiceMock, domMountPointServiceMock, eventSourceRegistry);
- netconfEventSourceManager.setStreamMap(new HashMap<>());
- }
-
- @Test
- public void onDataChangedCreateEventSourceTestByCreateEntry() throws Exception {
- onDataChangedTestHelper(true, false, true, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX);
- netconfEventSourceManager.onDataTreeChanged(Collections.singletonList(dataTreeModificationMock));
- verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class));
- }
-
- @Test
- public void onDataChangedCreateEventSourceTestByUpdateEntry() throws Exception {
- onDataChangedTestHelper(false, true, true, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX);
- netconfEventSourceManager.onDataTreeChanged(Collections.singletonList(dataTreeModificationMock));
- verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class));
- }
-
- @Test
- public void onDataChangedCreateEventSourceTestNotNeconf() throws Exception {
- onDataChangedTestHelper(false, true, false, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX);
- netconfEventSourceManager.onDataTreeChanged(Collections.singletonList(dataTreeModificationMock));
- verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class));
- }
-
- @Test
- public void onDataChangedCreateEventSourceTestNotNotificationCapability() throws Exception {
- onDataChangedTestHelper(true, false, true, "bad-prefix");
- netconfEventSourceManager.onDataTreeChanged(Collections.singletonList(dataTreeModificationMock));
- verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class));
- }
-
- @SuppressWarnings("unchecked")
- private void onDataChangedTestHelper(final boolean create, final boolean update, final boolean isNetconf,
- final String notificationCapabilityPrefix) throws Exception {
- dataTreeModificationMock = mock(DataTreeModification.class);
- DataObjectModification<Node> mockModification = mock(DataObjectModification.class);
- doReturn(create ? DataObjectModification.ModificationType.WRITE :
- DataObjectModification.ModificationType.SUBTREE_MODIFIED).when(mockModification).getModificationType();
- doReturn(mockModification).when(dataTreeModificationMock).getRootNode();
-
- final Node node01;
- String nodeId = "Node01";
- if (isNetconf) {
- node01 = NetconfTestUtils
- .getNetconfNode(nodeId, "node01.test.local", ConnectionStatus.Connected,
- notificationCapabilityPrefix);
-
- } else {
- node01 = NetconfTestUtils.getNode(nodeId);
- }
-
- doReturn(node01).when(mockModification).getDataAfter();
-
- doReturn(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
- NetconfTestUtils.getInstanceIdentifier(node01))).when(dataTreeModificationMock).getRootPath();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import com.google.common.collect.Collections2;
-import java.time.Instant;
-import java.time.ZoneId;
-import java.time.format.DateTimeFormatter;
-import java.util.Collection;
-import java.util.Optional;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
-import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInput;
-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;
-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.StreamBuilder;
-import org.opendaylight.yangtools.util.concurrent.FluentFutures;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-@Deprecated(forRemoval = true)
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfEventSourceMountTest extends AbstractCodecTest {
- public static final String STREAM_1 = "stream-1";
- public static final String STREAM_2 = "stream-2";
-
- @Mock
- private DOMMountPoint domMountPoint;
- @Mock
- DOMDataBroker dataBroker;
- @Mock
- DOMRpcService rpcService;
- @Mock
- DOMSchemaService schemaService;
- @Mock
- private DOMDataTreeReadTransaction tx;
- private NetconfEventSourceMount mount;
-
- @Before
- public void setUp() {
- doReturn(Optional.of(dataBroker)).when(domMountPoint).getService(DOMDataBroker.class);
- doReturn(Optional.of(rpcService)).when(domMountPoint).getService(DOMRpcService.class);
- doReturn(Optional.of(mock(DOMNotificationService.class))).when(domMountPoint)
- .getService(DOMNotificationService.class);
- doReturn(Optional.of(schemaService)).when(domMountPoint).getService(DOMSchemaService.class);
- doReturn(tx).when(dataBroker).newReadOnlyTransaction();
- final YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(Netconf.QNAME).node(Streams.QNAME)
- .build();
- final NormalizedNode<?, ?> streamsNode = NetconfTestUtils.getStreamsNode(STREAM_1, STREAM_2);
- doReturn(FluentFutures.immediateFluentFuture(Optional.of(streamsNode)))
- .when(tx).read(LogicalDatastoreType.OPERATIONAL, path);
- mount = new NetconfEventSourceMount(SERIALIZER, NetconfTestUtils.getNode("node-1"), domMountPoint);
- }
-
- @Test
- public void testInvokeCreateSubscription() throws Exception {
- Stream stream = new StreamBuilder()
- .setName(new StreamNameType(STREAM_1))
- .build();
- mount.invokeCreateSubscription(stream, Optional.empty());
- final QName type = QName.create(CreateSubscriptionInput.QNAME, "create-subscription");
- ArgumentCaptor<ContainerNode> captor = ArgumentCaptor.forClass(ContainerNode.class);
- verify(rpcService).invokeRpc(eq(type), captor.capture());
- Assert.assertEquals(STREAM_1, getStreamName(captor.getValue()));
- }
-
- @Test
- public void testInvokeCreateSubscription1() throws Exception {
- Stream stream = new StreamBuilder()
- .setName(new StreamNameType(STREAM_1))
- .setReplaySupport(true)
- .build();
- final Instant date = Instant.now();
- mount.invokeCreateSubscription(stream, Optional.of(date));
- final QName type = QName.create(CreateSubscriptionInput.QNAME, "create-subscription");
- ArgumentCaptor<ContainerNode> captor = ArgumentCaptor.forClass(ContainerNode.class);
- verify(rpcService).invokeRpc(eq(type), captor.capture());
- Assert.assertEquals(STREAM_1, getStreamName(captor.getValue()));
- final String expDate = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(date.atZone(ZoneId.systemDefault()));
- final Optional<LeafNode> actual = (Optional<LeafNode>) getDate(captor.getValue());
- Assert.assertTrue(actual.isPresent());
- String actualDate = (String) actual.get().getValue();
- Assert.assertEquals(expDate, actualDate);
- }
-
- @Test
- public void testInvokeCreateSubscription2() throws Exception {
- Stream stream = new StreamBuilder()
- .setName(new StreamNameType(STREAM_1))
- .setReplaySupport(true)
- .build();
- mount.invokeCreateSubscription(stream, Optional.empty());
- final QName type = QName.create(CreateSubscriptionInput.QNAME, "create-subscription");
- ArgumentCaptor<ContainerNode> captor = ArgumentCaptor.forClass(ContainerNode.class);
- verify(rpcService).invokeRpc(eq(type), captor.capture());
- Assert.assertEquals(STREAM_1, getStreamName(captor.getValue()));
- final Optional<LeafNode> date = (Optional<LeafNode>) getDate(captor.getValue());
- Assert.assertFalse(date.isPresent());
-
- }
-
- @Test
- public void testGetAvailableStreams() throws Exception {
- final Collection<Stream> availableStreams = mount.getAvailableStreams();
- Assert.assertEquals(2, availableStreams.size());
- final Collection<String> streamNames = Collections2.transform(availableStreams,
- input -> input.getName().getValue());
- streamNames.contains(STREAM_1);
- streamNames.contains(STREAM_2);
- }
-
- private static String getStreamName(final ContainerNode value) {
- YangInstanceIdentifier.NodeIdentifier stream =
- new YangInstanceIdentifier.NodeIdentifier(QName.create(CreateSubscriptionInput.QNAME, "stream"));
- return (String) value.getChild(stream).get().getValue();
- }
-
- private static Optional<?> getDate(final ContainerNode value) {
- YangInstanceIdentifier.NodeIdentifier startTime =
- new YangInstanceIdentifier.NodeIdentifier(QName.create(CreateSubscriptionInput.QNAME, "startTime"));
- return value.getChild(startTime);
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.only;
-import static org.mockito.Mockito.verify;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.controller.messagebus.app.util.TopicDOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicNotification;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.DisJoinTopicInput;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.DisJoinTopicInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicInput;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicInputBuilder;
-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.streams.Stream;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.util.concurrent.FluentFutures;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-
-@Deprecated(forRemoval = true)
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfEventSourceTest {
- private static final Absolute NOTIFICATION_1_PATH = Absolute.of(QName.create("ns1", "1970-01-15", "not1"));
- private static final Absolute NOTIFICATION_2_PATH = Absolute.of(QName.create("ns2", "1980-02-18", "not2"));
-
- NetconfEventSource netconfEventSource;
-
- @Mock
- DOMNotificationPublishService domNotificationPublishServiceMock;
- @Mock
- DOMNotification matchnigNotification;
- @Mock
- DOMNotification nonMachtingNotification;
- @Mock
- NetconfEventSourceMount mount;
-
- @Before
- public void setUp() throws Exception {
- //init notification mocks
- doReturn(NOTIFICATION_1_PATH).when(matchnigNotification).getType();
- doReturn(NOTIFICATION_2_PATH).when(nonMachtingNotification).getType();
- DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> body = Builders
- .containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("ns1",
- "1970-01-15", "not1data")));
- doReturn(body.build()).when(matchnigNotification).getBody();
- //init schema context mock
- Set<NotificationDefinition> notifications = new HashSet<>();
- notifications.add(getNotificationDefinitionMock(NOTIFICATION_1_PATH.lastNodeIdentifier()));
- notifications.add(getNotificationDefinitionMock(NOTIFICATION_2_PATH.lastNodeIdentifier()));
- EffectiveModelContext schemaContext = mock(EffectiveModelContext.class);
- doReturn(notifications).when(schemaContext).getNotifications();
- //init mount point mock
- List<Stream> streams = new ArrayList<>();
- streams.add(createStream("stream-1"));
- streams.add(createStream("stream-2"));
- doReturn(streams).when(mount).getAvailableStreams();
- doReturn(schemaContext).when(mount).getSchemaContext();
- doReturn(FluentFutures.immediateNullFluentFuture()).when(mount).invokeCreateSubscription(any());
- doReturn(mock(ListenerRegistration.class)).when(mount).registerNotificationListener(any(), any());
- final Node nodeId1 = NetconfTestUtils.getNetconfNode("NodeId1", "node.test.local", ConnectionStatus
- .Connected, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX);
- doReturn(nodeId1).when(mount).getNode();
- doReturn(nodeId1.getNodeId().getValue()).when(mount).getNodeId();
-
- Map<String, String> streamMap = new HashMap<>();
- streamMap.put(NOTIFICATION_1_PATH.lastNodeIdentifier().getNamespace().toString(), "stream-1");
- netconfEventSource = new NetconfEventSource(
- streamMap,
- mount,
- domNotificationPublishServiceMock);
-
- }
-
- @Test
- public void testJoinTopicOnNotification() throws Exception {
- final JoinTopicInput topic1 = new JoinTopicInputBuilder()
- .setTopicId(TopicId.getDefaultInstance("topic1"))
- .setNotificationPattern(NotificationPattern.getDefaultInstance(".*ns1"))
- .build();
- netconfEventSource.joinTopic(topic1);
-
- ArgumentCaptor<DOMNotification> captor = ArgumentCaptor.forClass(DOMNotification.class);
- //handle notification matching topic namespace
- netconfEventSource.onNotification(matchnigNotification);
- //handle notification that does not match topic namespace
- netconfEventSource.onNotification(nonMachtingNotification);
- //only matching notification should be published
- verify(domNotificationPublishServiceMock).putNotification(captor.capture());
- final TopicDOMNotification value = (TopicDOMNotification) captor.getValue();
- final QName qname = TopicNotification.QNAME;
- final YangInstanceIdentifier.NodeIdentifier topicIdNode =
- new YangInstanceIdentifier.NodeIdentifier(QName.create(qname, "topic-id"));
- final Object actualTopicId = value.getBody().getChild(topicIdNode).get().getValue();
- Assert.assertEquals(topic1.getTopicId(), actualTopicId);
- }
-
- @Test
- public void testDisjoinTopicOnNotification() throws Exception {
- final TopicId topicId = TopicId.getDefaultInstance("topic1");
- final JoinTopicInput topic1 = new JoinTopicInputBuilder()
- .setTopicId(topicId)
- .setNotificationPattern(NotificationPattern.getDefaultInstance(".*ns1"))
- .build();
- netconfEventSource.joinTopic(topic1);
-
- //handle notification matching topic namespace
- netconfEventSource.onNotification(matchnigNotification);
- //disjoin topic
- DisJoinTopicInput disjoinTopic = new DisJoinTopicInputBuilder().setTopicId(topicId).build();
- netconfEventSource.disJoinTopic(disjoinTopic);
- netconfEventSource.onNotification(matchnigNotification);
- //topic notification published only once before disjoin
- verify(domNotificationPublishServiceMock, only()).putNotification(any());
- }
-
- private static Stream createStream(final String name) {
- return new StreamBuilder()
- .setName(new StreamNameType(name))
- .setReplaySupport(true)
- .build();
- }
-
- private static NotificationDefinition getNotificationDefinitionMock(final QName qualifiedName) {
- NotificationDefinition notification = mock(NotificationDefinition.class);
- doReturn(qualifiedName).when(notification).getQName();
- doReturn(SchemaPath.create(true, qualifiedName)).when(notification).getPath();
- return notification;
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import com.google.common.collect.ImmutableMap;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-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.Streams;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.StreamsBuilder;
-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.StreamBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.AvailableCapabilitiesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapabilityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
-
-@Deprecated(forRemoval = true)
-public final class NetconfTestUtils {
- public static final String NOTIFICATION_CAPABILITY_PREFIX = "(urn:ietf:params:xml:ns:netconf:notification";
-
- private NetconfTestUtils() {
-
- }
-
- public static Node getNetconfNode(final String nodeIdent, final String hostName, final ConnectionStatus cs,
- final String notificationCapabilityPrefix) {
- List<AvailableCapability> avCapList = new ArrayList<>();
- avCapList.add(new AvailableCapabilityBuilder().setCapability(notificationCapabilityPrefix
- + "_availableCapabilityString1").build());
-
- return new NodeBuilder()
- .withKey(new NodeKey(new NodeId(nodeIdent)))
- .addAugmentation(new NetconfNodeBuilder()
- .setConnectionStatus(cs)
- .setHost(new Host(new DomainName(hostName)))
- .setAvailableCapabilities(new AvailableCapabilitiesBuilder()
- .setAvailableCapability(avCapList)
- .build())
- .build())
- .build();
- }
-
- public static Node getNode(final String nodeIdent) {
- return new NodeBuilder().withKey(new NodeKey(new NodeId(nodeIdent))).build();
- }
-
- public static InstanceIdentifier<Node> getInstanceIdentifier(final Node node) {
- return InstanceIdentifier.create(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())))
- .child(Node.class, node.key());
- }
-
- public static Optional<Streams> getAvailableStream(final String name, final boolean replaySupport) {
- Stream stream = new StreamBuilder().setName(new StreamNameType(name)).setReplaySupport(replaySupport).build();
- return Optional.of(new StreamsBuilder().setStream(ImmutableMap.of(stream.key(), stream)).build());
- }
-
- public static NormalizedNode<?, ?> getStreamsNode(final String... streamName) {
- QName nameNode = QName.create(Stream.QNAME, "name");
- Set<MapEntryNode> streamSet = new HashSet<>();
- for (String s : streamName) {
- MapEntryNode stream = Builders.mapEntryBuilder()
- .withNodeIdentifier(NodeIdentifierWithPredicates.of(Stream.QNAME, nameNode, s))
- .withChild(Builders.leafBuilder()
- .withNodeIdentifier(new NodeIdentifier(nameNode))
- .withValue(s)
- .build())
- .build();
- streamSet.add(stream);
- }
-
- CollectionNodeBuilder<MapEntryNode, MapNode> streams =
- Builders.mapBuilder().withNodeIdentifier(NodeIdentifier.create(Stream.QNAME));
- for (MapEntryNode mapEntryNode : streamSet) {
- streams.withChild(mapEntryNode);
- }
- return Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(Streams.QNAME))
- .withChild(streams.build())
- .build();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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
- */
-package org.opendaylight.netconf.messagebus.eventsources.netconf;
-
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateNullFluentFuture;
-
-import java.time.Instant;
-import java.util.Optional;
-import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
-import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
-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.streams.Stream;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-
-@Deprecated(forRemoval = true)
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class StreamNotificationTopicRegistrationTest {
-
- private static final String STREAM_NAME = "stream-1";
- private static final String PREFIX = ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH
- .lastNodeIdentifier().getNamespace().toString();
-
- @Mock
- private NetconfEventSource source;
- @Mock
- private NetconfEventSourceMount mount;
- @Mock
- private DOMNotificationService reference;
- @Mock
- private ListenerRegistration<DOMNotificationListener> listenerRegistration;
-
- private StreamNotificationTopicRegistration registration;
- private Stream stream;
-
- @Before
- public void setUp() throws Exception {
- Node node = new NodeBuilder().setNodeId(NodeId.getDefaultInstance("node-id")).build();
- when(mount.getNode()).thenReturn(node);
- when(mount.registerNotificationListener(source,
- ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath()))
- .thenReturn(listenerRegistration);
- doReturn(immediateNullFluentFuture()).when(mount).invokeCreateSubscription(any(), any());
- doReturn(immediateNullFluentFuture()).when(mount).invokeCreateSubscription(any());
-
- when(source.getMount()).thenReturn(mount);
- stream = new StreamBuilder().setName(StreamNameType.getDefaultInstance(STREAM_NAME)).setReplaySupport(true)
- .build();
-
- registration = new StreamNotificationTopicRegistration(stream, PREFIX, source);
- }
-
- @Test
- public void testActivateNotificationSource() throws Exception {
- registration.activateNotificationSource();
- assertTrue(registration.isActive());
- verify(mount).invokeCreateSubscription(stream);
-
- }
-
- @Test
- public void testReActivateNotificationSource() throws Exception {
- registration.setActive(true);
- registration.reActivateNotificationSource();
-
- assertTrue(registration.isActive());
- verify(mount).invokeCreateSubscription(stream, Optional.empty());
- }
-
- @Test
- public void testReActivateNotificationSourceWithReplay() throws Exception {
- final Instant lastEventTime = Instant.now();
- registration.setActive(true);
- registration.setLastEventTime(lastEventTime);
- registration.reActivateNotificationSource();
-
- assertTrue(registration.isActive());
- verify(mount).invokeCreateSubscription(stream, Optional.of(lastEventTime));
- }
-
- @Test
- public void testClose() throws Exception {
- registration.setActive(true);
- registration.close();
- assertFalse(registration.isActive());
- }
-
- @Test
- public void testRegisterAndUnregisterNotificationTopic() throws Exception {
- final TopicId topic1 = registerTopic("topic1");
- final TopicId topic2 = registerTopic("topic2");
- final TopicId topic3 = registerTopic("topic3");
- final Set<TopicId> notificationTopicIds = registration.getTopicsForNotification(
- ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath());
- assertNotNull(notificationTopicIds);
- assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3));
-
- registration.unRegisterNotificationTopic(topic3);
- final Set<TopicId> afterUnregister = registration.getTopicsForNotification(
- ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath());
- assertNotNull(afterUnregister);
- assertThat(afterUnregister, hasItems(topic1, topic2));
- assertFalse(afterUnregister.contains(topic3));
- }
-
- private TopicId registerTopic(final String value) {
- final TopicId topic = TopicId.getDefaultInstance(value);
- registration.registerNotificationTopic(
- ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath(), topic);
- return topic;
- }
-
-
-}
\ No newline at end of file
<module>netconf-topology-impl</module>
<module>netconf-topology-singleton</module>
<module>sal-netconf-connector</module>
- <module>messagebus-netconf</module>
<module>yanglib</module>
<module>models</module>
<module>tools</module>