Bug 7160 - operational store still has node after ovs disconnects 68/53168/2
authorAnil Vishnoi <vishnoianil@gmail.com>
Wed, 8 Mar 2017 08:06:48 +0000 (00:06 -0800)
committerAnil Vishnoi <vishnoianil@gmail.com>
Sat, 11 Mar 2017 00:31:10 +0000 (00:31 +0000)
Change-Id: I4b8c333bc24fd5d406a8df55f375bb9c51622eb0
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbDataTreeChangeListener.java

index fe473b9b3899c4fdd2c1a4f46bc8143f4e1bb872..c8d8ddaf64fdeb2bad1e453139ff4e88a4839897 100644 (file)
@@ -187,6 +187,9 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
         }
         Channel channel = connections.get(client);
         if (channel != null) {
+            //It's an explicit disconnect from user, so no need to notify back
+            //to user about the disconnect.
+            client.setConnectionPublished(false);
             channel.disconnect();
         }
         connections.remove(client);
index 3dd61c7043112dd00c138de708f54ff329e81101..33a203b5392a403476fbed6da4d9128db1aa7c06 100644 (file)
@@ -152,6 +152,31 @@ public class OvsdbDataTreeChangeListener implements ClusteredDataTreeChangeListe
                     }
                 }
             }
+
+            if (change.getRootNode().getModificationType() == DataObjectModification.ModificationType.WRITE) {
+                DataObjectModification<OvsdbNodeAugmentation> ovsdbNodeModification =
+                        change.getRootNode().getModifiedAugmentation(OvsdbNodeAugmentation.class);
+                if (ovsdbNodeModification != null
+                        && ovsdbNodeModification.getModifiedChildContainer(ConnectionInfo.class) != null) {
+                    DataObjectModification<ConnectionInfo> connectionInfoDOM =
+                            ovsdbNodeModification.getModifiedChildContainer(ConnectionInfo.class);
+
+                    if (connectionInfoDOM.getModificationType() == DataObjectModification.ModificationType.DELETE
+                            && connectionInfoDOM.getDataBefore() != null) {
+                        ConnectionInfo key = connectionInfoDOM.getDataBefore();
+                        InstanceIdentifier<Node> iid = cm.getInstanceIdentifier(key);
+                        try {
+                            OvsdbNodeAugmentation ovsdbNode = ovsdbNodeModification.getDataBefore();
+                            cm.disconnect(ovsdbNode);
+                            LOG.warn("OVSDB node {} has been disconnected, because connection-info related to "
+                                    + "the node is removed by user, but node still exist.", ovsdbNode);
+                            cm.stopConnectionReconciliationIfActive(iid.firstIdentifierOf(Node.class), ovsdbNode);
+                        } catch (UnknownHostException e) {
+                            LOG.warn("Failed to disconnect ovsdbNode", e);
+                        }
+                    }
+                }
+            }
         }
     }