From 65f5eca88489ba7941a5843e1a3703c5af3db6ee Mon Sep 17 00:00:00 2001 From: Anil Vishnoi Date: Wed, 23 Sep 2015 23:38:06 +0530 Subject: [PATCH] Fix ovsdb node update in clustered environment 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 (cherry picked from commit 6051e15c6f929c08f152417b1f19373b10e93647) --- .../md/OvsdbNodeRemoveCommand.java | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbNodeRemoveCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbNodeRemoveCommand.java index 63424f7d3..57154d8c6 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbNodeRemoveCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbNodeRemoveCommand.java @@ -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; + } } -- 2.36.6