Upgrade lightynode to Ca-SR1
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / listeners / DeviceListener221.java
index e718d02c781547a52288c1d97f1c408ba9edf34c..04d9969d924cd584d10e9ece2795ede14f0952fb 100644 (file)
@@ -8,22 +8,25 @@
 
 package org.opendaylight.transportpce.networkmodel.listeners;
 
-import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.ChangeNotification;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.CreateTechInfoNotification;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OrgOpenroadmDeviceListener;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OtdrScanResult;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.change.notification.Edit;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.Ports;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacks;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface;
+import org.opendaylight.yangtools.binding.DataObject;
+import org.opendaylight.yangtools.binding.DataObjectStep;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class DeviceListener221 implements OrgOpenroadmDeviceListener {
+public class DeviceListener221 {
 
     private static final Logger LOG = LoggerFactory.getLogger(DeviceListener221.class);
     private final String nodeId;
@@ -35,15 +38,22 @@ public class DeviceListener221 implements OrgOpenroadmDeviceListener {
         this.portMapping = portMapping;
     }
 
+    public CompositeListener getCompositeListener() {
+        return new CompositeListener(Set.of(
+            new CompositeListener.Component<>(ChangeNotification.class, this::onChangeNotification),
+            new CompositeListener.Component<>(CreateTechInfoNotification.class, this::onCreateTechInfoNotification),
+            new CompositeListener.Component<>(OtdrScanResult.class, this::onOtdrScanResult)
+        ));
+    }
+
     /**
      * Callback for change-notification.
      *
      * @param notification
      *            ChangeNotification object
      */
-    @Override
-    @SuppressWarnings("unchecked")
-    public void onChangeNotification(ChangeNotification notification) {
+    void onChangeNotification(ChangeNotification notification) {
+        LOG.info("notification received from device {}: {}", this.nodeId, notification.toString());
         if (notification.getEdit() == null) {
             LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
             return;
@@ -53,17 +63,13 @@ public class DeviceListener221 implements OrgOpenroadmDeviceListener {
                 continue;
             }
             // 1. Detect the org-openroadm-device object modified
-            switch (edit.getTarget().getTargetType().getSimpleName()) {
+            InstanceIdentifier<DataObject> path = InstanceIdentifier.unsafeOf(
+                     (List<? extends DataObjectStep<?>>) edit.getTarget().steps());
+            LOG.debug("Instance Identifier received = {} from node {}", path.toString(), nodeId);
+            switch (path.lastStep().type().getSimpleName()) {
                 case "Ports":
-                    LinkedList<PathArgument> path = new LinkedList<>();
-                    edit.getTarget().getPathArguments().forEach(p -> path.add(p));
-                    InstanceIdentifier<Ports> portIID = (InstanceIdentifier<Ports>) InstanceIdentifier
-                        .create(path);
-                    String portName = InstanceIdentifier.keyOf(portIID).getPortName();
-                    path.removeLast();
-                    InstanceIdentifier<CircuitPacks> cpIID = (InstanceIdentifier<CircuitPacks>) InstanceIdentifier
-                        .create(path);
-                    String cpName = InstanceIdentifier.keyOf(cpIID).getCircuitPackName();
+                    String portName = path.firstKeyOf(Ports.class).getPortName();
+                    String cpName = path.firstKeyOf(CircuitPacks.class).getCircuitPackName();
                     LOG.info("port {} of circruit-pack {} modified on device {}", portName, cpName, this.nodeId);
                     Mapping oldMapping = portMapping.getMapping(nodeId, cpName, portName);
                     if (oldMapping == null) {
@@ -80,15 +86,32 @@ public class DeviceListener221 implements OrgOpenroadmDeviceListener {
                     Thread thread = new Thread(handleNetconfEvent);
                     thread.start();
                     break;
+                case "Interface":
+                    String interfaceName = path.firstKeyOf(Interface.class).getName();
+                    LOG.info("interface {} modified on device {}", interfaceName, this.nodeId);
+                    Mapping oldMapping2 = portMapping.getMappingFromOtsInterface(nodeId, interfaceName);
+                    if (oldMapping2 == null) {
+                        return;
+                    }
+                    Runnable handleNetconfEvent2 = new Runnable() {
+                        @Override
+                        public void run() {
+                            portMapping.updateMapping(nodeId, oldMapping2);
+                            LOG.info("{} : mapping data for {} updated", nodeId,
+                                oldMapping2.getLogicalConnectionPoint());
+                        }
+                    };
+                    Thread thread2 = new Thread(handleNetconfEvent2);
+                    thread2.start();
+                    break;
                 default:
-                    LOG.debug("modification of type {} not managed yet", edit.getTarget().getTargetType());
+                    LOG.debug("modification of type {} not managed yet", edit.getTarget().getClass());
                     break;
             }
         }
     }
 
-    @Override
-    public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
+    private void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
     }
 
     /**
@@ -97,8 +120,7 @@ public class DeviceListener221 implements OrgOpenroadmDeviceListener {
      * @param notification
      *            OtdrScanResult object
      */
-    @Override
-    public void onOtdrScanResult(OtdrScanResult notification) {
+    private void onOtdrScanResult(OtdrScanResult notification) {
         LOG.info("Notification {} received {}", OtdrScanResult.QNAME, notification);
     }