dhcpservice: clean up Futures collections 71/63371/2
authorStephen Kitt <skitt@redhat.com>
Mon, 11 Sep 2017 14:06:46 +0000 (16:06 +0200)
committerSam Hague <shague@redhat.com>
Wed, 20 Sep 2017 23:50:52 +0000 (23:50 +0000)
This patch replaces lists of Futures with singleton lists where
possible. It also removes instances of passing such lists around,
using return values instead.

This patch also cleans up the job classes generally: instance fields
are final where possible, unused fields and parameters are removed.

Change-Id: Idd1add34a0ac75aaf7ae0afc137904cebfb7e741
Signed-off-by: Stephen Kitt <skitt@redhat.com>
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpAllocationPoolListener.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpExternalTunnelManager.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpInterfaceConfigListener.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpInterfaceEventListener.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpNeutronPortListener.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/jobs/DhcpAllocationPoolAddJob.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/jobs/DhcpAllocationPoolRemoveJob.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/jobs/DhcpInterfaceAddJob.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/jobs/DhcpInterfaceRemoveJob.java
vpnservice/dhcpservice/dhcpservice-impl/src/main/java/org/opendaylight/netvirt/dhcpservice/jobs/DhcpInterfaceUpdateJob.java

index f93b83e0b6be79f372b44bb62fb0ac601030b805..07bb51764540dc32d9f152a7e1280e6125695e0f 100644 (file)
@@ -52,8 +52,8 @@ public class DhcpAllocationPoolListener
         for (BigInteger dpnId : elanDpnInterfacesByName.keySet()) {
             for (String interfaceName : elanDpnInterfacesByName.get(dpnId)) {
                 LOG.debug("Install Dhcp Entries for dpId: {} interface : {}", dpnId, interfaceName);
-                DhcpAllocationPoolAddJob job = new DhcpAllocationPoolAddJob(dhcpAllocationPoolManager, dataBroker,
-                        interfaceName, dpnId);
+                DhcpAllocationPoolAddJob job = new DhcpAllocationPoolAddJob(dataBroker,
+                        interfaceName);
                 dataStoreJobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), job,
                         DhcpMConstants.RETRY_COUNT);
             }
@@ -78,8 +78,8 @@ public class DhcpAllocationPoolListener
         Map<BigInteger, List<String>> elanDpnInterfacesByName = getDpnInterfacesByNetwork(networkId);
         for (BigInteger dpnId : elanDpnInterfacesByName.keySet()) {
             for (String interfaceName : elanDpnInterfacesByName.get(dpnId)) {
-                DhcpAllocationPoolRemoveJob job = new DhcpAllocationPoolRemoveJob(dhcpAllocationPoolManager, dataBroker,
-                        interfaceName, dpnId);
+                DhcpAllocationPoolRemoveJob job = new DhcpAllocationPoolRemoveJob(dataBroker,
+                        interfaceName);
                 dataStoreJobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), job,
                         DhcpMConstants.RETRY_COUNT);
             }
index ac93d884eb093e564e50a2309fc924d96c4fff04..35b0eb469a260c3b12f8c9aacc80363612ffed95 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
@@ -497,18 +498,17 @@ public class DhcpExternalTunnelManager {
                 vmMacAddress, NwConstants.ADD_FLOW, mdsalUtil, tx);
     }
 
