Small improvement in Xponder-in/out link creation
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / NetConfTopologyListener.java
index 58830f5111a424fae5ce86c55b29688d42fbe83c..b2c5001d4aa484983a4a9f58c36fe63f192fd1b3 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.transportpce.networkmodel;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -14,20 +15,16 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
-
 import javax.annotation.Nonnull;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.binding.api.MountPoint;
-import org.opendaylight.controller.md.sal.binding.api.NotificationService;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.MountPoint;
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
 import org.opendaylight.transportpce.common.StringConstants;
-import org.opendaylight.transportpce.common.Timeouts;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.networkmodel.dto.NodeRegistration;
 import org.opendaylight.transportpce.networkmodel.dto.NodeRegistration22;
@@ -37,27 +34,21 @@ import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener
 import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener221;
 import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener;
 import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener221;
-import org.opendaylight.transportpce.networkmodel.listeners.LldpListener;
-import org.opendaylight.transportpce.networkmodel.listeners.LldpListener221;
 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.lldp.rev161014.OrgOpenroadmLldpListener;
 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.NotificationsService;
 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.opendaylight.netconf.node.topology.rev150114.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
 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.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,26 +57,25 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
     private static final Logger LOG = LoggerFactory.getLogger(NetConfTopologyListener.class);
 
     private final NetworkModelService networkModelService;
-    private final R2RLinkDiscovery linkDiscovery;
     private final DataBroker dataBroker;
     private final DeviceTransactionManager deviceTransactionManager;
     private final Map<String, NodeRegistration> registrations;
     private final Map<String, NodeRegistration22> registrations22;
 
     public NetConfTopologyListener(final NetworkModelService networkModelService, final DataBroker dataBroker,
-            final R2RLinkDiscovery linkDiscovery, DeviceTransactionManager deviceTransactionManager) {
+             DeviceTransactionManager deviceTransactionManager) {
         this.networkModelService = networkModelService;
-        this.linkDiscovery = linkDiscovery;
         this.dataBroker = dataBroker;
         this.deviceTransactionManager = deviceTransactionManager;
         this.registrations = new ConcurrentHashMap<>();
         this.registrations22 = new ConcurrentHashMap<>();
     }
 
