PortMapping Refactoring step 1 61/97661/4
authorguillaume.lambert <guillaume.lambert@orange.com>
Fri, 17 Sep 2021 08:47:28 +0000 (10:47 +0200)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Thu, 30 Sep 2021 14:21:33 +0000 (14:21 +0000)
This refactoring intends to optimize some parts of the code
and to fix sonar issues about cyclomatic complexity.

JIRA: TRNSPRTPCE-355 TRNSPRTPCE-356
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: Ia82c6129d10becf97e161bf4eccb905c1fb850d7

common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java

index 30d6224604b10ff236a3ca9fb979828a548cead2..661a532bb95d9bbab9973a33c20f1510711adba6 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.transportpce.common.mapping;
 
 import com.google.common.util.concurrent.FluentFuture;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -193,7 +192,7 @@ public class PortMappingVersion121 {
         Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
             LogicalDatastoreType.OPERATIONAL, deviceIID,
             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-        if (!deviceObject.isPresent()) {
+        if (deviceObject.isEmpty()) {
             LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
             return false;
         }
@@ -217,8 +216,6 @@ public class PortMappingVersion121 {
                 LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName);
                 continue;
             }
-
-            // com.google.common.collect.ImmutableList implementation of List
             List<Ports> portList = new ArrayList<>(cp.nonnullPorts().values());
             portList.sort(Comparator.comparing(Ports::getPortName));
             for (Ports port : portList) {
@@ -230,26 +227,24 @@ public class PortMappingVersion121 {
             }
         }
 
-        Collection<ConnectionMap> connectionMap = deviceObject.get().nonnullConnectionMap().values();
-        for (ConnectionMap cm : connectionMap) {
+        for (ConnectionMap cm : deviceObject.get().nonnullConnectionMap().values()) {
             String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
-            String slcp = lcpMap.containsKey(skey) ? lcpMap.get(skey) : null;
             Destination destination0 = cm.nonnullDestination().values().iterator().next();
             String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
-            if (slcp == null) {
+            if (!lcpMap.containsKey(skey)) {
                 LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
                 continue;
             }
-            String dlcp = lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null;
+            String slcp = lcpMap.get(skey);
             Mapping mapping = mappingMap.get(slcp);
             mappingMap.remove(slcp);
-            portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp));
+            portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
+                //dlcp
+                lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null));
         }
 
-        if (!mappingMap.isEmpty()) {
-            for (Mapping m : mappingMap.values()) {
-                portMapList.add(m);
-            }
+        for (Mapping m : mappingMap.values()) {
+            portMapList.add(m);
         }
         return true;
     }
@@ -485,7 +480,7 @@ public class PortMappingVersion121 {
             Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
                 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-            if (!interfaceObject.isPresent() || (interfaceObject.get().getSupportingCircuitPackName() == null)) {
+            if (interfaceObject.isEmpty() || interfaceObject.get().getSupportingCircuitPackName() == null) {
                 continue;
             }
             String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
@@ -496,7 +491,7 @@ public class PortMappingVersion121 {
             Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
                 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-            if (!circuitPackObject.isPresent() || (circuitPackObject.get().getParentCircuitPack() == null)) {
+            if (circuitPackObject.isEmpty() || circuitPackObject.get().getParentCircuitPack() == null) {
                 continue;
             }
             cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
@@ -821,22 +816,21 @@ public class PortMappingVersion121 {
 
         Map<Integer, List<ConnectionPorts>> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo);
         for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : connectionPortMap.entrySet()) {
-            switch (connectionPortMap.get(cpMapEntry.getKey()).size()) {
+            List<ConnectionPorts> cpMapValue = cpMapEntry.getValue();
+            ConnectionPorts cp1 = cpMapValue.get(0);
+            String cp1Name = cp1.getCircuitPackName();
+            switch (cpMapValue.size()) {
                 case 1:
                     // port is bidirectional
-                    String cpName = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
                     InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cpName))
-                        .child(Ports.class,
-                                new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
-                        nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cpName);
+                        .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
+                        .child(Ports.class, new PortsKey(cp1.getPortName()));
+                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                     Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
                         LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (!portObject.isPresent()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
-                            nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cpName);
+                    if (portObject.isEmpty()) {
+                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                         return false;
                     }
                     Ports port = portObject.get();
@@ -845,51 +839,46 @@ public class PortMappingVersion121 {
                     }
                     if (Port.PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
                         LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
-                            nodeId, port.getPortName(), cpName);
+                            nodeId, port.getPortName(), cp1Name);
                         continue;
                     }
                     if (Direction.Bidirectional.getIntValue() != port.getPortDirection().getIntValue()) {
                         LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTDIR_ERROR_LOGMSG,
-                            nodeId, port.getPortName(), cpName);
+                            nodeId, port.getPortName(), cp1Name);
                         continue;
                     }
 
                     String logicalConnectionPoint =
                             PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
                     LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
