Explictly cleanup all the bridges managed by the node 51/32351/2
authorAnil Vishnoi <vishnoianil@gmail.com>
Mon, 11 Jan 2016 18:01:40 +0000 (10:01 -0800)
committerAnil Vishnoi <vishnoianil@gmail.com>
Tue, 12 Jan 2016 02:42:00 +0000 (18:42 -0800)
Change-Id: I37d608a7bb1096d7291d12a0d50dd482f257542f
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java

index cc8f2a3b88c289a7ef09f4b696689f2b3e512b45..2ac0f496e23754a2b5c78f6c7035f9d88ba788cb 100644 (file)
@@ -48,6 +48,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -375,11 +376,30 @@ public class OvsdbConnectionManager implements OvsdbConnectionListener, AutoClos
 
     private void cleanEntityOperationalData(Entity entity) {
 
+        //Do explicit cleanup rather than using OvsdbNodeRemoveCommand, because there
+        // are chances that other controller instance went down abruptly and it does
+        // not clear manager entry, which OvsdbNodeRemoveCommand look for before cleanup.
+
         InstanceIdentifier<Node> nodeIid = (InstanceIdentifier<Node>) SouthboundUtil
                 .getInstanceIdentifierCodec().bindingDeserializer(entity.getId());
 
         final ReadWriteTransaction transaction = db.newReadWriteTransaction();
-        SouthboundUtil.deleteNode(transaction, nodeIid);
+        Optional<Node> ovsdbNodeOpt = SouthboundUtil.readNode(transaction,nodeIid);
+        if ( ovsdbNodeOpt.isPresent() ) {
+            Node ovsdbNode = ovsdbNodeOpt.get();
+            OvsdbNodeAugmentation nodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+            if (nodeAugmentation != null) {
+                if (nodeAugmentation.getManagedNodeEntry() != null) {
+                    for (ManagedNodeEntry managedNode : nodeAugmentation.getManagedNodeEntry()) {
+                        transaction.delete(
+                                LogicalDatastoreType.OPERATIONAL, managedNode.getBridgeRef().getValue());
+                    }
+                } else {
+                    LOG.debug("{} had no managed nodes", ovsdbNode.getNodeId().getValue());
+                }
+            }
+            SouthboundUtil.deleteNode(transaction, nodeIid);
+        }
     }
 
     private OpenVSwitch getOpenVswitchTableEntry(OvsdbConnectionInstance connectionInstance) {