From: Anil Vishnoi Date: Tue, 6 Oct 2015 20:41:25 +0000 (+0530) Subject: If controller joins the cluster late, and the owner of the device X-Git-Tag: release/beryllium~296^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=bf288f954947f35aca6425f7d180b4732dee6818;p=ovsdb.git If controller joins the cluster late, and the owner of the device 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 --- diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java index 54ff1e5a2..6dd5e5f9d 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java @@ -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 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); }