From 00eb21233e754b2e89b0cd7ef3b2a2da39e4788f Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 26 Apr 2021 13:07:39 +0200 Subject: [PATCH] Remove odl-messagebus feature and messagebus-netconf Controller is removing the PoC infrastructure we were relying on, let's just remove the component as well. JIRA: NETCONF-768 Change-Id: Idaa58b1c8ad06c3cb7bf90c0b654c967bc07eb49 Signed-off-by: Robert Varga --- artifacts/pom.xml | 12 - .../features-netconf-connector/pom.xml | 7 - .../netconf-connector/odl-message-bus/pom.xml | 42 --- .../src/main/feature/feature.xml | 13 - features/netconf-connector/pom.xml | 1 - netconf/messagebus-netconf/pom.xml | 61 ---- ...nnectionNotificationTopicRegistration.java | 156 --------- .../netconf/NetconfEventSource.java | 303 ------------------ .../netconf/NetconfEventSourceManager.java | 167 ---------- .../netconf/NetconfEventSourceMount.java | 159 --------- .../NetconfEventSourceRegistration.java | 183 ----------- .../NotificationTopicRegistration.java | 135 -------- .../StreamNotificationTopicRegistration.java | 170 ---------- .../OSGI-INF/blueprint/messagebus-netconf.xml | 42 --- .../netconf/AbstractCodecTest.java | 29 -- ...tionNotificationTopicRegistrationTest.java | 117 ------- .../NetconfEventSourceManagerTest.java | 154 --------- .../netconf/NetconfEventSourceMountTest.java | 150 --------- .../netconf/NetconfEventSourceTest.java | 166 ---------- .../netconf/NetconfTestUtils.java | 113 ------- ...reamNotificationTopicRegistrationTest.java | 138 -------- netconf/pom.xml | 1 - 22 files changed, 2319 deletions(-) delete mode 100644 features/netconf-connector/odl-message-bus/pom.xml delete mode 100644 features/netconf-connector/odl-message-bus/src/main/feature/feature.xml delete mode 100644 netconf/messagebus-netconf/pom.xml delete mode 100644 netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java delete mode 100644 netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java delete mode 100644 netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java delete mode 100644 netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMount.java delete mode 100644 netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java delete mode 100644 netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NotificationTopicRegistration.java delete mode 100644 netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistration.java delete mode 100644 netconf/messagebus-netconf/src/main/resources/OSGI-INF/blueprint/messagebus-netconf.xml delete mode 100644 netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/AbstractCodecTest.java delete mode 100644 netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistrationTest.java delete mode 100644 netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java delete mode 100644 netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMountTest.java delete mode 100644 netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java delete mode 100644 netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfTestUtils.java delete mode 100644 netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistrationTest.java diff --git a/artifacts/pom.xml b/artifacts/pom.xml index fba23b3258..c384e6ec6b 100644 --- a/artifacts/pom.xml +++ b/artifacts/pom.xml @@ -122,11 +122,6 @@ sal-netconf-connector ${project.version} - - ${project.groupId} - messagebus-netconf - ${project.version} - ${project.groupId} @@ -402,13 +397,6 @@ xml features - - ${project.groupId} - odl-message-bus - ${project.version} - xml - features - ${project.groupId} odl-netconf-clustered-topology diff --git a/features/netconf-connector/features-netconf-connector/pom.xml b/features/netconf-connector/features-netconf-connector/pom.xml index d9af228238..e2e8c96d3f 100644 --- a/features/netconf-connector/features-netconf-connector/pom.xml +++ b/features/netconf-connector/features-netconf-connector/pom.xml @@ -28,13 +28,6 @@ - - ${project.groupId} - odl-message-bus - ${project.version} - xml - features - ${project.groupId} odl-netconf-clustered-topology diff --git a/features/netconf-connector/odl-message-bus/pom.xml b/features/netconf-connector/odl-message-bus/pom.xml deleted file mode 100644 index f395e5c63f..0000000000 --- a/features/netconf-connector/odl-message-bus/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - 4.0.0 - - - org.opendaylight.netconf - feature-parent - 2.0.0-SNAPSHOT - ../../parent - - - odl-message-bus - feature - - - - - - ${project.groupId} - odl-netconf-connector-all - xml - features - - - org.opendaylight.controller - odl-controller-exp-messagebus - xml - features - - - ${project.groupId} - messagebus-netconf - - - diff --git a/features/netconf-connector/odl-message-bus/src/main/feature/feature.xml b/features/netconf-connector/odl-message-bus/src/main/feature/feature.xml deleted file mode 100644 index 3af6c49e37..0000000000 --- a/features/netconf-connector/odl-message-bus/src/main/feature/feature.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - odl-controller-exp-messagebus - - diff --git a/features/netconf-connector/pom.xml b/features/netconf-connector/pom.xml index b3b1af0383..1476bd2281 100644 --- a/features/netconf-connector/pom.xml +++ b/features/netconf-connector/pom.xml @@ -27,7 +27,6 @@ features-netconf-connector - odl-message-bus odl-netconf-clustered-topology odl-netconf-connector odl-netconf-connector-all diff --git a/netconf/messagebus-netconf/pom.xml b/netconf/messagebus-netconf/pom.xml deleted file mode 100644 index 71bb5614fe..0000000000 --- a/netconf/messagebus-netconf/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - 4.0.0 - - - org.opendaylight.netconf - netconf-parent - 2.0.0-SNAPSHOT - ../../parent - - - messagebus-netconf - ${project.artifactId} - bundle - - - - ${project.groupId} - ietf-netconf-notifications - - - org.opendaylight.yangtools - yang-data-impl - - - org.opendaylight.controller - messagebus-api - - - org.opendaylight.controller - messagebus-spi - - - org.opendaylight.controller - messagebus-util - - - ${project.groupId} - sal-netconf-connector - - - org.opendaylight.mdsal - mdsal-binding-dom-codec-api - - - - - org.opendaylight.mdsal - mdsal-binding-test-utils - - - diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java deleted file mode 100644 index 3cdd66052a..0000000000 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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 topicIds = getTopicsForNotification(notificationPath); - topicIds.add(topicId); - notificationTopicMap.put(notificationPath, topicIds); - return true; - } - - @Override - synchronized void unRegisterNotificationTopic(final TopicId topicId) { - List notificationPathToRemove = new ArrayList<>(); - for (SchemaPath notifKey : notificationTopicMap.keySet()) { - Set 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(); - } -} diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java deleted file mode 100644 index 72d27ff78f..0000000000 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java +++ /dev/null @@ -1,303 +0,0 @@ -/* - * 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 urnPrefixToStreamMap; // key = urnPrefix, value = StreamName - - /** - * Map notification uri -> registrations. - */ - private final Multimap - 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 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 availableStreams = getAvailableStreams(); - LOG.debug("Stream configuration compare..."); - for (Entry 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 getAvailableStreams() { - final Collection 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> joinTopic(final JoinTopicInput input) { - LOG.debug("Join topic {} on {}", input.getTopicId().getValue(), mount.getNodeId()); - final NotificationPattern notificationPattern = input.getNotificationPattern(); - final List matchingNotifications = getMatchingNotifications(notificationPattern); - return registerTopic(input.getTopicId(), matchingNotifications); - - } - - @Override - public ListenableFuture> disJoinTopic(final DisJoinTopicInput input) { - for (NotificationTopicRegistration reg : notificationTopicRegistrations.values()) { - reg.unRegisterNotificationTopic(input.getTopicId()); - } - return Util.resultRpcSuccessFor(new DisJoinTopicOutputBuilder().build()); - } - - private synchronized ListenableFuture> registerTopic( - final TopicId topicId, - final List 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 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 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 getMatchingNotifications(final NotificationPattern notificationPattern) { - final String regex = notificationPattern.getValue(); - - final Pattern pattern = Pattern.compile(regex); - List 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 getAvailableNotifications() { - - final List 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; - } - -} diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java deleted file mode 100644 index e9fcfc0980..0000000000 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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, 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 NETCONF_DEVICE_PATH = InstanceIdentifier.create(NetworkTopology.class) - .child(Topology.class, NETCONF_TOPOLOGY_KEY).child(Node.class); - - private Map streamMap; - private final ConcurrentHashMap, NetconfEventSourceRegistration> registrationMap = - new ConcurrentHashMap<>(); - private final DOMNotificationPublishService publishService; - private final DOMMountPointService domMounts; - private ListenerRegistration 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> changes) { - for (DataTreeModification change: changes) { - LOG.debug("DataTreeModification: {}", change); - final DataObjectModification rootNode = change.getRootNode(); - final InstanceIdentifier 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 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 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(); - } -} diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMount.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMount.java deleted file mode 100644 index 5f99d1e370..0000000000 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMount.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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 getService(final DOMMountPoint mountPoint, final Class service) { - final Optional 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 invokeCreateSubscription(final Stream stream, - final Optional 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 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 getAvailableStreams() throws InterruptedException, ExecutionException { - final Optional> 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 registerNotificationListener(final DOMNotificationListener listener, - final SchemaPath notificationPath) { - return notificationService.registerNotificationListener(listener, notificationPath.asAbsolute()); - } - -} diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java deleted file mode 100644 index ede15b0210..0000000000 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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 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 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> 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 = netconfEventSourceManager.getDomMounts() - .getMountPoint(domMountPath(node.getNodeId())); - EventSourceRegistration 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(); - } - -} diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NotificationTopicRegistration.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NotificationTopicRegistration.java deleted file mode 100644 index 286ac1db35..0000000000 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NotificationTopicRegistration.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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> 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 getTopicsForNotification(final SchemaPath notificationPath) { - final Set 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 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; - } - -} diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistration.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistration.java deleted file mode 100644 index d675217955..0000000000 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistration.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * 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> - 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 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 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 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 registration = - mountPoint.registerNotificationListener(netconfEventSource, notificationPath); - notificationRegistrationMap.put(notificationPath, registration); - Set topicIds = getTopicsForNotification(notificationPath); - topicIds.add(topicId); - - notificationTopicMap.put(notificationPath, topicIds); - return true; - } - - @Override - synchronized void unRegisterNotificationTopic(final TopicId topicId) { - List notificationPathToRemove = new ArrayList<>(); - for (SchemaPath notifKey : notificationTopicMap.keySet()) { - Set topicList = notificationTopicMap.get(notifKey); - if (topicList != null) { - topicList.remove(topicId); - if (topicList.isEmpty()) { - notificationPathToRemove.add(notifKey); - } - } - } - for (SchemaPath notifKey : notificationPathToRemove) { - notificationTopicMap.remove(notifKey); - ListenerRegistration reg = notificationRegistrationMap.remove(notifKey); - if (reg != null) { - reg.close(); - } - } - } - - @Override - public void close() { - closeStream(); - } - -} diff --git a/netconf/messagebus-netconf/src/main/resources/OSGI-INF/blueprint/messagebus-netconf.xml b/netconf/messagebus-netconf/src/main/resources/OSGI-INF/blueprint/messagebus-netconf.xml deleted file mode 100644 index f7d9966ca9..0000000000 --- a/netconf/messagebus-netconf/src/main/resources/OSGI-INF/blueprint/messagebus-netconf.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/AbstractCodecTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/AbstractCodecTest.java deleted file mode 100644 index caf6f5f37a..0000000000 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/AbstractCodecTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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; - } -} diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistrationTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistrationTest.java deleted file mode 100644 index 78b25847da..0000000000 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistrationTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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 notificationTopicIds = registration.getTopicsForNotification( - ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath()); - assertNotNull(notificationTopicIds); - assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3)); - - registration.unRegisterNotificationTopic(topic3); - final Set 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 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> 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 diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java deleted file mode 100644 index df38c0904d..0000000000 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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 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 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>> 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 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(); - } - -} diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMountTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMountTest.java deleted file mode 100644 index ec06c223b4..0000000000 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceMountTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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 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 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 actual = (Optional) 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 captor = ArgumentCaptor.forClass(ContainerNode.class); - verify(rpcService).invokeRpc(eq(type), captor.capture()); - Assert.assertEquals(STREAM_1, getStreamName(captor.getValue())); - final Optional date = (Optional) getDate(captor.getValue()); - Assert.assertFalse(date.isPresent()); - - } - - @Test - public void testGetAvailableStreams() throws Exception { - final Collection availableStreams = mount.getAvailableStreams(); - Assert.assertEquals(2, availableStreams.size()); - final Collection 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 diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java deleted file mode 100644 index 7ddbd9ea7b..0000000000 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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 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 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 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 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 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 diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfTestUtils.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfTestUtils.java deleted file mode 100644 index d6fcceab0d..0000000000 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfTestUtils.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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 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 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 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 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 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(); - } - -} diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistrationTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistrationTest.java deleted file mode 100644 index 436245400a..0000000000 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/StreamNotificationTopicRegistrationTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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 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 notificationTopicIds = registration.getTopicsForNotification( - ConnectionNotificationTopicRegistration.EVENT_SOURCE_STATUS_PATH.asSchemaPath()); - assertNotNull(notificationTopicIds); - assertThat(notificationTopicIds, hasItems(topic1, topic2, topic3)); - - registration.unRegisterNotificationTopic(topic3); - final Set 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 diff --git a/netconf/pom.xml b/netconf/pom.xml index faa5cf8e6c..42e97bd76c 100644 --- a/netconf/pom.xml +++ b/netconf/pom.xml @@ -51,7 +51,6 @@ netconf-topology-impl netconf-topology-singleton sal-netconf-connector - messagebus-netconf yanglib models tools -- 2.36.6