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;
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;
@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;
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,
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;
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) {
}
@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 .
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);
}
@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()) {
}
@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();
}
@Override
- protected ElanDpnInterfaceClusteredListener getDataTreeChangeListener() {
- return this;
+ @PreDestroy
+ public void close() {
+ super.close();
+ Executors.shutdownAndAwaitTermination(getExecutorService());
}
-
}