-    public void handleTunnelStateDown(IpAddress tunnelIp, BigInteger interfaceDpn,
-                                      List<ListenableFuture<Void>> futures) {
+    public List<ListenableFuture<Void>> handleTunnelStateDown(IpAddress tunnelIp, BigInteger interfaceDpn) {
         LOG.trace("In handleTunnelStateDown tunnelIp {}, interfaceDpn {}", tunnelIp, interfaceDpn);
         if (interfaceDpn == null) {
-            return;
+            return Collections.emptyList();
         }
         try {
             synchronized (getTunnelIpDpnKey(tunnelIp, interfaceDpn)) {
                 Set<Pair<IpAddress, String>> tunnelElanPairSet =
                         designatedDpnsToTunnelIpElanNameCache.get(interfaceDpn);
                 if (tunnelElanPairSet == null || tunnelElanPairSet.isEmpty()) {
-                    return;
+                    return Collections.emptyList();
                 }
                 WriteTransaction tx = broker.newWriteOnlyTransaction();
                 for (Pair<IpAddress, String> tunnelElanPair : tunnelElanPairSet) {
@@ -518,7 +518,7 @@ public class DhcpExternalTunnelManager {
                             LOG.trace("Couldn't find device for given tunnelIpElanPair {} in L2GwConnCache",
                                     tunnelElanPair);
                             tx.cancel();
-                            return;
+                            return Collections.emptyList();
                         }
                         List<BigInteger> dpns = DhcpServiceUtils.getListOfDpns(broker);
                         dpns.remove(interfaceDpn);
@@ -526,11 +526,12 @@ public class DhcpExternalTunnelManager {
                         updateCacheAndInstallNewFlows(interfaceDpn, dpns, tunnelElanPair, tx);
                     }
                 }
-                futures.add(tx.submit());
+                return Collections.singletonList(tx.submit());
             }
         } catch (ExecutionException e) {
             LOG.error("Error in handleTunnelStateDown {}", e.getMessage());
             LOG.trace("Exception details {}", e);
+            return Collections.emptyList();
         }
     }
 
@@ -762,7 +763,7 @@ public class DhcpExternalTunnelManager {
         return tunnelInterface.getOperStatus() == OperStatus.Up;
     }
 
-    public void handleTunnelStateUp(IpAddress tunnelIp, BigInteger interfaceDpn, List<ListenableFuture<Void>> futures) {
+    public List<ListenableFuture<Void>> handleTunnelStateUp(IpAddress tunnelIp, BigInteger interfaceDpn) {
         LOG.trace("In handleTunnelStateUp tunnelIp {}, interfaceDpn {}", tunnelIp, interfaceDpn);
         synchronized (getTunnelIpDpnKey(tunnelIp, interfaceDpn)) {
             Set<Pair<IpAddress, String>> tunnelIpElanPair =
@@ -770,7 +771,7 @@ public class DhcpExternalTunnelManager {
             List<BigInteger> dpns = DhcpServiceUtils.getListOfDpns(broker);
             if (tunnelIpElanPair == null || tunnelIpElanPair.isEmpty()) {
                 LOG.trace("There are no undesignated DPNs");
-                return;
+                return Collections.emptyList();
             }
             WriteTransaction tx = broker.newWriteOnlyTransaction();
             for (Pair<IpAddress, String> pair : tunnelIpElanPair) {
@@ -786,7 +787,7 @@ public class DhcpExternalTunnelManager {
                     }
                 }
             }
-            futures.add(tx.submit());
+            return Collections.singletonList(tx.submit());
         }
     }
 
index 2e65d6d12a530bc59dcf9ff553ae1cda5c532020..28a28e7d11f9e744bd1a485ce1119baa232dac2b 100644 (file)
@@ -8,10 +8,7 @@
 
 package org.opendaylight.netvirt.dhcpservice;
 
-import com.google.common.util.concurrent.ListenableFuture;
-
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collections;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -62,7 +59,6 @@ public class DhcpInterfaceConfigListener
     @Override
     protected void remove(InstanceIdentifier<Interface> identifier, Interface del) {
         dataStoreJobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(del.getName()), () -> {
-            List<ListenableFuture<Void>> futures = new ArrayList<>();
             IfTunnel tunnelInterface = del.getAugmentation(IfTunnel.class);
             IfL2vlan vlanInterface = del.getAugmentation(IfL2vlan.class);
             String interfaceName = del.getName();
@@ -74,17 +70,16 @@ public class DhcpInterfaceConfigListener
                         LOG.trace("Calling handleTunnelStateDown for tunnelIp {} and interface {}",
                                 tunnelIp, interfaceName);
                     }
-                    dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp,
-                            interfce.getDatapathNodeIdentifier(), futures);
-                    return futures;
+                    return dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp,
+                            interfce.getDatapathNodeIdentifier());
                 }
             }
             if (vlanInterface != null) {
                 WriteTransaction unbindTx = dataBroker.newWriteOnlyTransaction();
                 DhcpServiceUtils.unbindDhcpService(interfaceName, unbindTx);
-                futures.add(unbindTx.submit());
+                return Collections.singletonList(unbindTx.submit());
             }
