bug 8673 physical switch node is not removed 21/58821/3
authorK.V Suneelu Verma <k.v.suneelu.verma@ericsson.com>
Tue, 13 Jun 2017 13:19:39 +0000 (18:49 +0530)
committersuneel verma <k.v.suneelu.verma@ericsson.com>
Thu, 6 Jul 2017 06:31:12 +0000 (06:31 +0000)
When the node gets disconnected , its global node alone
is getting removed sometimes.

reuse GlobalNodeRemove command which cleans global aswell as
physical switch node.

Change-Id: Ic89fb1b0606bb1d42242c860ea2f7d9fa1e2b37d
Signed-off-by: K.V Suneelu Verma <k.v.suneelu.verma@ericsson.com>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepGlobalRemoveCommand.java

index 8312526e331e781a85d875ce734efa05cb596003..cd0c9c45b2106fd1332ab8fe6698d2d7cf01cfc9 100644 (file)
@@ -496,12 +496,6 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
             // might went down abruptly and didn't get a chance to clean up the operational data store.
             if (!ownershipChange.hasOwner()) {
                 LOG.debug("{} has no owner, cleaning up the operational data store", ownershipChange.getEntity());
-                // Below code might look weird but it's required. We want to give first opportunity to the
-                // previous owner of the device to clean up the operational data store if there is no owner now.
-                // That way we will avoid lot of nasty md-sal exceptions because of concurrent delete.
-                if (ownershipChange.wasOwner()) {
-                    cleanEntityOperationalData(ownershipChange.getEntity());
-                }
                 // If first cleanEntityOperationalData() was called, this call will be no-op.
                 cleanEntityOperationalData(ownershipChange.getEntity());
             }
@@ -543,8 +537,7 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
         @SuppressWarnings("unchecked") final InstanceIdentifier<Node> nodeIid =
                 (InstanceIdentifier<Node>) HwvtepSouthboundUtil
                         .getInstanceIdentifierCodec().bindingDeserializer(entity.getId());
-
-        txInvoker.invoke(transaction -> transaction.delete(LogicalDatastoreType.OPERATIONAL, nodeIid));
+        txInvoker.invoke(new HwvtepGlobalRemoveCommand(nodeIid));
     }
 
     private HwvtepConnectionInstance getConnectionInstanceFromEntity(Entity entity) {
index 8ee8917469dd3a353bff2ab0158574af38388884..74ef97d9178dfcee235db594d24d0c9aabc4fa5a 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
 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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -28,15 +29,22 @@ public class HwvtepGlobalRemoveCommand extends AbstractTransactionCommand {
     private static final Logger LOG = LoggerFactory.getLogger(HwvtepGlobalRemoveCommand.class);
     private static final long ONE_CONNECTED_MANAGER = 1;
     private static final long ONE_ACTIVE_CONNECTION_IN_PASSIVE_MODE = 1;
+    private final InstanceIdentifier<Node> nodeInstanceIdentifier;
 
     public HwvtepGlobalRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
+        this.nodeInstanceIdentifier = key.getInstanceIdentifier();
+    }
+
+    public HwvtepGlobalRemoveCommand(InstanceIdentifier<Node> nodeInstanceIdentifier) {
+        super(null, null, null);
+        this.nodeInstanceIdentifier = nodeInstanceIdentifier;
     }
 
     @Override
     public void execute(ReadWriteTransaction transaction) {
         CheckedFuture<Optional<Node>, ReadFailedException> hwvtepGlobalFuture = transaction.read(
-                LogicalDatastoreType.OPERATIONAL, getOvsdbConnectionInstance().getInstanceIdentifier());
+                LogicalDatastoreType.OPERATIONAL, nodeInstanceIdentifier);
         try {
             Optional<Node> hwvtepGlobalOptional = hwvtepGlobalFuture.get();
             if (hwvtepGlobalOptional.isPresent()) {
@@ -56,8 +64,7 @@ public class HwvtepGlobalRemoveCommand extends AbstractTransactionCommand {
                     } else {
                         LOG.warn("{} had no HwvtepGlobalAugmentation", hwvtepNode.getNodeId().getValue());
                     }
-                    transaction.delete(LogicalDatastoreType.OPERATIONAL,
-                            getOvsdbConnectionInstance().getInstanceIdentifier());
+                    transaction.delete(LogicalDatastoreType.OPERATIONAL, nodeInstanceIdentifier);
                 } else {
                     LOG.debug("Other southbound plugin instances in cluster are connected to the device,"
                             + " not deleting OvsdbNode form data store.");