Refactor (un)registration of device listeners 51/95751/2
authorGilles Thouenon <gilles.thouenon@orange.com>
Mon, 12 Apr 2021 07:07:38 +0000 (09:07 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Mon, 12 Apr 2021 16:11:19 +0000 (18:11 +0200)
- simplify the way to register/unregister node listeners, taking into
acount the different device versions
- adapt UT of NetConfTopologyListener class

JIRA: TRNSPRTPCE-430
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: Id8d1d04ac2f43035fb3de6e71d9a77a77a14faec

networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration22.java [deleted file]
networkmodel/src/test/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListenerTest.java

index 34d2a1ea8f38f3b377c4c28d2d031dc8d30e0a68..43e4c64e449a5e4ebf32a7d9ae535d89b1f3ae1a 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.transportpce.networkmodel;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collection;
 import java.util.Map;
@@ -25,20 +26,7 @@ import org.opendaylight.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
 import org.opendaylight.transportpce.networkmodel.dto.NodeRegistration;
-import org.opendaylight.transportpce.networkmodel.dto.NodeRegistration22;
-import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener;
-import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener221;
-import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener;
-import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener221;
-import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener121;
-import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener221;
-import org.opendaylight.transportpce.networkmodel.listeners.TcaListener;
-import org.opendaylight.transportpce.networkmodel.listeners.TcaListener221;
 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev161014.OrgOpenroadmAlarmListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev161014.OrgOpenroadmDeOperationsListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.tca.rev161014.OrgOpenroadmTcaListener;
 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.netconf.notification._1._0.rev080714.CreateSubscriptionOutput;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.NotificationsService;
@@ -47,7 +35,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev15
 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.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,7 +47,6 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
     private final DataBroker dataBroker;
     private final DeviceTransactionManager deviceTransactionManager;
     private final Map<String, NodeRegistration> registrations;
-    private final Map<String, NodeRegistration22> registrations22;
     private final PortMapping portMapping;
 
     public NetConfTopologyListener(final NetworkModelService networkModelService, final DataBroker dataBroker,
@@ -69,7 +55,6 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
         this.dataBroker = dataBroker;
         this.deviceTransactionManager = deviceTransactionManager;
         this.registrations = new ConcurrentHashMap<>();
-        this.registrations22 = new ConcurrentHashMap<>();
         this.portMapping = portMapping;
     }
 
@@ -85,13 +70,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
             switch (rootNode.getModificationType()) {
                 case DELETE:
                     this.networkModelService.deleteOpenRoadmnode(nodeId);
-                    String deviceVersion = netconfNodeBefore
-                        .getAvailableCapabilities().getAvailableCapability().stream()
-                        .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME))
-                        .sorted((c1, c2) -> c1.getCapability().compareTo(c2.getCapability()))
-                        .findFirst()
-                        .get().getCapability();
-                    onDeviceDisConnected(nodeId, deviceVersion);
+                    onDeviceDisConnected(nodeId);
                     LOG.info("Device {} correctly disconnected from controller", nodeId);
                     break;
                 case WRITE:
@@ -102,7 +81,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
                         Optional<AvailableCapability> deviceCapabilityOpt = netconfNodeAfter
                             .getAvailableCapabilities().getAvailableCapability().stream()
                             .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME))
-                            .sorted((c1, c2) -> c1.getCapability().compareTo(c2.getCapability()))
+                            .sorted((c1, c2) -> c2.getCapability().compareTo(c1.getCapability()))
                             .findFirst();
                         if (deviceCapabilityOpt.isEmpty()) {
                             LOG.error("Unable to get openroadm-device-capability");
@@ -140,105 +119,18 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
             LOG.error(RPC_SERVICE_FAILED, nodeId);
             return;
         }
-        switch (openRoadmVersion) {
-            case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
-                NodeRegistration node121Registration = registrateNode121Listeners(nodeId, notificationService.get());
-                registrations.put(nodeId, node121Registration);
-                break;
-            case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
-                NodeRegistration22 node221Registration = registrateNode221Listeners(nodeId, notificationService.get());
-                registrations22.put(nodeId, node221Registration);
-                break;
-            default:
-                break;
-        }
+        NodeRegistration nodeRegistration = new NodeRegistration(nodeId, openRoadmVersion,
+            notificationService.get(), this.dataBroker, this.portMapping);
+        nodeRegistration.registerListeners();
+        registrations.put(nodeId, nodeRegistration);
         String streamName = "NETCONF";
         subscribeStream(mountPoint, streamName, nodeId);
     }
 