-                        nodeId, port.getPortName(), cpName, logicalConnectionPoint);
-                    portMapList.add(createMappingObject(nodeId, port, cpName, logicalConnectionPoint));
+                        nodeId, port.getPortName(), cp1Name, logicalConnectionPoint);
+                    portMapList.add(createMappingObject(nodeId, port, cp1Name, logicalConnectionPoint));
                     break;
                 case 2:
                     // ports are unidirectionals
-                    String cp1Name = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
-                    String cp2Name = connectionPortMap.get(cpMapEntry.getKey()).get(1).getCircuitPackName();
+                    ConnectionPorts cp2 = cpMapValue.get(1);
+                    String cp2Name = cp2.getCircuitPackName();
                     InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                         .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
-                        .child(Ports.class,
-                            new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
-                        nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cp1Name);
+                        .child(Ports.class, new PortsKey(cp1.getPortName()));
+                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                     Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
                         LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
                     InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                         .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
-                        .child(Ports.class,
-                            new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName()));
+                        .child(Ports.class, new PortsKey(cp2.getPortName()));
                     LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
-                        nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName(), cp2Name);
+                        nodeId, cp2.getPortName(), cp2Name);
                     Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
                         LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (!port1Object.isPresent() || !port2Object.isPresent()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
-                            nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cp1Name);
+                    if (port1Object.isEmpty()) {
+                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                         return false;
                     }
-                    if (!port2Object.isPresent()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
-                            nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName(), cp2Name);
+                    if (port2Object.isEmpty()) {
+                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
                         return false;
                     }
 
@@ -949,7 +938,11 @@ public class PortMappingVersion121 {
         }
 
         NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
