Refactor few LOG messages management
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / graph / PceGraph.java
index 2b199309eb831afc3f5b6cac6f537ec994d4b8ac..583ac4572580c905ac9d3d918efa6417602fba83 100644 (file)
@@ -13,6 +13,10 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 import org.jgrapht.GraphPath;
 import org.jgrapht.alg.shortestpath.KShortestSimplePaths;
 import org.jgrapht.alg.shortestpath.PathValidator;
@@ -54,7 +58,7 @@ public class PceGraph {
     private List<PceLink> shortestPathAtoZ = null;
 
     // for path calculation
-    List<GraphPath<String, PceGraphEdge>> allWPaths = null;
+    Map<Integer, GraphPath<String, PceGraphEdge>> allWPaths = null;
 
     private List<PceLink> pathAtoZ = new ArrayList<>();
 
@@ -84,20 +88,21 @@ public class PceGraph {
         populateWithLinks(weightedGraph);
 
         if (!runKgraphs(weightedGraph)) {
-            LOG.info("In calcPath : pceResult {}", pceResult);
+            LOG.error("In calcPath : pceResult {}", pceResult);
             return false;
         }
-
         // validate found paths
         pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
-        for (GraphPath<String, PceGraphEdge> path : allWPaths) {
+        for (Entry<Integer, GraphPath<String, PceGraphEdge>> entry : allWPaths.entrySet()) {
+            GraphPath<String, PceGraphEdge> path = entry.getValue();
+            LOG.info("validating path n° {} - {}", entry.getKey(), path.getVertexList());
             PostAlgoPathValidator papv = new PostAlgoPathValidator();
             pceResult = papv.checkPath(path, allPceNodes, pceResult, pceHardConstraints, serviceType);
-            LOG.info("In calcPath after PostAlgoPathValidator {} {}",
-                    pceResult.getResponseCode(), ResponseCodes.RESPONSE_OK);
-
-            if (!pceResult.getResponseCode().equals(ResponseCodes.RESPONSE_OK)) {
-                LOG.warn("In calcPath: post algo validations DROPPED the path {}", path);
+            if (ResponseCodes.RESPONSE_OK.equals(pceResult.getResponseCode())) {
+                LOG.info("Path is validated");
+            } else {
+                LOG.warn("In calcPath: post algo validations DROPPED the path {}; for following cause: {}",
+                    path, pceResult.getLocalCause());
                 continue;
             }
 
@@ -110,10 +115,13 @@ public class PceGraph {
             shortestPathAtoZ = new ArrayList<>(pathAtoZ);
             switch (serviceType) {
 
-                case StringConstants.SERVICE_TYPE_100GE:
+                case StringConstants.SERVICE_TYPE_100GE_T:
+                case StringConstants.SERVICE_TYPE_OTUC2:
+                case StringConstants.SERVICE_TYPE_OTUC3:
+                case StringConstants.SERVICE_TYPE_OTUC4:
                 case StringConstants.SERVICE_TYPE_400GE:
                 case StringConstants.SERVICE_TYPE_OTU4:
-                    LOG.info(
+                    LOG.debug(
                         "In calcPath Path FOUND path for wl [{}], min Freq assignment {}, max Freq assignment {},"
                         + " hops {}, distance per metrics {}, path AtoZ {}",
                         pceResult.getResultWavelength(), pceResult.getMinFreq(), pceResult.getMaxFreq(),
@@ -121,7 +129,7 @@ public class PceGraph {
                     break;
 
                 default:
-                    LOG.info(
+                    LOG.debug(
                         "In calcPath Path FOUND path for hops {}, distance per metrics {}, path AtoZ {}",
                         pathAtoZ.size(), path.getWeight(), pathAtoZ);
                     break;
@@ -149,7 +157,12 @@ public class PceGraph {
         // KShortestPaths on weightedGraph
         KShortestSimplePaths<String, PceGraphEdge> swp =
             new KShortestSimplePaths<>(weightedGraph, mhopsPerPath, wpv);
-        allWPaths = swp.getPaths(apceNode.getNodeId().getValue(), zpceNode.getNodeId().getValue(), kpathsToBring);
+        List<GraphPath<String, PceGraphEdge>> weightedPathList = swp
+            .getPaths(apceNode.getNodeId().getValue(), zpceNode.getNodeId().getValue(), kpathsToBring);
+        allWPaths = IntStream
+            .range(0, weightedPathList.size())
+            .boxed()
+            .collect(Collectors.toMap(Function.identity(), weightedPathList::get));
 
         if (allWPaths.isEmpty()) {
             LOG.info(" In runKgraphs : algorithm didn't find any path");
@@ -159,10 +172,8 @@ public class PceGraph {
         }
 
         // debug print
-        for (GraphPath<String, PceGraphEdge> path : allWPaths) {
-            LOG.debug("path Weight: {} : {}", path.getWeight(), path.getVertexList());
-        }
-
+        allWPaths
+            .forEach((k, v) -> LOG.info("path n° {} - weight: {} - path: {}", k, v.getWeight(), v.getVertexList()));
         return true;
     }