Technical debt - Fix PCE sonar issues
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceOpticalNode.java
index e9273e1d279f5f92d482bbb2ccace2152f163722..80574e4cf62170024cf0460107f03c77fe3bf1e7 100644 (file)
@@ -14,7 +14,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.TreeMap;
-
 import org.opendaylight.transportpce.pce.SortPortsByName;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Node1;
@@ -24,11 +23,12 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.O
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
+import org.opendaylight.yangtools.yang.common.Uint16;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class PceOpticalNode implements PceNode {
-    private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
+    private static final Logger LOG = LoggerFactory.getLogger(PceOpticalNode.class);
 
     private boolean valid = true;
 
@@ -39,12 +39,12 @@ public class PceOpticalNode implements PceNode {
     private final String pceNodeType;
 
     // wavelength calculation per node type
-    private List<Long> availableWLindex = new ArrayList<Long>();
-    private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<String, OpenroadmTpType>();
-    private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<String, OpenroadmTpType>();
-    private List<String> usedXpndrNWTps = new ArrayList<String>();
-    private List<PceLink> outgoingLinks = new ArrayList<PceLink>();
-    private Map<String, String> clientPerNwTp = new HashMap<String, String>();
+    private List<Long> availableWLindex = new ArrayList<>();
+    private Map<String, OpenroadmTpType> availableSrgPp = new TreeMap<>();
+    private Map<String, OpenroadmTpType> availableSrgCp = new TreeMap<>();
+    private List<String> usedXpndrNWTps = new ArrayList<>();
+    private List<PceLink> outgoingLinks = new ArrayList<>();
+    private Map<String, String> clientPerNwTp = new HashMap<>();
 
     public PceOpticalNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId, ServiceFormat serviceFormat,
         String pceNodeType) {
@@ -71,9 +71,9 @@ public class PceOpticalNode implements PceNode {
                 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
                     .ietf.network.topology.rev180226.Node1.class);
         List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
-            .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
-        if (allTps == null) {
-            LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this.toString());
+            .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
+        if (allTps.isEmpty()) {
+            LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
             this.valid = false;
             return;
         }
@@ -84,7 +84,7 @@ public class PceOpticalNode implements PceNode {
                 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
                 .TerminationPoint1.class);
             OpenroadmTpType type = cntp1.getTpType();
-            LOG.info("type = {} for tp {}", type.getName(), tp.toString());
+            LOG.info("type = {} for tp {}", type.getName(), tp);
 
             switch (type) {
                 case SRGTXRXCP:
@@ -99,7 +99,8 @@ public class PceOpticalNode implements PceNode {
                     boolean used = true;
                     LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
                     try {
-                        List<UsedWavelength> usedWavelengths = nttp1.getPpAttributes().getUsedWavelength();
+                        List<UsedWavelength> usedWavelengths =
+                            new ArrayList<>(nttp1.getPpAttributes().getUsedWavelength().values());
                         if (usedWavelengths.isEmpty()) {
                             used = false;
                         }
@@ -118,14 +119,13 @@ public class PceOpticalNode implements PceNode {
                     break;
             }
         }
-        if (this.availableSrgPp.isEmpty() && this.availableSrgCp.isEmpty()) {
-            LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this.toString());
+        if (this.availableSrgPp.isEmpty() || this.availableSrgCp.isEmpty()) {
+            LOG.error("initSrgTpList: ROADM SRG TerminationPoint list is empty for node {}", this);
             this.valid = false;
             return;
         }
         LOG.info("initSrgTpList: availableSrgPp size = {} && availableSrgCp size = {} in {}",
-            this.availableSrgPp.size(), this.availableSrgCp.size(), this.toString());
-        return;
+            this.availableSrgPp.size(), this.availableSrgCp.size(), this);
     }
 
     public void initWLlist() {
@@ -138,30 +138,31 @@ public class PceOpticalNode implements PceNode {
             case SRG :
                 List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
                     .AvailableWavelengths> srgAvailableWL =
-                        node1.getSrgAttributes().getAvailableWavelengths();
-                if (srgAvailableWL == null) {
+                        new ArrayList<>(node1.getSrgAttributes().nonnullAvailableWavelengths().values());
+                if (srgAvailableWL.isEmpty()) {
                     this.valid = false;
-                    LOG.error("initWLlist: SRG AvailableWavelengths is empty for node  {}", this.toString());
+                    LOG.error("initWLlist: SRG AvailableWavelengths is empty for node  {}", this);
                     return;
                 }
                 for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
                         .AvailableWavelengths awl : srgAvailableWL) {
-                    this.availableWLindex.add(awl.getIndex());
-                    LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this.toString());
+                    this.availableWLindex.add(awl.getIndex().toJava());
+                    LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this);
                 }
                 break;
             case DEGREE :
                 List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
-                    .AvailableWavelengths> degAvailableWL = node1.getDegreeAttributes().getAvailableWavelengths();
-                if (degAvailableWL == null) {
+                        .AvailableWavelengths> degAvailableWL =
+                    new ArrayList<>(node1.getDegreeAttributes().nonnullAvailableWavelengths().values());
+                if (degAvailableWL.isEmpty()) {
                     this.valid = false;
-                    LOG.error("initWLlist: DEG AvailableWavelengths is empty for node  {}", this.toString());
+                    LOG.error("initWLlist: DEG AvailableWavelengths is empty for node  {}", this);
                     return;
                 }
                 for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
                             .AvailableWavelengths awl : degAvailableWL) {
-                    this.availableWLindex.add(awl.getIndex());
-                    LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this.toString());
+                    this.availableWLindex.add(awl.getIndex().toJava());
+                    LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this);
                 }
                 break;
             case XPONDER :
