Calculate spanloss crashes when OTS is not present
[transportpce.git] / olm / src / main / java / org / opendaylight / transportpce / olm / service / OlmPowerServiceImpl.java
index b306eee2a242357c42db7c8fbdf167c55f23d69a..0dcf6f1481e9529d64cd607eb3518096250cfda8 100644 (file)
@@ -490,7 +490,7 @@ public class OlmPowerServiceImpl implements OlmPowerService {
             }
         } catch (OpenRoadmInterfaceException e) {
             // TODO Auto-generated catch block
-            LOG.error("OpenRoadmInterfaceException occured {}",e);
+            LOG.error("OpenRoadmInterfaceException occured",e);
         } /**catch (InterruptedException e) {
          // TODO Auto-generated catch block
          } catch (ExecutionException e) {
@@ -517,12 +517,16 @@ public class OlmPowerServiceImpl implements OlmPowerService {
         LOG.info("Executing GetLinkSpanLoss");
         BigDecimal spanLoss = new BigDecimal(0);
         for (RoadmLinks link : roadmLinks) {
-            String sourceNodeId = link.getSrcNodeId().toString();
+            String sourceNodeId = link.getSrcNodeId();
             String sourceTpId = link.getSrcTpId();
-            String destNodeId = link.getDestNodeId().toString();
+            String destNodeId = link.getDestNodeId();
             String destTpId = link.getDestTpid();
             OtsPmHolder srcOtsPmHoler = getPmMeasurements(sourceNodeId, sourceTpId, "OpticalPowerOutput");
             OtsPmHolder destOtsPmHoler = getPmMeasurements(destNodeId, destTpId, "OpticalPowerInput");
+            if (srcOtsPmHoler.getOtsInterfaceName() == null || destOtsPmHoler.getOtsInterfaceName() == null) {
+                LOG.warn("OTS is not present for the link {}", link);
+                continue;
+            }
             spanLoss = new BigDecimal(srcOtsPmHoler.getOtsParameterVal() - destOtsPmHoler.getOtsParameterVal())
                 .setScale(0, RoundingMode.HALF_UP);
             LOG.info("Spanloss Calculated as :{}={}-{}",
@@ -550,7 +554,7 @@ public class OlmPowerServiceImpl implements OlmPowerService {
         try (ReadTransaction readOnlyTransaction = this.dataBroker.newReadOnlyTransaction()) {
             realNode = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, mappedNodeII).get();
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error(e.getMessage(), e);
+            LOG.error("Error on getRealNodeId {} :", mappedNodeId, e);
             throw new IllegalStateException(e);
         }
         if (!realNode.isPresent() || (realNode.get().getSupportingNode() == null)) {