From 39d5ff2ab4aaba61ba43470a6427d84eb7ac89b6 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Sun, 26 Sep 2021 20:56:56 +0200 Subject: [PATCH] Use constants for PortMapping log messages Step 3 Few PortMapping log messages were redundant and needed to be realigned. Some others were triggering Sonar issues. Since these messages are shared among all PortMappingVersion*** classes, migrating them to constants in the PortMappingUtils class is preferable. JIRA: TRNSPRTPCE-355 TRNSPRTPCE-356 Signed-off-by: guillaume.lambert Change-Id: I865145bc7207500d727e5778916d9f1f4879c1c0 --- .../common/mapping/PortMappingUtils.java | 62 ++++++++++++++----- .../common/mapping/PortMappingVersion121.java | 51 ++++++++------- .../common/mapping/PortMappingVersion221.java | 55 ++++++++-------- .../common/mapping/PortMappingVersion710.java | 55 ++++++++-------- 4 files changed, 125 insertions(+), 98 deletions(-) diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingUtils.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingUtils.java index 6b34b34c2..a525bb1aa 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingUtils.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingUtils.java @@ -29,49 +29,79 @@ public final class PortMappingUtils { public static final String CANNOT_CREATE_LCP_LOGMSG = "{} : port {} on {} - Impossible to create logical connection point"; public static final String CANNOT_GET_DEV_CONF_LOGMSG = - "{} : Impossible to get device configuration"; + "{} : impossible to get device configuration"; public static final String CANNOT_GET_LLDP_CONF_LOGMSG = "- cannot find port config under LLDP"; + public static final String CONMAP_ISSUE_LOGMSG = + "{} : connection-map analysis for source {} and dest (CP+port) {} - no entry found for source in LCP map"; public static final String CREATE_MAPPING_DATA_LOGMSG = "{} : OpenROADM version {} node - Creating Mapping Data"; public static final String DEVICE_HAS_LOGMSG = - "{} : Device has {} {}"; + "{} : device has {} {}"; public static final String FETCH_CONNECTIONPORT_LOGMSG = - "{} : Fetching connection-port {} at circuit pack {}"; + "{} : fetching connection-port {} at circuit-pack {}"; + public static final String GETTING_CONPORT_LOGMSG = + "{} : getting connection-ports for degree number {}"; + public static final String GETTING_CP_LOGMSG = + "{} : getting circuit-packs for SRG number {}"; public static final String GETTING_ETH_LIST_LOGMSG = "{} : getting Ethernet interfaces list"; public static final String GETTING_MC_CAPA_LOGMSG = - "{} : Getting the MC capabilities for {}"; + "{} : getting MC capabilities for {}"; + public static final String GOT_INTF_LOGMSG = + "{} : got interface {} of type {}"; + public static final String INTF_ISSUE_LOGMSG = + "{} : error while getting interface {} "; + public static final String MAP_LOOKS_LOGMSG = + "{} : map looks like this {}"; public static final String MISSING_CP_LOGMSG = - "{} : No Circuit-pack {} in the device"; + "{} : no circuit-pack {} in the device"; public static final String NO_ASSOC_FOUND_LOGMSG = "{} : port {} on {} - no association found {}"; + public static final String NO_CONMAP_LOGMSG = + "{} : no connection-map found inside device configuration"; public static final String NO_MC_LOGMSG = - "{} : No MC profile found on {} {} - assuming fixed grid"; + "{} : no MC profile found on {} {} - assuming fixed grid"; public static final String NO_PORT_ON_CP_LOGMSG = - "{} : No port {} on circuit pack {}"; - public static final String NO_VALID_PARTNERPORT_UNIDIR_LOGMSG = - "{} : port {} on {} is unidirectional but has no valid partnerPort"; + "{} : no port {} on circuit pack {}"; + public static final String NO_VALID_PARTNERPORT_LOGMSG = + "{} : port {} on {} has no valid partner port"; + public static final String NODE_TYPE_LOGMSG = + "{} : node-type {}"; + public static final String NOT_CORRECT_CONPORT_LOGMSG = + "{} : the number of connection-port is not correct for DEG{}"; public static final String NOT_CORRECT_PARTNERPORT_LOGMSG = "{} : port {} on {} is not a correct partner port of {} on {}"; public static final String PARTNERPORT_CONF_ERROR_LOGMSG = - " - Error with partner port configuration"; + " - error with partner port configuration"; public static final String PARTNERPORT_GET_ERROR_LOGMSG = - " - Error getting partner port"; + " - error getting partner port"; + public static final String PORT_ALREADY_HANDLED_LOGMSG = + "{} : port {} on {} has already been handled"; + public static final String PORT_NOT_RDMEXT_LOGMSG = + "{} : port {} on {} is not roadm-external"; public static final String PORTDIR_ERROR_LOGMSG = - " - Error in configuration with port-direction"; + " - error in configuration with port-direction"; public static final String PORTMAPPING_IGNORE_LOGMSG = " - ignoring it in port-mapping"; + public static final String PORTMAPPING_POST_FAIL_LOGMSG = + "{} : port-mapping post-treatment failure for {}"; public static final String PORTQUAL_ERROR_LOGMSG = - " - Error in configuration with port-qual"; + " - error in configuration with port-qual"; + public static final String PORTQUAL_LOGMSG = + "{} : port {} on {} - PortQual {}"; public static final String PROCESSING_DONE_LOGMSG = - "{} : Processing done {}"; + "{} : processing done {}"; public static final String UNABLE_MAPPING_LOGMSG = - "{} : Unable to {} mapping for {}"; + "{} : unable to {} mapping for {}"; public static final String UNABLE_MC_CAPA_LOGMSG = - "{} : Unable to create MC capabilities"; + "{} : unable to create MC capabilities"; public static final String UNSUPPORTED_DIR_LOGMSG = "{} : port {} on {} - unsupported Direction {}"; + public static final String UPDATE_MAPPING_LOGMSG = + "{} : Updating old mapping data {} for {} by new mapping data {}"; + public static final String XPDR_LIST_IN_CONF_LOGMSG = + "{} : list of Xponders {} in configuration"; /** * Implements the FNV-1 64bit algorithm. 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 5ad42df29..30d622460 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 @@ -170,7 +170,7 @@ public class PortMappingVersion121 { Ports port = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get(); Mapping newMapping = updateMappingObject(nodeId, port, oldMapping); - LOG.debug("{} : Updating old mapping Data {} for {} by new mapping data {}", + LOG.debug(PortMappingUtils.UPDATE_MAPPING_LOGMSG, nodeId, oldMapping, oldMapping.getLogicalConnectionPoint(), newMapping); final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction(); InstanceIdentifier mapIID = InstanceIdentifier.create(Network.class) @@ -237,8 +237,7 @@ public class PortMappingVersion121 { Destination destination0 = cm.nonnullDestination().values().iterator().next(); String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName(); if (slcp == null) { - LOG.error("{} : Error in connection-map analysis for source {} and destination (CP+port) {}", - nodeId, skey, dkey); + LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey); continue; } String dlcp = lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null; @@ -286,7 +285,7 @@ public class PortMappingVersion121 { for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) { List srgCps = new ArrayList<>(); - LOG.debug("{} : Getting Circuitpacks for Srg Number {}", deviceId, srgCounter); + LOG.debug(PortMappingUtils.GETTING_CP_LOGMSG, deviceId, srgCounter); InstanceIdentifier srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter))); Optional ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId, @@ -341,13 +340,13 @@ public class PortMappingVersion121 { } if (Port.PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) { - LOG.debug("{} : port {} on {} is not roadm-external" + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, + LOG.debug(PortMappingUtils.PORT_NOT_RDMEXT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, nodeId, port.getPortName(), circuitPackName); continue; } if (keys.contains(currentKey)) { - LOG.debug("{} : port {} on {} has already been handled" + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, + LOG.debug(PortMappingUtils.PORT_ALREADY_HANDLED_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, nodeId, port.getPortName(), circuitPackName); continue; } @@ -366,7 +365,7 @@ public class PortMappingVersion121 { case Rx: case Tx: if (!checkPartnerPortNotNull(port)) { - LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_UNIDIR_LOGMSG + LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, nodeId, port.getPortName(), circuitPackName); continue; @@ -442,7 +441,7 @@ public class PortMappingVersion121 { Integer maxDegree = ordmInfo.getMaxDegrees() == null ? 20 : ordmInfo.getMaxDegrees().toJava(); for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) { - LOG.debug("{} : Getting Connection ports for Degree Number {}", deviceId, degreeCounter); + LOG.debug(PortMappingUtils.GETTING_CONPORT_LOGMSG, deviceId, degreeCounter); InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter))); Optional ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId, @@ -510,7 +509,6 @@ public class PortMappingVersion121 { private List getCpToDegreeList(Map degrees, Map interfaceList) { List cpToDegreeList = new ArrayList<>(); for (Degree degree : degrees.values()) { - LOG.debug("Inside CP to degree list"); cpToDegreeList.addAll(degree.nonnullCircuitPacks().values().stream() .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(), degree.getDegreeNumber().toString(), interfaceList)) @@ -556,7 +554,7 @@ public class PortMappingVersion121 { commit.get(); return true; } catch (InterruptedException | ExecutionException e) { - LOG.warn("Failed to post {}", network, e); + LOG.warn(PortMappingUtils.PORTMAPPING_POST_FAIL_LOGMSG, nodeId, network, e); return false; } } @@ -621,11 +619,12 @@ public class PortMappingVersion121 { try { Optional openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId, interfaces.getInterfaceName()); - if (!openRoadmInterface.isPresent()) { - LOG.warn("{} : Interface {} was null!", nodeId, interfaces.getInterfaceName()); + if (openRoadmInterface.isEmpty()) { + LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG, + nodeId, interfaces.getInterfaceName() + "- empty interface"); continue; } - LOG.debug("{} : interface get from device is {} and of type {}", + LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG, nodeId, openRoadmInterface.get().getName(), openRoadmInterface.get().getType()); Class interfaceType = (Class) openRoadmInterface.get().getType(); @@ -637,7 +636,7 @@ public class PortMappingVersion121 { mpBldr.setSupportingOts(interfaces.getInterfaceName()); } } catch (OpenRoadmInterfaceException ex) { - LOG.warn("{} : Error while getting interface {} - ", nodeId, interfaces.getInterfaceName(), ex); + LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG, nodeId, interfaces.getInterfaceName(), ex); } } return mpBldr; @@ -679,7 +678,7 @@ public class PortMappingVersion121 { //circuitPackName2 will be updated by reference contrary to circuitPackName List circuitPackList, Map lcpMap) { if (!checkPartnerPortNotNull(port)) { - LOG.warn("{} : port {} on {} - Error in the configuration ", nodeId, port.getPortName(), circuitPackName); + LOG.warn(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG, nodeId, port.getPortName(), circuitPackName); return null; } if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { @@ -688,15 +687,15 @@ public class PortMappingVersion121 { Optional cpOpt = circuitPackList.stream() .filter(cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) .findFirst(); - if (!cpOpt.isPresent()) { - LOG.error("{} : Error fetching circuit-pack {}", nodeId, port.getPartnerPort().getCircuitPackName()); + if (cpOpt.isEmpty()) { + LOG.error(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, port.getPartnerPort().getCircuitPackName()); return null; } Optional poOpt = cpOpt.get().nonnullPorts().values().stream() .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName())) .findFirst(); - if (!poOpt.isPresent()) { - LOG.error("{} : Error fetching port {} on {}", + if (poOpt.isEmpty()) { + LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName()); return null; } @@ -741,7 +740,7 @@ public class PortMappingVersion121 { List circuitPackList, Map lcpMap, Map mappingMap) { if (port.getPortQual() == null) { - LOG.warn("{} : port {} on {} - PortQual was not found", nodeId, port.getPortName(), circuitPackName); + LOG.warn(PortMappingUtils.PORTQUAL_LOGMSG, nodeId, port.getPortName(), circuitPackName, "not found"); return new int[] {line, client}; } @@ -764,8 +763,8 @@ public class PortMappingVersion121 { break; default: - LOG.error("{} : port {} on {} - unsupported PortQual {}", - nodeId, port.getPortName(), circuitPackName, port.getPortQual()); + LOG.error(PortMappingUtils.PORTQUAL_LOGMSG, + nodeId, port.getPortName(), circuitPackName, port.getPortQual() + " not supported"); } return new int[] {line, client}; } @@ -817,7 +816,7 @@ public class PortMappingVersion121 { Map degrees = getDegreesMap(nodeId, deviceInfo); Map interfaceList = getEthInterfaceList(nodeId); List cpToDegreeList = getCpToDegreeList(degrees, interfaceList); - LOG.info("{} : Map looks like this {}", nodeId, interfaceList); + LOG.info(PortMappingUtils.MAP_LOOKS_LOGMSG, nodeId, interfaceList); postPortMapping(nodeId, null, null, cpToDegreeList); Map> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo); @@ -934,7 +933,7 @@ public class PortMappingVersion121 { portMapList.add(createMappingObject(nodeId, port2, cp2Name, logicalConnectionPoint2)); break; default: - LOG.error("{} : Number of connection port for DEG{} is incorrect", nodeId, cpMapEntry.getKey()); + LOG.error(PortMappingUtils.NOT_CORRECT_CONPORT_LOGMSG, nodeId, cpMapEntry.getKey()); continue; } } @@ -945,7 +944,7 @@ public class PortMappingVersion121 { if (deviceInfo.getNodeType() == null) { // TODO make mandatory in yang - LOG.error("Node type field is missing"); + LOG.error(PortMappingUtils.NODE_TYPE_LOGMSG, deviceInfo.getNodeId(), "field missing"); return null; } @@ -958,7 +957,7 @@ public class PortMappingVersion121 { nodeInfoBldr.setNodeType(NodeTypes.forValue(deviceInfo.getNodeType().getIntValue())); break; default: - LOG.error("Error with node-type of {}", deviceInfo.getNodeId()); + 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()) { 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 9017d9c5d..f96103e5d 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 @@ -194,7 +194,7 @@ public class PortMappingVersion221 { Ports port = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get(); Mapping newMapping = updateMappingObject(nodeId, port, oldMapping); - LOG.debug("{} : Updating old mapping Data {} for {} by new mapping data {}", + LOG.debug(PortMappingUtils.UPDATE_MAPPING_LOGMSG, nodeId, oldMapping, oldMapping.getLogicalConnectionPoint(), newMapping); final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction(); InstanceIdentifier mapIID = InstanceIdentifier.create(Network.class) @@ -232,7 +232,7 @@ public class PortMappingVersion221 { List circuitPackList = new ArrayList<>(device.nonnullCircuitPacks().values()); circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName)); if (device.getXponder() == null) { - LOG.warn("{} : configuration does not contain a list of Xponders", nodeId); + LOG.warn(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, "not found"); // Variables to keep track of number of line ports and client ports int line = 1; int client = 1; @@ -255,7 +255,7 @@ public class PortMappingVersion221 { } } } else { - LOG.info("{} : configuration contains a list of xponders", nodeId); + LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, "found"); for (Xponder xponder : deviceObject.get().nonnullXponder().values()) { // Variables to keep track of number of line ports and client ports int line = 1; @@ -299,7 +299,7 @@ public class PortMappingVersion221 { } if (device.getConnectionMap() == null) { - LOG.warn("{} : No connection-map inside device configuration", nodeId); + LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId); } else { Collection connectionMap = deviceObject.get().nonnullConnectionMap().values(); for (ConnectionMap cm : connectionMap) { @@ -308,8 +308,7 @@ public class PortMappingVersion221 { Destination destination0 = cm.nonnullDestination().values().iterator().next(); String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName(); if (slcp == null) { - LOG.error("{} : Error in connection-map analysis for source {} and destination (CP+port) {}", - nodeId, skey, dkey); + LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey); continue; } String dlcp = lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null; @@ -395,7 +394,7 @@ public class PortMappingVersion221 { for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) { List srgCps = new ArrayList<>(); - LOG.debug("{} : Getting Circuitpacks for Srg Number {}", deviceId, srgCounter); + LOG.debug(PortMappingUtils.GETTING_CP_LOGMSG, deviceId, srgCounter); InstanceIdentifier srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter))); Optional ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId, @@ -447,13 +446,13 @@ public class PortMappingVersion221 { } if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) { - LOG.debug("{} : port {} on {} is not roadm-external" + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, + LOG.debug(PortMappingUtils.PORT_NOT_RDMEXT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, nodeId, port.getPortName(), circuitPackName); continue; } if (keys.contains(currentKey)) { - LOG.debug("{} : port {} on {} has already been handled" + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, + LOG.debug(PortMappingUtils.PORT_ALREADY_HANDLED_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, nodeId, port.getPortName(), circuitPackName); continue; } @@ -472,7 +471,7 @@ public class PortMappingVersion221 { case Rx: case Tx: if (!checkPartnerPortNotNull(port)) { - LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_UNIDIR_LOGMSG + LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, nodeId, port.getPortName(), circuitPackName); continue; @@ -547,7 +546,7 @@ public class PortMappingVersion221 { Integer maxDegree = ordmInfo.getMaxDegrees() == null ? 20 : ordmInfo.getMaxDegrees().toJava(); for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) { - LOG.debug("{} : Getting Connection ports for Degree Number {}", deviceId, degreeCounter); + LOG.debug(PortMappingUtils.GETTING_CONPORT_LOGMSG, deviceId, degreeCounter); InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter))); Optional ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId, @@ -634,7 +633,6 @@ public class PortMappingVersion221 { private List getCpToDegreeList(Map degrees, Map interfaceList) { List cpToDegreeList = new ArrayList<>(); for (Degree degree : degrees.values()) { - LOG.debug("Inside CP to degree list"); cpToDegreeList.addAll(degree.nonnullCircuitPacks().values().stream() .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(), degree.getDegreeNumber().toString(), interfaceList)) @@ -705,7 +703,7 @@ public class PortMappingVersion221 { commit.get(); return true; } catch (InterruptedException | ExecutionException e) { - LOG.warn("{} : Failed to post {}", nodeId, network, e); + LOG.warn(PortMappingUtils.PORTMAPPING_POST_FAIL_LOGMSG, nodeId, network, e); return false; } } @@ -813,11 +811,12 @@ public class PortMappingVersion221 { try { Optional openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId, interfaces.getInterfaceName()); - if (!openRoadmInterface.isPresent()) { - LOG.warn("{} : Interface {} was null!", nodeId, interfaces.getInterfaceName()); + if (openRoadmInterface.isEmpty()) { + LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG, + nodeId, interfaces.getInterfaceName() + "- empty interface"); continue; } - LOG.debug("{} : interface get from device is {} and of type {}", + LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG, nodeId, openRoadmInterface.get().getName(), openRoadmInterface.get().getType()); Class interfaceType = (Class) openRoadmInterface.get().getType(); @@ -832,7 +831,7 @@ public class PortMappingVersion221 { mpBldr.setSupportingOdu4(interfaces.getInterfaceName()); } } catch (OpenRoadmInterfaceException ex) { - LOG.warn("{} : Error while getting interface {} - ", nodeId, interfaces.getInterfaceName(), ex); + LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG, nodeId, interfaces.getInterfaceName(), ex); } } return mpBldr; @@ -888,7 +887,7 @@ public class PortMappingVersion221 { //circuitPackName2 will be updated by reference contrary to circuitPackName List circuitPackList, Map lcpMap) { if (!checkPartnerPortNotNull(port)) { - LOG.warn("{} : port {} on {} - Error in the configuration ", nodeId, port.getPortName(), circuitPackName); + LOG.warn(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG, nodeId, port.getPortName(), circuitPackName); return null; } if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { @@ -898,15 +897,15 @@ public class PortMappingVersion221 { .filter( cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) .findFirst(); - if (!cpOpt.isPresent()) { - LOG.error("{} : Error fetching circuit-pack {}", nodeId, port.getPartnerPort().getCircuitPackName()); + if (cpOpt.isEmpty()) { + LOG.error(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, port.getPartnerPort().getCircuitPackName()); return null; } Optional poOpt = cpOpt.get().nonnullPorts().values().stream() .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName())) .findFirst(); - if (!poOpt.isPresent()) { - LOG.error("{} : Error fetching port {} on {}", + if (poOpt.isEmpty()) { + LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName()); return null; } @@ -951,7 +950,7 @@ public class PortMappingVersion221 { String circuitPackName, Ports port, List circuitPackList, Map lcpMap, Map mappingMap) { if (port.getPortQual() == null) { - LOG.warn("{} : port {} on {} - PortQual was not found", nodeId, port.getPortName(), circuitPackName); + LOG.warn(PortMappingUtils.PORTQUAL_LOGMSG, nodeId, port.getPortName(), circuitPackName, "not found"); return new int[] {line, client}; } @@ -976,8 +975,8 @@ public class PortMappingVersion221 { break; default: - LOG.error("{} : port {} on {} - unsupported PortQual {}", - nodeId, port.getPortName(), circuitPackName, port.getPortQual()); + LOG.error(PortMappingUtils.PORTQUAL_LOGMSG, + nodeId, port.getPortName(), circuitPackName, port.getPortQual() + " not supported"); } return new int[] {line, client}; } @@ -1036,7 +1035,7 @@ public class PortMappingVersion221 { Map degrees = getDegreesMap(nodeId, deviceInfo); Map interfaceList = getEthInterfaceList(nodeId); List cpToDegreeList = getCpToDegreeList(degrees, interfaceList); - LOG.info("{} : Map looks like this {}", nodeId, interfaceList); + LOG.info(PortMappingUtils.MAP_LOOKS_LOGMSG, nodeId, interfaceList); postPortMapping(nodeId, null, null, cpToDegreeList, null, null); Map> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo); @@ -1153,7 +1152,7 @@ public class PortMappingVersion221 { portMapList.add(createMappingObject(nodeId, port2, cp2Name, logicalConnectionPoint2)); break; default: - LOG.error("{} : Number of connection port for DEG{} is incorrect", nodeId, cpMapEntry.getKey()); + LOG.error(PortMappingUtils.NOT_CORRECT_CONPORT_LOGMSG, nodeId, cpMapEntry.getKey()); continue; } } @@ -1164,7 +1163,7 @@ public class PortMappingVersion221 { if (deviceInfo.getNodeType() == null) { // TODO make mandatory in yang - LOG.error("Node type field is missing"); + LOG.error(PortMappingUtils.NODE_TYPE_LOGMSG, deviceInfo.getNodeId(), "field missing"); return null; } 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 81ea55fb1..21f1ae54a 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 @@ -214,7 +214,7 @@ public class PortMappingVersion710 { Ports port = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get(); Mapping newMapping = updateMappingObject(nodeId, port, oldMapping); - LOG.debug("{} : Updating old mapping Data {} for {} by new mapping data {}", + LOG.debug(PortMappingUtils.UPDATE_MAPPING_LOGMSG, nodeId, oldMapping, oldMapping.getLogicalConnectionPoint(), newMapping); final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction(); InstanceIdentifier mapIID = InstanceIdentifier.create(Network.class) @@ -327,7 +327,7 @@ public class PortMappingVersion710 { List circuitPackList = new ArrayList<>(device.nonnullCircuitPacks().values()); circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName)); if (device.getXponder() == null) { - LOG.warn("{} : configuration does not contain a list of Xponders", nodeId); + LOG.warn(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, "not found"); // Variables to keep track of number of line ports and client ports int line = 1; int client = 1; @@ -350,7 +350,7 @@ public class PortMappingVersion710 { } } } else { - LOG.info("{} : configuration contains a list of xponders", nodeId); + LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, "found"); for (Xponder xponder : deviceObject.get().nonnullXponder().values()) { // Variables to keep track of number of line ports and client ports int line = 1; @@ -394,7 +394,7 @@ public class PortMappingVersion710 { } if (device.getConnectionMap() == null) { - LOG.warn("{} : No connection-map inside device configuration", nodeId); + LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId); } else { Collection connectionMap = deviceObject.get().nonnullConnectionMap().values(); for (ConnectionMap cm : connectionMap) { @@ -403,8 +403,7 @@ public class PortMappingVersion710 { Destination destination0 = cm.nonnullDestination().values().iterator().next(); String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName(); if (slcp == null) { - LOG.error("{} : Error in connection-map analysis for source {} and destination (CP+port) {}", - nodeId, skey, dkey); + LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey); continue; } String dlcp = lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null; @@ -491,7 +490,7 @@ public class PortMappingVersion710 { for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) { List srgCps = new ArrayList<>(); - LOG.debug("{} : Getting Circuitpacks for Srg Number {}", deviceId, srgCounter); + LOG.debug(PortMappingUtils.GETTING_CP_LOGMSG, deviceId, srgCounter); InstanceIdentifier srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter))); Optional ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId, @@ -543,13 +542,13 @@ public class PortMappingVersion710 { } if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) { - LOG.debug("{} : port {} on {} is not roadm-external" + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, + LOG.debug(PortMappingUtils.PORT_NOT_RDMEXT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, nodeId, port.getPortName(), circuitPackName); continue; } if (keys.contains(currentKey)) { - LOG.debug("{} : port {} on {} has already been handled" + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, + LOG.debug(PortMappingUtils.PORT_ALREADY_HANDLED_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, nodeId, port.getPortName(), circuitPackName); continue; } @@ -568,7 +567,7 @@ public class PortMappingVersion710 { case Rx: case Tx: if (!checkPartnerPortNotNull(port)) { - LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_UNIDIR_LOGMSG + LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG, nodeId, port.getPortName(), circuitPackName); continue; @@ -660,7 +659,7 @@ public class PortMappingVersion710 { Integer maxDegree = ordmInfo.getMaxDegrees() == null ? 20 : ordmInfo.getMaxDegrees().toJava(); for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) { - LOG.debug("{} : Getting Connection ports for Degree Number {}", deviceId, degreeCounter); + LOG.debug(PortMappingUtils.GETTING_CONPORT_LOGMSG, deviceId, degreeCounter); InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter))); Optional ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId, @@ -747,7 +746,6 @@ public class PortMappingVersion710 { private List getCpToDegreeList(Map degrees, Map interfaceList) { List cpToDegreeList = new ArrayList<>(); for (Degree degree : degrees.values()) { - LOG.debug("Inside CP to degree list"); cpToDegreeList.addAll(degree.nonnullCircuitPacks().values().stream() .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(), degree.getDegreeNumber().toString(), interfaceList)) @@ -821,7 +819,7 @@ public class PortMappingVersion710 { commit.get(); return true; } catch (InterruptedException | ExecutionException e) { - LOG.warn("{} : Failed to post {}", nodeId, network, e); + LOG.warn(PortMappingUtils.PORTMAPPING_POST_FAIL_LOGMSG, nodeId, network, e); return false; } } @@ -964,11 +962,12 @@ public class PortMappingVersion710 { try { Optional openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId, interfaces.getInterfaceName()); - if (!openRoadmInterface.isPresent()) { - LOG.warn("{} : Interface {} was null!", nodeId, interfaces.getInterfaceName()); + if (openRoadmInterface.isEmpty()) { + LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG, + nodeId, interfaces.getInterfaceName() + "- empty interface"); continue; } - LOG.debug("{} : interface get from device is {} and of type {}", + LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG, nodeId, openRoadmInterface.get().getName(), openRoadmInterface.get().getType()); Class interfaceType = (Class) openRoadmInterface.get().getType(); @@ -992,7 +991,7 @@ public class PortMappingVersion710 { } } catch (OpenRoadmInterfaceException ex) { - LOG.warn("{} : Error while getting interface {} - ", + LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG, nodeId, interfaces.getInterfaceName(), ex); } } @@ -1091,7 +1090,7 @@ public class PortMappingVersion710 { //circuitPackName2 will be updated by reference contrary to circuitPackName List circuitPackList, Map lcpMap) { if (!checkPartnerPortNotNull(port)) { - LOG.warn("{} : port {} on {} - Error in the configuration ", nodeId, port.getPortName(), circuitPackName); + LOG.warn(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG, nodeId, port.getPortName(), circuitPackName); return null; } if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { @@ -1101,15 +1100,15 @@ public class PortMappingVersion710 { .filter( cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) .findFirst(); - if (!cpOpt.isPresent()) { - LOG.error("{} : Error fetching circuit-pack {}", nodeId, port.getPartnerPort().getCircuitPackName()); + if (cpOpt.isEmpty()) { + LOG.error(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, port.getPartnerPort().getCircuitPackName()); return null; } Optional poOpt = cpOpt.get().nonnullPorts().values().stream() .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName())) .findFirst(); - if (!poOpt.isPresent()) { - LOG.error("{} : Error fetching port {} on {}", + if (poOpt.isEmpty()) { + LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName()); return null; } @@ -1155,7 +1154,7 @@ public class PortMappingVersion710 { List circuitPackList, Map lcpMap, Map mappingMap) { if (port.getPortQual() == null) { - LOG.warn("{} : port {} on {} - PortQual was not found", nodeId, port.getPortName(), circuitPackName); + LOG.warn(PortMappingUtils.PORTQUAL_LOGMSG, nodeId, port.getPortName(), circuitPackName, "not found"); return new int[] {line, client}; } @@ -1180,8 +1179,8 @@ public class PortMappingVersion710 { break; default: - LOG.error("{} : port {} on {} - unsupported PortQual {}", - nodeId, port.getPortName(), circuitPackName, port.getPortQual()); + LOG.error(PortMappingUtils.PORTQUAL_LOGMSG, + nodeId, port.getPortName(), circuitPackName, port.getPortQual() + " not supported"); } return new int[] {line, client}; } @@ -1264,7 +1263,7 @@ public class PortMappingVersion710 { Map degrees = getDegreesMap(nodeId, deviceInfo); Map interfaceList = getEthInterfaceList(nodeId); List cpToDegreeList = getCpToDegreeList(degrees, interfaceList); - LOG.info("{} : Map looks like this {}", nodeId, interfaceList); + LOG.info(PortMappingUtils.MAP_LOOKS_LOGMSG, nodeId, interfaceList); postPortMapping(nodeId, null, null, cpToDegreeList, null, null); Map> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo); @@ -1381,7 +1380,7 @@ public class PortMappingVersion710 { portMapList.add(createMappingObject(nodeId, port2, cp2Name, logicalConnectionPoint2)); break; default: - LOG.error("{} : Number of connection port for DEG{} is incorrect", nodeId, cpMapEntry.getKey()); + LOG.error(PortMappingUtils.NOT_CORRECT_CONPORT_LOGMSG, nodeId, cpMapEntry.getKey()); continue; } } @@ -1392,7 +1391,7 @@ public class PortMappingVersion710 { if (deviceInfo.getNodeType() == null) { // TODO make mandatory in yang - LOG.error("Node type field is missing"); + LOG.error(PortMappingUtils.NODE_TYPE_LOGMSG, deviceInfo.getNodeId(), "field missing"); return null; } -- 2.36.6