Remove GENIUS UTIL references in Elanmanager Module
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / listeners / ElanGroupListener.java
index 7a98143a704ba8312e3a748802284a1f31f037d8..7cc4f936489118a5eb436c7751dd1221dd509008 100644 (file)
@@ -7,26 +7,26 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.listeners;
 
-import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
 
-import java.math.BigInteger;
 import java.util.List;
-import java.util.concurrent.ConcurrentMap;
+import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.eclipse.jdt.annotation.Nullable;
-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.infra.ManagedNewTransactionRunner;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+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;
@@ -35,11 +35,12 @@ 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<Group, ElanGroupListener> {
+public class ElanGroupListener extends AbstractClusteredAsyncDataTreeChangeListener<Group> {
 
     private static final Logger LOG = LoggerFactory.getLogger(ElanGroupListener.class);
     private final ManagedNewTransactionRunner txRunner;
@@ -51,24 +52,29 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
     @Inject
     public ElanGroupListener(DataBroker db, ElanClusterUtils elanClusterUtils, ElanUtils elanUtils,
             ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, ElanInstanceCache elanInstanceCache) {
-        super(Group.class, ElanGroupListener.class);
+        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, db);
         LOG.trace("ElanGroupListener registered");
     }
 
+    public void init() {
+        LOG.info("{} init", getClass().getSimpleName());
+    }
+
     @Override
-    protected InstanceIdentifier<Group> 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<Group> identifier, Group del) {
+    public void remove(InstanceIdentifier<Group> identifier, Group del) {
         LOG.trace("received group removed {}", del.key().getGroupId());
     }
 
@@ -77,9 +83,9 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
     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;
                 }
             }
@@ -88,19 +94,19 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
     }
 
     @Nullable
-    private BigInteger getDpnId(String node) {
+    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<Group> identifier, @Nullable Group original, Group update) {
+    public void update(InstanceIdentifier<Group> identifier, @Nullable Group original, Group update) {
         LOG.trace("received group updated {}", update.key().getGroupId());
-        final BigInteger dpnId = getDpnId(identifier.firstKeyOf(Node.class).getId().getValue());
+        final Uint64 dpnId = getDpnId(identifier.firstKeyOf(Node.class).getId().getValue());
         if (dpnId == null) {
             return;
         }
@@ -117,9 +123,8 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
             return;
         }
 
-        ConcurrentMap<String, L2GatewayDevice> 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.key().getGroupId());
             return;
@@ -131,7 +136,7 @@ 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;
@@ -142,7 +147,7 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
         }
         if (updateGroup) {
             List<Bucket> 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
@@ -151,7 +156,7 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
             LOG.trace("no of buckets mismatched {} {}", elanInstance.getElanInstanceName(),
                     update.key().getGroupId());
             elanClusterUtils.runOnlyInOwnerNode(elanInstance.getElanInstanceName(), "updating broadcast group", () -> {
-                ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                LoggingFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                     confTx -> elanL2GatewayMulticastUtils.setupElanBroadcastGroups(elanInstance, dpnId, confTx)),
                     LOG, "Error setting up ELAN BGs");
                 return null;
@@ -163,15 +168,10 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
     }
 
     @Override
-    protected void add(InstanceIdentifier<Group> identifier, Group added) {
+    public void add(InstanceIdentifier<Group> identifier, Group added) {
         LOG.trace("received group add {}", added.key().getGroupId());
         update(identifier, null/*original*/, added);
     }
-
-    @Override
-    protected ElanGroupListener getDataTreeChangeListener() {
-        return this;
-    }
 }