-            return futures;
+            return Collections.emptyList();
         }, DhcpMConstants.RETRY_COUNT);
     }
 
@@ -96,11 +91,10 @@ public class DhcpInterfaceConfigListener
     @Override
     protected void add(InstanceIdentifier<Interface> identifier, Interface add) {
         dataStoreJobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(add.getName()), () -> {
-            List<ListenableFuture<Void>> futures = new ArrayList<>();
             String interfaceName = add.getName();
             IfL2vlan vlanInterface = add.getAugmentation(IfL2vlan.class);
             if (vlanInterface == null) {
-                return futures;
+                return Collections.emptyList();
             }
             Port port = dhcpManager.getNeutronPort(interfaceName);
             Subnet subnet = dhcpManager.getNeutronSubnet(port);
@@ -110,9 +104,9 @@ public class DhcpInterfaceConfigListener
                     LOG.debug("Binding DHCP service for interface {}", interfaceName);
                 }
                 DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, bindServiceTx);
-                futures.add(bindServiceTx.submit());
+                return Collections.singletonList(bindServiceTx.submit());
             }
-            return futures;
+            return Collections.emptyList();
         }, DhcpMConstants.RETRY_COUNT);
     }
 
index 228bb71d90a1cd59bc88c0741a24833f0ced331e..058f4de9a6415b62743f6d0f8dd79310d24d4266 100644 (file)
@@ -109,7 +109,7 @@ public class DhcpInterfaceEventListener
         NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0));
         BigInteger dpnId = BigInteger.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId));
         String interfaceName = update.getName();
-        DhcpInterfaceUpdateJob job = new DhcpInterfaceUpdateJob(dhcpManager, dhcpExternalTunnelManager, dataBroker,
+        DhcpInterfaceUpdateJob job = new DhcpInterfaceUpdateJob(dhcpExternalTunnelManager, dataBroker,
                 interfaceName, dpnId, update.getOperStatus(), interfaceManager);
         dataStoreJobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), job, DhcpMConstants.RETRY_COUNT);
     }
index c19b09bb9f97f05231d65ca5b22587295bd4bdc7..978cacd55627d348b91bd774d0466e8bf0c22d05 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.netvirt.dhcpservice;
 
-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.function.Consumer;
 
