Add node-info in portmapping structure
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / DeviceRendererServiceImpl.java
index ef2cf9a599612b8026517b84aa056e2786a50380..74a8c5ff0cd7d2c2923bb8778f567612e55d9907 100644 (file)
@@ -27,20 +27,20 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.common.Timeouts;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
-import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServiceListTopology;
 import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.ServicePathDirection;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.ServiceNodelist;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.NodelistBuilder;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.alarmsuppression.rev171102.service.nodelist.NodelistKey;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.nodes.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.Mapping;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.CreateOtsOmsInput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.CreateOtsOmsOutput;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.CreateOtsOmsOutputBuilder;
@@ -54,10 +54,6 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.renderer.rollback.output.FailedToRollbackBuilder;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.renderer.rollback.output.FailedToRollbackKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.Topology;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.get.connection.port.trail.output.Ports;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.OchAttributes.ModulationFormat;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.R100G;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceList;
@@ -120,7 +116,7 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                     String srcTp = node.getSrcTp();
                     String destTp = node.getDestTp();
                     Long waveNumber = input.getWaveNumber();
-                    if ((destTp != null) && destTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) {
+                    if ((destTp != null) && destTp.contains(StringConstants.NETWORK_TOKEN)) {
                         crossConnectFlag++;
                         // create OpenRoadm Xponder Line Interfaces
                         String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
@@ -132,13 +128,13 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                         createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
                                 destTp, supportingOtuInterface));
                     }
-                    if ((srcTp != null) && srcTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)) {
+                    if ((srcTp != null) && srcTp.contains(StringConstants.CLIENT_TOKEN)) {
                         crossConnectFlag++;
                         // create OpenRoadm Xponder Client Interfaces
                         createdEthInterfaces.add(
                             this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(nodeId, srcTp));
                     }
-                    if ((srcTp != null) && srcTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) {
+                    if ((srcTp != null) && srcTp.contains(StringConstants.NETWORK_TOKEN)) {
                         crossConnectFlag++;
                         // create OpenRoadm Xponder Line Interfaces
                         String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
@@ -150,21 +146,21 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                         createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
                                 srcTp, supportingOtuInterface));
                     }
