fix deprecated openroadm interfaces/objects
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceCalculation.java
index 7ce9b80d11f253c60b0990cf8c868c5d7a262be1..113135541659e803c9345e7c1fe5a3c00a66dc9a 100644 (file)
@@ -8,24 +8,24 @@
 
 package org.opendaylight.transportpce.pce.networkanalyzer;
 
-import com.google.common.base.Optional;
-
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
 
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.NetworkUtils;
 import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestInput;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Node1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Node1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmNodeType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
@@ -52,7 +52,6 @@ public class PceCalculation {
     private String znodeId = "";
 
     private PceConstraints pceHardConstraints;
-//    private PceConstraints pceSoftConstraints;
 
     ///////////// Intermediate data/////////////////
     private List<PceLink> addLinks = new ArrayList<PceLink>();
@@ -67,7 +66,7 @@ public class PceCalculation {
 
     // this List serves graph calculation
     private Map<NodeId, PceNode> allPceNodes = new HashMap<NodeId, PceNode>();
-    // this List serves calculation of ZtoA path descritopn
+    // this List serves calculation of ZtoA path description
     // TODO maybe better solution is possible
     private Map<LinkId, PceLink> allPceLinks = new HashMap<LinkId, PceLink>();
     private Set<LinkId> linksToExclude = new HashSet<LinkId>();
@@ -84,7 +83,6 @@ public class PceCalculation {
         this.returnStructure = rc;
 
         this.pceHardConstraints = pceHardConstraints;
-//        this.pceSoftConstraints = pceSoftConstraints;
         parseInput();
     }
 
@@ -103,9 +101,7 @@ public class PceCalculation {
             returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
             return;
         }
-
         printNodesInfo(allPceNodes);
-        // printLinksInfo(allPceLinks);
 
         returnStructure.setRC(ResponseCodes.RESPONSE_OK);
         return;
@@ -144,10 +140,12 @@ public class PceCalculation {
             LOG.error("readMdSal: network is null: {}", nwInstanceIdentifier);
             return false;
         }
-        allNodes = nw.getNode();
+        allNodes = nw.getNode().stream().sorted((n1, n2) -> n1.getNodeId().getValue().compareTo(n2.getNodeId()
+            .getValue())).collect(Collectors.toList());
         Network1 nw1 = nw.augmentation(Network1.class);
 
-        allLinks = nw1.getLink();
+        allLinks = nw1.getLink().stream().sorted((l1, l2) -> l1.getSource().getSourceTp().toString().compareTo(l2
+            .getSource().getSourceTp().toString())).collect(Collectors.toList());
         if (allNodes == null || allNodes.isEmpty()) {
             LOG.error("readMdSal: no nodes ");
             return false;
@@ -312,7 +310,8 @@ public class PceCalculation {
                 LOG.debug("validateLink: DROP-LINK saved  {}", pcelink.toString());
                 break;
             case XPONDERINPUT :
-                azSrgs.add(sourceId); // store separately all SRG links directly
+                // store separately all SRG links directly
+                azSrgs.add(sourceId);
                 // connected to A/Z
                 if (!dest.checkTP(pcelink.getDestTP().toString())) {
                     LOG.debug("validateLink: XPONDER-INPUT is rejected as NW port is busy - {} ", pcelink.toString());
@@ -323,8 +322,10 @@ public class PceCalculation {
                 source.addOutgoingLink(pcelink);
                 LOG.debug("validateLink: XPONDER-INPUT link added to allPceLinks {}", pcelink.toString());
                 break;
-            case XPONDEROUTPUT : // does it mean XPONDER==>>SRG ?
-                azSrgs.add(destId); // store separately all SRG links directly
+            // does it mean XPONDER==>>SRG ?
+            case XPONDEROUTPUT :
+                // store separately all SRG links directly
+                azSrgs.add(destId);
                 // connected to A/Z
                 if (!source.checkTP(pcelink.getSourceTP().toString())) {
                     LOG.debug("validateLink: XPONDER-OUTPUT is rejected as NW port is busy - {} ", pcelink.toString());
@@ -370,15 +371,21 @@ public class PceCalculation {
                 break;
         }
 
-        if (pceNode.getSupNodeIdPceNode().equals(anodeId)) {
-            if (endPceNode(nodeType,pceNode.getNodeId(), pceNode)) {
+        if (pceNode.getSupNodeIdPceNode().equals(this.anodeId)) {
+            if (this.aendPceNode != null) {
+                LOG.debug("aendPceNode already gets: {}", this.aendPceNode);
+            } else if (endPceNode(nodeType,pceNode.getNodeId(), pceNode)) {
                 this.aendPceNode = pceNode;
             }
+            // returning false otherwise would break E2E test
         }
-        if (pceNode.getSupNodeIdPceNode().equals(znodeId)) {
-            if (endPceNode(nodeType,pceNode.getNodeId(), pceNode)) {
+        if (pceNode.getSupNodeIdPceNode().equals(this.znodeId)) {
+            if (this.zendPceNode != null) {
+                LOG.debug("zendPceNode already gets: {}", this.zendPceNode);
+            } else if (endPceNode(nodeType,pceNode.getNodeId(), pceNode)) {
                 this.zendPceNode = pceNode;
             }
+            // returning false otherwise would break E2E test
         }
 
         allPceNodes.put(pceNode.getNodeId(), pceNode);
@@ -388,7 +395,7 @@ public class PceCalculation {
 
     private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
 
-        if (pceHardConstraints.getExcludeSupNodes().isEmpty()  && pceHardConstraints.getExcludeCLLI().isEmpty()) {
+        if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
             return ConstraintTypes.NONE;
         }
 
@@ -436,7 +443,6 @@ public class PceCalculation {
     }
 
     private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceNode pceNode) {
-        Boolean add = true;
         switch (openroadmNodeType) {
             case SRG :
                 pceNode.initSrgTps();
@@ -446,11 +452,15 @@ public class PceCalculation {
                 pceNode.initXndrTps();
                 break;
             default:
-                add = false;
                 LOG.warn("endPceNode: Node {} is not SRG or XPONDER !", nodeId);
-                break;
+                return false;
+        }
+
+        if (!pceNode.isValid()) {
+            LOG.error("validateNode : there are no availaible wavelengths in node {}", pceNode.getNodeId().getValue());
+            return false;
         }
-        return add;
+        return true;
     }
 
     public PceNode getaendPceNode() {
@@ -482,11 +492,11 @@ public class PceCalculation {
         }
     }
 
-    private static void printLinksInfo(Map<LinkId, PceLink> allpcelinks) {
+    /*private static void printLinksInfo(Map<LinkId, PceLink> allpcelinks) {
         Iterator<Map.Entry<LinkId, PceLink>> links = allpcelinks.entrySet().iterator();
         while (links.hasNext()) {
             LOG.info("In printLinksInfo link {} : ", links.next().getValue().toString());
         }
-    }
+    }*/
 
 }