-    private void onDeviceDisConnected(final String nodeId, String openRoadmVersion) {
+    private void onDeviceDisConnected(final String nodeId) {
         LOG.info("onDeviceDisConnected: {}", nodeId);
-        switch (openRoadmVersion) {
-            case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
-                NodeRegistration nodeRegistration = this.registrations.remove(nodeId);
-                if (nodeRegistration != null) {
-                    nodeRegistration.getAccessAlarmNotificationListenerRegistration().close();
-                    nodeRegistration.getAccessDeOperationasNotificationListenerRegistration().close();
-                    nodeRegistration.getAccessDeviceNotificationListenerRegistration().close();
-                    nodeRegistration.getAccessTcaNotificationListenerRegistration().close();
-                }
-                break;
-            case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
-                NodeRegistration22 nodeRegistration221 = this.registrations22.remove(nodeId);
-                if (nodeRegistration221 != null) {
-                    nodeRegistration221.getAccessAlarmNotificationListenerRegistration().close();
-                    nodeRegistration221.getAccessDeOperationasNotificationListenerRegistration().close();
-                    nodeRegistration221.getAccessDeviceNotificationListenerRegistration().close();
-                    nodeRegistration221.getAccessTcaNotificationListenerRegistration().close();
-                }
-                break;
-            default:
-                break;
-        }
-    }
-
-    private NodeRegistration registrateNode121Listeners(String nodeId, NotificationService notificationService) {
-        final OrgOpenroadmAlarmListener alarmListener = new AlarmNotificationListener(this.dataBroker);
-        LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
-        final ListenerRegistration<OrgOpenroadmAlarmListener> accessAlarmNotificationListenerRegistration =
-            notificationService.registerNotificationListener(alarmListener);
-
-        final OrgOpenroadmDeOperationsListener deOperationsListener = new DeOperationsListener();
-        LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
-        final ListenerRegistration<OrgOpenroadmDeOperationsListener>
-            accessDeOperationasNotificationListenerRegistration =
-            notificationService.registerNotificationListener(deOperationsListener);
-
-        final OrgOpenroadmDeviceListener deviceListener = new DeviceListener121(nodeId, this.portMapping);
-        LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
-        final ListenerRegistration<OrgOpenroadmDeviceListener> accessDeviceNotificationListenerRegistration =
-            notificationService.registerNotificationListener(deviceListener);
-
-        TcaListener tcaListener = new TcaListener();
-        LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
-        final ListenerRegistration<OrgOpenroadmTcaListener> accessTcaNotificationListenerRegistration =
-            notificationService.registerNotificationListener(tcaListener);
-        return new NodeRegistration(nodeId, accessAlarmNotificationListenerRegistration,
-            accessDeOperationasNotificationListenerRegistration, accessDeviceNotificationListenerRegistration,
-            null, accessTcaNotificationListenerRegistration);
-    }
-
-    private NodeRegistration22 registrateNode221Listeners(String nodeId, NotificationService notificationService) {
-        final org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev181019.OrgOpenroadmAlarmListener
-            alarmListener = new AlarmNotificationListener221(dataBroker);
-        LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
-        final ListenerRegistration<org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev181019
-            .OrgOpenroadmAlarmListener> accessAlarmNotificationListenerRegistration =
-            notificationService.registerNotificationListener(alarmListener);
-
-        final org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev181019
-            .OrgOpenroadmDeOperationsListener deOperationsListener = new DeOperationsListener221();
-        LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
-        final ListenerRegistration<org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev181019
-            .OrgOpenroadmDeOperationsListener> accessDeOperationasNotificationListenerRegistration =
-            notificationService.registerNotificationListener(deOperationsListener);
-
-        final org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OrgOpenroadmDeviceListener
-            deviceListener = new DeviceListener221(nodeId, this.portMapping);
-        LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
-        final ListenerRegistration<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019
-            .OrgOpenroadmDeviceListener> accessDeviceNotificationListenerRegistration =
-            notificationService.registerNotificationListener(deviceListener);
-
-        final org.opendaylight.yang.gen.v1.http.org.openroadm.tca.rev181019.OrgOpenroadmTcaListener
-            tcaListener = new TcaListener221();
-        LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
-        final ListenerRegistration<org.opendaylight.yang.gen.v1.http.org.openroadm.tca.rev181019
-            .OrgOpenroadmTcaListener> accessTcaNotificationListenerRegistration =
-            notificationService.registerNotificationListener(tcaListener);
-        return new NodeRegistration22(nodeId, accessAlarmNotificationListenerRegistration,
-            accessDeOperationasNotificationListenerRegistration, accessDeviceNotificationListenerRegistration,
-            null, accessTcaNotificationListenerRegistration);
+        NodeRegistration nodeRegistration = this.registrations.remove(nodeId);
+        nodeRegistration.unregisterListeners();
     }
 
     private boolean subscribeStream(MountPoint mountPoint, String streamName, String nodeId) {
@@ -263,4 +155,15 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
         }
         return true;
     }