-                    if ((destTp != null) && destTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)) {
+                    if ((destTp != null) && destTp.contains(StringConstants.CLIENT_TOKEN)) {
                         crossConnectFlag++;
                         // create OpenRoadm Xponder Client Interfaces
                         createdEthInterfaces.add(
                             this.openRoadmInterfaceFactory.createOpenRoadmEthInterface(nodeId, destTp));
                     }
-                    if ((srcTp != null) && (srcTp.contains(OpenRoadmInterfacesImpl.TTP_TOKEN)
-                            || srcTp.contains(OpenRoadmInterfacesImpl.PP_TOKEN))) {
-                        createdOchInterfaces.add(
+                    if ((srcTp != null) && (srcTp.contains(StringConstants.TTP_TOKEN)
+                            || srcTp.contains(StringConstants.PP_TOKEN))) {
+                        createdOchInterfaces.addAll(
                             this.openRoadmInterfaceFactory
                                 .createOpenRoadmOchInterface(nodeId, srcTp, waveNumber));
                     }
-                    if ((destTp != null) && (destTp.contains(OpenRoadmInterfacesImpl.TTP_TOKEN)
-                            || destTp.contains(OpenRoadmInterfacesImpl.PP_TOKEN))) {
-                        createdOchInterfaces.add(
+                    if ((destTp != null) && (destTp.contains(StringConstants.TTP_TOKEN)
+                            || destTp.contains(StringConstants.PP_TOKEN))) {
+                        createdOchInterfaces.addAll(
                             this.openRoadmInterfaceFactory
                                 .createOpenRoadmOchInterface(nodeId, destTp, waveNumber));
                     }
@@ -175,14 +171,6 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                                 this.crossConnect.postCrossConnect(nodeId, waveNumber, srcTp, destTp);
                         if (connectionNameOpt.isPresent()) {
                             nodesProvisioned.add(nodeId);
-                            List<Ports> ports =
-                                    this.crossConnect.getConnectionPortTrail(nodeId, waveNumber, srcTp, destTp);
-                            if (ServicePathDirection.A_TO_Z.equals(direction)) {
-                                topology.updateAtoZTopologyList(ports, nodeId);
-                            }
-                            if (ServicePathDirection.Z_TO_A.equals(direction)) {
-                                topology.updateZtoATopologyList(ports, nodeId);
-                            }
                             createdConnections.add(connectionNameOpt.get());
                         } else {
                             processErrorMessage("Unable to post Roadm-connection for node " + nodeId, forkJoinPool,
@@ -214,6 +202,7 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
             LOG.error("Error while setting up service paths!", e);
         }
         forkJoinPool.shutdown();
+
         if (success.get()) {
             results.add("Roadm-connection successfully created for nodes: " + String.join(", ", nodesProvisioned));
         }
@@ -263,42 +252,39 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
             }
             // if the node is currently mounted then proceed.
             if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
-                if (destTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)
-                        || srcTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)
-                        || srcTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)
-                        || destTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)) {
-                    if (destTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) {
+                if (destTp.contains(StringConstants.NETWORK_TOKEN)
+                        || srcTp.contains(StringConstants.CLIENT_TOKEN)
+                        || srcTp.contains(StringConstants.NETWORK_TOKEN)
+                        || destTp.contains(StringConstants.CLIENT_TOKEN)) {
+                    if (destTp.contains(StringConstants.NETWORK_TOKEN)) {
                         interfacesToDelete.add(destTp + "-ODU");
                         interfacesToDelete.add(destTp + "-OTU");
                         interfacesToDelete.add(
                                 this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(destTp, waveNumber));
                     }
-                    if (srcTp.contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) {
+                    if (srcTp.contains(StringConstants.NETWORK_TOKEN)) {
                         interfacesToDelete.add(srcTp + "-ODU");
                         interfacesToDelete.add(srcTp + "-OTU");
                         interfacesToDelete
                                 .add(this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(srcTp, waveNumber));
                     }
-                    if (srcTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)) {
+                    if (srcTp.contains(StringConstants.CLIENT_TOKEN)) {
                         interfacesToDelete.add(srcTp + "-ETHERNET");
                     }
-                    if (destTp.contains(OpenRoadmInterfacesImpl.CLIENT_TOKEN)) {
+                    if (destTp.contains(StringConstants.CLIENT_TOKEN)) {
                         interfacesToDelete.add(destTp + "-ETHERNET");
                     }
                 } else {
                     String connectionNumber = srcTp + "-" + destTp + "-" + waveNumber;
-                    if (!this.crossConnect.deleteCrossConnect(nodeId, connectionNumber)) {
-                        LOG.error("Failed to delete cross connect {}", connectionNumber);
-                    }
+                    List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber);
                     connectionNumber = destTp + "-" + srcTp + "-" + waveNumber;
-                    String interfName =
-                            this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(srcTp, waveNumber);
-                    if (!isUsedByXc(nodeId, interfName, connectionNumber)) {
-                        interfacesToDelete.add(interfName);
-                    }
-                    interfName = this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(destTp, waveNumber);
-                    if (!isUsedByXc(nodeId, interfName, connectionNumber)) {
-                        interfacesToDelete.add(interfName);
+                    if (intToDelete != null) {
+                        for (String interf : intToDelete) {
+                            if (!this.openRoadmInterfaceFactory.isUsedbyXc(nodeId, interf, connectionNumber,
+                                this.deviceTransactionManager)) {
+                                interfacesToDelete.add(interf);
+                            }
+                        }
                     }
                 }
             } else {
@@ -346,7 +332,8 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
             List<String> failedInterfaces = new ArrayList<>();
             String nodeId = nodeInterfaces.getNodeId();
             for (String connectionId : nodeInterfaces.getConnectionId()) {
-                if (this.crossConnect.deleteCrossConnect(nodeId, connectionId)) {
+                List<String> listInter = this.crossConnect.deleteCrossConnect(nodeId, connectionId);
+                if (listInter != null) {
                     LOG.info("Cross connect {} on node {} successfully deleted.", connectionId, nodeId);
                 } else {
                     LOG.error("Failed to delete cross connect {} on node {}!", connectionId, nodeId);
@@ -460,34 +447,15 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
             throw e;
         }
         if (services.isPresent()) {
+            LOG.info("service {} already exists", name);
             servicesBuilder = new ServicesBuilder(services.get());
+            servicesBuilder.setTopology(topo);
+            WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
+            writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicesBuilder.build());
+            writeTx.submit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
         } else {
-            servicesBuilder = new ServicesBuilder();
-            servicesBuilder.withKey(serviceKey);
-        }
-        servicesBuilder.setTopology(topo);
-        WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
-        writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicesBuilder.build());
-        writeTx.submit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
-    }
-
-    private boolean isUsedByXc(String nodeid, String interfaceid, String xcid) {
-        InstanceIdentifier<RoadmConnections> xciid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                .child(RoadmConnections.class, new RoadmConnectionsKey(xcid));
-        LOG.info("reading xc {} in node {}", xcid, nodeid);
-        Optional<RoadmConnections> crossconnection =
-                this.deviceTransactionManager.getDataFromDevice(nodeid, LogicalDatastoreType.CONFIGURATION, xciid,
-                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-        if (crossconnection.isPresent()) {
-            RoadmConnections xc = crossconnection.get();
-            LOG.info("xd {} found", xcid);
-            if (xc.getSource().getSrcIf().equals(interfaceid) || xc.getDestination().getDstIf().equals(interfaceid)) {
-                return true;
-            }
-        } else {
-            LOG.info("xd {} not found !", xcid);
+            LOG.warn("Service {} does not exist - topology can not be updated", name);
         }
-        return false;
     }
 
     @Override