clean OTN renderer code
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / DeviceRendererServiceImpl.java
index 8c40f005131f2e0c48db8d68d5cc02526c3da819..23d08b672dc064596f4899da1b6b4a41770a9379 100644 (file)
@@ -41,30 +41,29 @@ import org.opendaylight.transportpce.renderer.provisiondevice.servicepath.Servic
 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.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;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.RendererRollbackInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.RendererRollbackOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.RendererRollbackOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.renderer.rollback.output.FailedToRollback;
-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.opendaylight.transportpce.portmapping.rev200128.network.nodes.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.CreateOtsOmsInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.CreateOtsOmsOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.CreateOtsOmsOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.RendererRollbackInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.RendererRollbackOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.RendererRollbackOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.renderer.rollback.output.FailedToRollback;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.renderer.rollback.output.FailedToRollbackBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.renderer.rollback.output.FailedToRollbackKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.Topology;
 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.rev190531.ServiceList;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesKey;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterface;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterfaceBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.node.interfaces.NodeInterfaceKey;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.olm.renderer.input.Nodes;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.node.interfaces.NodeInterface;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.node.interfaces.NodeInterfaceBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.node.interfaces.NodeInterfaceKey;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.olm.renderer.input.Nodes;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -119,15 +118,22 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                     Long waveNumber = input.getWaveNumber();
                     if ((destTp != null) && destTp.contains(StringConstants.NETWORK_TOKEN)) {
                         crossConnectFlag++;
-                        // create OpenRoadm Xponder Line Interfaces
+                        Mapping mapping = this.portMapping.getMapping(nodeId,destTp);
                         String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
-                                nodeId, destTp, waveNumber, R100G.class, ModulationFormat.DpQpsk);
+                                nodeId, destTp, waveNumber, ModulationFormat.DpQpsk);
                         createdOchInterfaces.add(supportingOchInterface);
                         String supportingOtuInterface = this.openRoadmInterfaceFactory
                                 .createOpenRoadmOtu4Interface(nodeId, destTp, supportingOchInterface);
                         createdOtuInterfaces.add(supportingOtuInterface);
-                        createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
-                                destTp, supportingOtuInterface));
+                        if (mapping != null && mapping.getXponderType() != null
+                            && (mapping.getXponderType().getIntValue() == 3
+                            || mapping.getXponderType().getIntValue() == 2)) {
+                            createdOduInterfaces.add(this.openRoadmInterfaceFactory
+                                .createOpenRoadmOtnOdu4Interface(nodeId,destTp, supportingOtuInterface));
+                        } else {
+                            createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
+                                    destTp, supportingOtuInterface));
+                        }
                     }
                     if ((srcTp != null) && srcTp.contains(StringConstants.CLIENT_TOKEN)) {
                         crossConnectFlag++;
@@ -139,13 +145,23 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                         crossConnectFlag++;
                         // create OpenRoadm Xponder Line Interfaces
                         String supportingOchInterface = this.openRoadmInterfaceFactory.createOpenRoadmOchInterface(
-                                nodeId, srcTp, waveNumber, R100G.class, ModulationFormat.DpQpsk);
+                                nodeId, srcTp, waveNumber, ModulationFormat.DpQpsk);
                         createdOchInterfaces.add(supportingOchInterface);
                         String supportingOtuInterface = this.openRoadmInterfaceFactory
                                 .createOpenRoadmOtu4Interface(nodeId, srcTp, supportingOchInterface);
                         createdOtuInterfaces.add(supportingOtuInterface);
                         createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
                                 srcTp, supportingOtuInterface));
+                        Mapping mapping = this.portMapping.getMapping(nodeId,srcTp);
+                        if (mapping != null && mapping.getXponderType() != null
+                            && (mapping.getXponderType().getIntValue() == 3
+                            || mapping.getXponderType().getIntValue() == 2)) {
+                            createdOduInterfaces.add(this.openRoadmInterfaceFactory
+                                .createOpenRoadmOtnOdu4Interface(nodeId, destTp, supportingOtuInterface));
+                        } else {
+                            createdOduInterfaces.add(this.openRoadmInterfaceFactory.createOpenRoadmOdu4Interface(nodeId,
+                                    destTp, supportingOtuInterface));
+                        }
                     }
                     if ((destTp != null) && destTp.contains(StringConstants.CLIENT_TOKEN)) {
                         crossConnectFlag++;
@@ -244,12 +260,19 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
             List<String> interfacesToDelete = new LinkedList<>();
             String nodeId = node.getNodeId();
             LOG.info("Deleting service setup on node {}", nodeId);
-            String srcTp = node.getSrcTp();
-            String destTp = node.getDestTp();
+            String srcTp;
+            String destTp;
             Long waveNumber = input.getWaveNumber();
-            if ((srcTp == null) || (destTp == null)) {
-                LOG.error("Source ({}) or destination ({}) termination point is null.", srcTp, destTp);
+            if (node.getDestTp() == null) {
+                LOG.error("Destination termination point must not be null.");
                 return;
+            } else {
+                destTp = node.getDestTp();
+            }
+            if (node.getSrcTp() != null) {
+                srcTp = node.getSrcTp();
+            } else {
+                srcTp = "";
             }
             // if the node is currently mounted then proceed.
             if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
@@ -258,7 +281,17 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                         || srcTp.contains(StringConstants.NETWORK_TOKEN)
                         || destTp.contains(StringConstants.CLIENT_TOKEN)) {
                     if (destTp.contains(StringConstants.NETWORK_TOKEN)) {
-                        interfacesToDelete.add(destTp + "-ODU");
+                        try {
+                            if (this.openRoadmInterfaces.getInterface(nodeId, destTp + "-ODU").isPresent()) {
+                                interfacesToDelete.add(destTp + "-ODU");
+                            }
+                            if (this.openRoadmInterfaces.getInterface(nodeId, destTp + "-ODU4").isPresent()) {
+                                interfacesToDelete.add(destTp + "-ODU4");
+                            }
+                        }
+                        catch (OpenRoadmInterfaceException e) {
+                            LOG.error("impossible to get interface {} or {}", destTp + "-ODU", destTp + "-ODU4", e);
+                        }
                         interfacesToDelete.add(destTp + "-OTU");
                         interfacesToDelete.add(
                                 this.openRoadmInterfaceFactory.createOpenRoadmOchInterfaceName(destTp, waveNumber));
@@ -277,7 +310,7 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
                     }
                 } else {
                     String connectionNumber = srcTp + "-" + destTp + "-" + waveNumber;
-                    List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber);
+                    List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, false);
                     connectionNumber = destTp + "-" + srcTp + "-" + waveNumber;
                     if (intToDelete != null) {
                         for (String interf : intToDelete) {
@@ -334,7 +367,7 @@ public class DeviceRendererServiceImpl implements DeviceRendererService {
             List<String> failedInterfaces = new ArrayList<>();
             String nodeId = nodeInterfaces.getNodeId();
             for (String connectionId : nodeInterfaces.getConnectionId()) {
-                List<String> listInter = this.crossConnect.deleteCrossConnect(nodeId, connectionId);
+                List<String> listInter = this.crossConnect.deleteCrossConnect(nodeId, connectionId, false);
                 if (listInter != null) {
                     LOG.info("Cross connect {} on node {} successfully deleted.", connectionId, nodeId);
                 } else {