@@ -90,7 +89,6 @@ public class DhcpNeutronPortListener
             DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
             portDataStoreCoordinator.enqueueJob(getJobKey(del), () -> {
                 WriteTransaction wrtConfigTxn = broker.newWriteOnlyTransaction();
-                List<ListenableFuture<Void>> futures = new ArrayList<>();
                 DhcpServiceUtils.removeSubnetDhcpPortData(del, subnetDhcpPortIdfr -> wrtConfigTxn
                         .delete(LogicalDatastoreType.CONFIGURATION, subnetDhcpPortIdfr));
                 processArpResponderForElanDpns(del, arpInput -> {
@@ -98,8 +96,7 @@ public class DhcpNeutronPortListener
                             arpInput.getInterfaceName(), arpInput.getSpa(), arpInput.getSha(), arpInput.getDpId());
                     elanService.removeArpResponderFlow(arpInput);
                 });
-                futures.add(wrtConfigTxn.submit());
-                return futures;
+                return Collections.singletonList(wrtConfigTxn.submit());
             });
         }
         if (isVnicTypeDirectOrMacVtap(del)) {
@@ -149,7 +146,6 @@ public class DhcpNeutronPortListener
             DataStoreJobCoordinator portDataStoreCoordinator = DataStoreJobCoordinator.getInstance();
             portDataStoreCoordinator.enqueueJob(getJobKey(add), () -> {
                 WriteTransaction wrtConfigTxn = broker.newWriteOnlyTransaction();
-                List<ListenableFuture<Void>> futures = new ArrayList<>();
                 DhcpServiceUtils.createSubnetDhcpPortData(add, (subnetDhcpPortIdfr, subnetToDhcpport) -> wrtConfigTxn
                         .put(LogicalDatastoreType.CONFIGURATION, subnetDhcpPortIdfr, subnetToDhcpport));
                 processArpResponderForElanDpns(add, arpInput -> {
@@ -160,8 +156,7 @@ public class DhcpNeutronPortListener
                             arpInput.getInterfaceName(), arpInput.getSpa(), arpInput.getSha()));
                     elanService.addArpResponderFlow(builder.buildForInstallFlow());
                 });
-                futures.add(wrtConfigTxn.submit());
-                return futures;
+                return Collections.singletonList(wrtConfigTxn.submit());
             });
         }
         if (!isVnicTypeDirectOrMacVtap(add)) {
index 61362563c27924e2d8cf65c72e08de80c6805f86..97f7e4aba7ad1827c963bcb659defc84e0ea00f4 100644 (file)
@@ -7,62 +7,34 @@
  */
 package org.opendaylight.netvirt.dhcpservice.jobs;
 
-import com.google.common.util.concurrent.FutureCallback;
 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.concurrent.Callable;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.genius.mdsalutil.NwConstants;
-import org.opendaylight.netvirt.dhcpservice.DhcpAllocationPoolManager;
 import org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class DhcpAllocationPoolAddJob implements Callable<List<ListenableFuture<Void>>> {
 
-    private static final Logger LOG = LoggerFactory.getLogger(DhcpAllocationPoolAddJob.class);
-    private final DhcpAllocationPoolManager dhcpAllocationPoolManager;
-    DataBroker dataBroker;
-    String interfaceName;
-    BigInteger dpnId;
-
-    private static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
-        @Override
-        public void onSuccess(Void result) {
-            LOG.debug("Success in Datastore write operation");
-        }
-
-        @Override
-        public void onFailure(Throwable error) {
-            LOG.error("Error in Datastore write operation", error);
-        }
-    };
+    private final DataBroker dataBroker;
+    private final String interfaceName;
 
-    public DhcpAllocationPoolAddJob(DhcpAllocationPoolManager dhcpAllocationPoolManager,
-            DataBroker dataBroker, String interfaceName, BigInteger dpnId) {
-        super();
-        this.dhcpAllocationPoolManager = dhcpAllocationPoolManager;
+    public DhcpAllocationPoolAddJob(DataBroker dataBroker, String interfaceName) {
         this.dataBroker = dataBroker;
         this.interfaceName = interfaceName;
-        this.dpnId = dpnId;
     }
 
     @Override
-    public List<ListenableFuture<Void>> call() throws Exception {
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
-        installDhcpEntries(interfaceName, dpnId, futures);
-        return futures;
+    public List<ListenableFuture<Void>> call() {
+        return installDhcpEntries(interfaceName);
     }
 
-    private void installDhcpEntries(String interfaceName, BigInteger dpId, List<ListenableFuture<Void>> futures) {
+    private List<ListenableFuture<Void>> installDhcpEntries(String interfaceName) {
         WriteTransaction bindServiceTx = dataBroker.newWriteOnlyTransaction();
         DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, bindServiceTx);
-        futures.add(bindServiceTx.submit());
+        return Collections.singletonList(bindServiceTx.submit());
     }
 
 }
\ No newline at end of file
index 262aae4db26f242ecc1c0905cb843a39d2406b8d..3e9e784f8f3812406df9a170ddb6dbee93ab1c2c 100644 (file)
@@ -7,61 +7,34 @@
  */
 package org.opendaylight.netvirt.dhcpservice.jobs;
 
-import com.google.common.util.concurrent.FutureCallback;
 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.concurrent.Callable;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.netvirt.dhcpservice.DhcpAllocationPoolManager;
 import org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class DhcpAllocationPoolRemoveJob implements Callable<List<ListenableFuture<Void>>> {
 
-    private static final Logger LOG = LoggerFactory.getLogger(DhcpAllocationPoolRemoveJob.class);
-    private final DhcpAllocationPoolManager dhcpAllocationPoolManager;
-    DataBroker dataBroker;
-    String interfaceName;
-    BigInteger dpnId;
-
-    private static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
-        @Override
-        public void onSuccess(Void result) {
-            LOG.debug("Success in Datastore write operation");
-        }
-
-        @Override
-        public void onFailure(Throwable error) {
-            LOG.error("Error in Datastore write operation", error);
-        }
-    };
+    private final DataBroker dataBroker;
+    private final String interfaceName;
 
-    public DhcpAllocationPoolRemoveJob(DhcpAllocationPoolManager dhcpAllocationPoolManager,
-            DataBroker dataBroker, String interfaceName, BigInteger dpnId) {
+    public DhcpAllocationPoolRemoveJob(DataBroker dataBroker, String interfaceName) {
         super();
-        this.dhcpAllocationPoolManager = dhcpAllocationPoolManager;
         this.dataBroker = dataBroker;
         this.interfaceName = interfaceName;
-        this.dpnId = dpnId;
     }
 
     @Override
     public List<ListenableFuture<Void>> call() throws Exception {
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
-        unInstallDhcpEntries(interfaceName, dpnId, futures);
-        return futures;
+        return unInstallDhcpEntries(interfaceName);
     }
 
-    private void unInstallDhcpEntries(String interfaceName, BigInteger dpId, List<ListenableFuture<Void>> futures) {
+    private List<ListenableFuture<Void>> unInstallDhcpEntries(String interfaceName) {
         WriteTransaction unbindServiceTx = dataBroker.newWriteOnlyTransaction();
         DhcpServiceUtils.unbindDhcpService(interfaceName, unbindServiceTx);
-        futures.add(unbindServiceTx.submit());
+        return Collections.singletonList(unbindServiceTx.submit());
     }
 
 }
index 49f6578e4bc9b030df3ff2d996330c412b115de5..d231775ca26871f44b02b6182ffc9fd7ab47ff7d 100644 (file)
@@ -47,12 +47,12 @@ import org.slf4j.LoggerFactory;
 public class DhcpInterfaceAddJob implements Callable<List<ListenableFuture<Void>>> {
 
     private static final Logger LOG = LoggerFactory.getLogger(DhcpInterfaceAddJob.class);
-    DhcpManager dhcpManager;
-    DhcpExternalTunnelManager dhcpExternalTunnelManager;
-    DataBroker dataBroker;
+    private final DhcpManager dhcpManager;
+    private final DhcpExternalTunnelManager dhcpExternalTunnelManager;
+    private final DataBroker dataBroker;
     private final Interface interfaceAdd;
-    BigInteger dpnId;
-    IInterfaceManager interfaceManager;
+    private final BigInteger dpnId;
+    private final IInterfaceManager interfaceManager;
     private final IElanService elanService;
     private static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
         @Override
@@ -81,7 +81,6 @@ public class DhcpInterfaceAddJob implements Callable<List<ListenableFuture<Void>
 
     @Override
     public List<ListenableFuture<Void>> call() throws Exception {
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
         String interfaceName = interfaceAdd.getName();
         LOG.trace("Received add DCN for interface {}, dpid {}", interfaceName, dpnId);
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
@@ -92,9 +91,9 @@ public class DhcpInterfaceAddJob implements Callable<List<ListenableFuture<Void>
                 IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
                 List<BigInteger> dpns = DhcpServiceUtils.getListOfDpns(dataBroker);
                 if (dpns.contains(dpnId)) {
-                    dhcpExternalTunnelManager.handleTunnelStateUp(tunnelIp, dpnId, futures);
+                    return dhcpExternalTunnelManager.handleTunnelStateUp(tunnelIp, dpnId);
                 }
-                return futures;
+                return Collections.emptyList();
             }
         }
         if (!dpnId.equals(DhcpMConstants.INVALID_DPID)) {
@@ -104,8 +103,9 @@ public class DhcpInterfaceAddJob implements Callable<List<ListenableFuture<Void>
                 LOG.debug("DHCP is not enabled for port {}", port.getName());
                 return Collections.emptyList();
             }
+            List<ListenableFuture<Void>> futures = new ArrayList<>();
             LOG.info("DhcpInterfaceEventListener add isEnableDhcp:{}", subnet.isEnableDhcp());
-            installDhcpEntries(interfaceAdd.getName(), dpnId, futures);
+            futures.addAll(installDhcpEntries(interfaceAdd.getName(), dpnId));
             LOG.trace("Checking ElanDpnInterface {} for dpn {} ", interfaceName, dpnId);
             String subnetId = subnet.getUuid().getValue();
             java.util.Optional<SubnetToDhcpPort> subnetToDhcp = DhcpServiceUtils
@@ -121,15 +121,16 @@ public class DhcpInterfaceAddJob implements Callable<List<ListenableFuture<Void>
             builder.setInstructions(ArpResponderUtil.getInterfaceInstructions(interfaceManager, interfaceName,
                     subnetToDhcp.get().getPortFixedip(), subnetToDhcp.get().getPortMacaddress()));
             elanService.addArpResponderFlow(builder.buildForInstallFlow());
+            return futures;
         }
-        return futures;
+        return Collections.emptyList();
     }
 
-    private void installDhcpEntries(String interfaceName, BigInteger dpId, List<ListenableFuture<Void>> futures) {
+    private List<ListenableFuture<Void>> installDhcpEntries(String interfaceName, BigInteger dpId) {
         String vmMacAddress = getAndUpdateVmMacAddress(interfaceName);
         WriteTransaction flowTx = dataBroker.newWriteOnlyTransaction();
         dhcpManager.installDhcpEntries(dpId, vmMacAddress, flowTx);
-        futures.add(flowTx.submit());
+        return Collections.singletonList(flowTx.submit());
     }
 
     private String getAndUpdateVmMacAddress(String interfaceName) {
index 10e7545507842b39642cba9414294ed5c7a8908d..a7da1c24a6e2f28291fbeb4b2612b7e4db517fe3 100644 (file)
@@ -11,7 +11,7 @@ import com.google.common.base.Optional;
 import com.google.common.util.concurrent.FutureCallback;
 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.concurrent.Callable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -40,12 +40,12 @@ import org.slf4j.LoggerFactory;
 public class DhcpInterfaceRemoveJob implements Callable<List<ListenableFuture<Void>>> {
 
     private static final Logger LOG = LoggerFactory.getLogger(DhcpInterfaceRemoveJob.class);
-    DhcpManager dhcpManager;
-    DhcpExternalTunnelManager dhcpExternalTunnelManager;
-    DataBroker dataBroker;
-    Interface interfaceDel;
-    BigInteger dpnId;
-    IInterfaceManager interfaceManager;
+    private final DhcpManager dhcpManager;
+    private final DhcpExternalTunnelManager dhcpExternalTunnelManager;
+    private final DataBroker dataBroker;
+    private final Interface interfaceDel;
+    private final BigInteger dpnId;
+    private final IInterfaceManager interfaceManager;
     private final IElanService elanService;
     private static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
         @Override
@@ -75,7 +75,6 @@ public class DhcpInterfaceRemoveJob implements Callable<List<ListenableFuture<Vo
 
     @Override
     public List<ListenableFuture<Void>> call() throws Exception {
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
         String interfaceName = interfaceDel.getName();
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
                 interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
@@ -85,9 +84,9 @@ public class DhcpInterfaceRemoveJob implements Callable<List<ListenableFuture<Vo
                 IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
                 List<BigInteger> dpns = DhcpServiceUtils.getListOfDpns(dataBroker);
                 if (dpns.contains(dpnId)) {
-                    dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp, dpnId, futures);
+                    return dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp, dpnId);
                 }
-                return futures;
+                return Collections.emptyList();
             }
         }
         Port port = dhcpManager.getNeutronPort(interfaceName);
@@ -103,15 +102,14 @@ public class DhcpInterfaceRemoveJob implements Callable<List<ListenableFuture<Vo
                 elanService.removeArpResponderFlow(arpInput);
             }
         }
