Convert elanmanager-impl to use mdsal EOS APIs 41/64141/7
authorTom Pantelis <tompantelis@gmail.com>
Wed, 11 Oct 2017 02:17:53 +0000 (22:17 -0400)
committerStephen Kitt <skitt@redhat.com>
Thu, 26 Oct 2017 09:53:13 +0000 (09:53 +0000)
The controller EOS APIs are deprecated.

Change-Id: Ic0b4cbc2fc6b3e11958841d2704407f38edf7504
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
15 files changed:
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfaceClusteredListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceStateClusteredListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanServiceProvider.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanInstanceListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepLogicalSwitchListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepPhysicalSwitchListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepTerminationPointListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayUtils.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayUtils.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2gwServiceProvider.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanClusterUtils.java
vpnservice/elanmanager/elanmanager-impl/src/main/resources/org/opendaylight/blueprint/elanmanager.xml
vpnservice/elanmanager/elanmanager-impl/src/test/java/org/opendaylight/netvirt/elanmanager/tests/ElanServiceTestModule.java

index 1e09194914f743af518732d6ec68a2290e0191a0..0bf695112a0d7ff997a4573cf65bc60da842c29f 100644 (file)
@@ -7,17 +7,12 @@
  */
 package org.opendaylight.netvirt.elan.internal;
 
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-
 import java.util.Collections;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
 import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
-import org.opendaylight.genius.utils.clustering.ClusteringUtils;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
@@ -39,14 +34,14 @@ public class ElanDpnInterfaceClusteredListener
     private static final Logger LOG = LoggerFactory.getLogger(ElanDpnInterfaceClusteredListener.class);
 
     private final DataBroker broker;
-    private final EntityOwnershipService entityOwnershipService;
+    private final EntityOwnershipUtils entityOwnershipUtils;
     private final ElanL2GatewayUtils elanL2GatewayUtils;
     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
 
-    public ElanDpnInterfaceClusteredListener(DataBroker broker, EntityOwnershipService entityOwnershipService,
+    public ElanDpnInterfaceClusteredListener(DataBroker broker, EntityOwnershipUtils entityOwnershipUtils,
                                              ElanUtils elanUtils, ElanL2GatewayUtils elanL2GatewayUtils) {
         this.broker = broker;
-        this.entityOwnershipService = entityOwnershipService;
+        this.entityOwnershipUtils = entityOwnershipUtils;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
         this.elanL2GatewayMulticastUtils = elanUtils.getElanL2GatewayMulticastUtils();
     }
@@ -68,7 +63,7 @@ public class ElanDpnInterfaceClusteredListener
                     dpnInterfaces.getDpId());
             return;
         }
-        ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, elanName, "updating mcast mac upon tunnel event",
+        ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, elanName, "updating mcast mac upon tunnel event",
             () -> Collections.singletonList(
                     elanL2GatewayMulticastUtils.updateRemoteMcastMacOnElanL2GwDevices(elanName)));
     }
@@ -79,36 +74,26 @@ public class ElanDpnInterfaceClusteredListener
         final String elanName = getElanName(identifier);
         //Cache need to be updated in all cluster nodes and not only by leader node .
         //Hence moved out from DJC job