@@ -171,15 +172,14 @@ public class PceOpticalNode implements PceNode {
                 }
                 break;
             default:
-                LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this.toString());
+                LOG.error("initWLlist: unsupported node type {} in node {}", this.nodeType, this);
                 break;
         }
-        if (this.availableWLindex.size() == 0) {
-            LOG.debug("initWLlist: There are no available wavelengths in node {}", this.toString());
+        if (this.availableWLindex.isEmpty()) {
+            LOG.debug("initWLlist: There are no available wavelengths in node {}", this);
             this.valid = false;
         }
-        LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this.toString());
-        return;
+        LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this);
     }
 
     public void initXndrTps() {
@@ -191,10 +191,10 @@ public class PceOpticalNode implements PceNode {
                 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
                     .ietf.network.topology.rev180226.Node1.class);
         List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
-            .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
-        if (allTps == null) {
+            .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
+        if (allTps.isEmpty()) {
             this.valid = false;
-            LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this.toString());
+            LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
             return;
         }
         this.valid = false;
@@ -222,8 +222,8 @@ public class PceOpticalNode implements PceNode {
                         this.clientPerNwTp.put(tp.getTpId().getValue(), client);
                         this.valid = true;
                     } else {
-                        LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}", this.toString(),
-                            tp.getTpId().getValue());
+                        LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}",
+                            this, tp.getTpId().getValue());
                     }
                 } else if (ServiceFormat.OTU.equals(this.serviceFormat)) {
                     LOG.info("Infrastructure OTU4 connection");
@@ -234,8 +234,7 @@ public class PceOpticalNode implements PceNode {
             }
         }
         if (!isValid()) {
-            LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node  {}", this.toString());
-            return;
+            LOG.error("initXndrTps: XPONDER doesn't have available wavelengths for node  {}", this);
         }
     }
 
@@ -274,13 +273,13 @@ public class PceOpticalNode implements PceNode {
                     .sorted(new SortPortsByName())
                     .findFirst();
             if (!client.isPresent()) {
-                LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this.toString(), tp);
+                LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
                 return null;
             }
             LOG.info("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
             return client.get();
         } else {
-            LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this.toString());
+            LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
             return null;
         }
     }
@@ -332,6 +331,7 @@ public class PceOpticalNode implements PceNode {
         return nodeId;
     }
 
+    @Override
     public String toString() {
         return "PceNode type=" + nodeType + " ID=" + nodeId.getValue() + " CLLI=" + this.getSupClliNodeId();
     }
@@ -362,14 +362,12 @@ public class PceOpticalNode implements PceNode {
     }
 
     @Override
-    public Map<String, List<Integer>> getAvailableTribPorts() {
-        // TODO Auto-generated method stub
+    public Map<String, List<Uint16>> getAvailableTribPorts() {
         return null;
     }
 
     @Override
-    public Map<String, List<Integer>> getAvailableTribSlots() {
-        // TODO Auto-generated method stub
+    public Map<String, List<Uint16>> getAvailableTribSlots() {
         return null;
     }
 }