Fix: Disconnection of netconf node 96/98196/2
authorGilles Thouenon <gilles.thouenon@orange.com>
Wed, 13 Oct 2021 13:49:29 +0000 (15:49 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Fri, 29 Oct 2021 09:08:21 +0000 (11:08 +0200)
- Add protection to check that a node exists in TransportPCE datastores
before removing it. Appeared when the node connection remained in a
transient state, and that the node had not been created in PortMapping
and the different topologies.
- Add a new isNodeExist method in PortMapping to test presence or not of
a node in the datastore.

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

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

index 8b04bd5ca2cbd82aefc9fb16cc18fa8995b56065..fc7090c853b7bbb55156f25d8a47a9dad8fc871b 100644 (file)
@@ -180,4 +180,16 @@ public interface PortMapping {
      */
     boolean updatePortMappingWithOduSwitchingPools(String nodeId, InstanceIdentifier<OduSwitchingPools> ospIID,
         Map<Uint16, List<InstanceIdentifier<PortList>>> nbliidMap);
+
+    /**
+     * This method check the presence or not of a given node inside the PortMapping
+     * datastore.
+     *
+     * @param nodeId
+     *            Unique Identifier for the node of interest.
+     *
+     * @return Result true/false based on existance or not of a given node.
+     */
+    boolean isNodeExist(String nodeId);
+
 }
index 13d52cf707d298322ad9e75681373fb5ee79d504..d92ec0e853ec867c44aff26bbf37823c582e6ad1 100644 (file)
@@ -204,4 +204,9 @@ public class PortMappingImpl implements PortMapping {
                 return false;
         }
     }
+
+    @Override
+    public boolean isNodeExist(String nodeId) {
+        return this.getNode(nodeId) != null;
+    }
 }
index dfc90dd3de49f5f83f83cca751fe52cccbf0a5db..b1b2cc0b0f25e841639337f862cf83241f2ceac6 100644 (file)
@@ -75,9 +75,10 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
             NetconfNode netconfNodeBefore = rootNode.getDataBefore().augmentation(NetconfNode.class);
             switch (rootNode.getModificationType()) {
                 case DELETE:
-                    this.networkModelService.deleteOpenRoadmnode(nodeId);
-                    onDeviceDisConnected(nodeId);
-                    LOG.info("Device {} correctly disconnected from controller", nodeId);
+                    if (this.networkModelService.deleteOpenRoadmnode(nodeId)) {
+                        onDeviceDisConnected(nodeId);
+                        LOG.info("Device {} correctly disconnected from controller", nodeId);
+                    }
                     break;
                 case WRITE:
                     NetconfNode netconfNodeAfter = rootNode.getDataAfter().augmentation(NetconfNode.class);
index 4845ba30789cf3c1f25323e9dd34d514f87df960..aaa515238bcdfb1578a372d3b41e229663f686e6 100644 (file)
@@ -29,13 +29,14 @@ public interface NetworkModelService {
     void createOpenRoadmNode(String nodeId, String nodeVersion);
 
     /**
-     * Delete OpenROADM node mapping and topologies.
+     * Delete OpenROADM node from portmapping and topologies.
      *
      * @param nodeId
      *     unique node ID of OpenROADM node.
      *
+     * @return result of node deletion from portmapping and topologies
      */
-    void deleteOpenRoadmnode(String nodeId);
+    boolean deleteOpenRoadmnode(String nodeId);
 
     /**
      * Update termination point, and if need, be associated links, of
index e5370ee33ebffd2226fff19d576c43abc07884f3..5c1ab9dac131cc22163d74cf4e1d260e1377c340 100644 (file)
@@ -191,8 +191,11 @@ public class NetworkModelServiceImpl implements NetworkModelService {
      */
 
     @Override
-    public void deleteOpenRoadmnode(String nodeId) {
+    public boolean deleteOpenRoadmnode(String nodeId) {
         try {
+            if (!this.portMapping.isNodeExist(nodeId)) {
+                return false;
+            }
             NodeKey nodeIdKey = new NodeKey(new NodeId(nodeId));
 
             LOG.info("deleting node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
@@ -263,7 +266,9 @@ public class NetworkModelServiceImpl implements NetworkModelService {
             LOG.info("all nodes and links deleted ! ");
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             LOG.error("Error when trying to delete node : {}", nodeId, e);
+            return false;
         }
+        return true;
     }
 
     @Override
index 8e57c872044184748c69360e4aeabb6d6fcfcfe1..3656c8f02c4abb198e3b1081b6ec6daf383f6b53 100644 (file)
@@ -78,7 +78,6 @@ public class NetConfTopologyListenerTest {
             OPENROADM_DEVICE_VERSION_2_2_1);
         when(node.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
         when(node.getDataBefore()).thenReturn(netconfNode);
-        when(registrations.remove(anyString())).thenReturn(nodeRegistration);
 
         NetConfTopologyListener listener = new NetConfTopologyListener(networkModelService, dataBroker,
             deviceTransactionManager, portMapping, registrations);
@@ -87,7 +86,7 @@ public class NetConfTopologyListenerTest {
         verify(node, times(1)).getModificationType();
         verify(node, times(3)).getDataBefore();
         verify(networkModelService, times(1)).deleteOpenRoadmnode(anyString());
-        verify(nodeRegistration, times(1)).unregisterListeners();
+        verify(nodeRegistration, times(0)).unregisterListeners();
     }
 
     @Test