Hack to update degree port on portmapping
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / mapping / PortMappingImpl.java
index 9d15dffac4826e5cd3f3a569b3c6d789ae4c88ac..d19b07b64fe015f12ac2733468c754383bb93cd5 100644 (file)
@@ -123,7 +123,7 @@ public class PortMappingImpl implements PortMapping {
             .child(Nodes.class, new NodesKey(nodeId));
         try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
             Optional<Nodes> portMapppingOpt = readTx.read(LogicalDatastoreType.CONFIGURATION, portMappingIID).get();
-            if (!portMapppingOpt.isPresent()) {
+            if (portMapppingOpt.isEmpty()) {
                 LOG.warn("Could not get portMapping for node {}", nodeId);
                 return null;
             }
@@ -248,4 +248,27 @@ public class PortMappingImpl implements PortMapping {
         return this.getNode(nodeId) != null;
     }
 
+    @Override
+    public Mapping getMappingFromOtsInterface(String nodeId, String interfName) {
+        KeyedInstanceIdentifier<Nodes, NodesKey> nodePortmappingIID = InstanceIdentifier.create(Network.class)
+            .child(Nodes.class, new NodesKey(nodeId));
+        try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
+            Optional<Nodes> nodePortmapppingOpt
+                = readTx.read(LogicalDatastoreType.CONFIGURATION, nodePortmappingIID).get();
+            if (nodePortmapppingOpt.isEmpty()) {
+                LOG.warn("Could not get portMapping for node {}", nodeId);
+                return null;
+            }
+            Map<MappingKey, Mapping> mappings = nodePortmapppingOpt.get().getMapping();
+            for (Mapping mapping : mappings.values()) {
+                if (interfName.equals(mapping.getSupportingOts())) {
+                    return mapping;
+                }
+            }
+        } catch (InterruptedException | ExecutionException ex) {
+            LOG.error("Unable to get mapping list for nodeId {}", nodeId, ex);
+        }
+        return null;
+    }
+
 }