From 9d8ca4c07245ca21921b6c5f1330394cb08a48eb Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Fri, 17 Sep 2021 10:47:28 +0200 Subject: [PATCH] PortMapping Refactoring step 1 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 Change-Id: Ia82c6129d10becf97e161bf4eccb905c1fb850d7 --- .../common/mapping/PortMappingVersion121.java | 90 ++++++++---------- .../common/mapping/PortMappingVersion221.java | 90 ++++++++---------- .../common/mapping/PortMappingVersion710.java | 92 +++++++++---------- 3 files changed, 120 insertions(+), 152 deletions(-) diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java index 30d622460..661a532bb 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java @@ -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 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 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 = 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 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 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> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo); for (Entry> cpMapEntry : connectionPortMap.entrySet()) { - switch (connectionPortMap.get(cpMapEntry.getKey()).size()) { + List 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 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 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 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 port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); InstanceIdentifier 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 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()); } diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java index f96103e5d..cbc4eb575 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java @@ -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 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 = 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 oduSwithcingPools = device.nonnullOduSwitchingPools().values(); List switchingPoolList = new ArrayList<>(); - for (OduSwitchingPools odp : oduSwithcingPools) { + for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) { Map 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 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 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 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> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo); - for (Entry> cpMapEntry : connectionPortMap.entrySet()) { - switch (connectionPortMap.get(cpMapEntry.getKey()).size()) { + for (Entry> cpMapEntry : getPerDegreePorts(nodeId, deviceInfo).entrySet()) { + List 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 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 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 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 port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); InstanceIdentifier 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 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()); } diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java index 21f1ae54a..ebaffd169 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java @@ -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 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 = 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 oduSwithcingPools = device.nonnullOduSwitchingPools().values(); List switchingPoolList = new ArrayList<>(); - for (OduSwitchingPools odp : oduSwithcingPools) { + for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) { Map 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 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 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 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> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo); - for (Entry> cpMapEntry : connectionPortMap.entrySet()) { - switch (connectionPortMap.get(cpMapEntry.getKey()).size()) { + for (Entry> cpMapEntry : getPerDegreePorts(nodeId, deviceInfo).entrySet()) { + List 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 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 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 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 port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); InstanceIdentifier 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 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()); } -- 2.36.6