Fix deprecated warnings caused by YangTools update
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / constraints / PceConstraintsCalc.java
index 2cd7ec8065da200469d2b2e64037bb8c83dddeec..3fdc00a61e373402d138ef902a37be608252d751 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.transportpce.pce.constraints;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
@@ -17,11 +19,11 @@ import java.util.stream.Collectors;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.Timeouts;
 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestInput;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.PathDescription;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZ;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.Link;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.Node;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.PathDescription;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.atoz.direction.AToZ;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce.resource.resource.resource.Link;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.pce.resource.resource.resource.Node;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.RoutingConstraintsSp.PceMetric;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.CoRoutingOrGeneral;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.CoRouting;
@@ -39,13 +41,14 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class PceConstraintsCalc {
     /* Logging. */
     private static final Logger LOG = LoggerFactory.getLogger(PceConstraintsCalc.class);
+    private static final Comparator<OrderedHops> ORDERED_HOP_COMPARATOR =
+            Comparator.comparing(OrderedHops::getHopNumber);
 
     private PceConstraints pceHardConstraints = new PceConstraints();
     private PceConstraints pceSoftConstraints = new PceConstraints();
@@ -60,7 +63,7 @@ public class PceConstraintsCalc {
         this.networkTransactionService = networkTransactionService;
 
         // TODO. for now metrics are set into hard structure
-        LOG.info("In PceConstraintsCalc: read PceMetric {}", pceMetrics.toString());
+        LOG.info("In PceConstraintsCalc: read PceMetric {}", pceMetrics);
         pceHardConstraints.setPceMetrics(pceMetrics);
 
         calcHardconstraints(input);
@@ -103,21 +106,17 @@ public class PceConstraintsCalc {
         CoRouting tmpCoRouting = null;
 
         if (coRoutingOrGeneral instanceof General) {
-            LOG.info("In readconstraints General {}", coRoutingOrGeneral.toString());
+            LOG.info("In readconstraints General {}", coRoutingOrGeneral);
             tmpGeneral = (General) coRoutingOrGeneral;
             readGeneralContrains(tmpGeneral, constraints);
             return;
         }
 
         if (coRoutingOrGeneral instanceof CoRouting) {
-            LOG.info("In readconstraints CoRouting {}", coRoutingOrGeneral.toString());
+            LOG.info("In readconstraints CoRouting {}", coRoutingOrGeneral);
             tmpCoRouting = (CoRouting) coRoutingOrGeneral;
             readCoRoutingContrains(tmpCoRouting, constraints);
-            return;
         }
-
-        return;
-
     }
 
     private void readGeneralContrains(General tmpGeneral, PceConstraints constraints) {
@@ -130,8 +129,8 @@ public class PceConstraintsCalc {
 
         Latency latency = tmpGeneral.getLatency();
         if (latency != null) {
-            constraints.setMaxLatency(latency.getMaxLatency());
-            LOG.info("In readGeneralContrains: read latency {}", latency.toString());
+            constraints.setMaxLatency(latency.getMaxLatency().toJava());
+            LOG.info("In readGeneralContrains: read latency {}", latency);
         }
 
         Exclude exclude = tmpGeneral.getExclude();
@@ -144,7 +143,7 @@ public class PceConstraintsCalc {
 
             elementsToExclude = exclude.getSRLG();
             if (elementsToExclude != null) {
-                List<Long> srlgToExclude = new ArrayList<Long>();
+                List<Long> srlgToExclude = new ArrayList<>();
                 for (String str : elementsToExclude) {
                     srlgToExclude.add(Long.parseLong(str));
                 }
@@ -159,11 +158,11 @@ public class PceConstraintsCalc {
 
         Include include = tmpGeneral.getInclude();
         if (include != null) {
-            List<OrderedHops> listHops = include.getOrderedHops();
+            List<OrderedHops> listHops = new ArrayList<>(include.nonnullOrderedHops().values());
             if (listHops != null) {
                 readIncludeNodes(listHops, constraints);
             }
-            LOG.debug("in readGeneralContrains INCLUDE {} ", include.toString());
+            LOG.debug("in readGeneralContrains INCLUDE {} ", include);
         }
 
         Diversity diversity = tmpGeneral.getDiversity();
@@ -173,26 +172,27 @@ public class PceConstraintsCalc {
             if (temp == null) {
                 return;
             }
-            if (temp.isNode()) {
+            if (Boolean.TRUE.equals(temp.getNode())) {
                 rt = PceConstraints.ResourceType.NODE;
             }
-            if (temp.isSrlg()) {
+            if (Boolean.TRUE.equals(temp.getSrlg())) {
                 rt = PceConstraints.ResourceType.SRLG;
             }
-            if (temp.isClli()) {
+            if (Boolean.TRUE.equals(temp.getClli())) {
                 rt = PceConstraints.ResourceType.CLLI;
             }
-            LOG.info("in readGeneralContrains {} list is :{}", rt, diversity.toString());
+            LOG.info("in readGeneralContrains {} list is :{}", rt, diversity);
             readDiversity(diversity.getExistingService(), constraints, rt);
         }
 
     }
 
     private void readIncludeNodes(List<OrderedHops> listHops, PceConstraints constraints) {
+        Collections.sort(listHops, ORDERED_HOP_COMPARATOR);
         for (int i = 0; i < listHops.size(); i++) {
             HopType hoptype = listHops.get(i).getHopType().getHopType();
 
-            String hopt = hoptype.getImplementedInterface().getSimpleName();
+            String hopt = hoptype.implementedInterface().getSimpleName();
             LOG.info("in readIncludeNodes next hop to include {}", hopt);
             switch (hopt) {
                 case "Node":
@@ -200,7 +200,7 @@ public class PceConstraintsCalc {
                             .rev171017.ordered.constraints.sp.hop.type.hop.type.Node
                             node = (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
                             .constraints.rev171017.ordered.constraints.sp.hop.type.hop.type.Node) hoptype;
-                    constraints.setListToInclude(constraints.new ResourcePair(PceConstraints.ResourceType.NODE,
+                    constraints.setListToInclude(new PceConstraints.ResourcePair(PceConstraints.ResourceType.NODE,
                             node.getNodeId()));
                     break;
                 case "SRLG":
@@ -208,7 +208,7 @@ public class PceConstraintsCalc {
                             .rev171017.ordered.constraints.sp.hop.type.hop.type.SRLG
                             srlg = (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
                             .constraints.rev171017.ordered.constraints.sp.hop.type.hop.type.SRLG) hoptype;
-                    constraints.setListToInclude(constraints.new ResourcePair(PceConstraints.ResourceType.SRLG,
+                    constraints.setListToInclude(new PceConstraints.ResourcePair(PceConstraints.ResourceType.SRLG,
                             srlg.getSRLG()));
                     break;
                 case "Clli":
@@ -216,7 +216,7 @@ public class PceConstraintsCalc {
                             .rev171017.ordered.constraints.sp.hop.type.hop.type.Clli
                             clli = (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
                             .constraints.rev171017.ordered.constraints.sp.hop.type.hop.type.Clli) hoptype;
-                    constraints.setListToInclude(constraints.new ResourcePair(PceConstraints.ResourceType.CLLI,
+                    constraints.setListToInclude(new PceConstraints.ResourcePair(PceConstraints.ResourceType.CLLI,
                             clli.getClli()));
                     break;
                 default:
@@ -227,25 +227,23 @@ public class PceConstraintsCalc {
 
     private void readDiversity(List<String> srvList, PceConstraints constraints, PceConstraints.ResourceType rt) {
 
-        List<String> elementsToExclude = new ArrayList<String>();
-        LOG.info("in readDiversity {}", srvList.toString());
+        List<String> elementsToExclude = new ArrayList<>();
+        LOG.info("in readDiversity {}", srvList);
 
         for (String srv : srvList) {
             Optional<PathDescription> service = getPathDescriptionFromDatastore(srv);
             if (service.isPresent()) {
-                LOG.info("in readDiversity service list {}", service.toString());
+                LOG.info("in readDiversity service list {}", service);
                 switch (rt) {
                     case NODE:
-                        elementsToExclude
-                                .addAll(getAToZNodeList(service.get()));
+                        elementsToExclude.addAll(getAToZNodeList(service.get()));
                         LOG.info("readDiversity NODE : {}", elementsToExclude);
                         if (elementsToExclude != null) {
                             constraints.setExcludeNodes(elementsToExclude);
                         }
                         break;
                     case SRLG:
-                        elementsToExclude
-                                .addAll(getSRLGList(service.get()));
+                        elementsToExclude.addAll(getSRLGList(service.get()));
                         LOG.info("readDiversity SRLG : {}", elementsToExclude);
                         if (elementsToExclude != null) {
                             constraints.setExcludeSrlgLinks(elementsToExclude);
@@ -254,15 +252,14 @@ public class PceConstraintsCalc {
                     case CLLI:
                         /// Retrieve nodes into dedicated CLLI list
                         /// during node validation check their CLLI and build CLLI exclude list
-                        elementsToExclude
-                                .addAll(getAToZNodeList(service.get()));
+                        elementsToExclude.addAll(getAToZNodeList(service.get()));
                         LOG.info("readDiversity CLLI : {}", elementsToExclude);
                         if (elementsToExclude != null) {
                             constraints.setExcludeClliNodes(elementsToExclude);
                         }
                         break;
                     default:
-                        LOG.info("in readDiversity unsupported divercity type", rt);
+                        LOG.info("in readDiversity unsupported divercity type {}", rt);
                 }
 
             } else {
@@ -273,7 +270,7 @@ public class PceConstraintsCalc {
     }
 
     private List<String> getAToZNodeList(PathDescription pathDescription) {
-        List<AToZ> aendToZList = pathDescription.getAToZDirection().getAToZ();
+        List<AToZ> aendToZList = new ArrayList<>(pathDescription.getAToZDirection().nonnullAToZ().values());
         return aendToZList.stream().filter(aToZ -> {
             if (aToZ.getResource() == null || aToZ.getResource().getResource() == null) {
                 LOG.warn("Diversity constraint: Resource of AToZ node {} is null! Skipping this node!", aToZ.getId());
@@ -289,12 +286,12 @@ public class PceConstraintsCalc {
             return true;
         }).map(aToZ -> {
             Node node = ((Node) aToZ.getResource().getResource());
-            return node.getNodeId().toString();
+            return node.getNodeId();
         }).collect(Collectors.toList());
     }
 
     private List<String> getSRLGList(PathDescription pathDescription) {
-        List<AToZ> aendToZList = pathDescription.getAToZDirection().getAToZ();
+        List<AToZ> aendToZList = new ArrayList<>(pathDescription.getAToZDirection().nonnullAToZ().values());
         return aendToZList.stream().filter(aToZ -> {
             if (aToZ.getResource() == null
                     || aToZ.getResource().getResource() == null) {
@@ -343,7 +340,6 @@ public class PceConstraintsCalc {
 
         if (tmpcoRouting == null) {
             LOG.info("In readCoRoutingContrains: no General constraints.");
-            return;
         }
 
     }