Corrects various javadoc problems
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / mapping / PortMapping.java
index 9ff32a24c28528b79eae4a66abd35f05541f55c5..1cd38e87da19531275c1f7cc8785d393ba88025f 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaces;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.NodeTypes;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.PortsKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
@@ -104,6 +105,7 @@ public class PortMapping {
         DataBroker deviceDb = getDeviceDataBroker(nodeId, mps);
         List<Mapping> portMapList = new ArrayList<>();
         Info deviceInfo;
+        Integer nodeType = 1;
         if (deviceDb != null) {
             deviceInfo = getDeviceInfo(deviceDb);
             if (deviceInfo != null) {
@@ -111,7 +113,7 @@ public class PortMapping {
                     LOG.info("Node type mandatory field is missing");
                     return false;
                 }
-                Integer nodeType = deviceInfo.getNodeType().getIntValue();
+                nodeType = deviceInfo.getNodeType().getIntValue();
                 // Create Mapping for Roadm Node
                 if (nodeType == 1) {
                     // Get TTP port mapping
@@ -144,7 +146,7 @@ public class PortMapping {
             LOG.info("Unable to get Data broker for node " + nodeId);
             return false;
         }
-        return postPortMapping(deviceInfo, portMapList);
+        return postPortMapping(deviceInfo, portMapList, nodeType);
     }
 
     /**
@@ -405,12 +407,16 @@ public class PortMapping {
         try {
             Optional<Info> ordmInfoObject = rtx.read(LogicalDatastoreType.OPERATIONAL, infoIID).get();
             if (ordmInfoObject.isPresent()) {
+                LOG.info("Info subtree is present {}", ordmInfoObject.get());
                 return ordmInfoObject.get();
             } else {
-                LOG.info("Info subtree is not present");
+                LOG.error("Info subtree is not present");
             }
+        } catch (NullPointerException ex) {
+            LOG.warn("Try to get Info from a non Open ROADM device {}", deviceDb);
+            return null;
         } catch (InterruptedException | ExecutionException ex) {
-            LOG.info("Read failed on info subtree ",ex);
+            LOG.error("Read failed on info subtree ", ex);
             return null;
         }
         return null;
@@ -450,14 +456,14 @@ public class PortMapping {
                 Optional<Degree> ordmDegreeObject = rtx.read(LogicalDatastoreType.CONFIGURATION, deviceIID).get();
 
                 if (ordmDegreeObject.isPresent()) {
-                    degreeConPorts.addAll(new ArrayList<ConnectionPorts>(ordmDegreeObject.get().getConnectionPorts()));
+                    degreeConPorts.addAll(new ArrayList<>(ordmDegreeObject.get().getConnectionPorts()));
 
                 } else {
                     LOG.info("Device has " + (degreeCounter - 1) + " degree");
                     break;
                 }
             } catch (InterruptedException | ExecutionException ex) {
-                LOG.info("Failed to read degree " + degreeCounter,ex);
+                LOG.error("Failed to read degree " + degreeCounter,ex);
                 break;
 
             }
@@ -506,8 +512,7 @@ public class PortMapping {
                 if (ordmSrgObject.isPresent()) {
 
                     srgCps.addAll(
-                        new ArrayList<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
-                            .CircuitPacks>(ordmSrgObject.get().getCircuitPacks()));
+                        new ArrayList<>(ordmSrgObject.get().getCircuitPacks()));
 
                 } else {
                     LOG.info("Device has " + (srgCounter - 1) + " Srg");
@@ -539,12 +544,13 @@ public class PortMapping {
      *
      * @return Result true/false based on status of operation.
      */
-    private boolean postPortMapping(Info deviceInfo, List<Mapping> portMapList) {
+    private boolean postPortMapping(Info deviceInfo, List<Mapping> portMapList, Integer nodeType) {
 
-        List<Nodes> nodesList = new ArrayList<>();
         NodesBuilder nodesBldr = new NodesBuilder();
         nodesBldr.setKey(new NodesKey(deviceInfo.getNodeId())).setNodeId(deviceInfo.getNodeId());
+        nodesBldr.setNodeType(NodeTypes.forValue(nodeType));
         nodesBldr.setMapping(portMapList);
+        List<Nodes> nodesList = new ArrayList<>();
         nodesList.add(nodesBldr.build());
         NetworkBuilder nwBldr = new NetworkBuilder();
         nwBldr.setNodes(nodesList);
@@ -583,6 +589,8 @@ public class PortMapping {
      *            Unique Identifier for the node of interest.
      * @param logicalConnPoint
      *            Name of the logical point
+     * @param db
+     *            Databroker / MD-SAL data store
      *
      * @return Result Mapping object if success otherwise null.
      */
@@ -606,7 +614,7 @@ public class PortMapping {
                 return null;
             }
         } catch (InterruptedException | ExecutionException ex) {
-            LOG.info("Unable to read mapping for logical connection point : " + logicalConnPoint + " for nodeId "
+            LOG.error("Unable to read mapping for logical connection point : " + logicalConnPoint + " for nodeId "
                 + nodeId,ex);
         }
         return null;
@@ -627,7 +635,7 @@ public class PortMapping {
             DataBroker netconfNodeDataBroker = netconfNode.getService(DataBroker.class).get();
             return netconfNodeDataBroker;
         } else {
-            LOG.info("Device Data broker not found for :" + nodeId);
+            LOG.error("Device Data broker not found for :" + nodeId);
             return null;
         }
     }
@@ -643,10 +651,9 @@ public class PortMapping {
             MountPoint netconfNode = netconfNodeOptional.get();
             return netconfNode;
         } else {
-            LOG.info("Mount Point not found for :" + nodeId);
+            LOG.error("Mount Point not found for :" + nodeId);
             return null;
         }
 
     }
-
-}
\ No newline at end of file
+}