-        unInstallDhcpEntries(interfaceDel.getName(), dpnId, futures);
-        return futures;
+        return unInstallDhcpEntries(interfaceDel.getName(), dpnId);
     }
 
-    private void unInstallDhcpEntries(String interfaceName, BigInteger dpId, List<ListenableFuture<Void>> futures) {
+    private List<ListenableFuture<Void>> unInstallDhcpEntries(String interfaceName, BigInteger dpId) {
         String vmMacAddress = getAndRemoveVmMacAddress(interfaceName);
         WriteTransaction flowTx = dataBroker.newWriteOnlyTransaction();
         dhcpManager.unInstallDhcpEntries(dpId, vmMacAddress, flowTx);
-        futures.add(flowTx.submit());
+        return Collections.singletonList(flowTx.submit());
     }
 
     private String getAndRemoveVmMacAddress(String interfaceName) {
index f96e4ba413c39a73322ee6c1cb0db697fedf2652..8962c09addb1d54105025260b5c38538b028544f 100644 (file)
@@ -9,13 +9,12 @@ package org.opendaylight.netvirt.dhcpservice.jobs;
 
 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.concurrent.Callable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager;
-import org.opendaylight.netvirt.dhcpservice.DhcpManager;
 import org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -27,19 +26,17 @@ import org.slf4j.LoggerFactory;
 public class DhcpInterfaceUpdateJob implements Callable<List<ListenableFuture<Void>>> {
 
     private static final Logger LOG = LoggerFactory.getLogger(DhcpInterfaceUpdateJob.class);
-    DhcpManager dhcpManager;
-    DhcpExternalTunnelManager dhcpExternalTunnelManager;
-    DataBroker dataBroker;
-    String interfaceName;
-    BigInteger dpnId;
-    OperStatus operStatus;
-    IInterfaceManager interfaceManager;
+    private final DhcpExternalTunnelManager dhcpExternalTunnelManager;
+    private final DataBroker dataBroker;
+    private final String interfaceName;
+    private final BigInteger dpnId;
+    private final OperStatus operStatus;
+    private final IInterfaceManager interfaceManager;
 
-    public DhcpInterfaceUpdateJob(DhcpManager dhcpManager, DhcpExternalTunnelManager dhcpExternalTunnelManager,
+    public DhcpInterfaceUpdateJob(DhcpExternalTunnelManager dhcpExternalTunnelManager,
                                   DataBroker dataBroker, String interfaceName, BigInteger dpnId,
                                   OperStatus operStatus, IInterfaceManager interfaceManager) {
         super();
-        this.dhcpManager = dhcpManager;
         this.dhcpExternalTunnelManager = dhcpExternalTunnelManager;
         this.dataBroker = dataBroker;
         this.interfaceName = interfaceName;
@@ -50,12 +47,11 @@ public class DhcpInterfaceUpdateJob implements Callable<List<ListenableFuture<Vo
 
     @Override
     public List<ListenableFuture<Void>> call() throws Exception {
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
                 interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
         if (iface == null) {
             LOG.trace("Interface {} is not present in the config DS", interfaceName);
-            return futures;
+            return Collections.emptyList();
         }
         if (Tunnel.class.equals(iface.getType())) {
             IfTunnel tunnelInterface = iface.getAugmentation(IfTunnel.class);
@@ -64,13 +60,13 @@ public class DhcpInterfaceUpdateJob implements Callable<List<ListenableFuture<Vo
                 List<BigInteger> dpns = DhcpServiceUtils.getListOfDpns(dataBroker);
                 if (dpns.contains(dpnId)) {
                     if (operStatus == OperStatus.Down) {
-                        dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp, dpnId, futures);
+                        return dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp, dpnId);
                     } else if (operStatus == OperStatus.Up) {
-                        dhcpExternalTunnelManager.handleTunnelStateUp(tunnelIp, dpnId, futures);
+                        return dhcpExternalTunnelManager.handleTunnelStateUp(tunnelIp, dpnId);
                     }
                 }
             }
         }
-        return futures;
+        return Collections.emptyList();
     }
 }
\ No newline at end of file