-        ListenableFuture<Boolean> checkEntityOwnerFuture = ClusteringUtils.checkNodeEntityOwner(
-                entityOwnershipService, HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
-                HwvtepSouthboundConstants.ELAN_ENTITY_NAME);
-        Futures.addCallback(checkEntityOwnerFuture, new FutureCallback<Boolean>() {
-            @Override
-            public void onSuccess(Boolean isOwner) {
-                DataStoreJobCoordinator.getInstance().enqueueJob(elanName + ":l2gw", () -> {
-                    try {
-                        if (isOwner) {
-                            // deleting Elan L2Gw Devices UcastLocalMacs From Dpn
-                            elanL2GatewayUtils.deleteElanL2GwDevicesUcastLocalMacsFromDpn(elanName,
-                                    dpnInterfaces.getDpId());
-
-                            //Removing this dpn from cache to avoid race between this and local ucast mac listener
-                            ElanUtils.removeDPNInterfaceFromElanInCache(getElanName(identifier), dpnInterfaces);
-
-                            // updating remote mcast mac on l2gw devices
-                            elanL2GatewayMulticastUtils.updateRemoteMcastMacOnElanL2GwDevices(elanName);
-                        }
-                    } finally {
-                        ElanUtils.addDPNInterfaceToElanInCache(getElanName(identifier), dpnInterfaces);
-                    }
-                    return null;
-                });
-            }
 
-            @Override
-            public void onFailure(Throwable error) {
-                LOG.error("Error while fetching checkNodeEntityOwner", error);
+        DataStoreJobCoordinator.getInstance().enqueueJob(elanName + ":l2gw", () -> {
+            try {
+                if (entityOwnershipUtils.isEntityOwner(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
+                        HwvtepSouthboundConstants.ELAN_ENTITY_NAME)) {
+                    // deleting Elan L2Gw Devices UcastLocalMacs From Dpn
+                    elanL2GatewayUtils.deleteElanL2GwDevicesUcastLocalMacsFromDpn(elanName,
+                            dpnInterfaces.getDpId());
+
+                    //Removing this dpn from cache to avoid race between this and local ucast mac listener
+                    ElanUtils.removeDPNInterfaceFromElanInCache(getElanName(identifier), dpnInterfaces);
+
+                    // updating remote mcast mac on l2gw devices
+                    elanL2GatewayMulticastUtils.updateRemoteMcastMacOnElanL2GwDevices(elanName);
+                }
+            } finally {
+                ElanUtils.addDPNInterfaceToElanInCache(getElanName(identifier), dpnInterfaces);
             }
+
+            return null;
         });
     }
 
@@ -127,34 +112,23 @@ public class ElanDpnInterfaceClusteredListener
     @Override
     protected void add(InstanceIdentifier<DpnInterfaces> identifier, final DpnInterfaces dpnInterfaces) {
         final String elanName = getElanName(identifier);
-        ListenableFuture<Boolean> checkEntityOwnerFuture = ClusteringUtils.checkNodeEntityOwner(
-                entityOwnershipService, HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
-                HwvtepSouthboundConstants.ELAN_ENTITY_NAME);
-        Futures.addCallback(checkEntityOwnerFuture, new FutureCallback<Boolean>() {
-            @Override
-            public void onSuccess(Boolean isOwner) {
-                DataStoreJobCoordinator.getInstance().enqueueJob(elanName + ":l2gw", () -> {
-                    try {
-                        if (isOwner) {
-                            ElanUtils.addDPNInterfaceToElanInCache(getElanName(identifier), dpnInterfaces);
-                            ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
-                            elanL2GatewayUtils.installElanL2gwDevicesLocalMacsInDpn(
-                                    dpnInterfaces.getDpId(), elanInstance, dpnInterfaces.getInterfaces().get(0));
-
-                            // updating remote mcast mac on l2gw devices
-                            elanL2GatewayMulticastUtils.updateRemoteMcastMacOnElanL2GwDevices(elanName);
-                        }
-                    } finally {
-                        ElanUtils.addDPNInterfaceToElanInCache(getElanName(identifier), dpnInterfaces);
-                    }
-                    return null;
-                });
-            }
 
-            @Override
-            public void onFailure(Throwable error) {
-                LOG.error("Error while fetching checkNodeEntityOwner", error);
+        DataStoreJobCoordinator.getInstance().enqueueJob(elanName + ":l2gw", () -> {
+            try {
+                if (entityOwnershipUtils.isEntityOwner(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
+                        HwvtepSouthboundConstants.ELAN_ENTITY_NAME)) {
+                    ElanUtils.addDPNInterfaceToElanInCache(getElanName(identifier), dpnInterfaces);
+                    ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
+                    elanL2GatewayUtils.installElanL2gwDevicesLocalMacsInDpn(
+                            dpnInterfaces.getDpId(), elanInstance, dpnInterfaces.getInterfaces().get(0));
+
+                    // updating remote mcast mac on l2gw devices
+                    elanL2GatewayMulticastUtils.updateRemoteMcastMacOnElanL2GwDevices(elanName);
+                }
+            } finally {
+                ElanUtils.addDPNInterfaceToElanInCache(getElanName(identifier), dpnInterfaces);
             }
+            return null;
         });
     }
 
index 62a1bd7f57024a5f95317f7f80a5c4eb2d78275c..db3be853eb038e82bb46ff8c9d73aa2b0f95c70d 100644 (file)
@@ -8,9 +8,9 @@
 package org.opendaylight.netvirt.elan.internal;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.netvirt.elan.ElanException;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
@@ -30,18 +30,18 @@ public class ElanInterfaceStateClusteredListener extends
     private final DataBroker broker;
     private final ElanInterfaceManager elanInterfaceManager;
     private final ElanUtils elanUtils;
-    private final EntityOwnershipService entityOwnershipService;
+    private final EntityOwnershipUtils entityOwnershipUtils;
 
     /* FIXME:
      * Why do we have ElanInterfaceStateChangeListener and ElanInterfaceStateClusteredListener
      * both within same module? Refactor this code into single listener.
      */
     public ElanInterfaceStateClusteredListener(DataBroker broker, ElanInterfaceManager elanInterfaceManager,
-                                               ElanUtils elanUtils, EntityOwnershipService entityOwnershipService) {
+                                               ElanUtils elanUtils, EntityOwnershipUtils entityOwnershipUtils) {
         this.broker = broker;
         this.elanInterfaceManager = elanInterfaceManager;
         this.elanUtils = elanUtils;
-        this.entityOwnershipService = entityOwnershipService;
+        this.entityOwnershipUtils = entityOwnershipUtils;
     }
 
     public void init() {
@@ -68,7 +68,7 @@ public class ElanInterfaceStateClusteredListener extends
             if (intrf.getOperStatus().equals(Interface.OperStatus.Up)) {
                 final String interfaceName = intrf.getName();
 
-                ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, () -> {
+                ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, "external tunnel update", () -> {
                     LOG.debug("running external tunnel update job for interface {} added", interfaceName);
                     try {
                         handleExternalTunnelUpdate(interfaceName, intrf);
index fcea2a3c88f20f2c0c074b08d5f43b53db0f20c9..ea974abec3875f91d9205e9d5db20ebdf8b5b3a3 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.netvirt.elan.internal;
 
 import com.google.common.base.Optional;
-
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -23,8 +22,6 @@ import java.util.function.BiFunction;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.interfacemanager.exceptions.InterfaceAlreadyExistsException;
 import org.opendaylight.genius.interfacemanager.globals.IfmConstants;
@@ -35,9 +32,12 @@ import org.opendaylight.genius.mdsalutil.MetaDataUtil;
 import org.opendaylight.genius.mdsalutil.NwConstants;
 import org.opendaylight.genius.mdsalutil.nxmatches.NxMatchRegister;
 import org.opendaylight.genius.utils.ServiceIndex;
-import org.opendaylight.genius.utils.clustering.EntityOwnerUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.infrautils.inject.AbstractLifecycle;
+import org.opendaylight.mdsal.eos.binding.api.Entity;
+import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipCandidateRegistration;
+import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
+import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput;
 import org.opendaylight.netvirt.elan.statusanddiag.ElanStatusMonitor;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
@@ -94,6 +94,8 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
     private boolean generateIntBridgeMac = true;
     private boolean isL2BeforeL3;
 
+    private final EntityOwnershipCandidateRegistration candidateRegistration;
+
     @Inject
     public ElanServiceProvider(IdManagerService idManager, IInterfaceManager interfaceManager,
                                ElanInstanceManager elanInstanceManager, ElanBridgeManager bridgeMgr,
@@ -109,12 +111,18 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
         this.elanStatusMonitor = elanStatusMonitor;
         this.elanUtils = elanUtils;
         elanInterfaceManager.setElanUtils(elanUtils);
+
+        candidateRegistration = registerCandidate(entityOwnershipService);
+    }
+
+    private static EntityOwnershipCandidateRegistration registerCandidate(
+            EntityOwnershipService entityOwnershipService) {
         try {
-            EntityOwnerUtils.registerEntityCandidateForOwnerShip(entityOwnershipService,
-                    HwvtepSouthboundConstants.ELAN_ENTITY_TYPE, HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
-                    null/*listener*/);
+            return entityOwnershipService.registerCandidate(
+                    new Entity(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE, HwvtepSouthboundConstants.ELAN_ENTITY_TYPE));
         } catch (CandidateAlreadyRegisteredException e) {
             LOG.error("failed to register the entity");
+            return null;
         }
     }
 
@@ -134,7 +142,10 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
     }
 
     @Override
-    protected void stop() throws Exception {
+    protected void stop() {
+        if (candidateRegistration != null) {
+            candidateRegistration.close();
+        }
     }
 
     @Override
index 529eb942b6cb010d660f94dd7919e56babb9f1c4..1f8f3d5cba271e2055f14884cfefe430cd7f3a9d 100644 (file)
@@ -12,9 +12,9 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ConcurrentMap;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.netvirt.elan.internal.ElanInstanceManager;
 import org.opendaylight.netvirt.elan.internal.ElanInterfaceManager;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
@@ -39,14 +39,14 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
     private final ElanInterfaceManager elanInterfaceManager;
     private final DataBroker broker;
     private final ElanInstanceManager elanInstanceManager;
-    private final EntityOwnershipService entityOwnershipService;
+    private final EntityOwnershipUtils entityOwnershipUtils;
 
     public ElanGroupListener(ElanInterfaceManager elanInterfaceManager, final DataBroker db,
-                             EntityOwnershipService entityOwnershipService, ElanInstanceManager elanInstanceManager) {
+            EntityOwnershipUtils entityOwnershipUtils, ElanInstanceManager elanInstanceManager) {
         super(Group.class, ElanGroupListener.class);
         this.elanInterfaceManager = elanInterfaceManager;
         broker = db;
-        this.entityOwnershipService = entityOwnershipService;
+        this.entityOwnershipUtils = entityOwnershipUtils;
         this.elanInstanceManager = elanInstanceManager;
         registerListener(LogicalDatastoreType.CONFIGURATION, broker);
         LOG.trace("ElanGroupListener registered");
@@ -141,7 +141,7 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
             }
             LOG.trace("no of buckets mismatched {} {}", elanInstance.getElanInstanceName(),
                     update.getKey().getGroupId());
-            ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, elanInstance.getElanInstanceName(),
+            ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, elanInstance.getElanInstanceName(),
                     "updating broadcast group",
                 () -> {
                     elanInterfaceManager.setupElanBroadcastGroups(elanInstance, dpnId);
index 8061a4cee1101481927b51a25decbc2cc3ed61c9..b9fb33bb689950bc21b927382ccb90b32acca1ba 100644 (file)
@@ -13,10 +13,10 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
@@ -34,46 +34,48 @@ public class ElanInstanceListener extends AsyncClusteredDataTreeChangeListenerBa
     private static final Logger LOG = LoggerFactory.getLogger(ElanInstanceListener.class);
 
     private final DataBroker broker;
-    private final EntityOwnershipService entityOwnershipService;
+    private final EntityOwnershipUtils entityOwnershipUtils;
     private static final Map<String, List<Runnable>> WAITING_JOB_LIST = new ConcurrentHashMap<>();
 
-    public ElanInstanceListener(final DataBroker db, final EntityOwnershipService entityOwnershipService) {
+    public ElanInstanceListener(final DataBroker db, final EntityOwnershipUtils entityOwnershipUtils) {
         super(ElanInstance.class, ElanInstanceListener.class);
         broker = db;
-        this.entityOwnershipService = entityOwnershipService;
+        this.entityOwnershipUtils = entityOwnershipUtils;
         registerListener(LogicalDatastoreType.CONFIGURATION, db);
     }
 
     public void init() {
     }
 
+    @Override
     public void close() {
     }
 
     @Override
     protected void remove(final InstanceIdentifier<ElanInstance> identifier,
                           final ElanInstance del) {
-        ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, del.getElanInstanceName(), () -> {
-            LOG.info("Elan instance {} deleted from Configuration tree ", del);
-            List<L2gatewayConnection> connections =
-                    L2GatewayConnectionUtils.getL2GwConnectionsByElanName(
-                            this.broker, del.getElanInstanceName());
-            if (connections == null || connections.isEmpty()) {
-                return null;
-            }
-            try {
-                ReadWriteTransaction tx = this.broker.newReadWriteTransaction();
-                for (L2gatewayConnection connection : connections) {
-                    InstanceIdentifier<L2gatewayConnection> iid = InstanceIdentifier.create(Neutron.class)
+        ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, del.getElanInstanceName(),
+            "delete Elan instance", () -> {
+                LOG.info("Elan instance {} deleted from Configuration tree ", del);
+                List<L2gatewayConnection> connections =
+                        L2GatewayConnectionUtils.getL2GwConnectionsByElanName(
+                                this.broker, del.getElanInstanceName());
+                if (connections == null || connections.isEmpty()) {
+                    return null;
+                }
+                try {
+                    ReadWriteTransaction tx = this.broker.newReadWriteTransaction();
+                    for (L2gatewayConnection connection : connections) {
+                        InstanceIdentifier<L2gatewayConnection> iid = InstanceIdentifier.create(Neutron.class)
                             .child(L2gatewayConnections.class).child(L2gatewayConnection.class, connection.getKey());
-                    tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
+                        tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
+                    }
+                    tx.submit().checkedGet();
+                } catch (TransactionCommitFailedException e) {
+                    LOG.error("Failed to delete associated l2gwconnection while deleting network", e);
                 }
-                tx.submit().checkedGet();
-            } catch (TransactionCommitFailedException e) {
-                LOG.error("Failed to delete associated l2gwconnection while deleting network", e);
-            }
-            return null;
-        });
+                return null;
+            });
     }
 
     @Override
@@ -104,4 +106,4 @@ public class ElanInstanceListener extends AsyncClusteredDataTreeChangeListenerBa
         return InstanceIdentifier.create(ElanInstances.class).child(ElanInstance.class);
     }
 
-}
\ No newline at end of file
+}
index 0c3836679fbb411190d21dd893df3ebfce4980e1..7ff1ed4a22490c9d9b5e4a2b90c56b873b09dd15 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.netvirt.elan.l2gw.listeners;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.genius.datastoreutils.hwvtep.HwvtepClusteredDataTreeChangeListener;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.netvirt.elan.l2gw.jobs.LogicalSwitchAddedJob;
 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
@@ -40,26 +40,26 @@ public class HwvtepLogicalSwitchListener extends
     private static final Logger LOG = LoggerFactory.getLogger(HwvtepLogicalSwitchListener.class);
 
     /** The node id. */
-    private NodeId nodeId;
+    private final NodeId nodeId;
 
     /** The logical switch name. */
-    private String logicalSwitchName;
+    private final String logicalSwitchName;
 
     /** The physical device. */
-    private Devices physicalDevice;
+    private final Devices physicalDevice;
 
     /** The l2 gateway device. */
-    private L2GatewayDevice l2GatewayDevice;
+    private final L2GatewayDevice l2GatewayDevice;
 
     // The default vlan id
-    private Integer defaultVlanId;
+    private final Integer defaultVlanId;
 
     // Id of L2 Gateway connection responsible for this logical switch creation
-    private Uuid l2GwConnId;
+    private final Uuid l2GwConnId;
 
     private final DataBroker broker;
     private final ElanL2GatewayUtils elanL2GatewayUtils;
-    private final EntityOwnershipService entityOwnershipService;
+    private final EntityOwnershipUtils entityOwnershipUtils;
     private final ElanUtils elanUtils;
     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
 
@@ -68,7 +68,7 @@ public class HwvtepLogicalSwitchListener extends
      *
      * @param dataBroker DataBroker
      * @param elanL2GatewayUtils l2 gateway utils
-     * @param entityOwnershipService the entity ownership service
+     * @param entityOwnershipUtils the entity ownership utils
      * @param elanUtils the ELAN utilities
      * @param elanL2GatewayMulticastUtils l2 gateway multicast utils
      * @param l2GatewayDevice the l2 gateway device
@@ -78,7 +78,7 @@ public class HwvtepLogicalSwitchListener extends
      * @param l2GwConnId l2 gateway connection id
      */
     public HwvtepLogicalSwitchListener(DataBroker dataBroker, ElanL2GatewayUtils elanL2GatewayUtils,
-                                       EntityOwnershipService entityOwnershipService, ElanUtils elanUtils,
+                                       EntityOwnershipUtils entityOwnershipUtils, ElanUtils elanUtils,
                                        ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
                                        L2GatewayDevice l2GatewayDevice,
                                        String logicalSwitchName,
@@ -86,7 +86,7 @@ public class HwvtepLogicalSwitchListener extends
         super(LogicalSwitches.class, HwvtepLogicalSwitchListener.class);
         this.broker = dataBroker;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
-        this.entityOwnershipService = entityOwnershipService;
+        this.entityOwnershipUtils = entityOwnershipUtils;
         this.elanUtils = elanUtils;
         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
         this.nodeId = new NodeId(l2GatewayDevice.getHwvtepNodeId());
@@ -158,9 +158,8 @@ public class HwvtepLogicalSwitchListener extends
             LogicalSwitchAddedJob logicalSwitchAddedWorker = new LogicalSwitchAddedJob(elanL2GatewayUtils,
                     elanL2GatewayMulticastUtils, logicalSwitchName, physicalDevice, elanDevice,
                     defaultVlanId);
-            ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, logicalSwitchAddedWorker.getJobKey() ,
-                    "create vlan mappings and mcast configurations",
-                    logicalSwitchAddedWorker);
+            ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, logicalSwitchAddedWorker.getJobKey(),
+                    "create vlan mappings and mcast configurations", logicalSwitchAddedWorker);
         } catch (RuntimeException e) {
             LOG.error("Failed to handle HwVTEPLogicalSwitch - add for: {}", identifier, e);
         } finally {
index 6b1c250daf66389834e92eb2999c44eb1146cb2b..0c690851bea817a7d25ee5f214f1389164fcf244 100644 (file)
@@ -15,14 +15,13 @@ import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.function.BiPredicate;
 import java.util.function.Predicate;
-
 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.hwvtep.HwvtepAbstractDataTreeChangeListener;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepHACache;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
@@ -66,8 +65,7 @@ public class HwvtepPhysicalSwitchListener
     /** The itm rpc service. */
     private final ItmRpcService itmRpcService;
 
-    /** The entity ownership service. */
-    private final EntityOwnershipService entityOwnershipService;
+    private final EntityOwnershipUtils entityOwnershipUtils;
 
     private final L2GatewayConnectionUtils l2GatewayConnectionUtils;
 
@@ -131,27 +129,28 @@ public class HwvtepPhysicalSwitchListener
      * @param dataBroker
      *            the data broker
      * @param itmRpcService itm rpc
-     * @param entityOwnershipService entity ownership service
+     * @param entityOwnershipUtils entity ownership utils
      * @param l2GatewayConnectionUtils l2gw connection utils
      * @param l2gwServiceProvider l2gw service Provider
      * @param l2GatewayUtils utils
      * @param haListener HA Op node listners
      */
     public HwvtepPhysicalSwitchListener(final DataBroker dataBroker, ItmRpcService itmRpcService,
-                                        EntityOwnershipService entityOwnershipService,
+                                        EntityOwnershipUtils entityOwnershipUtils,
                                         L2GatewayConnectionUtils l2GatewayConnectionUtils,
                                         L2gwServiceProvider l2gwServiceProvider,
                                         L2GatewayUtils l2GatewayUtils, HAOpClusteredListener haListener) {
         super(PhysicalSwitchAugmentation.class, HwvtepPhysicalSwitchListener.class);
         this.dataBroker = dataBroker;
         this.itmRpcService = itmRpcService;
-        this.entityOwnershipService = entityOwnershipService;
+        this.entityOwnershipUtils = entityOwnershipUtils;
         this.l2GatewayConnectionUtils = l2GatewayConnectionUtils;
         this.l2gwServiceProvider = l2gwServiceProvider;
         this.l2GatewayUtils = l2GatewayUtils;
         this.haOpClusteredListener = haListener;
     }
 
+    @Override
     public void init() {
         registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
     }
@@ -228,7 +227,7 @@ public class HwvtepPhysicalSwitchListener
                     && TUNNEL_IP_CHANGED.test(phySwitchAfter, existingDevice)) {
 
                 final String hwvtepId = existingDevice.getHwvtepNodeId();
-                ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService,
+                ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, existingDevice.getDeviceName(),
                         "handling Physical Switch add create itm tunnels ", () -> {
                         LOG.info("Deleting itm tunnels for device {}", existingDevice.getDeviceName());
                         L2GatewayUtils.deleteItmTunnels(itmRpcService, hwvtepId,
index d0d53f3d9e9d8b1db7f91238abd8f22cd8ad5acb..78f90279909093908445de405b225ba18cc7e926 100644 (file)
@@ -19,10 +19,10 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.genius.datastoreutils.hwvtep.HwvtepClusteredDataTreeChangeListener;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
@@ -61,15 +61,15 @@ public class HwvtepTerminationPointListener
 
     private final DataBroker broker;
     private final ElanL2GatewayUtils elanL2GatewayUtils;
-    private final EntityOwnershipService entityOwnershipService;
+    private final EntityOwnershipUtils entityOwnershipUtils;
 
     public HwvtepTerminationPointListener(DataBroker broker, ElanL2GatewayUtils elanL2GatewayUtils,
-                                          EntityOwnershipService entityOwnershipService) {
+            EntityOwnershipUtils entityOwnershipUtils) {
         super(TerminationPoint.class, HwvtepTerminationPointListener.class);
 
         this.broker = broker;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
-        this.entityOwnershipService = entityOwnershipService;
+        this.entityOwnershipUtils = entityOwnershipUtils;
         //No longer needed as port reconciliation is added in plugin
         //registerListener(LogicalDatastoreType.OPERATIONAL, broker);
         LOG.debug("created HwvtepTerminationPointListener");
@@ -99,9 +99,8 @@ public class HwvtepTerminationPointListener
                 del.getAugmentation(HwvtepPhysicalPortAugmentation.class);
         if (portAugmentation != null) {
             final NodeId nodeId = identifier.firstIdentifierOf(Node.class).firstKeyOf(Node.class).getNodeId();
-            ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, HwvtepSouthboundConstants.ELAN_ENTITY_NAME,
-                    "Handling Physical port delete", () ->
-                            handlePortDeleted(identifier, portAugmentation, del, nodeId));
+            ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, HwvtepSouthboundConstants.ELAN_ENTITY_NAME,
+                "Handling Physical port delete", () -> handlePortDeleted(identifier, portAugmentation, del, nodeId));
             return;
         }
     }
@@ -118,8 +117,8 @@ public class HwvtepTerminationPointListener
                 add.getAugmentation(HwvtepPhysicalPortAugmentation.class);
         if (portAugmentation != null) {
             final NodeId nodeId = identifier.firstIdentifierOf(Node.class).firstKeyOf(Node.class).getNodeId();
-            ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, HwvtepSouthboundConstants.ELAN_ENTITY_NAME,
-                    "handling Physical Switch add", () -> handlePortAdded(portAugmentation, add, nodeId));
+            ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, HwvtepSouthboundConstants.ELAN_ENTITY_NAME,
+                () -> handlePortAdded(portAugmentation, add, nodeId));
             return;
         }
 
index 3da900a7beaa5ff89176ca90957b98c2ec0d02d1..f861cdb861ebde23afb0dddd0b6cda6af8b695d7 100644 (file)
@@ -32,13 +32,13 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.utils.SystemPropertyReader;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
@@ -110,7 +110,7 @@ public class ElanL2GatewayUtils {
     private final DataBroker broker;
     private final ElanDmacUtils elanDmacUtils;
     private final ElanItmUtils elanItmUtils;
-    private final EntityOwnershipService entityOwnershipService;
+    private final EntityOwnershipUtils entityOwnershipUtils;
     private final OdlInterfaceRpcService interfaceManagerRpcService;
 
     private final DataStoreJobCoordinator dataStoreJobCoordinator = DataStoreJobCoordinator.getInstance();
@@ -120,12 +120,12 @@ public class ElanL2GatewayUtils {
 
     @Inject
     public ElanL2GatewayUtils(DataBroker broker, ElanDmacUtils elanDmacUtils, ElanItmUtils elanItmUtils,
-                              EntityOwnershipService entityOwnershipService,
+                              EntityOwnershipUtils entityOwnershipUtils,
                               OdlInterfaceRpcService interfaceManagerRpcService) {
         this.broker = broker;
         this.elanDmacUtils = elanDmacUtils;
         this.elanItmUtils = elanItmUtils;
-        this.entityOwnershipService = entityOwnershipService;
+        this.entityOwnershipUtils = entityOwnershipUtils;
         this.interfaceManagerRpcService = interfaceManagerRpcService;
     }
 
@@ -353,7 +353,7 @@ public class ElanL2GatewayUtils {
         // DMAC table
         if (elanDpns != null && elanDpns.size() > 0) {
             String jobKey = elan.getElanInstanceName() + ":" + macToBeAdded;
-            ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, jobKey, "install l2gw macs in dmac table",
+            ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, jobKey, "install l2gw macs in dmac table",
                 () -> {
                     if (doesLocalUcastMacExistsInCache(extL2GwDevice, localUcastMacs)) {
                         for (DpnInterfaces elanDpn : elanDpns) {
@@ -373,7 +373,7 @@ public class ElanL2GatewayUtils {
         macList.add(new PhysAddress(macToBeAdded));
 
         String jobKey = "hwvtep:" + elan.getElanInstanceName() + ":" + macToBeAdded;
-        ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, jobKey, "install remote ucast macs in l2gw device",
+        ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, jobKey, "install remote ucast macs in l2gw device",
             () -> {
                 if (!doesLocalUcastMacExistsInCache(extL2GwDevice, localUcastMacs)) {
                     LOG.trace(
@@ -452,7 +452,7 @@ public class ElanL2GatewayUtils {
         for (final MacAddress mac : macAddresses) {
             if (elanDpns != null && !elanDpns.isEmpty()) {
                 String jobKey = elanName + ":" + mac.getValue();
-                ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, jobKey, "delete l2gw macs from dmac table",
+                ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, jobKey, "delete l2gw macs from dmac table",
                     () -> {
                         List<ListenableFuture<Void>> futures = new ArrayList<>();
                         for (DpnInterfaces elanDpn : elanDpns) {
@@ -469,7 +469,7 @@ public class ElanL2GatewayUtils {
         //Batched job
         DeleteL2GwDeviceMacsFromElanJob job = new DeleteL2GwDeviceMacsFromElanJob(elanName, l2GwDevice,
                 macAddresses);
-        ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, job.getJobKey(),
+        ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, job.getJobKey(),
                 "delete remote ucast macs in l2gw devices", job);
     }
 
@@ -500,8 +500,7 @@ public class ElanL2GatewayUtils {
             if (localMacs != null && !localMacs.isEmpty()) {
                 for (final MacAddress mac : localMacs) {
                     String jobKey = elanName + ":" + mac.getValue();
-                    ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, jobKey,
-                            "delete l2gw macs from dmac table",
+                    ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, jobKey,
                         () -> elanDmacUtils.deleteDmacFlowsToExternalMac(elanTag, dpnId,
                                 l2GwDevice.getHwvtepNodeId(), mac.getValue()));
                 }
index b0d83c99f9826ad37b03489cfae6720ef0182d9b..b2dc647b0aae5a8cadd7b94e5deeb7623cbd2be1 100644 (file)
@@ -22,10 +22,10 @@ import java.util.List;
 import java.util.Set;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepUtils;
 import org.opendaylight.netvirt.elan.internal.ElanInstanceManager;
@@ -63,17 +63,17 @@ public class L2GatewayConnectionUtils {
     private final DataBroker broker;
     private final ElanInstanceManager elanInstanceManager;
     private final ElanL2GatewayUtils elanL2GatewayUtils;
-    private final EntityOwnershipService entityOwnershipService;
+    private final EntityOwnershipUtils entityOwnershipUtils;
     private final ElanUtils elanUtils;
     private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
 
     public L2GatewayConnectionUtils(DataBroker dataBroker, ElanInstanceManager elanInstanceManager,
-                                    EntityOwnershipService entityOwnershipService, ElanUtils elanUtils,
+                                    EntityOwnershipUtils entityOwnershipUtils, ElanUtils elanUtils,
                                     ElanL2GatewayUtils elanL2GatewayUtils) {
         this.broker = dataBroker;
         this.elanInstanceManager = elanInstanceManager;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
-        this.entityOwnershipService = entityOwnershipService;
+        this.entityOwnershipUtils = entityOwnershipUtils;
         this.elanUtils = elanUtils;
         this.elanL2GatewayMulticastUtils = elanUtils.getElanL2GatewayMulticastUtils();
     }
@@ -244,8 +244,8 @@ public class L2GatewayConnectionUtils {
                     new DisAssociateHwvtepFromElanJob(broker, elanL2GatewayUtils, elanL2GatewayMulticastUtils,
                             elanL2GwDevice, elanName,
                             l2Device, defaultVlan, hwvtepNodeId, isLastL2GwConnDeleted);
-            ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, disAssociateHwvtepToElanJob.getJobKey(),
-                    "remove l2gw connection job ", disAssociateHwvtepToElanJob);
+            ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, disAssociateHwvtepToElanJob.getJobKey(),
+                    "remove l2gw connection job", disAssociateHwvtepToElanJob);
         }
     }
 
@@ -283,7 +283,7 @@ public class L2GatewayConnectionUtils {
                         hwvtepNodeId, elanName);
                 if (logicalSwitch == null) {
                     HwvtepLogicalSwitchListener hwVTEPLogicalSwitchListener = new HwvtepLogicalSwitchListener(broker,
-                            elanL2GatewayUtils, entityOwnershipService, elanUtils, elanL2GatewayMulticastUtils,
+                            elanL2GatewayUtils, entityOwnershipUtils, elanUtils, elanL2GatewayMulticastUtils,
                             l2GatewayDevice, elanName, l2Device, defaultVlan, l2GwConnId);
                     hwVTEPLogicalSwitchListener.registerListener(LogicalDatastoreType.OPERATIONAL, broker);
                     createLogicalSwitch = true;
@@ -296,9 +296,8 @@ public class L2GatewayConnectionUtils {
                         elanL2GatewayUtils, elanL2GatewayMulticastUtils, l2GatewayDevice, elanInstance,
                         l2Device, defaultVlan, createLogicalSwitch);
 
-                ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService, associateHwvtepToElanJob.getJobKey() ,
-                        "create logical switch in hwvtep topo",
-                        associateHwvtepToElanJob);
+                ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, associateHwvtepToElanJob.getJobKey() ,
+                        "create logical switch in hwvtep topo", associateHwvtepToElanJob);
 
             } else {
                 LOG.info("L2GwConn create is not handled for device with id {} as it's not connected", l2DeviceName);
@@ -359,7 +358,7 @@ public class L2GatewayConnectionUtils {
                             HwvtepLocalUcastMacListener localUcastMacListener =
                                     new HwvtepLocalUcastMacListener(broker, elanL2GatewayUtils);
                             settableFuture.set(resultNode);
-                            Optional<Node> nodeOptional = (Optional<Node>) resultNode;
+                            Optional<Node> nodeOptional = resultNode;
                             if (nodeOptional.isPresent()) {
                                 Node node = nodeOptional.get();
                                 if (node.getAugmentation(HwvtepGlobalAugmentation.class) != null) {
index 331775a703fb28d9e9f12e08427cbe0afdffecb7..6fb1c3bd6449b91b12a7b6a4b061c362062320c8 100644 (file)
@@ -9,9 +9,7 @@ package org.opendaylight.netvirt.elan.l2gw.utils;
 
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -29,16 +27,12 @@ public class L2GatewayUtils {
 
     private final ItmRpcService itmRpcService;
 
-    private final EntityOwnershipService entityOwnershipService;
-
     private final L2GatewayConnectionUtils l2GatewayConnectionUtils;
 
     public L2GatewayUtils(DataBroker dataBroker, ItmRpcService itmRpcService,
-                          EntityOwnershipService entityOwnershipService,
                           L2GatewayConnectionUtils l2GatewayConnectionUtils) {
         this.dataBroker = dataBroker;
         this.itmRpcService = itmRpcService;
-        this.entityOwnershipService = entityOwnershipService;
         this.l2GatewayConnectionUtils = l2GatewayConnectionUtils;
     }
 
index c5fba3d7c95d4dba306f01478bfd0f9c3abd2268..1cc344cf83a180cf5ed278609038192dccce7110 100644 (file)
@@ -11,9 +11,8 @@ package org.opendaylight.netvirt.elan.l2gw.utils;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.infrautils.inject.AbstractLifecycle;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
 import org.opendaylight.netvirt.elanmanager.api.IL2gwService;
@@ -36,12 +35,12 @@ public class L2gwServiceProvider extends AbstractLifecycle implements IL2gwServi
     private final DataBroker dataBroker;
     private final ItmRpcService itmRpcService;
     private final L2GatewayConnectionUtils l2GatewayConnectionUtils;
-    private final EntityOwnershipService entityOwnershipService;
+    private final EntityOwnershipUtils entityOwnershipUtils;
 
-    public L2gwServiceProvider(final DataBroker dataBroker, final EntityOwnershipService entityOwnershipService,
+    public L2gwServiceProvider(final DataBroker dataBroker, final EntityOwnershipUtils entityOwnershipUtils,
                                ItmRpcService itmRpcService, L2GatewayConnectionUtils l2GatewayConnectionUtils) {
         this.dataBroker = dataBroker;
-        this.entityOwnershipService = entityOwnershipService;
+        this.entityOwnershipUtils = entityOwnershipUtils;
         this.itmRpcService = itmRpcService;
         this.l2GatewayConnectionUtils = l2GatewayConnectionUtils;
     }
@@ -49,7 +48,7 @@ public class L2gwServiceProvider extends AbstractLifecycle implements IL2gwServi
     @Override
     public void provisionItmAndL2gwConnection(L2GatewayDevice l2GwDevice, String psName,
                                               String hwvtepNodeId, IpAddress tunnelIpAddr) {
-        ElanClusterUtils.runOnlyInLeaderNode(entityOwnershipService,
+        ElanClusterUtils.runOnlyInOwnerNode(entityOwnershipUtils, hwvtepNodeId,
                 "Handling Physical Switch add create itm tunnels ", () -> {
                 ElanL2GatewayUtils.createItmTunnels(itmRpcService, hwvtepNodeId, psName, tunnelIpAddr);
                 return Collections.emptyList();
index 6bdd07e89e23612d5424ee2c868dc71f17c54852..457c7314f1d6bcb38e5c9fc8688c8169f2729290 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netvirt.elan.utils;
 
 import com.google.common.base.Optional;
-import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
@@ -17,14 +16,11 @@ import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.function.Function;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
-import org.opendaylight.genius.utils.SystemPropertyReader;
-import org.opendaylight.genius.utils.clustering.ClusteringUtils;
+import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.netvirt.elan.l2gw.utils.SettableFutureCallback;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -38,60 +34,15 @@ public final class ElanClusterUtils {
     private ElanClusterUtils() {
     }
 
-    public static void runOnlyInLeaderNode(EntityOwnershipService entityOwnershipService, Runnable job) {
-        runOnlyInLeaderNode(entityOwnershipService, job, "");
-    }
-
-    public static void runOnlyInLeaderNode(EntityOwnershipService entityOwnershipService, final Runnable job,
-                                           final String jobDescription) {
-        ListenableFuture<Boolean> checkEntityOwnerFuture = ClusteringUtils.checkNodeEntityOwner(
-            entityOwnershipService, HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
-            HwvtepSouthboundConstants.ELAN_ENTITY_NAME);
-        Futures.addCallback(checkEntityOwnerFuture, new FutureCallback<Boolean>() {
-            @Override
-            public void onSuccess(Boolean isOwner) {
-                if (isOwner) {
-                    job.run();
-                } else {
-                    LOG.trace("job is not run as i m not cluster owner desc :{} ", jobDescription);
-                }
-            }
-
-            @Override
-            public void onFailure(Throwable error) {
-                LOG.error("Failed to identity cluster owner ", error);
-            }
-        }, MoreExecutors.directExecutor());
+    public static void runOnlyInOwnerNode(EntityOwnershipUtils entityOwnershipUtils, String jobDesc, Runnable job) {
+        entityOwnershipUtils.runOnlyInOwnerNode(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
+            HwvtepSouthboundConstants.ELAN_ENTITY_NAME, DataStoreJobCoordinator.getInstance(), jobDesc, job);
     }
 
-    public static void runOnlyInLeaderNode(EntityOwnershipService entityOwnershipService, String jobKey,
-                                           Callable<List<ListenableFuture<Void>>> dataStoreJob) {
-        runOnlyInLeaderNode(entityOwnershipService, jobKey, "", dataStoreJob);
-    }
-
-    public static void runOnlyInLeaderNode(EntityOwnershipService entityOwnershipService, final String jobKey,
-                                           final String jobDescription,
-                                           final Callable<List<ListenableFuture<Void>>> dataStoreJob) {
-        ListenableFuture<Boolean> checkEntityOwnerFuture = ClusteringUtils.checkNodeEntityOwner(
-            entityOwnershipService, HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
-            HwvtepSouthboundConstants.ELAN_ENTITY_NAME);
-        Futures.addCallback(checkEntityOwnerFuture, new FutureCallback<Boolean>() {
-            @Override
-            public void onSuccess(Boolean isOwner) {
-                if (isOwner) {
-                    LOG.trace("scheduling job {} ", jobDescription);
-                    DataStoreJobCoordinator.getInstance().enqueueJob(jobKey, dataStoreJob,
-                        SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
-                } else {
-                    LOG.trace("job is not run as i m not cluster owner desc :{} ", jobDescription);
-                }
-            }
-
-            @Override
-            public void onFailure(Throwable error) {
-                LOG.error("Failed to identity cluster owner for job " + jobDescription, error);
-            }
-        }, MoreExecutors.directExecutor());
+    public static void runOnlyInOwnerNode(EntityOwnershipUtils entityOwnershipUtils, String jobKey, String jobDesc,
+            Callable<List<ListenableFuture<Void>>> job) {
+        entityOwnershipUtils.runOnlyInOwnerNode(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
+            HwvtepSouthboundConstants.ELAN_ENTITY_NAME, DataStoreJobCoordinator.getInstance(), jobKey, jobDesc, job);
     }
 
     public static <T extends DataObject> void asyncReadAndExecute(final DataBroker broker,
@@ -107,6 +58,7 @@ public final class ElanClusterUtils {
 
             Futures.addCallback(tx.read(datastoreType, iid),
                                 new SettableFutureCallback<Optional<T>>(settableFuture) {
+                        @Override
                         public void onSuccess(Optional<T> data) {
                             function.apply(data);
                             super.onSuccess(data);
index 8098741181de23cb82584a3cec0b72548d6fd2c4..0ae684e2275c245b182cfc067d5ad8031136e8a3 100644 (file)
@@ -9,7 +9,7 @@
   <reference id="notificationService"
     interface="org.opendaylight.controller.md.sal.binding.api.NotificationService" />
   <reference id="entityOwnershipService"
-    interface="org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService" />
+    interface="org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService" />
   <reference id="mdsalUtils"
     interface="org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager" />
   <reference id="interfaceManager"
     update-strategy="none">
   </odl:clustered-app-config>
 
+  <bean id="entityOwnershipUtils" class="org.opendaylight.genius.utils.clustering.EntityOwnershipUtils">
+    <argument ref="entityOwnershipService" />
+  </bean>
+
   <bean id="elanBridgeManager"
     class="org.opendaylight.netvirt.elan.internal.ElanBridgeManager">
     <argument ref="dataBroker" />
     <argument ref="dataBroker" />
     <argument ref="elanInterfaceManager" />
     <argument ref="elanUtils" />
-    <argument ref="entityOwnershipService" />
+    <argument ref="entityOwnershipUtils" />
   </bean>
 
   <bean id="elanDpnInterfaceClusteredListener"
     class="org.opendaylight.netvirt.elan.internal.ElanDpnInterfaceClusteredListener"
     init-method="init" destroy-method="close">
     <argument ref="dataBroker" />
-    <argument ref="entityOwnershipService" />
+    <argument ref="entityOwnershipUtils" />
     <argument ref="elanUtils" />
     <argument ref="elanL2GatewayUtils" />
   </bean>
   <bean id="l2GatewayConnectionUtils" class="org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils">
     <argument ref="dataBroker" />
     <argument ref="elanInstanceManager" />
-    <argument ref="entityOwnershipService" />
+    <argument ref="entityOwnershipUtils" />
     <argument ref="elanUtils" />
     <argument ref="elanL2GatewayUtils" />
   </bean>
     <argument ref="dataBroker" />
     <argument ref="elanDmacUtils" />
     <argument ref="elanItmUtils" />
-    <argument ref="entityOwnershipService" />
+    <argument ref="entityOwnershipUtils" />
     <argument ref="odlInterfaceRpcService" />
   </bean>
 
     init-method="init" destroy-method="close">
     <argument ref="dataBroker" />
     <argument ref="itmRpcService" />
-    <argument ref="entityOwnershipService" />
+    <argument ref="entityOwnershipUtils" />
     <argument ref="l2GatewayConnectionUtils" />
     <argument ref="l2gwService" />
     <argument ref="l2gatewayUtils" />
     destroy-method="close">
     <argument ref="dataBroker" />
     <argument ref="elanL2GatewayUtils" />
-    <argument ref="entityOwnershipService" />
+    <argument ref="entityOwnershipUtils" />
   </bean>
 
   <bean id="haEventHandler"
     class="org.opendaylight.netvirt.elan.l2gw.listeners.ElanGroupListener">
     <argument ref="elanInterfaceManager" />
     <argument ref="dataBroker" />
-    <argument ref="entityOwnershipService" />
+    <argument ref="entityOwnershipUtils" />
     <argument ref="elanInstanceManager" />
   </bean>
 
         class="org.opendaylight.netvirt.elan.l2gw.utils.L2gwServiceProvider"
         init-method="init">
     <argument ref="dataBroker" />
-    <argument ref="entityOwnershipService" />
+    <argument ref="entityOwnershipUtils" />
     <argument ref="itmRpcService" />
     <argument ref="l2GatewayConnectionUtils" />
   </bean>
         class="org.opendaylight.netvirt.elan.l2gw.listeners.ElanInstanceListener"
         init-method="init" destroy-method="close">
     <argument ref="dataBroker" />
-    <argument ref="entityOwnershipService" />
+    <argument ref="entityOwnershipUtils" />
   </bean>
 
   <bean id="evpnUtils" class="org.opendaylight.netvirt.elan.evpn.utils.EvpnUtils"
         init-method="init" destroy-method="close">
     <argument ref="dataBroker" />
     <argument ref="itmRpcService" />
-    <argument ref="entityOwnershipService" />
     <argument ref="l2GatewayConnectionUtils" />
   </bean>
 
index 589990d8296fc8112f4d8db62ec52b0cc3490426..d904af8d163e56b5f84766b75eae851f3883a895 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.netvirt.elanmanager.tests;
 import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.test.DataBrokerTestModule;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.daexim.DataImportBootReady;
 import org.opendaylight.genius.idmanager.IdManager;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
@@ -20,6 +19,7 @@ import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.genius.mdsalutil.interfaces.testutils.TestIMdsalApiManager;
 import org.opendaylight.genius.testutils.TestInterfaceManager;
 import org.opendaylight.infrautils.inject.guice.testutils.AbstractGuiceJsr250Module;
+import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
 import org.opendaylight.netvirt.elan.evpn.utils.EvpnUtils;
 import org.opendaylight.netvirt.elan.internal.ElanServiceProvider;
 import org.opendaylight.netvirt.elan.statusanddiag.ElanStatusMonitor;