Net-virt is not checking if the master of the net-virt-application is
authorAnil Vishnoi <vishnoianil@gmail.com>
Mon, 7 Mar 2016 19:00:22 +0000 (11:00 -0800)
committerSam Hague <shague@redhat.com>
Thu, 10 Mar 2016 13:13:06 +0000 (13:13 +0000)
elected at the clustering level or not. Because of this it can end up in a situation
where candidates are registered but owner is not elected and all the instances
gets false when they check for the owner. This patch fixes the issue, where
it waits till owner is selected

Change-Id: I2c720aeac44e4252091952383fe3bb4ed9bed97b
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/NetvirtProvider.java
openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/impl/OvsdbInventoryServiceImpl.java

index 1542cec28c794e51ad38161daeeb443c2061c53f..9d068337099d0e929aa902047cfae90c4837394f 100644 (file)
@@ -47,6 +47,14 @@ public class NetvirtProvider implements BindingAwareProvider, AutoCloseable {
         return false;
     }
 
+    public static boolean isMasterElected(){
+        if (entityOwnershipService != null) {
+            Optional<EntityOwnershipState> state = entityOwnershipService.getOwnershipState(ownerInstanceEntity);
+            return state.isPresent() && state.get().hasOwner();
+        }
+        return false;
+    }
+
     @Override
     public void close() throws Exception {
         LOG.info("NetvirtProvider closed");
index 120e3ce938ddd46ada19f0c78e944fb6d2f15f93..0ce75a5600a4f0e88d461247ca0c898ea5fdff19 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.ovsdb.openstack.netvirt.ClusterAwareMdsalUtils;
 import org.opendaylight.ovsdb.openstack.netvirt.ConfigInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.NetvirtProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
 import org.opendaylight.ovsdb.openstack.netvirt.api.OvsdbInventoryService;
 import org.opendaylight.ovsdb.openstack.netvirt.api.OvsdbInventoryListener;
@@ -87,6 +88,13 @@ public class OvsdbInventoryServiceImpl implements ConfigInterface, OvsdbInventor
     public void setDependencies(Object impl) {}
 
     private void initializeNetvirtTopology() {
+        while(!NetvirtProvider.isMasterElected()){
+            try {
+                Thread.sleep(100);
+            } catch (InterruptedException e) {
+                LOG.warn("Netvirt thread waiting on Netvirt Ownership Election is interrupted");
+            }
+        }
         final TopologyId topologyId = new TopologyId(new Uri(Constants.NETVIRT_TOPOLOGY_ID));
         InstanceIdentifier<Topology> path =
                 InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));