From 700eb0475db06f97244c382d598ab04b8d774f53 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Fri, 8 Oct 2021 12:04:05 +0200 Subject: [PATCH] Use constants for PortMapping log messages Step 4 Few PortMapping log messages were redundant and needed to be realigned. They were fixed previously but this created new string for the words "create" and "update" and "found". Sonar complains they are used multiples times. Since these words 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: I71a5e8eb654256004f11d10e9f3d3273d79bcede --- .../common/mapping/PortMappingUtils.java | 3 +++ .../common/mapping/PortMappingVersion121.java | 20 ++++++++--------- .../common/mapping/PortMappingVersion221.java | 22 +++++++++---------- .../common/mapping/PortMappingVersion710.java | 22 +++++++++---------- 4 files changed, 35 insertions(+), 32 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 0a2ed8cc5..2951e2c81 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 @@ -32,12 +32,14 @@ public final class PortMappingUtils { "- 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 = "create"; public static final String CREATE_MAPPING_DATA_LOGMSG = "{} : OpenROADM version {} node - Creating Mapping Data"; public static final String DEVICE_HAS_LOGMSG = "{} : device has {} {}"; public static final String FETCH_CONNECTIONPORT_LOGMSG = "{} : fetching connection-port {} at circuit-pack {}"; + public static final String FOUND = "found"; public static final String GETTING_CONPORT_LOGMSG = "{} : getting connection-ports for degree number {}"; public static final String GETTING_CP_LOGMSG = @@ -94,6 +96,7 @@ public final class PortMappingUtils { "{} : unable to create MC capabilities"; public static final String UNSUPPORTED_DIR_LOGMSG = "{} : port {} on {} - unsupported Direction {}"; + public static final String UPDATE = "update"; 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 = 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 7be7778a2..7994c4bd8 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 @@ -128,26 +128,26 @@ public class PortMappingVersion121 { // Get TTP port mapping if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) { // return false if mapping creation for TTP's failed - LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "TTP's"); + LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "TTP's"); return false; } // Get PP port mapping if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) { // return false if mapping creation for PP's failed - LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "PP's"); + LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "PP's"); return false; } break; case Xpdr: if (!createXpdrPortMapping(nodeId, portMapList)) { - LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "Xponder"); + LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "Xponder"); return false; } break; default: LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, - nodeId, "create", deviceInfo.getNodeType() + " - unknown nodetype"); + nodeId, PortMappingUtils.CREATE, deviceInfo.getNodeType() + " - unknown nodetype"); break; } @@ -156,11 +156,11 @@ public class PortMappingVersion121 { public boolean updateMapping(String nodeId, Mapping oldMapping) { if (nodeId == null) { - LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , "update", "a null value"); + LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , PortMappingUtils.UPDATE, "a null value"); return false; } if (oldMapping == null) { - LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "update", "a null value"); + LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.UPDATE, "a null value"); return false; } InstanceIdentifier portId = InstanceIdentifier.create(OrgOpenroadmDevice.class) @@ -182,7 +182,7 @@ public class PortMappingVersion121 { return true; } catch (InterruptedException | ExecutionException e) { LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, - nodeId, "update", oldMapping.getLogicalConnectionPoint(), e); + nodeId, PortMappingUtils.UPDATE, oldMapping.getLogicalConnectionPoint(), e); return false; } } @@ -199,7 +199,7 @@ public class PortMappingVersion121 { } OrgOpenroadmDevice device = deviceObject.get(); if (device.getCircuitPacks() == null) { - LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, "found"); + LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND); return false; } // Variable to keep track of number of line ports @@ -214,7 +214,7 @@ public class PortMappingVersion121 { for (CircuitPacks cp : circuitPackList) { String circuitPackName = cp.getCircuitPackName(); if (cp.getPorts() == null) { - LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName); + LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName); continue; } List portList = new ArrayList<>(cp.nonnullPorts().values()); @@ -390,7 +390,7 @@ public class PortMappingVersion121 { return new ArrayList<>(); } if (circuitPackObject.get().getPorts() == null) { - LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName); + LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName); return new ArrayList<>(); } return new ArrayList<>(circuitPackObject.get().nonnullPorts().values()); 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 3a7839ddd..595af60fa 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 @@ -147,14 +147,14 @@ public class PortMappingVersion221 { // Get TTP port mapping if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) { // return false if mapping creation for TTP's failed - LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "TTP's"); + LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "TTP's"); return false; } // Get PP port mapping if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) { // return false if mapping creation for PP's failed - LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "PP's"); + LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "PP's"); return false; } // Get MC capabilities @@ -166,13 +166,13 @@ public class PortMappingVersion221 { break; case Xpdr: if (!createXpdrPortMapping(nodeId, portMapList)) { - LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "Xponder"); + LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "Xponder"); return false; } break; default: LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, - nodeId, "create", deviceInfo.getNodeType() + " - unknown nodetype"); + nodeId, PortMappingUtils.CREATE, deviceInfo.getNodeType() + " - unknown nodetype"); break; } @@ -181,11 +181,11 @@ public class PortMappingVersion221 { public boolean updateMapping(String nodeId, Mapping oldMapping) { if (nodeId == null) { - LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , "update", "a null value"); + LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , PortMappingUtils.UPDATE, "a null value"); return false; } if (oldMapping == null) { - LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "update", "a null value"); + LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.UPDATE, "a null value"); return false; } InstanceIdentifier portId = InstanceIdentifier.create(OrgOpenroadmDevice.class) @@ -207,7 +207,7 @@ public class PortMappingVersion221 { return true; } catch (InterruptedException | ExecutionException e) { LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, - nodeId, "update", oldMapping.getLogicalConnectionPoint(), e); + nodeId, PortMappingUtils.UPDATE, oldMapping.getLogicalConnectionPoint(), e); return false; } } @@ -224,7 +224,7 @@ public class PortMappingVersion221 { } OrgOpenroadmDevice device = deviceObject.get(); if (device.getCircuitPacks() == null) { - LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, "found"); + LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND); return false; } @@ -242,7 +242,7 @@ public class PortMappingVersion221 { for (CircuitPacks cp : circuitPackList) { String circuitPackName = cp.getCircuitPackName(); if (cp.getPorts() == null) { - LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName); + LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName); continue; } List portList = new ArrayList<>(cp.nonnullPorts().values()); @@ -256,7 +256,7 @@ public class PortMappingVersion221 { } } } else { - LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, "found"); + LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, PortMappingUtils.FOUND); for (Xponder xponder : deviceObject.get().nonnullXponder().values()) { // Variables to keep track of number of line ports and client ports int line = 1; @@ -497,7 +497,7 @@ public class PortMappingVersion221 { return new ArrayList<>(); } if (circuitPackObject.get().getPorts() == null) { - LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName); + LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName); return new ArrayList<>(); } return new ArrayList<>(circuitPackObject.get().nonnullPorts().values()); 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 c36cc86a0..7c13bf054 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 @@ -157,14 +157,14 @@ public class PortMappingVersion710 { // Get TTP port mapping if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) { // return false if mapping creation for TTP's failed - LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "TTP's"); + LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "TTP's"); return false; } // Get PP port mapping if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) { // return false if mapping creation for PP's failed - LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "PP's"); + LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "PP's"); return false; } // Get MC capabilities @@ -176,7 +176,7 @@ public class PortMappingVersion710 { break; case Xpdr: if (!createXpdrPortMapping(nodeId, portMapList)) { - LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "Xponder"); + LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "Xponder"); return false; } // In the case of 7.1 models, even XPDR advertizes mc-capabilities, @@ -190,7 +190,7 @@ public class PortMappingVersion710 { break; default: LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, - nodeId, "create", deviceInfo.getNodeType() + " - unknown nodetype"); + nodeId, PortMappingUtils.CREATE, deviceInfo.getNodeType() + " - unknown nodetype"); break; } @@ -199,11 +199,11 @@ public class PortMappingVersion710 { public boolean updateMapping(String nodeId, Mapping oldMapping) { if (nodeId == null) { - LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , "update", "a null value"); + LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , PortMappingUtils.UPDATE, "a null value"); return false; } if (oldMapping == null) { - LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "update", "a null value"); + LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.UPDATE, "a null value"); return false; } InstanceIdentifier portId = InstanceIdentifier.create(OrgOpenroadmDevice.class) @@ -225,7 +225,7 @@ public class PortMappingVersion710 { return true; } catch (InterruptedException | ExecutionException e) { LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, - nodeId, "update", oldMapping.getLogicalConnectionPoint(), e); + nodeId, PortMappingUtils.UPDATE, oldMapping.getLogicalConnectionPoint(), e); return false; } } @@ -308,7 +308,7 @@ public class PortMappingVersion710 { } OrgOpenroadmDevice device = deviceObject.get(); if (device.getCircuitPacks() == null) { - LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, "found"); + LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND); return false; } @@ -326,7 +326,7 @@ public class PortMappingVersion710 { for (CircuitPacks cp : circuitPackList) { String circuitPackName = cp.getCircuitPackName(); if (cp.getPorts() == null) { - LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName); + LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName); continue; } List portList = new ArrayList<>(cp.nonnullPorts().values()); @@ -340,7 +340,7 @@ public class PortMappingVersion710 { } } } else { - LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, "found"); + LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, PortMappingUtils.FOUND); for (Xponder xponder : deviceObject.get().nonnullXponder().values()) { // Variables to keep track of number of line ports and client ports int line = 1; @@ -582,7 +582,7 @@ public class PortMappingVersion710 { return new ArrayList<>(); } if (circuitPackObject.get().getPorts() == null) { - LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName); + LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName); return new ArrayList<>(); } return new ArrayList<>(circuitPackObject.get().nonnullPorts().values()); -- 2.36.6