Bulk merge of l2gw changes
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / internal / ElanDpnInterfaceClusteredListener.java
index f2bca580efa91899721edf82bf20c77e5b77e74a..172ed67591c04ece3e6719202e38aac4736032b7 100644 (file)
@@ -10,15 +10,16 @@ package org.opendaylight.netvirt.elan.internal;
 import static java.util.Collections.emptyList;
 
 import java.util.List;
-import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 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.data.LogicalDatastoreType;
-import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
+import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.genius.utils.clustering.EntityOwnershipUtils;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.infrautils.utils.concurrent.Executors;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.cache.ElanInstanceDpnsCache;
 import org.opendaylight.netvirt.elan.l2gw.jobs.BcGroupUpdateJob;
@@ -30,7 +31,9 @@ import org.opendaylight.netvirt.elan.l2gw.utils.ElanRefUtil;
 import org.opendaylight.netvirt.elan.utils.ElanClusterUtils;
 import org.opendaylight.netvirt.elan.utils.ElanDmacUtils;
 import org.opendaylight.netvirt.elan.utils.ElanItmUtils;
+import org.opendaylight.netvirt.elan.utils.Scheduler;
 import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils;
+import org.opendaylight.serviceutils.tools.listener.AbstractClusteredAsyncDataTreeChangeListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces;
@@ -41,9 +44,10 @@ import org.slf4j.LoggerFactory;
 
 @Singleton
 public class ElanDpnInterfaceClusteredListener
