Fix some small issues pointed by Sonar 73/97873/1
authorguillaume.lambert <guillaume.lambert@orange.com>
Tue, 12 Oct 2021 19:59:53 +0000 (21:59 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Tue, 12 Oct 2021 19:59:53 +0000 (21:59 +0200)
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: I05cce46dfa32ed000cc5c3ce1b4a3d9d1b910029

common/src/main/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl221.java
inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java
inventory/src/main/java/org/opendaylight/transportpce/inventory/INode121.java
inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java
nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/serialization/NotificationAlarmServiceSerializer.java
nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/serialization/NotificationServiceSerializer.java
nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/utils/NbiNotificationsUtils.java
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/openroadminterface/OpenRoadmInterface710.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/utils/TapiContext.java

index b3b9643c1c1e3157f9cf0d0ffb1fac2e7abc64ed..f22c3eb9420979cd3b8549f5aa813fab4869c1d2 100644 (file)
@@ -50,6 +50,8 @@ import org.slf4j.LoggerFactory;
 public class CrossConnectImpl221 {
 
     private static final Logger LOG = LoggerFactory.getLogger(CrossConnectImpl221.class);
+    private static final String DEV_TRANSACTION_NOT_FOUND = "Device transaction for device {} was not found!";
+    private static final String UNABLE_DEV_TRANSACTION = "Unable to obtain device transaction for device {}!";
     private final DeviceTransactionManager deviceTransactionManager;
 
     public CrossConnectImpl221(DeviceTransactionManager deviceTransactionManager) {
@@ -95,11 +97,11 @@ public class CrossConnectImpl221 {
             if (deviceTxOpt.isPresent()) {
                 deviceTx = deviceTxOpt.get();
             } else {
-                LOG.error("Device transaction for device {} was not found!", deviceId);
+                LOG.error(DEV_TRANSACTION_NOT_FOUND, deviceId);
                 return Optional.empty();
             }
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Unable to obtain device transaction for device {}!", deviceId, e);
+            LOG.error(UNABLE_DEV_TRANSACTION, deviceId, e);
             return Optional.empty();
         }
 
@@ -145,11 +147,11 @@ public class CrossConnectImpl221 {
             if (deviceTxOpt.isPresent()) {
                 deviceTx = deviceTxOpt.get();
             } else {
-                LOG.error("Device transaction for device {} was not found!", deviceId);
+                LOG.error(DEV_TRANSACTION_NOT_FOUND, deviceId);
                 return null;
             }
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Unable to obtain device transaction for device {}!", deviceId, e);
+            LOG.error(UNABLE_DEV_TRANSACTION, deviceId, e);
             return null;
         }
 
@@ -309,11 +311,11 @@ public class CrossConnectImpl221 {
             if (deviceTxOpt.isPresent()) {
                 deviceTx = deviceTxOpt.get();
             } else {
-                LOG.error("Device transaction for device {} was not found!", deviceId);
+                LOG.error(DEV_TRANSACTION_NOT_FOUND, deviceId);
                 return Optional.empty();
             }
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Unable to obtain device transaction for device {}!", deviceId, e);
+            LOG.error(UNABLE_DEV_TRANSACTION, deviceId, e);
             return Optional.empty();
         }
 
index cdcfc621ef6d5e2bb71cc8796a702240ad15d7e7..c7299c835b230c05d60ca0d7e821627c3b159407 100644 (file)
@@ -39,7 +39,7 @@ public class INode {
     }
 
     public boolean addNode(String deviceId, String openROADMversion) {
-        boolean sqlResult = false;
+        //boolean sqlResult = false;
         return inode121.addNode(deviceId);
 
     }
@@ -60,7 +60,7 @@ public class INode {
         } catch (SQLException e) {
             LOG.error("Something wrong when fetching node in DB", e);
         }
-        return nodeExists == 0 ? false : true;
+        return nodeExists != 0;
     }
 
     public boolean dataExists(String tableName, String searchKeys) {
@@ -79,7 +79,7 @@ public class INode {
         } catch (SQLException e) {
             LOG.error("Something wrong when fetching data in DB", e);
         }
-        return dataExists == 0 ? false : true;
+        return dataExists != 0;
     }
 
   /*  public void getRoadmShelves(String nodeId, String openRoadmVersion)
index e5ba1d8334a3f1ee4bc76c57a919a5a0683bdf6b..bc185290114126cb3d59ca1fbb0bd32ab4013c84 100644 (file)
@@ -194,7 +194,7 @@ public class INode121 {
         } catch (SQLException e) {
             LOG.error("Something wrong when fetching node in DB", e);
         }
-        return nodeExists == 0 ? false : true;
+        return nodeExists != 0;
     }
 
     public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException {
index eef0289b1bf1fc8078d90275c06dd134661398bb..852a7a849c6dc78c106ac6f765363ec915bb2931 100644 (file)
@@ -192,7 +192,7 @@ public class INode221 {
         } catch (SQLException e) {
             LOG.error("Something wrong when fetching node in DB", e);
         }
-        return nodeExists == 0 ? false : true;
+        return nodeExists != 0;
     }
 
     public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException {
index fcf5f026fe1dcdd48a82675b7fe78720f5047523..9d0371a125cab43fab04588c34d0267a470c83d4 100644 (file)
@@ -48,6 +48,7 @@ public class NotificationAlarmServiceSerializer implements Serializer<Notificati
             LOG.info("Serialized event {}", serialized);
             return serialized.getBytes(StandardCharsets.UTF_8);
         } catch (IOException e) {
+            LOG.error("exception raised during serialization", e);
             return new byte[0];
         }
     }
index b3f6ae119c5d86cb44be50145ef48da9c6ea9b6b..dc2c3d775737d8a290baf77416d4f4726a90224b 100644 (file)
@@ -47,6 +47,7 @@ public class NotificationServiceSerializer implements Serializer<NotificationPro
             LOG.info("Serialized event {}", serialized);
             return serialized.getBytes(StandardCharsets.UTF_8);
         } catch (IOException e) {
+            LOG.error("exception raised during serialization", e);
             return new byte[0];
         }
     }
index 0c00503b751c8f1f459bb455743488ec606017d4..af097c35b86d1ec0b222a59126c97f77ad95338b 100644 (file)
@@ -30,7 +30,7 @@ public final class NbiNotificationsUtils {
                 LOG.warn("Kafka property file '{}' is empty", propertyFileName);
             }
         } catch (IOException e) {
-            LOG.warn("Kafka property file '{}' was not found in the classpath", propertyFileName);
+            LOG.error("Kafka property file '{}' was not found in the classpath", propertyFileName, e);
         }
         return props;
     }
index b13bc009730ce7b1e88d87c84a2bffbf5600a945..36faf86e0f5c852171ce31e85e408b8bd4694356 100644 (file)
@@ -143,7 +143,7 @@ public class GnpyResult {
                         counter++;
                     }
                 } catch (IllegalArgumentException e) {
-                    LOG.debug(" in GnpyResult: the element {} is not a ipv4Address ", nodeIp);
+                    LOG.error(" in GnpyResult: the element {} is not a ipv4Address ", nodeIp, e);
                 }
             }
         }
index 51bb5aedac965a292e61bf8999fa8435b3a1c61e..25136668019f08a453c376e67c8973728bfc0393 100644 (file)
@@ -69,6 +69,7 @@ import org.opendaylight.yangtools.yang.common.Uint8;
 public class OpenRoadmInterface710 {
     private static final String MAPPING_ERROR_EXCEPTION_MESSAGE =
         "Unable to get mapping from PortMapping for node % and logical connection port %s";
+    private static final String ODUC4 = "-ODUC4";
     private final PortMapping portMapping;
     private final OpenRoadmInterfaces openRoadmInterfaces;
 
@@ -342,7 +343,7 @@ public class OpenRoadmInterface710 {
             .setMaintTestsignal(maintTestsignal.build());
 
         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
-            logicalConnPoint + "-ODUC4");
+            logicalConnPoint + ODUC4);
 
         // Create a list
         List<String> listSupportingOtucnInterface = new ArrayList<>();
@@ -413,7 +414,7 @@ public class OpenRoadmInterface710 {
             .setMaintTestsignal(maintTestsignal.build());
 
         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
-            alogicalConnPoint + "-ODUC4");
+            alogicalConnPoint + ODUC4);
 
         // Create a list
         List<String> listSupportingOtucnInterface = new ArrayList<>();
@@ -471,7 +472,7 @@ public class OpenRoadmInterface710 {
             .setMaintTestsignal(maintTestsignal.build());
 
         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
-            logicalConnPoint + "-ODUC4");
+            logicalConnPoint + ODUC4);
 
         // Create a list
         List<String> listSupportingOtucnInterface = new ArrayList<>();
@@ -544,7 +545,7 @@ public class OpenRoadmInterface710 {
             .setMaintTestsignal(maintTestsignal.build());
 
         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
-            alogicalConnPoint + "-ODUC4");
+            alogicalConnPoint + ODUC4);
 
         // Create a list
         List<String> listSupportingOtucnInterface = new ArrayList<>();
index 8de4e6faf3d24e7538cfaf8660cbb700ccd90dca..14fdb46df990f45c6776d470db1309b71c9001bc 100644 (file)
@@ -56,6 +56,7 @@ public class TapiContext {
 
     private static final Logger LOG = LoggerFactory.getLogger(TapiContext.class);
     public static final String TAPI_CONTEXT = "T-API context";
+    public static final String NODE_NOT_PRESENT = "Node is not present in datastore";
     private final NetworkTransactionService networkTransactionService;
 
     public TapiContext(NetworkTransactionService networkTransactionService) {
@@ -256,7 +257,7 @@ public class TapiContext {
             Optional<Node> optNode = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, nodeIID)
                     .get();
             if (!optNode.isPresent()) {
-                LOG.error("Node is not present in datastore");
+                LOG.error(NODE_NOT_PRESENT);
                 return null;
             }
             // TODO -> Need to remove CEPs from NEPs. If not error from get Topology details output
@@ -305,7 +306,7 @@ public class TapiContext {
                     .read(LogicalDatastoreType.OPERATIONAL, nepIID)
                     .get();
             if (!optNode.isPresent()) {
-                LOG.error("Node is not present in datastore");
+                LOG.error(NODE_NOT_PRESENT);
                 return null;
             }
             return optNode.get();
@@ -325,7 +326,7 @@ public class TapiContext {
             Optional<Link> optLink = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, linkIID)
                     .get();
             if (!optLink.isPresent()) {
-                LOG.error("Node is not present in datastore");
+                LOG.error(NODE_NOT_PRESENT);
                 return null;
             }
             return optLink.get();
@@ -483,7 +484,7 @@ public class TapiContext {
             Optional<OwnedNodeEdgePoint> optNode = this.networkTransactionService
                 .read(LogicalDatastoreType.OPERATIONAL, nepIID).get();
             if (!optNode.isPresent()) {
-                LOG.error("Node is not present in datastore");
+                LOG.error(NODE_NOT_PRESENT);
                 return null;
             }
             if (optNode.get().augmentation(OwnedNodeEdgePoint1.class) == null) {
@@ -493,7 +494,7 @@ public class TapiContext {
             return optNode.get().augmentation(OwnedNodeEdgePoint1.class).getCepList().getConnectionEndPoint()
                 .get(new ConnectionEndPointKey(cepUuid));
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Couldnt read node in topology");
+            LOG.error("Couldnt read node in topology", e);
             return null;
         }
     }