Fix ovsdb node update in clustered environment 46/27446/1
authorAnil Vishnoi <vishnoianil@gmail.com>
Wed, 23 Sep 2015 18:08:06 +0000 (23:38 +0530)
committerAnil Vishnoi <vishnoianil@gmail.com>
Fri, 25 Sep 2015 15:27:24 +0000 (15:27 +0000)
In cluster environment same switch can be connected to multiple
controller instance running southbound plugin. In the existing implementation
if device disconnect from any of the controller instances OVSDB-SB remove
OvsdbNode from operational data store. In cluster environment that will
break contract with customer, given that device is still connected to
atleast one of the two controller instances running. This patch modifying the
behavior where controller will see if its the only connected controller,
then it will delete the data from operational data store, else it will skip
any clean up from operational data store, because other instances will anyway
update about the disconnected controller manager entry in the managers list.

Change-Id: Iaa043f6632eb2de660b623604e8f8e0938dbc4d5
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
(cherry picked from commit 6051e15c6f929c08f152417b1f19373b10e93647)

southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbNodeRemoveCommand.java

index 63424f7d3c4f8717f33ef8ed13585ae59bd2be70..57154d8c6055d7472edd8b7cc9bda961975b48a5 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
 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.ManagedNodeEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntry;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,23 +41,43 @@ public class OvsdbNodeRemoveCommand extends AbstractTransactionCommand {
             if (ovsdbNodeOptional.isPresent()) {
                 Node ovsdbNode = ovsdbNodeOptional.get();
                 OvsdbNodeAugmentation ovsdbNodeAugmentation = ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
-                if (ovsdbNodeAugmentation != null) {
-                    if (ovsdbNodeAugmentation.getManagedNodeEntry() != null) {
-                        for (ManagedNodeEntry managedNode : ovsdbNodeAugmentation.getManagedNodeEntry()) {
-                            transaction.delete(LogicalDatastoreType.OPERATIONAL, managedNode.getBridgeRef().getValue());
+                if (checkIfOnlyConnectedManager(ovsdbNodeAugmentation)) {
+                    if (ovsdbNodeAugmentation != null) {
+                        if (ovsdbNodeAugmentation.getManagedNodeEntry() != null) {
+                            for (ManagedNodeEntry managedNode : ovsdbNodeAugmentation.getManagedNodeEntry()) {
+                                transaction.delete(
+                                        LogicalDatastoreType.OPERATIONAL, managedNode.getBridgeRef().getValue());
+                            }
+                        } else {
+                            LOG.debug("{} had no managed nodes", ovsdbNode.getNodeId().getValue());
                         }
                     } else {
-                        LOG.debug("{} had no managed nodes", ovsdbNode.getNodeId().getValue());
+                        LOG.warn("{} had no OvsdbNodeAugmentation", ovsdbNode.getNodeId().getValue());
                     }
+                    transaction.delete(LogicalDatastoreType.OPERATIONAL,
+                            getOvsdbConnectionInstance().getInstanceIdentifier());
                 } else {
-                    LOG.warn("{} had no OvsdbNodeAugmentation", ovsdbNode.getNodeId().getValue());
+                    LOG.debug("Other southbound plugin instances in cluster are connected to the device,"
+                            + " not deleting OvsdbNode form data store.");
                 }
-                transaction.delete(LogicalDatastoreType.OPERATIONAL,
-                        getOvsdbConnectionInstance().getInstanceIdentifier());
             }
         } catch (Exception e) {
             LOG.warn("Failure to delete ovsdbNode {}",e);
         }
     }
 
+    private boolean checkIfOnlyConnectedManager(OvsdbNodeAugmentation ovsdbNodeAugmentation) {
+        if (ovsdbNodeAugmentation != null) {
+            int connectedManager = 0;
+            for (ManagerEntry manager : ovsdbNodeAugmentation.getManagerEntry()) {
+                if (manager.isIsConnected()) {
+                    connectedManager++;
+                    if (connectedManager > 1) {
+                        return false;
+                    }
+                }
+            }
+        }
+        return true;
+    }
 }