-                .setOpenroadmVersion(OpenroadmNodeVersion._121);
+                .setOpenroadmVersion(OpenroadmNodeVersion._121)
+                .setNodeClli(
+                    deviceInfo.getClli() == null || deviceInfo.getClli().isEmpty()
+                        ? "defaultCLLI"
+                        : deviceInfo.getClli());
         // TODO check if we can use here .setNodeType(NodeTypes.forValue(..) such as with 221
         switch (deviceInfo.getNodeType().getIntValue()) {
             case 1:
@@ -960,11 +953,6 @@ public class PortMappingVersion121 {
                 LOG.error(PortMappingUtils.NODE_TYPE_LOGMSG, deviceInfo.getNodeId(), "value not supported");
                 // TODO: is this protection useful ? it is not present in Portmapping 221
         }
-        if (deviceInfo.getClli() != null && !deviceInfo.getClli().isEmpty()) {
-            nodeInfoBldr.setNodeClli(deviceInfo.getClli());
-        } else {
-            nodeInfoBldr.setNodeClli("defaultCLLI");
-        }
         if (deviceInfo.getModel() != null) {
             nodeInfoBldr.setNodeModel(deviceInfo.getModel());
         }
index f96103e5d770dc107b4ccc99ac0b5cee54e161fe..cbc4eb575c2cac4064ac84d0280952aafc10c27c 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.transportpce.common.mapping;
 
 import com.google.common.util.concurrent.FluentFuture;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -217,7 +216,7 @@ public class PortMappingVersion221 {
         Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
             LogicalDatastoreType.OPERATIONAL, deviceIID,
             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-        if (!deviceObject.isPresent()) {
+        if (deviceObject.isEmpty()) {
             LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
             return false;
         }
@@ -301,27 +300,27 @@ public class PortMappingVersion221 {
         if (device.getConnectionMap() == null) {
             LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId);
         } else {
-            Collection<ConnectionMap> connectionMap = deviceObject.get().nonnullConnectionMap().values();
-            for (ConnectionMap cm : connectionMap) {
+            for (ConnectionMap cm : deviceObject.get().nonnullConnectionMap().values()) {
                 String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
-                String slcp = lcpMap.containsKey(skey) ? lcpMap.get(skey) : null;
                 Destination destination0 = cm.nonnullDestination().values().iterator().next();
                 String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
-                if (slcp == null) {
+                if (!lcpMap.containsKey(skey)) {
                     LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
                     continue;
                 }
-                String dlcp = lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null;
+                String slcp = lcpMap.get(skey);
                 Mapping mapping = mappingMap.get(slcp);
                 mappingMap.remove(slcp);
-                portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp, null));
+                portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
+                        //dlcp
+                        lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null,
+                        null));
             }
         }
 
         if (device.getOduSwitchingPools() != null) {
-            Collection<OduSwitchingPools> oduSwithcingPools = device.nonnullOduSwitchingPools().values();
             List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
-            for (OduSwitchingPools odp : oduSwithcingPools) {
+            for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) {
                 Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
                 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org
                     .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
@@ -595,7 +594,7 @@ public class PortMappingVersion221 {
         Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
             LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
             Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-        if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class).getLldp() == null) {
+        if (protocolObject.isEmpty() || protocolObject.get().augmentation(Protocols1.class).getLldp() == null) {
             LOG.warn(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, PortMappingUtils.CANNOT_GET_LLDP_CONF_LOGMSG);
             return new HashMap<>();
         }
@@ -610,7 +609,7 @@ public class PortMappingVersion221 {
             Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
                 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-            if (!interfaceObject.isPresent() || (interfaceObject.get().getSupportingCircuitPackName() == null)) {
+            if (interfaceObject.isEmpty() || interfaceObject.get().getSupportingCircuitPackName() == null) {
                 continue;
             }
             String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
@@ -620,7 +619,7 @@ public class PortMappingVersion221 {
             Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
                 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-            if (!circuitPackObject.isPresent() || (circuitPackObject.get().getParentCircuitPack() == null)) {
+            if (circuitPackObject.isEmpty() || circuitPackObject.get().getParentCircuitPack() == null) {
                 continue;
             }
             cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
@@ -1038,24 +1037,22 @@ public class PortMappingVersion221 {
         LOG.info(PortMappingUtils.MAP_LOOKS_LOGMSG, nodeId, interfaceList);
         postPortMapping(nodeId, null, null, cpToDegreeList, null, null);
 
-        Map<Integer, List<ConnectionPorts>> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo);
-        for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : connectionPortMap.entrySet()) {
-            switch (connectionPortMap.get(cpMapEntry.getKey()).size()) {
+        for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : getPerDegreePorts(nodeId, deviceInfo).entrySet()) {
+            List<ConnectionPorts> cpMapValue = cpMapEntry.getValue();
+            ConnectionPorts cp1 = cpMapValue.get(0);
+            String cp1Name = cp1.getCircuitPackName();
+            switch (cpMapValue.size()) {
                 case 1:
                     // port is bidirectional
-                    String cpName = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
                     InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cpName))
-                        .child(Ports.class,
-                                new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
-                        nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cpName);
+                        .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
+                        .child(Ports.class, new PortsKey(cp1.getPortName()));
+                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                     Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
                         LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (!portObject.isPresent()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
-                            nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cpName);
+                    if (portObject.isEmpty()) {
+                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                         return false;
                     }
                     Ports port = portObject.get();
@@ -1064,51 +1061,45 @@ public class PortMappingVersion221 {
                     }
                     if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
                         LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
-                            nodeId, port.getPortName(), cpName);
+                            nodeId, port.getPortName(), cp1Name);
                         continue;
                     }
                     if (Direction.Bidirectional.getIntValue() != port.getPortDirection().getIntValue()) {
                         LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTDIR_ERROR_LOGMSG,
-                            nodeId, port.getPortName(), cpName);
+                            nodeId, port.getPortName(), cp1Name);
                         continue;
                     }
 
                     String logicalConnectionPoint =
                             PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
                     LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
-                        nodeId, port.getPortName(), cpName, logicalConnectionPoint);
-                    portMapList.add(createMappingObject(nodeId, port, cpName, logicalConnectionPoint));
+                        nodeId, port.getPortName(), cp1Name, logicalConnectionPoint);
+                    portMapList.add(createMappingObject(nodeId, port, cp1Name, logicalConnectionPoint));
                     break;
                 case 2:
                     // ports are unidirectionals
-                    String cp1Name = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
-                    String cp2Name = connectionPortMap.get(cpMapEntry.getKey()).get(1).getCircuitPackName();
+                    ConnectionPorts cp2 = cpMapValue.get(1);
+                    String cp2Name = cp2.getCircuitPackName();
                     InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                         .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
-                        .child(Ports.class,
-                            new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
-                        nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cp1Name);
+                        .child(Ports.class, new PortsKey(cp1.getPortName()));
+                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                     Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
                         LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
                     InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                         .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
