If controller joins the cluster late, and the owner of the device 89/27989/2
authorAnil Vishnoi <vishnoianil@gmail.com>
Tue, 6 Oct 2015 20:41:25 +0000 (02:11 +0530)
committerAnil Vishnoi <vishnoianil@gmail.com>
Tue, 6 Oct 2015 21:01:10 +0000 (21:01 +0000)
is already decided, EntityOwnershipService won't notify new candidate that register
for ownership. Adding a proactive check on the ownership state of the device,
so if it's already owned, adding the connection instances in the connection cache.

Change-Id: I7e87b55599f0ebd408814d72789c86f231b7907c
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java

index 54ff1e5a21b811fb66a797c1a00f21dc90100fd5..6dd5e5f9d2bfaa06c7d5e211c0bad9c6516baa91 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipC
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.ovsdb.lib.OvsdbClient;
@@ -444,6 +445,22 @@ public class OvsdbConnectionManager implements OvsdbConnectionListener, AutoClos
                     entityOwnershipService.registerCandidate(candidateEntity);
             ovsdbConnectionInstance.setDeviceOwnershipCandidateRegistration(registration);
             LOG.info("OVSDB entity {} is registred for ownership.", candidateEntity);
+
+            //If entity already has owner, it won't get notification from EntityOwnershipService
+            //so cache the connection instances.
+            Optional<EntityOwnershipState> ownershipStateOpt =
+                    entityOwnershipService.getOwnershipState(candidateEntity);
+            if (ownershipStateOpt.isPresent()) {
+                EntityOwnershipState ownershipState = ownershipStateOpt.get();
+                if (ownershipState.hasOwner() && !ownershipState.isOwner()) {
+                    if (getConnectionInstance(ovsdbConnectionInstance.getMDConnectionInfo()) != null) {
+                        LOG.info("OVSDB entity {} is already owned by other southbound plugin "
+                                + "instance, so *this* instance is NOT an OWNER of the device",
+                                ovsdbConnectionInstance.getConnectionInfo());
+                        putConnectionInstance(ovsdbConnectionInstance.getMDConnectionInfo(),ovsdbConnectionInstance);
+                    }
+                }
+            }
         } catch (CandidateAlreadyRegisteredException e) {
             LOG.warn("OVSDB entity {} was already registered for {} ownership", candidateEntity, e);
         }