pce(gnpy) for Sulfur
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / graph / PostAlgoPathValidator.java
index ba4eee7d692ddd6b69f9f04baa2ee4345a92b152..960ae3bc1e6e407399d5aa99b40b042e11631d6a 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 import org.jgrapht.GraphPath;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.common.StringConstants;
@@ -202,42 +203,19 @@ public class PostAlgoPathValidator {
             pceHardConstraintsInput));
 
         // validation: check each type for each element
-        for (ResourcePair next : listToInclude) {
-            int indx = -1;
-            switch (next.getType()) {
-                case NODE:
-                    if (listOfElementsSubNode.contains(next.getName())) {
-                        indx = listOfElementsSubNode.indexOf(next.getName());
-                    }
-                    break;
-                case SRLG:
-                    if (listOfElementsSRLG.contains(next.getName())) {
-                        indx = listOfElementsSRLG.indexOf(next.getName());
-                    }
-                    break;
-                case CLLI:
-                    if (listOfElementsCLLI.contains(next.getName())) {
-                        indx = listOfElementsCLLI.indexOf(next.getName());
-                    }
-                    break;
-                default:
-                    LOG.warn(" in checkInclude vertex list unsupported resource type: [{}]", next.getType());
-            }
-
-            if (indx < 0) {
-                LOG.debug(" in checkInclude stopped : {} ", next.getName());
-                return false;
-            }
-
-            LOG.debug(" in checkInclude next found {} in {}", next.getName(), path.getVertexList());
-
-            listOfElementsSubNode.subList(0, indx).clear();
-            listOfElementsCLLI.subList(0, indx).clear();
-            listOfElementsSRLG.subList(0, indx).clear();
-        }
-
-        LOG.info(" in checkInclude passed : {} ", path.getVertexList());
-        return true;
+        List<String> listNodeToInclude = listToInclude
+                .stream().filter(rp -> PceConstraints.ResourceType.NODE.equals(rp.getType()))
+                .map(ResourcePair::getName).collect(Collectors.toList());
+        List<String> listSrlgToInclude = listToInclude
+                .stream().filter(rp -> PceConstraints.ResourceType.SRLG.equals(rp.getType()))
+                .map(ResourcePair::getName).collect(Collectors.toList());
+        List<String> listClliToInclude = listToInclude
+                .stream().filter(rp -> PceConstraints.ResourceType.CLLI.equals(rp.getType()))
+                .map(ResourcePair::getName).collect(Collectors.toList());
+
+        return listOfElementsSubNode.containsAll(listNodeToInclude)
+                && listOfElementsSRLG.containsAll(listSrlgToInclude)
+                && listOfElementsCLLI.containsAll(listClliToInclude);
     }
 
     private List<String> listOfElementsBuild(List<PceGraphEdge> pathEdges, PceConstraints.ResourceType type,
@@ -452,7 +430,7 @@ public class PostAlgoPathValidator {
                         .equals(GridConstant.SLOT_WIDTH_50))
                         && (pceNode.getCentralFreqGranularity().setScale(0, RoundingMode.CEILING)
                         .equals(GridConstant.SLOT_WIDTH_50))) {
-                    LOG.info("Node {}: version is {} with slot width granularity  {} and central "
+                    LOG.debug("Node {}: version is {} with slot width granularity  {} and central "
                             + "frequency granularity is {} -> fixed grid mode",
                         pceNode.getNodeId(), pceNode.getVersion(), pceNode.getSlotWidthGranularity(),
                         pceNode.getCentralFreqGranularity());