X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=elanmanager%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetvirt%2Felan%2Fl2gw%2Flisteners%2FElanGroupListener.java;h=7cc4f936489118a5eb436c7751dd1221dd509008;hb=refs%2Fchanges%2F77%2F92077%2F4;hp=829a8369e12f39790399302a0073485ca17f9e9a;hpb=c15b776b5c27d0980e0dcd097df2a609d863dcd5;p=netvirt.git diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java index 829a8369e1..7cc4f93648 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java @@ -7,20 +7,26 @@ */ package org.opendaylight.netvirt.elan.l2gw.listeners; -import java.math.BigInteger; +import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION; + import java.util.List; -import java.util.concurrent.ConcurrentMap; +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.eclipse.jdt.annotation.Nullable; +import org.opendaylight.infrautils.utils.concurrent.Executors; +import org.opendaylight.infrautils.utils.concurrent.LoggingFutures; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner; +import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.netvirt.elan.cache.ElanInstanceCache; import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils; import org.opendaylight.netvirt.elan.utils.ElanClusterUtils; import org.opendaylight.netvirt.elan.utils.ElanUtils; import org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils; import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice; +import org.opendaylight.serviceutils.tools.listener.AbstractClusteredAsyncDataTreeChangeListener; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group; @@ -29,14 +35,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces; import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.Uint64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Singleton -public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase { +public class ElanGroupListener extends AbstractClusteredAsyncDataTreeChangeListener { private static final Logger LOG = LoggerFactory.getLogger(ElanGroupListener.class); - private final DataBroker broker; + private final ManagedNewTransactionRunner txRunner; private final ElanClusterUtils elanClusterUtils; private final ElanUtils elanUtils; private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils; @@ -45,34 +52,40 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase< @Inject public ElanGroupListener(DataBroker db, ElanClusterUtils elanClusterUtils, ElanUtils elanUtils, ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, ElanInstanceCache elanInstanceCache) { - super(Group.class, ElanGroupListener.class); - broker = db; + super(db, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Nodes.class).child(Node.class) + .augmentation(FlowCapableNode.class).child(Group.class), + Executors.newListeningSingleThreadExecutor("ElanGroupListener", LOG)); + this.txRunner = new ManagedNewTransactionRunnerImpl(db); this.elanClusterUtils = elanClusterUtils; this.elanUtils = elanUtils; this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils; this.elanInstanceCache = elanInstanceCache; - registerListener(LogicalDatastoreType.CONFIGURATION, broker); LOG.trace("ElanGroupListener registered"); } + public void init() { + LOG.info("{} init", getClass().getSimpleName()); + } + @Override - protected InstanceIdentifier getWildCardPath() { - return InstanceIdentifier.create(Nodes.class).child(Node.class) - .augmentation(FlowCapableNode.class).child(Group.class); + @PreDestroy + public void close() { + super.close(); } @Override - protected void remove(InstanceIdentifier identifier, Group del) { - LOG.trace("received group removed {}", del.getKey().getGroupId()); + public void remove(InstanceIdentifier identifier, Group del) { + LOG.trace("received group removed {}", del.key().getGroupId()); } + @Nullable ElanInstance getElanInstanceFromGroupId(Group update) { for (ElanInstance elanInstance : elanInstanceCache.getAllPresent()) { if (elanInstance.getElanTag() != null) { - long elanTag = elanInstance.getElanTag(); + long elanTag = elanInstance.getElanTag().longValue(); long elanBCGroupId = ElanUtils.getElanRemoteBroadCastGroupID(elanTag); - if (elanBCGroupId == update.getGroupId().getValue()) { + if (elanBCGroupId == update.getGroupId().getValue().longValue()) { return elanInstance; } } @@ -80,40 +93,40 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase< return null; } - private BigInteger getDpnId(String node) { + @Nullable + private static Uint64 getDpnId(String node) { //openflow:1] String[] temp = node.split(":"); if (temp.length == 2) { - return new BigInteger(temp[1]); + return Uint64.valueOf(temp[1]); } return null; } @Override - protected void update(InstanceIdentifier identifier, Group original, Group update) { - LOG.trace("received group updated {}", update.getKey().getGroupId()); - final BigInteger dpnId = getDpnId(identifier.firstKeyOf(Node.class).getId().getValue()); + public void update(InstanceIdentifier identifier, @Nullable Group original, Group update) { + LOG.trace("received group updated {}", update.key().getGroupId()); + final Uint64 dpnId = getDpnId(identifier.firstKeyOf(Node.class).getId().getValue()); if (dpnId == null) { return; } List allDevices = ElanL2GwCacheUtils.getAllElanDevicesFromCache(); - if (allDevices == null || allDevices.isEmpty()) { - LOG.trace("no elan devices present in cache {}", update.getKey().getGroupId()); + if (allDevices.isEmpty()) { + LOG.trace("no elan devices present in cache {}", update.key().getGroupId()); return; } int expectedElanFootprint = 0; final ElanInstance elanInstance = getElanInstanceFromGroupId(update); if (elanInstance == null) { - LOG.trace("no elan instance is null {}", update.getKey().getGroupId()); + LOG.trace("no elan instance is null {}", update.key().getGroupId()); return; } - ConcurrentMap devices = - ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanInstance.getElanInstanceName()); - if (devices == null || devices.isEmpty()) { + final int devicesSize = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanInstance.getElanInstanceName()).size(); + if (devicesSize == 0) { LOG.trace("no elan devices in elan cache {} {}", elanInstance.getElanInstanceName(), - update.getKey().getGroupId()); + update.key().getGroupId()); return; } boolean updateGroup = false; @@ -123,45 +136,42 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase< } else { updateGroup = true; } - expectedElanFootprint += devices.size(); + expectedElanFootprint += devicesSize; if (update.getBuckets() != null && update.getBuckets().getBucket() != null) { if (update.getBuckets().getBucket().size() != expectedElanFootprint) { updateGroup = true; } else { LOG.trace("no of buckets matched perfectly {} {}", elanInstance.getElanInstanceName(), - update.getKey().getGroupId()); + update.key().getGroupId()); } } if (updateGroup) { List bucketList = elanL2GatewayMulticastUtils.getRemoteBCGroupBuckets(elanInstance, null, dpnId, 0, - elanInstance.getElanTag()); + elanInstance.getElanTag().toJava()); expectedElanFootprint--;//remove local bcgroup bucket if (bucketList.size() != expectedElanFootprint) { //no point in retrying if not able to meet expected foot print return; } LOG.trace("no of buckets mismatched {} {}", elanInstance.getElanInstanceName(), - update.getKey().getGroupId()); + update.key().getGroupId()); elanClusterUtils.runOnlyInOwnerNode(elanInstance.getElanInstanceName(), "updating broadcast group", () -> { - elanL2GatewayMulticastUtils.setupElanBroadcastGroups(elanInstance, dpnId); + LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, + confTx -> elanL2GatewayMulticastUtils.setupElanBroadcastGroups(elanInstance, dpnId, confTx)), + LOG, "Error setting up ELAN BGs"); return null; }); } else { LOG.trace("no buckets in the update {} {}", elanInstance.getElanInstanceName(), - update.getKey().getGroupId()); + update.key().getGroupId()); } } @Override - protected void add(InstanceIdentifier identifier, Group added) { - LOG.trace("received group add {}", added.getKey().getGroupId()); + public void add(InstanceIdentifier identifier, Group added) { + LOG.trace("received group add {}", added.key().getGroupId()); update(identifier, null/*original*/, added); } - - @Override - protected ElanGroupListener getDataTreeChangeListener() { - return this; - } }