fix deprecated openroadm interfaces/objects
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceCalculation.java
index 692d49a4478682ef6b28f982846135481dfc7c8f..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;
@@ -66,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>();
@@ -101,7 +101,6 @@ public class PceCalculation {
             returnStructure.setRC(ResponseCodes.RESPONSE_FAILED);
             return;
         }
-
         printNodesInfo(allPceNodes);
 
         returnStructure.setRC(ResponseCodes.RESPONSE_OK);
@@ -141,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;
@@ -370,11 +371,21 @@ public class PceCalculation {
                 break;
         }
 
-        if ((pceNode.getSupNodeIdPceNode().equals(anodeId)) && (endPceNode(nodeType,pceNode.getNodeId(), pceNode))) {
-            this.aendPceNode = 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)) && (endPceNode(nodeType,pceNode.getNodeId(), pceNode))) {
-            this.zendPceNode = 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);
@@ -384,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;
         }
 
@@ -432,7 +443,6 @@ public class PceCalculation {
     }
 
     private Boolean endPceNode(OpenroadmNodeType openroadmNodeType, NodeId nodeId, PceNode pceNode) {
-        Boolean add = true;
         switch (openroadmNodeType) {
             case SRG :
                 pceNode.initSrgTps();
@@ -442,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;
         }
-        return add;
+
+        if (!pceNode.isValid()) {
+            LOG.error("validateNode : there are no availaible wavelengths in node {}", pceNode.getNodeId().getValue());
+            return false;
+        }
+        return true;
     }
 
     public PceNode getaendPceNode() {