-        extends AsyncClusteredDataTreeChangeListenerBase<DpnInterfaces, ElanDpnInterfaceClusteredListener> {
+        extends AbstractClusteredAsyncDataTreeChangeListener<DpnInterfaces> {
 
     private static final Logger LOG = LoggerFactory.getLogger(ElanDpnInterfaceClusteredListener.class);
+    private static final Logger EVENT_LOGGER = LoggerFactory.getLogger("NetvirtEventLogger");
 
     private final DataBroker broker;
     private final EntityOwnershipUtils entityOwnershipUtils;
@@ -56,6 +60,8 @@ public class ElanDpnInterfaceClusteredListener
     private final JobCoordinator jobCoordinator;
     private final ElanInstanceCache elanInstanceCache;
     private final ElanInstanceDpnsCache elanInstanceDpnsCache;
+    private final IMdsalApiManager mdsalApiManager;
+    private final Scheduler scheduler;
 
     @Inject
     public ElanDpnInterfaceClusteredListener(DataBroker broker, EntityOwnershipUtils entityOwnershipUtils,
@@ -63,9 +69,14 @@ public class ElanDpnInterfaceClusteredListener
                                              ElanClusterUtils elanClusterUtils, JobCoordinator jobCoordinator,
                                              ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils,
                                              ElanInstanceCache elanInstanceCache,
+                                             Scheduler scheduler,
+                                             IMdsalApiManager mdsalApiManager,
                                              ElanInstanceDpnsCache elanInstanceDpnsCache,
                                              ElanRefUtil elanRefUtil, ElanDmacUtils elanDmacUtils,
                                              ElanItmUtils elanItmUtils) {
+        super(broker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ElanDpnInterfaces.class)
+                .child(ElanDpnInterfacesList.class).child(DpnInterfaces.class),
+                Executors.newListeningSingleThreadExecutor("ElanDpnInterfaceClusteredListener", LOG));
         this.broker = broker;
         this.entityOwnershipUtils = entityOwnershipUtils;
         this.elanL2GatewayUtils = elanL2GatewayUtils;
@@ -77,17 +88,12 @@ public class ElanDpnInterfaceClusteredListener
         this.jobCoordinator = jobCoordinator;
         this.elanInstanceCache = elanInstanceCache;
         this.elanInstanceDpnsCache = elanInstanceDpnsCache;
+        this.mdsalApiManager = mdsalApiManager;
+        this.scheduler = scheduler;
     }
 
-    @PostConstruct
     public void init() {
-        registerListener(LogicalDatastoreType.OPERATIONAL, this.broker);
-    }
-
-    @Override
-    public InstanceIdentifier<DpnInterfaces> getWildCardPath() {
-        return InstanceIdentifier.builder(ElanDpnInterfaces.class).child(ElanDpnInterfacesList.class)
-                .child(DpnInterfaces.class).build();
+        LOG.info("{} start", getClass().getSimpleName());
     }
 
     void handleUpdate(InstanceIdentifier<DpnInterfaces> id, DpnInterfaces dpnInterfaces) {
@@ -105,7 +111,7 @@ public class ElanDpnInterfaceClusteredListener
     }
 
     @Override
-    protected void remove(InstanceIdentifier<DpnInterfaces> identifier, final DpnInterfaces dpnInterfaces) {
+    public void remove(InstanceIdentifier<DpnInterfaces> identifier, final DpnInterfaces dpnInterfaces) {
         // this is the last dpn interface on this elan
         final String elanName = getElanName(identifier);
         //Cache need to be updated in all cluster nodes and not only by leader node .
@@ -116,17 +122,18 @@ public class ElanDpnInterfaceClusteredListener
                 if (entityOwnershipUtils.isEntityOwner(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
                         HwvtepSouthboundConstants.ELAN_ENTITY_NAME)) {
                     // deleting Elan L2Gw Devices UcastLocalMacs From Dpn
-                    DpnDmacJob.uninstallDmacFromL2gws(elanName, dpnInterfaces, elanL2GatewayUtils, elanRefUtil,
-                            elanDmacUtils);
+                    DpnDmacJob.uninstallDmacFromL2gws(elanName, dpnInterfaces, elanL2GatewayUtils, elanClusterUtils,
+                        elanInstanceCache, elanDmacUtils, scheduler, jobCoordinator);
 
                     //Removing this dpn from cache to avoid race between this and local ucast mac listener
                     elanInstanceDpnsCache.remove(getElanName(identifier), dpnInterfaces);
 
                     // updating remote mcast mac on l2gw devices
-                    McastUpdateJob.updateAllMcastsForDpnDelete(elanName, elanL2GatewayMulticastUtils,
-                            elanClusterUtils, dpnInterfaces.getDpId(), elanItmUtils);
-                    BcGroupUpdateJob.updateAllBcGroups(elanName, elanRefUtil, elanL2GatewayMulticastUtils,
-                            broker, false);
+                    McastUpdateJob.updateAllMcastsForDpnDelete(elanName, elanL2GatewayMulticastUtils, elanClusterUtils,
+                        dpnInterfaces.getDpId().toJava(), elanItmUtils, scheduler, jobCoordinator);
+                    BcGroupUpdateJob.updateAllBcGroups(elanName, false, dpnInterfaces.getDpId(),
+                        null, elanRefUtil, elanL2GatewayMulticastUtils, mdsalApiManager,
+                        elanInstanceDpnsCache, elanItmUtils);
                 }
             } finally {
                 elanInstanceDpnsCache.remove(getElanName(identifier), dpnInterfaces);
@@ -137,7 +144,7 @@ public class ElanDpnInterfaceClusteredListener
     }
 
     @Override
-    protected void update(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces original,
+    public void update(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces original,
                           final DpnInterfaces dpnInterfaces) {
         List<String> interfaces = dpnInterfaces.getInterfaces();
         if (interfaces != null && !interfaces.isEmpty()) {
@@ -151,22 +158,23 @@ public class ElanDpnInterfaceClusteredListener
     }
 
     @Override
-    protected void add(InstanceIdentifier<DpnInterfaces> identifier, final DpnInterfaces dpnInterfaces) {
+    public void add(InstanceIdentifier<DpnInterfaces> identifier, final DpnInterfaces dpnInterfaces) {
         final String elanName = getElanName(identifier);
-
+        EVENT_LOGGER.debug("ELAN-DpnInterface, ADD DPN {} Instance {}", dpnInterfaces.getDpId(), elanName);
         jobCoordinator.enqueueJob(elanName + ":l2gw", () -> {
             elanInstanceDpnsCache.add(getElanName(identifier), dpnInterfaces);
             if (entityOwnershipUtils.isEntityOwner(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
                     HwvtepSouthboundConstants.ELAN_ENTITY_NAME)) {
-                ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
+                ElanInstance elanInstance = elanInstanceCache.get(elanName).orElse(null);
                 if (elanInstance != null) {
-                    BcGroupUpdateJob.updateAllBcGroups(elanName, elanRefUtil, elanL2GatewayMulticastUtils,
-                            broker, true);
+                    BcGroupUpdateJob.updateAllBcGroups(elanName, true, dpnInterfaces.getDpId(),
+                        null, elanRefUtil, elanL2GatewayMulticastUtils, mdsalApiManager,
+                        elanInstanceDpnsCache, elanItmUtils);
                     // updating remote mcast mac on l2gw devices
-                    McastUpdateJob.updateAllMcastsForDpnAdd(elanName, elanL2GatewayMulticastUtils,
-                            elanClusterUtils);
-                    DpnDmacJob.installDmacFromL2gws(elanName, dpnInterfaces, elanL2GatewayUtils, elanRefUtil,
-                            elanDmacUtils);
+                    McastUpdateJob.updateAllMcastsForDpnAdd(elanName, elanL2GatewayMulticastUtils, elanClusterUtils,
+                        scheduler, jobCoordinator);
+                    DpnDmacJob.installDmacFromL2gws(elanName, dpnInterfaces, elanL2GatewayUtils, elanClusterUtils,
+                        elanInstanceCache, elanDmacUtils, scheduler, jobCoordinator);
                 }
             }
             return emptyList();
@@ -178,8 +186,9 @@ public class ElanDpnInterfaceClusteredListener
     }
 
     @Override
-    protected ElanDpnInterfaceClusteredListener getDataTreeChangeListener() {
-        return this;
+    @PreDestroy
+    public void close() {
+        super.close();
+        Executors.shutdownAndAwaitTermination(getExecutorService());
     }
-
 }