+    @SuppressFBWarnings(
+        value = "RV_RETURN_VALUE_IGNORED",
+        justification = "nothing to verify once rpc has been sent")
     private void onDeviceConnected(final String nodeId, String openRoadmVersion) {
         LOG.info("onDeviceConnected: {}", nodeId);
-        LOG.info(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1);
-        LOG.info(openRoadmVersion);
         Optional<MountPoint> mountPointOpt = this.deviceTransactionManager.getDeviceMountPoint(nodeId);
         MountPoint mountPoint;
         if (mountPointOpt.isPresent()) {
@@ -96,7 +86,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
         }
 
         final Optional<NotificationService> notificationService =
-                mountPoint.getService(NotificationService.class).toJavaUtil();
+                mountPoint.getService(NotificationService.class);
         if (!notificationService.isPresent()) {
             LOG.error("Failed to get RpcService for node {}", nodeId);
             return;
@@ -115,29 +105,24 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
                 accessDeOperationasNotificationListenerRegistration =
                 notificationService.get().registerNotificationListener(deOperationsListener);
 
-            final OrgOpenroadmDeviceListener deviceListener = new DeviceListener();
+            final OrgOpenroadmDeviceListener deviceListener = new DeviceListener(this.deviceTransactionManager,
+                    nodeId, this.networkModelService);
             LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
             final ListenerRegistration<OrgOpenroadmDeviceListener> accessDeviceNotificationListenerRegistration =
                 notificationService.get().registerNotificationListener(deviceListener);
 
-            final OrgOpenroadmLldpListener lldpListener = new LldpListener(this.linkDiscovery, nodeId);
-            LOG.info("Registering notification listener on OrgOpenroadmLldpListener for node: {}", nodeId);
-            final ListenerRegistration<OrgOpenroadmLldpListener> accessLldpNotificationListenerRegistration =
-                notificationService.get().registerNotificationListener(lldpListener);
-
-            final OrgOpenroadmTcaListener tcaListener = new TcaListener();
+            TcaListener tcaListener = new TcaListener();
             LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
             final ListenerRegistration<OrgOpenroadmTcaListener> accessTcaNotificationListenerRegistration =
                 notificationService.get().registerNotificationListener(tcaListener);
 
-            String streamName = "NETCONF"; //getSupportedStream(nodeId);
+            String streamName = "NETCONF";
 
             if (streamName == null) {
                 streamName = "OPENROADM";
             }
 
-            final Optional<RpcConsumerRegistry> service = mountPoint.getService(RpcConsumerRegistry.class)
-                .toJavaUtil();
+            final Optional<RpcConsumerRegistry> service = mountPoint.getService(RpcConsumerRegistry.class);
             if (service.isPresent()) {
                 final NotificationsService rpcService = service.get().getRpcService(NotificationsService.class);
                 if (rpcService == null) {
@@ -180,13 +165,6 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
                 .OrgOpenroadmDeviceListener> accessDeviceNotificationListenerRegistration =
                 notificationService.get().registerNotificationListener(deviceListener);
 
-            final org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.OrgOpenroadmLldpListener
-                lldpListener = new LldpListener221(linkDiscovery, nodeId);
-            LOG.info("Registering notification listener on OrgOpenroadmLldpListener for node: {}", nodeId);
-            final ListenerRegistration<org.opendaylight.yang.gen.v1.http.org.openroadm
-                .lldp.rev181019.OrgOpenroadmLldpListener> accessLldpNotificationListenerRegistration =
-                notificationService.get().registerNotificationListener(lldpListener);
-
             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);
@@ -196,11 +174,10 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
 
 
             String streamName = "NETCONF";
-            //getSupportedStream(nodeId);
             if (streamName == null) {
                 streamName = "OPENROADM";
             }
-            final Optional<RpcConsumerRegistry> service = mountPoint.getService(RpcConsumerRegistry.class).toJavaUtil();
+            final Optional<RpcConsumerRegistry> service = mountPoint.getService(RpcConsumerRegistry.class);
             if (service.isPresent()) {
                 final NotificationsService rpcService = service.get().getRpcService(NotificationsService.class);
                 if (rpcService == null) {
@@ -218,7 +195,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
             NodeRegistration22 nodeRegistration22 = new NodeRegistration22(nodeId,
                 accessAlarmNotificationListenerRegistration,
                 accessDeOperationasNotificationListenerRegistration, accessDeviceNotificationListenerRegistration,
-                accessLldpNotificationListenerRegistration, accessTcaNotificationListenerRegistration);
+                null, accessTcaNotificationListenerRegistration);
             registrations22.put(nodeId, nodeRegistration22);
 
         }
@@ -232,13 +209,14 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
             nodeRegistration.getAccessAlarmNotificationListenerRegistration().close();
             nodeRegistration.getAccessDeOperationasNotificationListenerRegistration().close();
             nodeRegistration.getAccessDeviceNotificationListenerRegistration().close();
-            nodeRegistration.getAccessLldpNotificationListenerRegistration().close();
             nodeRegistration.getAccessTcaNotificationListenerRegistration().close();
         }
     }
 
     @Override
-    @SuppressWarnings("checkstyle:FallThrough")
+    @SuppressFBWarnings(
+        value = "SF_SWITCH_FALLTHROUGH",
+        justification = "intentional fallthrough")
     public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> changes) {
         LOG.info("onDataTreeChanged");
         for (DataTreeModification<Node> change : changes) {
@@ -251,7 +229,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
                 if (rootNode.getDataBefore() != null) {
                     String nodeId = rootNode.getDataBefore().key().getNodeId().getValue();
                     LOG.info("Node {} deleted", nodeId);
-                    this.networkModelService.deleteOpenROADMnode(nodeId);
+                    this.networkModelService.deleteOpenRoadmnode(nodeId);
                     onDeviceDisConnected(nodeId);
                 } else {
                     LOG.error("rootNode.getDataBefore is null !");
@@ -265,6 +243,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
                 switch (rootNode.getModificationType()) {
                     case WRITE:
                         LOG.info("Node added: {}", nodeId);
+                    //fallthrough
                     case SUBTREE_MODIFIED:
                         NetconfNodeConnectionStatus.ConnectionStatus connectionStatus =
                                 netconfNode.getConnectionStatus();
@@ -278,13 +257,13 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
                                 LOG.info("OpenROADM node detected: {} {}", nodeId, connectionStatus.name());
                                 switch (connectionStatus) {
                                     case Connected:
-                                        this.networkModelService.createOpenROADMnode(nodeId, deviceCapabilities.get(0)
+                                        this.networkModelService.createOpenRoadmNode(nodeId, deviceCapabilities.get(0)
                                             .getCapability());
                                         onDeviceConnected(nodeId,deviceCapabilities.get(0).getCapability());
                                         break;
                                     case Connecting:
                                     case UnableToConnect:
-                                        this.networkModelService.setOpenROADMnodeStatus(nodeId, connectionStatus);
+                                        this.networkModelService.setOpenRoadmNodeStatus(nodeId, connectionStatus);
                                         onDeviceDisConnected(nodeId);
                                         break;
                                     default:
@@ -306,7 +285,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
     }
 
 
-    private String getSupportedStream(String nodeId) {
+    /*private String getSupportedStream(String nodeId) {
         InstanceIdentifier<Streams> streamsIID = InstanceIdentifier.create(Netconf.class).child(Streams.class);
         try {
             Optional<Streams> ordmInfoObject =
@@ -328,5 +307,5 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
             LOG.error("NullPointerException thrown while getting Info from a non Open ROADM device {}", nodeId);
             return "NETCONF";
         }
-    }
+    }*/
 }