Add new method in PortMapping interface 27/97827/12
authorGilles Thouenon <gilles.thouenon@orange.com>
Fri, 1 Oct 2021 12:10:55 +0000 (14:10 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Thu, 9 Dec 2021 08:50:43 +0000 (09:50 +0100)
- change the name of deleteMappingData method to deletePortMappingNode
to be more explicit about the deletion of the all port-mapping node when
disconnecting a node
- create a new deleteMapping method that remove a given mapping from the
mapping list for a given node. Such method is necessary when we want to
update a mapping removing one leaf (typically, supporting odu and otu
interface of xponder when we delete ODU4 or OTU4 services).

JIRA: TRNSPRTPCE-538
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: I477b7a6ddbf3a97b65e12ec317271d45a3a83da3

common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMapping.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingImpl.java
common/src/test/java/org/opendaylight/transportpce/common/mapping/PortMappingImplTest.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java

index 921a3eed125eca896f341501f500a95de20d861e..799af027251dd5c911d31e2c998b6bcdb5e1b83a 100644 (file)
@@ -56,13 +56,13 @@ public interface PortMapping {
     boolean createMappingData(String nodeId, String nodeVersion);
 
     /**
-     * This method removes mapping data from the datastore after disconnecting ODL
-     * from a Netconf device.
+     * This method removes all mapping data of a given node from the datastore
+     * after disconnecting ODL from a Netconf device.
      *
      * @param nodeId
      *            node ID
      */
-    void deleteMappingData(String nodeId);
+    void deletePortMappingNode(String nodeId);
 
     /**
      * This method for a given node's termination point returns the Mapping object
@@ -105,6 +105,18 @@ public interface PortMapping {
      */
     Mapping getMapping(String nodeId, String circuitPackName, String portName);
 
+    /**
+     * This method removes a given mapping data from the mapping list
+     * stored in the datastore while the Netconf device is already
+     * connected to the controller.
+     *
+     * @param nodeId
+     *            node ID
+     * @param logicalConnectionPoint
+     *            key of the mapping inside the mapping list
+     */
+    void deleteMapping(String nodeId, String logicalConnectionPoint);
+
     /**
      * This method, for a given node media channel-capabilities, returns the object
      * based on portmapping.yang model stored in the MD-SAL data store which is
index 0a4ff6b7e9df769f9329910f979fc230927bb1d3..980501cbe59c6a97cd6947e9a3ebf077fd1ee74f 100644 (file)
@@ -117,6 +117,22 @@ public class PortMappingImpl implements PortMapping {
         return null;
     }
 
+
+    @Override
+    public void deleteMapping(String nodeId, String logicalConnectionPoint) {
+        LOG.info("Deleting Mapping {} of node '{}'", logicalConnectionPoint, nodeId);
+        WriteTransaction rw = this.dataBroker.newWriteOnlyTransaction();
+        InstanceIdentifier<Mapping> mappingIID = InstanceIdentifier.create(Network.class)
+            .child(Nodes.class, new NodesKey(nodeId)).child(Mapping.class, new MappingKey(logicalConnectionPoint));
+        rw.delete(LogicalDatastoreType.CONFIGURATION, mappingIID);
+        try {
+            rw.commit().get(1, TimeUnit.SECONDS);
+            LOG.info("Mapping {} removed for node '{}'", logicalConnectionPoint, nodeId);
+        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+            LOG.error("Error for removing mapping {} for node '{}'", logicalConnectionPoint, nodeId);
+        }
+    }
+
     @Override
     public McCapabilities getMcCapbilities(String nodeId, String mcLcp) {
         /*
@@ -142,7 +158,7 @@ public class PortMappingImpl implements PortMapping {
 
 
     @Override
-    public void deleteMappingData(String nodeId) {
+    public void deletePortMappingNode(String nodeId) {
         LOG.info("Deleting Mapping Data corresponding at node '{}'", nodeId);
         WriteTransaction rw = this.dataBroker.newWriteOnlyTransaction();
         InstanceIdentifier<Nodes> nodesIID = InstanceIdentifier.create(Network.class)
@@ -154,7 +170,6 @@ public class PortMappingImpl implements PortMapping {
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             LOG.error("Error for removing port mapping infos for node '{}'", nodeId, e);
         }
-
     }
 
     @Override
index 8f2644f7aabeae39dc5cf26528547b3824d87afa..bcf0518003214249e28de525089f441b13228d37 100644 (file)
@@ -119,7 +119,7 @@ public class PortMappingImplTest {
                 .getMapping("node", "logicalConnectionPoint"), mapping);
 
         //test delete portmapping for existing node
-        portMapping.deleteMappingData("node");
+        portMapping.deletePortMappingNode("node");
 
         //test get portmapping that was deleted above and doesn't exist anymore
         assertNull(portMapping.getMapping("node", "logicalConnectionPoint"));
index 5d3d3644d209c85590b36eb4a16da4bbf95ffd11..35ab8504f0d478450bdd1ca39908b1f3e54e6af7 100644 (file)
@@ -260,7 +260,7 @@ public class NetworkModelServiceImpl implements NetworkModelService {
             }
 
             LOG.info("deleteOpenROADMnode: {} version {}", nodeId, deviceVersion.getName());
-            this.portMapping.deleteMappingData(nodeId);
+            this.portMapping.deletePortMappingNode(nodeId);
 
             this.networkTransactionService.commit().get(1, TimeUnit.SECONDS);
             LOG.info("all nodes and links deleted ! ");