Remove GENIUS UTIL references in Elanmanager Module
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / internal / ElanLearntVpnVipToPortListener.java
index 33022de7a1b85552a11dbe0c92d033517b38be3a..df8ba7ed34d07e9e5b0b8e4b90fc53bb753f6a15 100644 (file)
@@ -5,32 +5,40 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
+/*
 package org.opendaylight.netvirt.elan.internal;
 
-import com.google.common.base.Optional;
+import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
+import static org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL;
+
 import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.Callable;
-import javax.annotation.PostConstruct;
+import java.util.concurrent.ExecutionException;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-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.data.LogicalDatastoreType;
-import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.mdsal.binding.util.Datastore.Configuration;
+import org.opendaylight.mdsal.binding.util.Datastore.Operational;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
+import org.opendaylight.mdsal.binding.util.TypedWriteTransaction;
 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
-import org.opendaylight.netvirt.elan.ElanException;
+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.ElanInterfaceCache;
 import org.opendaylight.netvirt.elan.utils.ElanConstants;
 import org.opendaylight.netvirt.elan.utils.ElanUtils;
+import org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
@@ -45,7 +53,7 @@ import org.slf4j.LoggerFactory;
 
 @Singleton
 public class ElanLearntVpnVipToPortListener extends
-        AsyncDataTreeChangeListenerBase<LearntVpnVipToPort, ElanLearntVpnVipToPortListener> {
+        AbstractAsyncDataTreeChangeListener<LearntVpnVipToPort> {
     private static final Logger LOG = LoggerFactory.getLogger(ElanLearntVpnVipToPortListener.class);
     private final DataBroker broker;
     private final ManagedNewTransactionRunner txRunner;
@@ -58,7 +66,9 @@ public class ElanLearntVpnVipToPortListener extends
     @Inject
     public ElanLearntVpnVipToPortListener(DataBroker broker, IInterfaceManager interfaceManager, ElanUtils elanUtils,
             JobCoordinator jobCoordinator, ElanInstanceCache elanInstanceCache, ElanInterfaceCache elanInterfaceCache) {
-        super(LearntVpnVipToPort.class, ElanLearntVpnVipToPortListener.class);
+        super(broker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(LearntVpnVipToPortData.class)
+                .child(LearntVpnVipToPort.class),
+                Executors.newListeningSingleThreadExecutor("ElanLearntVpnVipToPortListener", LOG));
         this.broker = broker;
         this.txRunner = new ManagedNewTransactionRunnerImpl(broker);
         this.interfaceManager = interfaceManager;
@@ -68,19 +78,16 @@ public class ElanLearntVpnVipToPortListener extends
         this.elanInterfaceCache = elanInterfaceCache;
     }
 
-    @Override
-    @PostConstruct
     public void init() {
-        registerListener(LogicalDatastoreType.OPERATIONAL, broker);
-    }
+        LOG.info("{} registered", getClass().getSimpleName());
+
+       // ELAN will learn the MAC by itself using ElanPacketInHandler class.
+        //registerListener(LogicalDatastoreType.OPERATIONAL, broker);
 
-    @Override
-    protected InstanceIdentifier<LearntVpnVipToPort> getWildCardPath() {
-        return InstanceIdentifier.create(LearntVpnVipToPortData.class).child(LearntVpnVipToPort.class);
     }
 
     @Override
-    protected void remove(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModification) {
+    public void remove(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModification) {
         String macAddress = dataObjectModification.getMacAddress();
         String interfaceName = dataObjectModification.getPortName();
         LOG.trace("Removing mac address {} from interface {} ", macAddress, interfaceName);
@@ -89,12 +96,12 @@ public class ElanLearntVpnVipToPortListener extends
     }
 
     @Override
-    protected void update(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModificationBefore,
+    public void update(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModificationBefore,
             LearntVpnVipToPort dataObjectModificationAfter) {
     }
 
     @Override
-    protected void add(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModification) {
+    public void add(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort dataObjectModification) {
         String macAddress = dataObjectModification.getMacAddress();
         String interfaceName = dataObjectModification.getPortName();
         LOG.trace("Adding mac address {} to interface {} ", macAddress, interfaceName);
@@ -102,12 +109,7 @@ public class ElanLearntVpnVipToPortListener extends
                 new StaticMacAddWorker(macAddress, interfaceName));
     }
 
-    @Override
-    protected ElanLearntVpnVipToPortListener getDataTreeChangeListener() {
-        return this;
-    }
-
-    private class StaticMacAddWorker implements Callable<List<ListenableFuture<Void>>> {
+    private class StaticMacAddWorker implements Callable<List<? extends ListenableFuture<?>>> {
         String macAddress;
         String interfaceName;
 
@@ -117,42 +119,42 @@ public class ElanLearntVpnVipToPortListener extends
         }
 
         @Override
-        public List<ListenableFuture<Void>> call() throws Exception {
+        public List<ListenableFuture<Void>> call() {
             Optional<ElanInterface> elanInterface = elanInterfaceCache.get(interfaceName);
             if (!elanInterface.isPresent()) {
                 LOG.debug("ElanInterface Not present for interfaceName {} for add event", interfaceName);
                 return Collections.emptyList();
             }
             List<ListenableFuture<Void>> futures = new ArrayList<>();
-            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(interfaceTx -> futures.add(
-                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(
-                        flowTx -> addMacEntryToDsAndSetupFlows(elanInterface.get().getElanInstanceName(),
-                                interfaceTx, flowTx, ElanConstants.STATIC_MAC_TIMEOUT)))));
+            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, interfaceTx ->
+                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, flowTx ->
+                    addMacEntryToDsAndSetupFlows(elanInterface.get().getElanInstanceName(), interfaceTx,
+                            flowTx, ElanConstants.STATIC_MAC_TIMEOUT)))));
             return futures;
         }
 
-        private void addMacEntryToDsAndSetupFlows(String elanName, WriteTransaction interfaceTx,
-                WriteTransaction flowTx, int macTimeOut) throws ElanException {
+        private void addMacEntryToDsAndSetupFlows(String elanName, TypedWriteTransaction<Operational> interfaceTx,
+                TypedWriteTransaction<Configuration> flowTx, int macTimeOut) {
             LOG.trace("Adding mac address {} and interface name {} to ElanInterfaceForwardingEntries and "
                 + "ElanForwardingTables DS", macAddress, interfaceName);
             BigInteger timeStamp = new BigInteger(String.valueOf(System.currentTimeMillis()));
             PhysAddress physAddress = new PhysAddress(macAddress);
             MacEntry macEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress)
-                    .setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp)
+                    .withKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp)
                     .setIsStaticAddress(false).build();
             InstanceIdentifier<MacEntry> macEntryId = ElanUtils
                     .getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
-            interfaceTx.put(LogicalDatastoreType.OPERATIONAL, macEntryId, macEntry);
+            interfaceTx.put(macEntryId, macEntry);
             InstanceIdentifier<MacEntry> elanMacEntryId =
                     ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress);
-            interfaceTx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, macEntry);
-            ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
+            interfaceTx.put(elanMacEntryId, macEntry);
+            ElanInstance elanInstance = elanInstanceCache.get(elanName).orElse(null);
             elanUtils.setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut,
                     macAddress, true, flowTx);
         }
     }
 
-    private class StaticMacRemoveWorker implements Callable<List<ListenableFuture<Void>>> {
+    private class StaticMacRemoveWorker implements Callable<List<? extends ListenableFuture<?>>> {
         String macAddress;
         String interfaceName;
 
@@ -169,33 +171,35 @@ public class ElanLearntVpnVipToPortListener extends
                 return Collections.emptyList();
             }
             List<ListenableFuture<Void>> futures = new ArrayList<>();
-            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(interfaceTx -> futures.add(
-                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(
-                        flowTx -> deleteMacEntryFromDsAndRemoveFlows(elanInterface.get().getElanInstanceName(),
-                                interfaceTx, flowTx)))));
+            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, interfaceTx ->
+                futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, flowTx ->
+                    deleteMacEntryFromDsAndRemoveFlows(elanInterface.get().getElanInstanceName(),
+                            interfaceTx, flowTx)))));
             return futures;
         }
 
-        private void deleteMacEntryFromDsAndRemoveFlows(String elanName, WriteTransaction interfaceTx,
-                WriteTransaction flowTx) {
+        private void deleteMacEntryFromDsAndRemoveFlows(String elanName,
+                TypedWriteTransaction<Operational> interfaceTx, TypedReadWriteTransaction<Configuration> flowTx)
+                throws ExecutionException, InterruptedException {
             LOG.trace("Deleting mac address {} and interface name {} from ElanInterfaceForwardingEntries "
                     + "and ElanForwardingTables DS", macAddress, interfaceName);
             PhysAddress physAddress = new PhysAddress(macAddress);
             MacEntry macEntry = elanUtils.getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
             InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
             if (macEntry != null && interfaceInfo != null) {
-                elanUtils.deleteMacFlows(elanInstanceCache.get(elanName).orNull(), interfaceInfo, macEntry, flowTx);
-                interfaceTx.delete(LogicalDatastoreType.OPERATIONAL,
+                elanUtils.deleteMacFlows(elanInstanceCache.get(elanName).orElse(null), interfaceInfo, macEntry, flowTx);
+                interfaceTx.delete(
                         ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress));
-                interfaceTx.delete(LogicalDatastoreType.OPERATIONAL,
+                interfaceTx.delete(
                         ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress));
             }
         }
     }
 
-    private String buildJobKey(String mac, String interfaceName) {
+    private static String buildJobKey(String mac, String interfaceName) {
         return "ENTERPRISEMACJOB" + mac + interfaceName;
     }
 
 
 }
+*/