-                        .child(Ports.class,
-                            new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
-                        nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName(), cp2Name);
+                        .child(Ports.class, new PortsKey(cp2.getPortName()));
+                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
                     Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
                         LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (!port1Object.isPresent() || !port2Object.isPresent()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
-                            nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cp1Name);
+                    if (port1Object.isEmpty()) {
+                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                         return false;
                     }
-                    if (!port2Object.isPresent()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
-                            nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName(), cp2Name);
+                    if (port2Object.isEmpty()) {
+                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
                         return false;
                     }
 
@@ -1169,12 +1160,11 @@ public class PortMappingVersion221 {
 
         NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
                 .setOpenroadmVersion(OpenroadmNodeVersion._221)
+                .setNodeClli(
+                    deviceInfo.getClli() == null || deviceInfo.getClli().isEmpty()
+                        ? "defaultCLLI"
+                        : deviceInfo.getClli())
                 .setNodeType(NodeTypes.forValue(deviceInfo.getNodeType().getIntValue()));
-        if (deviceInfo.getClli() != null && !deviceInfo.getClli().isEmpty()) {
-            nodeInfoBldr.setNodeClli(deviceInfo.getClli());
-        } else {
-            nodeInfoBldr.setNodeClli("defaultCLLI");
-        }
         if (deviceInfo.getModel() != null) {
             nodeInfoBldr.setNodeModel(deviceInfo.getModel());
         }
index 21f1ae54ab3a270238388d1eb6dc76a4f303fd28..ebaffd1696fcdb11c7e19d6c738fd4b59cd3be8a 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.transportpce.common.mapping;
 
 import com.google.common.util.concurrent.FluentFuture;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -312,7 +311,7 @@ public class PortMappingVersion710 {
         Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
             LogicalDatastoreType.OPERATIONAL, deviceIID,
             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-        if (!deviceObject.isPresent()) {
+        if (deviceObject.isEmpty()) {
             LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
             return false;
         }
@@ -396,27 +395,27 @@ public class PortMappingVersion710 {
         if (device.getConnectionMap() == null) {
             LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId);
         } else {
-            Collection<ConnectionMap> connectionMap = deviceObject.get().nonnullConnectionMap().values();
-            for (ConnectionMap cm : connectionMap) {
+            for (ConnectionMap cm : deviceObject.get().nonnullConnectionMap().values()) {
                 String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
-                String slcp = lcpMap.containsKey(skey) ? lcpMap.get(skey) : null;
                 Destination destination0 = cm.nonnullDestination().values().iterator().next();
                 String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
-                if (slcp == null) {
+                if (!lcpMap.containsKey(skey)) {
                     LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
                     continue;
                 }
-                String dlcp = lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null;
+                String slcp = lcpMap.get(skey);
                 Mapping mapping = mappingMap.get(slcp);
                 mappingMap.remove(slcp);
-                portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp, null));
+                portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
+                        //dlcp
+                        lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null,
+                        null));
             }
         }
 
         if (device.getOduSwitchingPools() != null) {
-            Collection<OduSwitchingPools> oduSwithcingPools = device.nonnullOduSwitchingPools().values();
             List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
-            for (OduSwitchingPools odp : oduSwithcingPools) {
+            for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) {
                 Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
                 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org
                     .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
@@ -641,7 +640,7 @@ public class PortMappingVersion710 {
             LogicalDatastoreType.OPERATIONAL, deviceIID,
             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         OrgOpenroadmDevice device = null;
-        if (!deviceObject.isPresent()) {
+        if (deviceObject.isEmpty()) {
             LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, deviceId);
             LOG.warn("MC-capabilities profile will be empty for node {}", deviceId);
             return mcCapabilityProfiles;
@@ -708,7 +707,7 @@ public class PortMappingVersion710 {
         Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
             LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
             Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-        if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class).getLldp() == null) {
+        if (protocolObject.isEmpty() || protocolObject.get().augmentation(Protocols1.class).getLldp() == null) {
             LOG.warn(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, PortMappingUtils.CANNOT_GET_LLDP_CONF_LOGMSG);
             return new HashMap<>();
         }
@@ -723,7 +722,7 @@ public class PortMappingVersion710 {
             Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
                 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-            if (!interfaceObject.isPresent() || (interfaceObject.get().getSupportingCircuitPackName() == null)) {
+            if (interfaceObject.isEmpty() || interfaceObject.get().getSupportingCircuitPackName() == null) {
                 continue;
             }
             String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
@@ -733,7 +732,7 @@ public class PortMappingVersion710 {
             Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
                 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-            if (!circuitPackObject.isPresent() || (circuitPackObject.get().getParentCircuitPack() == null)) {
+            if (circuitPackObject.isEmpty() || circuitPackObject.get().getParentCircuitPack() == null) {
                 continue;
             }
             cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
@@ -1266,24 +1265,22 @@ public class PortMappingVersion710 {
         LOG.info(PortMappingUtils.MAP_LOOKS_LOGMSG, nodeId, interfaceList);
         postPortMapping(nodeId, null, null, cpToDegreeList, null, null);
 
-        Map<Integer, List<ConnectionPorts>> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo);
-        for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : connectionPortMap.entrySet()) {
-            switch (connectionPortMap.get(cpMapEntry.getKey()).size()) {
+        for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : getPerDegreePorts(nodeId, deviceInfo).entrySet()) {
+            List<ConnectionPorts> cpMapValue = cpMapEntry.getValue();
+            ConnectionPorts cp1 = cpMapValue.get(0);
+            String cp1Name = cp1.getCircuitPackName();
+            switch (cpMapValue.size()) {
                 case 1:
                     // port is bidirectional
-                    String cpName = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
                     InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cpName))
-                        .child(Ports.class,
-                                new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
-                        nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cpName);
+                        .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
+                        .child(Ports.class, new PortsKey(cp1.getPortName()));
+                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                     Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
                         LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (!portObject.isPresent()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
-                            nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cpName);
+                    if (portObject.isEmpty()) {
+                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                         return false;
                     }
                     Ports port = portObject.get();
@@ -1292,51 +1289,45 @@ public class PortMappingVersion710 {
                     }
                     if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
                         LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
-                            nodeId, port.getPortName(), cpName);
+                            nodeId, port.getPortName(), cp1Name);
                         continue;
                     }
                     if (Direction.Bidirectional.getIntValue() != port.getPortDirection().getIntValue()) {
                         LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTDIR_ERROR_LOGMSG,
-                            nodeId, port.getPortName(), cpName);
+                            nodeId, port.getPortName(), cp1Name);
                         continue;
                     }
 
                     String logicalConnectionPoint =
                             PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
                     LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
-                        nodeId, port.getPortName(), cpName, logicalConnectionPoint);
-                    portMapList.add(createMappingObject(nodeId, port, cpName, logicalConnectionPoint));
+                        nodeId, port.getPortName(), cp1Name, logicalConnectionPoint);
+                    portMapList.add(createMappingObject(nodeId, port, cp1Name, logicalConnectionPoint));
                     break;
                 case 2:
                     // ports are unidirectionals
-                    String cp1Name = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
-                    String cp2Name = connectionPortMap.get(cpMapEntry.getKey()).get(1).getCircuitPackName();
+                    ConnectionPorts cp2 = cpMapValue.get(1);
+                    String cp2Name = cp2.getCircuitPackName();
                     InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                         .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
-                        .child(Ports.class,
-                            new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
-                        nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cp1Name);
+                        .child(Ports.class, new PortsKey(cp1.getPortName()));
+                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                     Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
                         LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
                     InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                         .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
-                        .child(Ports.class,
-                            new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
-                        nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName(), cp2Name);
+                        .child(Ports.class, new PortsKey(cp2.getPortName()));
+                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
                     Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
                         LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (!port1Object.isPresent() || !port2Object.isPresent()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
-                            nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cp1Name);
+                    if (port1Object.isEmpty()) {
+                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
                         return false;
                     }
-                    if (!port2Object.isPresent()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
-                            nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName(), cp2Name);
+                    if (port2Object.isEmpty()) {
+                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
                         return false;
                     }
 
@@ -1397,13 +1388,12 @@ public class PortMappingVersion710 {
 
         NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
                 .setOpenroadmVersion(OpenroadmNodeVersion._71)
+                .setNodeClli(
+                    deviceInfo.getClli() == null || deviceInfo.getClli().isEmpty()
+                        ? "defaultCLLI"
+                        : deviceInfo.getClli())
                 .setNodeType(deviceInfo.getNodeType());
         // TODO: 221 versions expects an int value - need to check whether it is bug or an evolution here
-        if (deviceInfo.getClli() != null && !deviceInfo.getClli().isEmpty()) {
-            nodeInfoBldr.setNodeClli(deviceInfo.getClli());
-        } else {
-            nodeInfoBldr.setNodeClli("defaultCLLI");
-        }
         if (deviceInfo.getModel() != null) {
             nodeInfoBldr.setNodeModel(deviceInfo.getModel());
         }