+
+    @VisibleForTesting
+    public NetConfTopologyListener(final NetworkModelService networkModelService, final DataBroker dataBroker,
+        DeviceTransactionManager deviceTransactionManager, PortMapping portMapping,
+        Map<String, NodeRegistration> registrations) {
+        this.networkModelService = networkModelService;
+        this.dataBroker = dataBroker;
+        this.deviceTransactionManager = deviceTransactionManager;
+        this.portMapping = portMapping;
+        this.registrations = registrations;
+    }
 }
index e802091b5e2d7fcaa1997dfa5975e1914e649231..8bcfaab596df8099dd5be4c2ed4e75719c86cfb5 100644 (file)
  */
 package org.opendaylight.transportpce.networkmodel.dto;
 
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.transportpce.common.StringConstants;
+import org.opendaylight.transportpce.common.mapping.PortMapping;
+import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener;
+import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener221;
+import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener;
+import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener221;
+import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener121;
+import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener221;
+import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener710;
+import org.opendaylight.transportpce.networkmodel.listeners.TcaListener;
+import org.opendaylight.transportpce.networkmodel.listeners.TcaListener221;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev161014.OrgOpenroadmAlarmListener;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev161014.OrgOpenroadmDeOperationsListener;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.OrgOpenroadmLldpListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.tca.rev161014.OrgOpenroadmTcaListener;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class NodeRegistration {
-
+    private static final Logger LOG = LoggerFactory.getLogger(NodeRegistration.class);
     private final String nodeId;
-    private final ListenerRegistration<OrgOpenroadmAlarmListener> accessAlarmNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmDeOperationsListener>
-        accessDeOperationasNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmDeviceListener> accessDeviceNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmLldpListener> accessLldpNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmTcaListener> accessTcaNotificationListenerRegistration;
+    private final String nodeVersion;
+    private final NotificationService notificationService;
+    private final DataBroker dataBroker;
+    private final PortMapping portMapping;
+    private final List<ListenerRegistration<?>> listeners;
 
-    public NodeRegistration(String nodeId,
-            ListenerRegistration<OrgOpenroadmAlarmListener> accessAlarmNotificationListenerRegistration,
-            ListenerRegistration<OrgOpenroadmDeOperationsListener> accessDeOperationasNotificationListenerRegistration,
-            ListenerRegistration<OrgOpenroadmDeviceListener> accessDeviceNotificationListenerRegistration,
-            ListenerRegistration<OrgOpenroadmLldpListener> accessLldpNotificationListenerRegistration,
-            ListenerRegistration<OrgOpenroadmTcaListener> accessTcaNotificationListenerRegistration) {
+    public NodeRegistration(String nodeId, String nodeVersion, NotificationService notificationService,
+            DataBroker dataBroker, PortMapping portMapping) {
         this.nodeId = nodeId;
-        this.accessAlarmNotificationListenerRegistration = accessAlarmNotificationListenerRegistration;
-        this.accessDeOperationasNotificationListenerRegistration = accessDeOperationasNotificationListenerRegistration;
-        this.accessDeviceNotificationListenerRegistration = accessDeviceNotificationListenerRegistration;
-        this.accessLldpNotificationListenerRegistration = accessLldpNotificationListenerRegistration;
-        this.accessTcaNotificationListenerRegistration = accessTcaNotificationListenerRegistration;
+        this.nodeVersion = nodeVersion;
+        this.notificationService = notificationService;
+        this.dataBroker = dataBroker;
+        this.portMapping = portMapping;
+        listeners = new ArrayList<ListenerRegistration<?>>();
     }
 
-    public String getNodeId() {
-        return nodeId;
+    public void registerListeners() {
+        switch (this.nodeVersion) {
+            case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
+                registerListeners121();
+                break;
+            case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
+                registerListeners221();
+                break;
+            case StringConstants.OPENROADM_DEVICE_VERSION_7_1_0:
+                registerListeners710();
+                break;
+            default:
+                LOG.debug("Unable to register listeners - unknown device version for {}", this.nodeId);
+                break;
+        }
     }
 
-    public ListenerRegistration<OrgOpenroadmAlarmListener> getAccessAlarmNotificationListenerRegistration() {
-        return accessAlarmNotificationListenerRegistration;
+    public void unregisterListeners() {
+        LOG.info("Unregistering notification listeners for node: {}", this.nodeId);
+        for (ListenerRegistration<?> listenerRegistration : listeners) {
+            listenerRegistration.close();
+        }
     }
 
-    public ListenerRegistration<OrgOpenroadmDeOperationsListener>
-        getAccessDeOperationasNotificationListenerRegistration() {
-        return accessDeOperationasNotificationListenerRegistration;
-    }
+    private void registerListeners121() {
+        OrgOpenroadmAlarmListener alarmListener = new AlarmNotificationListener(this.dataBroker);
+        LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
+        listeners.add(notificationService.registerNotificationListener(alarmListener));
 
-    public ListenerRegistration<OrgOpenroadmDeviceListener> getAccessDeviceNotificationListenerRegistration() {
-        return accessDeviceNotificationListenerRegistration;
-    }
+        OrgOpenroadmDeOperationsListener deOperationsListener = new DeOperationsListener();
+        LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
+        listeners.add(notificationService.registerNotificationListener(deOperationsListener));
+
+        OrgOpenroadmDeviceListener deviceListener = new DeviceListener121(nodeId, this.portMapping);
+        LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
+        listeners.add(notificationService.registerNotificationListener(deviceListener));
 
-    public ListenerRegistration<OrgOpenroadmLldpListener> getAccessLldpNotificationListenerRegistration() {
-        return accessLldpNotificationListenerRegistration;
+        TcaListener tcaListener = new TcaListener();
+        LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
+        listeners.add(notificationService.registerNotificationListener(tcaListener));
     }
 
-    public ListenerRegistration<OrgOpenroadmTcaListener> getAccessTcaNotificationListenerRegistration() {
-        return accessTcaNotificationListenerRegistration;
+    private void registerListeners221() {
+        AlarmNotificationListener221 alarmListener = new AlarmNotificationListener221(dataBroker);
+        LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
+        listeners.add(notificationService.registerNotificationListener(alarmListener));
+
+        DeOperationsListener221 deOperationsListener = new DeOperationsListener221();
+        LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
+        listeners.add(notificationService.registerNotificationListener(deOperationsListener));
+
+        DeviceListener221 deviceListener = new DeviceListener221(nodeId, this.portMapping);
+        LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
+        listeners.add(notificationService.registerNotificationListener(deviceListener));
+
+        TcaListener221 tcaListener = new TcaListener221();
+        LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
+        listeners.add(notificationService.registerNotificationListener(tcaListener));
     }
 
+    private void registerListeners710() {
+        DeviceListener710 deviceListener = new DeviceListener710(nodeId, this.portMapping);
+        LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
+        listeners.add(notificationService.registerNotificationListener(deviceListener));
+    }
 }
diff --git a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration22.java b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/dto/NodeRegistration22.java
deleted file mode 100644 (file)
index 9178864..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright © 2016 AT&T 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.transportpce.networkmodel.dto;
-
-import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev181019.OrgOpenroadmAlarmListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev181019.OrgOpenroadmDeOperationsListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OrgOpenroadmDeviceListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.OrgOpenroadmLldpListener;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.tca.rev181019.OrgOpenroadmTcaListener;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-
-public class NodeRegistration22 {
-
-    private final String nodeId;
-    private final ListenerRegistration<OrgOpenroadmAlarmListener> accessAlarmNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmDeOperationsListener>
-        accessDeOperationasNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmDeviceListener> accessDeviceNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmLldpListener> accessLldpNotificationListenerRegistration;
-    private final ListenerRegistration<OrgOpenroadmTcaListener> accessTcaNotificationListenerRegistration;
-
-    public NodeRegistration22(String nodeId,
-                              ListenerRegistration<OrgOpenroadmAlarmListener>
-                                  accessAlarmNotificationListenerRegistration,
-                              ListenerRegistration<OrgOpenroadmDeOperationsListener>
-                                  accessDeOperationasNotificationListenerRegistration,
-                              ListenerRegistration<OrgOpenroadmDeviceListener>
-                                  accessDeviceNotificationListenerRegistration,
-                              ListenerRegistration<OrgOpenroadmLldpListener>
-                                  accessLldpNotificationListenerRegistration,
-                              ListenerRegistration<OrgOpenroadmTcaListener>
-                                  accessTcaNotificationListenerRegistration) {
-        this.nodeId = nodeId;
-        this.accessAlarmNotificationListenerRegistration = accessAlarmNotificationListenerRegistration;
-        this.accessDeOperationasNotificationListenerRegistration = accessDeOperationasNotificationListenerRegistration;
-        this.accessDeviceNotificationListenerRegistration = accessDeviceNotificationListenerRegistration;
-        this.accessLldpNotificationListenerRegistration = accessLldpNotificationListenerRegistration;
-        this.accessTcaNotificationListenerRegistration = accessTcaNotificationListenerRegistration;
-    }
-
-    public String getNodeId() {
-        return nodeId;
-    }
-
-    public ListenerRegistration<OrgOpenroadmAlarmListener> getAccessAlarmNotificationListenerRegistration() {
-        return accessAlarmNotificationListenerRegistration;
-    }
-
-    public ListenerRegistration<OrgOpenroadmDeOperationsListener>
-        getAccessDeOperationasNotificationListenerRegistration() {
-        return accessDeOperationasNotificationListenerRegistration;
-    }
-
-    public ListenerRegistration<OrgOpenroadmDeviceListener> getAccessDeviceNotificationListenerRegistration() {
-        return accessDeviceNotificationListenerRegistration;
-    }
-
-    public ListenerRegistration<OrgOpenroadmLldpListener> getAccessLldpNotificationListenerRegistration() {
-        return accessLldpNotificationListenerRegistration;
-    }
-
-    public ListenerRegistration<OrgOpenroadmTcaListener> getAccessTcaNotificationListenerRegistration() {
-        return accessTcaNotificationListenerRegistration;
-    }
-
-}
index 7085174b85a36f2449544da115d35a5f1ea865fc..4e8a5e908b6270d91c5df7b6d2d8ad65bbb20c56 100644 (file)
@@ -20,6 +20,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -29,6 +30,7 @@ import org.opendaylight.mdsal.binding.api.DataObjectModification;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
+import org.opendaylight.transportpce.networkmodel.dto.NodeRegistration;
 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -60,12 +62,15 @@ public class NetConfTopologyListenerTest {
     private DeviceTransactionManager deviceTransactionManager;
     @Mock
     private PortMapping portMapping;
+    @Mock
+    private Map<String, NodeRegistration> registrations;
 
     @Test
     public void testOnDataTreeChangedWhenDeleteNode() {
         final DataObjectModification<Node> node = mock(DataObjectModification.class);
         final Collection<DataTreeModification<Node>> changes = new HashSet<>();
         final DataTreeModification<Node> ch = mock(DataTreeModification.class);
+        final NodeRegistration nodeRegistration = mock(NodeRegistration.class);
         changes.add(ch);
         when(ch.getRootNode()).thenReturn(node);
 
@@ -73,13 +78,16 @@ public class NetConfTopologyListenerTest {
             OPENROADM_DEVICE_VERSION_2_2_1);
         when(node.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
         when(node.getDataBefore()).thenReturn(netconfNode);
+        when(registrations.remove(anyString())).thenReturn(nodeRegistration);
+
         NetConfTopologyListener listener = new NetConfTopologyListener(networkModelService, dataBroker,
-            deviceTransactionManager, portMapping);
+            deviceTransactionManager, portMapping, registrations);
         listener.onDataTreeChanged(changes);
         verify(ch, times(1)).getRootNode();
         verify(node, times(1)).getModificationType();
         verify(node, times(3)).getDataBefore();
         verify(networkModelService, times(1)).deleteOpenRoadmnode(anyString());
+        verify(nodeRegistration, times(1)).unregisterListeners();
     }
 
     @Test