elanmanager: drop nullToEmpty and reqNonNullOrElse 16/79916/4
authorStephen Kitt <skitt@redhat.com>
Fri, 25 Jan 2019 08:53:22 +0000 (09:53 +0100)
committerSam Hague <shague@redhat.com>
Mon, 28 Jan 2019 15:21:28 +0000 (15:21 +0000)
Change-Id: Ibef665d4f6701219282a4b30533b03a72b376d05
Signed-off-by: Stephen Kitt <skitt@redhat.com>
17 files changed:
elanmanager/api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwValidateCli.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/NetworkL2gwDeviceInfoCli.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/utils/EvpnUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfaceClusteredListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfacesListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanServiceProvider.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/LocalMcastCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/RemoteMcastCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepTerminationPointListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayMulticastUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/TransportZoneNotificationUtil.java

index 79ad578a54c1729e669ee9b00c0c43fbfafaa325..953774572f57f473dffc97499be5291aff5b8338 100644 (file)
@@ -9,9 +9,11 @@
 package org.opendaylight.netvirt.elanmanager.utils;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.genius.utils.cache.CacheUtil;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
@@ -85,13 +87,13 @@ public final class ElanL2GwCacheUtils {
         return result;
     }
 
-    @Nullable
+    @Nonnull
     public static List<L2GatewayDevice> getAllElanDevicesFromCache() {
         ConcurrentMap<String, ConcurrentMap<String, L2GatewayDevice>> cachedMap =
                 (ConcurrentMap<String, ConcurrentMap<String, L2GatewayDevice>>) CacheUtil.getCache(
                         ElanL2GwCacheUtils.L2GATEWAY_CONN_CACHE_NAME);
         if (cachedMap == null || cachedMap.isEmpty()) {
-            return null;
+            return Collections.emptyList();
         }
 
         List<L2GatewayDevice> l2GwDevices = new ArrayList<>();
index 00c9598aa2305eb01586af5da6306fe2e7aa730d..189a4b7ae938d295eea4f104cfde368ec2cd61e7 100644 (file)
@@ -8,9 +8,6 @@
 
 package org.opendaylight.netvirt.elan.cli.l2gw;
 
-import static java.util.Collections.emptyList;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
-
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.collect.Sets;
@@ -137,15 +134,13 @@ public class L2GwValidateCli extends OsgiCommandSupport {
             Optional<Topology> configTopoOptional = tx.read(LogicalDatastoreType.CONFIGURATION, topoId).checkedGet();
 
             if (operationalTopoOptional.isPresent()) {
-                for (Node node : requireNonNullElse(operationalTopoOptional.get().getNode(),
-                        Collections.<Node>emptyList())) {
+                for (Node node : operationalTopoOptional.get().nonnullNode()) {
                     InstanceIdentifier<Node> nodeIid = topoId.child(Node.class, node.key());
                     operationalNodes.put(nodeIid, node);
                 }
             }
             if (configTopoOptional.isPresent()) {
-                for (Node node : requireNonNullElse(configTopoOptional.get().getNode(),
-                        Collections.<Node>emptyList())) {
+                for (Node node : configTopoOptional.get().nonnullNode()) {
                     InstanceIdentifier<Node> nodeIid = topoId.child(Node.class, node.key());
                     configNodes.put(nodeIid, node);
                 }
@@ -393,7 +388,7 @@ public class L2GwValidateCli extends OsgiCommandSupport {
 
             L2gateway l2gateway = uuidToL2Gateway.get(l2gatewayConnection.getL2gatewayId());
             String logicalSwitchName = l2gatewayConnection.getNetworkId().getValue();
-            List<Devices> devices = requireNonNullElse(l2gateway.getDevices(), emptyList());
+            List<Devices> devices = l2gateway.nonnullDevices();
 
             for (Devices device : devices) {
 
@@ -557,8 +552,8 @@ public class L2GwValidateCli extends OsgiCommandSupport {
             }
             VlanBindings expectedBindings = !expectedVlans.isEmpty() ? expectedVlans.get(0) : null;
             boolean foundBindings = false;
-            List<VlanBindings> vlanBindingses = requireNonNullElse(configTerminationPoint.augmentation(
-                    HwvtepPhysicalPortAugmentation.class).getVlanBindings(), emptyList());
+            List<VlanBindings> vlanBindingses = configTerminationPoint.augmentation(
+                    HwvtepPhysicalPortAugmentation.class).nonnullVlanBindings();
             for (VlanBindings actual : vlanBindingses) {
                 if (actual.equals(expectedBindings)) {
                     foundBindings = true;
index 95f0c3801da76be8913706f7378c16c3b5012184..23f898936075a203be4db6f739cae37be13c1bf2 100644 (file)
@@ -8,12 +8,8 @@
 
 package org.opendaylight.netvirt.elan.cli.l2gw;
 
-import static java.util.Collections.emptyList;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
-
 import com.google.common.base.Optional;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -103,7 +99,7 @@ public class NetworkL2gwDeviceInfoCli extends OsgiCommandSupport {
             Optional<Topology> topologyOptional = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
                     createHwvtepTopologyInstanceIdentifier());
             if (topologyOptional.isPresent()) {
-                nodes = requireNonNullElse(topologyOptional.get().getNode(), emptyList());
+                nodes.addAll(topologyOptional.get().nonnullNode());
             }
         } else {
             Optional<Node> nodeOptional = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
@@ -257,8 +253,7 @@ public class NetworkL2gwDeviceInfoCli extends OsgiCommandSupport {
             if (elanName.equals(lsFromLocalMac)) {
                 String mac = localMac.getMacEntryKey().getValue();
                 List<String> locatorsets = new ArrayList<>();
-                for (LocatorSet locatorSet : requireNonNullElse(localMac.getLocatorSet(),
-                        Collections.<LocatorSet>emptyList())) {
+                for (LocatorSet locatorSet : localMac.nonnullLocatorSet()) {
                     locatorsets.add(getLocatorValue(locatorSet.getLocatorRef()));
                 }
                 session.getConsole().println(mac + GAP + locatorsets.toString());
@@ -285,8 +280,7 @@ public class NetworkL2gwDeviceInfoCli extends OsgiCommandSupport {
             if (elanName.equals(lsFromremoteMac)) {
                 String mac = remoteMac.getMacEntryKey().getValue();
                 List<String> locatorsets = new ArrayList<>();
-                for (LocatorSet locatorSet : requireNonNullElse(remoteMac.getLocatorSet(),
-                        Collections.<LocatorSet>emptyList())) {
+                for (LocatorSet locatorSet : remoteMac.nonnullLocatorSet()) {
                     locatorsets.add(getLocatorValue(locatorSet.getLocatorRef()));
                 }
                 session.getConsole().println(mac + GAP + locatorsets.toString());
index 1c0f2ca23a057391d6d9a97f4f10663113636b78..5f5652ae28c226e1c125872c7c3812c3f6c359e3 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.evpn.utils;
 
-import static java.util.Collections.emptyList;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.Futures;
@@ -353,18 +351,16 @@ public class EvpnUtils {
             LOG.info("No DC gateways configured while programming the l2vni table.");
             return tunnelInterfaceNameList;
         }
-        List<DcGatewayIp> dcGatewayIps = dcGatewayIpListOptional.get().getDcGatewayIp();
+        List<DcGatewayIp> dcGatewayIps = dcGatewayIpListOptional.get().nonnullDcGatewayIp();
 
         Optional<ExternalTunnelList> externalTunnelListOptional = getExternalTunnelList();
         if (!externalTunnelListOptional.isPresent()) {
             LOG.info("No External Tunnel Configured while programming the l2vni table.");
             return tunnelInterfaceNameList;
         }
-        List<ExternalTunnel> externalTunnels =
-            requireNonNullElse(externalTunnelListOptional.get().getExternalTunnel(), emptyList());
+        List<ExternalTunnel> externalTunnels = externalTunnelListOptional.get().nonnullExternalTunnel();
 
-        requireNonNullElse(dcGatewayIps, Collections.<DcGatewayIp>emptyList())
-                .forEach(dcIp -> externalTunnels
+        dcGatewayIps.forEach(dcIp -> externalTunnels
                 .stream()
                 .filter(externalTunnel -> externalTunnel.getDestinationDevice()
                         .contains(dcIp.getIpAddress().getIpv4Address().toString()))
index 6b69e7193d544816d6295594aab369a709e8ace7..ed4410192646c6f934d03e56f9d7ad70cb7db460 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netvirt.elan.internal;
 
 import static java.util.Collections.emptyList;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import java.util.List;
 import javax.annotation.PostConstruct;
@@ -123,9 +122,9 @@ public class ElanDpnInterfaceClusteredListener
     @Override
     protected void update(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces original,
                           final DpnInterfaces dpnInterfaces) {
-        List<String> interfaces = requireNonNullElse(dpnInterfaces.getInterfaces(), emptyList());
-        LOG.debug("dpninterfaces update fired new size {}", interfaces.size());
-        if (interfaces.isEmpty()) {
+        List<String> interfaces = dpnInterfaces.getInterfaces();
+        if (interfaces != null && !interfaces.isEmpty()) {
+            LOG.debug("dpninterfaces update fired new size {}", interfaces.size());
             elanInstanceDpnsCache.remove(getElanName(identifier), dpnInterfaces);
             LOG.debug("dpninterfaces last dpn interface on this elan {} ", dpnInterfaces.key());
             // this is the last dpn interface on this elan
index 23650aa7a5785196178e5e11e770346be4a72985..b825ac6ca0a3a7fe631c6b5fff83d98bf9e91f2d 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.netvirt.elan.internal;
 
 import static java.util.Collections.emptyList;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import java.math.BigInteger;
 import java.util.List;
@@ -78,9 +77,10 @@ public class ElanDpnInterfacesListener
         ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
 
         if (elanInstance != null && !elanInstance.isExternal() && ElanUtils.isVlan(elanInstance)) {
-            List<String> interfaces = requireNonNullElse(update.getInterfaces(), emptyList());
+            List<String> interfaces = update.getInterfaces();
             // trigger deletion for vlan provider intf on the DPN for the vlan provider network
-            if (interfaces.size() == 1 && interfaceManager.isExternalInterface(interfaces.get(0))) {
+            if (interfaces != null && interfaces.size() == 1 && interfaceManager.isExternalInterface(
+                    interfaces.get(0))) {
                 LOG.debug("deleting vlan prv intf for elan {}, dpn {}", elanInstanceName, dpnId);
                 jobCoordinator.enqueueJob(dpnId.toString(), () -> {
                     elanService.deleteExternalElanNetwork(elanInstance, dpnId);
index 62255cec3e5cd121808b4a9d4b448cc4c78405f7..27f6aa744295e60de846499e3f7d194e17692353 100644 (file)
@@ -12,7 +12,6 @@ import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CR
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
 import static org.opendaylight.netvirt.elan.utils.ElanUtils.isVxlanNetworkOrVxlanSegment;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -31,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.locks.ReentrantLock;
+import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -268,8 +268,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 return;
             }
             futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, flowTx -> {
-                List<String> elanInterfaces = requireNonNullElse(elanState.getElanInterfaces(), emptyList());
-                if (elanInterfaces.isEmpty()) {
+                @Nullable List<String> elanInterfaces = elanState.getElanInterfaces();
+                if (elanInterfaces == null || elanInterfaces.isEmpty()) {
                     holder.isLastElanInterface = true;
                 }
                 if (interfaceInfo != null) {
@@ -371,8 +371,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         if (elanState == null) {
             return elanState;
         }
-        List<String> elanInterfaces = requireNonNullElse(elanState.getElanInterfaces(), emptyList());
-        boolean isRemoved = elanInterfaces.remove(interfaceName);
+        List<String> elanInterfaces = elanState.getElanInterfaces();
+        boolean isRemoved = elanInterfaces != null && elanInterfaces.remove(interfaceName);
         if (!isRemoved) {
             return elanState;
         }
@@ -493,9 +493,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, confTx -> {
             for (DpnInterfaces dpnInterface : dpnInterfaces) {
                 BigInteger currentDpId = dpnInterface.getDpId();
-                if (!currentDpId.equals(dpId)) {
-                    for (String elanInterface : requireNonNullElse(dpnInterface.getInterfaces(),
-                            Collections.<String>emptyList())) {
+                if (!currentDpId.equals(dpId) && dpnInterface.getInterfaces() != null) {
+                    for (String elanInterface : dpnInterface.getInterfaces()) {
                         ElanInterfaceMac macs = elanUtils.getElanInterfaceMacByInterfaceName(elanInterface);
                         if (macs == null || macs.getMacEntry() == null) {
                             continue;
@@ -729,8 +728,9 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                             holder.dpnInterfaces =
                                 createElanInterfacesList(elanInstanceName, interfaceName, holder.dpId, operTx);
                         } else {
+                            @Nullable List<String> existingInterfaces = existingElanDpnInterfaces.get().getInterfaces();
                             List<String> elanInterfaces =
-                                requireNonNullElse(existingElanDpnInterfaces.get().getInterfaces(), emptyList());
+                                existingInterfaces != null ? new ArrayList<>(existingInterfaces) : new ArrayList<>();
                             elanInterfaces.add(interfaceName);
                             holder.dpnInterfaces = updateElanDpnInterfacesList(elanInstanceName, holder.dpId,
                                 elanInterfaces, operTx);
@@ -744,8 +744,9 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                         elanL2GatewayUtils.installElanL2gwDevicesLocalMacsInDpn(holder.dpId, elanInstance,
                             interfaceName);
                     } else {
+                        @Nullable List<String> existingInterfaces = existingElanDpnInterfaces.get().getInterfaces();
                         List<String> elanInterfaces =
-                            requireNonNullElse(existingElanDpnInterfaces.get().getInterfaces(), emptyList());
+                            existingInterfaces != null ? new ArrayList<>(existingInterfaces) : new ArrayList<>();
                         elanInterfaces.add(interfaceName);
                         if (elanInterfaces.size() == 1) { // 1st dpn interface
                             elanL2GatewayUtils.installElanL2gwDevicesLocalMacsInDpn(holder.dpId, elanInstance,
@@ -896,14 +897,17 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         }
         DpnInterfaces dpnInterfaces = existingElanDpnInterfaces.get();
         int dummyInterfaceCount =  0;
-        List<String> interfaces = requireNonNullElse(dpnInterfaces.getInterfaces(), emptyList());
+        List<String> interfaces = dpnInterfaces.getInterfaces();
+        if (interfaces == null) {
+            return true;
+        }
         if (interfaces.contains(routerPortUuid)) {
             dummyInterfaceCount++;
         }
         if (interfaces.contains(elanInstanceName)) {
             dummyInterfaceCount++;
         }
-        return interfaces.size() - dummyInterfaceCount == 0;
+        return interfaces.size() == dummyInterfaceCount;
     }
 
     private InstanceIdentifier<MacEntry> getMacEntryOperationalDataPath(String elanName, PhysAddress physAddress) {
@@ -1025,7 +1029,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         int bucketId = 0;
         ElanDpnInterfacesList elanDpns = elanUtils.getElanDpnInterfacesList(elanInfo.getElanInstanceName());
         if (elanDpns != null) {
-            List<DpnInterfaces> dpnInterfaces = requireNonNullElse(elanDpns.getDpnInterfaces(), emptyList());
+            List<DpnInterfaces> dpnInterfaces = elanDpns.nonnullDpnInterfaces();
             for (DpnInterfaces dpnInterface : dpnInterfaces) {
                 List<Bucket> remoteListBucketInfo = new ArrayList<>();
                 if (elanUtils.isDpnPresent(dpnInterface.getDpId()) && !Objects.equals(dpnInterface.getDpId(), dpId)
@@ -1582,8 +1586,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         if (dpnInterfaceLists == null) {
             return;
         }
-        List<ElanDpnInterfacesList> elanDpnIf =
-            requireNonNullElse(dpnInterfaceLists.getElanDpnInterfacesList(), emptyList());
+        List<ElanDpnInterfacesList> elanDpnIf = dpnInterfaceLists.nonnullElanDpnInterfacesList();
         for (ElanDpnInterfacesList elanDpns : elanDpnIf) {
             int cnt = 0;
             String elanName = elanDpns.getElanInstanceName();
@@ -1675,8 +1678,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         if (dpnInterfaceLists == null) {
             return;
         }
-        List<ElanDpnInterfacesList> elanDpnIf =
-            requireNonNullElse(dpnInterfaceLists.getElanDpnInterfacesList(), emptyList());
+        List<ElanDpnInterfacesList> elanDpnIf = dpnInterfaceLists.nonnullElanDpnInterfacesList();
         for (ElanDpnInterfacesList elanDpns : elanDpnIf) {
             String elanName = elanDpns.getElanInstanceName();
             ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
index e5420d19bb9ea1ff86552fd17b9717735df45b25..44a4e463d7f0774cf526be5a8c77f2e09425fb2f 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.netvirt.elan.internal;
 
 import static java.util.Collections.emptyList;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -449,8 +448,7 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
         if (!elanInterfacesOptional.isPresent()) {
             return elanInterfaces;
         }
-        List<ElanInterface> elanInterfaceList =
-            requireNonNullElse(elanInterfacesOptional.get().getElanInterface(), emptyList());
+        List<ElanInterface> elanInterfaceList = elanInterfacesOptional.get().nonnullElanInterface();
         for (ElanInterface elanInterface : elanInterfaceList) {
             if (Objects.equals(elanInterface.getElanInstanceName(), elanInstanceName)) {
                 elanInterfaces.add(elanInterface.getName());
index 913dd6bc83f420fb7f0023b165a087fa8d3c24f9..0ffecc6b138ca46defab2ec9e151573f059e3d8c 100644 (file)
@@ -7,10 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
-
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import javax.annotation.Nullable;
@@ -61,7 +58,7 @@ public class LocalMcastCmd
     public LocalMcastMacs transform(InstanceIdentifier<Node> nodePath, LocalMcastMacs src) {
         LocalMcastMacsBuilder ucmlBuilder = new LocalMcastMacsBuilder(src);
         List<LocatorSet> locatorSet = new ArrayList<>();
-        for (LocatorSet locator : requireNonNullElse(src.getLocatorSet(), Collections.<LocatorSet>emptyList())) {
+        for (LocatorSet locator : src.nonnullLocatorSet()) {
             locatorSet.add(new LocatorSetBuilder().setLocatorRef(HwvtepHAUtil.buildLocatorRef(nodePath,
                     HwvtepHAUtil.getTepIpVal(locator.getLocatorRef()))).build());
         }
index 6e2b024804c0c67c3151f64952301a46178549b2..02c16e2aa78c461d9e4c8b37520e32802fa022eb 100644 (file)
@@ -7,10 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
-
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import javax.annotation.Nullable;
@@ -61,7 +58,7 @@ public class RemoteMcastCmd extends
     public RemoteMcastMacs transform(InstanceIdentifier<Node> nodePath, RemoteMcastMacs src) {
         RemoteMcastMacsBuilder ucmlBuilder = new RemoteMcastMacsBuilder(src);
         List<LocatorSet> locatorSet = new ArrayList<>();
-        for (LocatorSet locator : requireNonNullElse(src.getLocatorSet(), Collections.<LocatorSet>emptyList())) {
+        for (LocatorSet locator : src.nonnullLocatorSet()) {
             locatorSet.add(new LocatorSetBuilder().setLocatorRef(HwvtepHAUtil.buildLocatorRef(nodePath,
                     HwvtepHAUtil.getTepIpVal(locator.getLocatorRef()))).build());
         }
index c7a78ddc121b3d1e79c5a261855faff63a4312be..f610b45ec798170a65e011dec66bc5a3db2f8066 100644 (file)
@@ -106,7 +106,7 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
         }
 
         List<L2GatewayDevice> allDevices = ElanL2GwCacheUtils.getAllElanDevicesFromCache();
-        if (allDevices == null || allDevices.isEmpty()) {
+        if (allDevices.isEmpty()) {
             LOG.trace("no elan devices present in cache {}", update.key().getGroupId());
             return;
         }
index 452f2d581becfa7297a17cbc00f7b944d1fae80c..fbbaee87d31a6989078c1046239b8ac15e96cf0d 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.netvirt.elan.l2gw.listeners;
 
 import static java.util.Collections.emptyList;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
@@ -167,12 +166,11 @@ public class HwvtepTerminationPointListener
             } else {
                 String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(
                         l2GwConn.getNetworkId().getValue());
-                List<Devices> l2Devices = requireNonNullElse(l2Gateway.getDevices(), emptyList());
+                List<Devices> l2Devices = l2Gateway.nonnullDevices();
                 for (Devices l2Device : l2Devices) {
                     String l2DeviceName = l2Device.getDeviceName();
                     if (l2DeviceName != null && l2DeviceName.equals(psName)) {
-                        for (Interfaces deviceInterface : requireNonNullElse(l2Device.getInterfaces(),
-                                Collections.<Interfaces>emptyList())) {
+                        for (Interfaces deviceInterface : l2Device.nonnullInterfaces()) {
                             if (Objects.equals(deviceInterface.getInterfaceName(), newPortId)) {
                                 if (deviceInterface.getSegmentationIds() != null
                                         && !deviceInterface.getSegmentationIds().isEmpty()) {
index 97dfa4922d9790e4c5bbaa0a664db8d34c498835..c258e8772ecc7b97ed2362b0c65359cd2c5107fd 100644 (file)
@@ -10,14 +10,12 @@ package org.opendaylight.netvirt.elan.l2gw.utils;
 import static java.util.Collections.emptyList;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.netvirt.elan.utils.ElanUtils.isVxlanNetworkOrVxlanSegment;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentMap;
@@ -286,8 +284,7 @@ public class ElanL2GatewayMulticastUtils {
     @Nullable
     private DpnInterfaces getDpnInterfaces(ElanDpnInterfacesList elanDpns, BigInteger dpnId) {
         if (elanDpns != null) {
-            for (DpnInterfaces dpnInterface : requireNonNullElse(elanDpns.getDpnInterfaces(),
-                    Collections.<DpnInterfaces>emptyList())) {
+            for (DpnInterfaces dpnInterface : elanDpns.nonnullDpnInterfaces()) {
                 if (Objects.equals(dpnInterface.getDpId(), dpnId)) {
                     return dpnInterface;
                 }
@@ -401,8 +398,7 @@ public class ElanL2GatewayMulticastUtils {
             long elanTagOrVni) {
         List<Bucket> listBucketInfo = new ArrayList<>();
         if (elanDpns != null) {
-            for (DpnInterfaces dpnInterface : requireNonNullElse(elanDpns.getDpnInterfaces(),
-                    Collections.<DpnInterfaces>emptyList())) {
+            for (DpnInterfaces dpnInterface : elanDpns.nonnullDpnInterfaces()) {
                 if (elanUtils.isDpnPresent(dpnInterface.getDpId()) && !Objects.equals(dpnInterface.getDpId(), dpnId)
                         && dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty()) {
                     try {
index 6be28a03701c3fa2a45ac8dcd6ebf5cf8110bd5c..0b69b50b6f2f6c3772c385e5762283288845e058 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netvirt.elan.l2gw.utils;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
@@ -76,7 +75,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpc
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddL2GwDeviceInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddL2GwDeviceOutput;
@@ -1010,8 +1008,7 @@ public class ElanL2GatewayUtils {
                 return;
             }
             String psNodeId = globalNodeId + HwvtepHAUtil.PHYSICALSWITCH + psName;
-            requireNonNullElse(tzonesoptional.get().getTransportZone(),
-                Collections.<TransportZone>emptyList()).stream()
+            tzonesoptional.get().nonnullTransportZone().stream()
                 .filter(transportZone -> transportZone.getSubnets() != null)
                 .flatMap(transportZone -> transportZone.getSubnets().stream())
                 .filter(subnet -> subnet.getDeviceVteps() != null)
@@ -1053,10 +1050,8 @@ public class ElanL2GatewayUtils {
             }
             JdkFutures.addErrorLogging(
                 new ManagedNewTransactionRunnerImpl(dataBroker).callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
-                    tx -> requireNonNullElse(optionalElan.get().getElanInstance(),
-                        Collections.<ElanInstance>emptyList()).stream()
-                        .flatMap(elan -> requireNonNullElse(elan.getExternalTeps(),
-                            Collections.<ExternalTeps>emptyList()).stream()
+                    tx -> optionalElan.get().nonnullElanInstance().stream()
+                        .flatMap(elan -> elan.nonnullExternalTeps().stream()
                             .map(externalTep -> ElanL2GatewayMulticastUtils.buildExternalTepPath(
                                 elan.getElanInstanceName(), externalTep.getTepIp())))
                         .filter(externalTepIid -> Objects.equals(
index 6e3a42cdc743093b7b53bb2d74716a450265ae8b..8cb813b52c44d6d7eb4ae9068cca0aff531769a6 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.netvirt.elan.l2gw.utils;
 
 import static java.util.Collections.emptyList;
 import static org.opendaylight.netvirt.elan.utils.ElanUtils.isVxlanNetworkOrVxlanSegment;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
@@ -228,8 +227,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
 
     private void disAssociateHwvtepsFromElan(String elanName, L2gatewayConnection input) {
         Integer defaultVlan = input.getSegmentId();
-        List<L2GatewayDevice> l2Devices =
-            requireNonNullElse(ElanL2GwCacheUtils.getAllElanDevicesFromCache(), emptyList());
+        List<L2GatewayDevice> l2Devices = ElanL2GwCacheUtils.getAllElanDevicesFromCache();
         List<Devices> l2gwDevicesToBeDeleted = new ArrayList<>();
         for (L2GatewayDevice elanL2gwDevice : l2Devices) {
             if (elanL2gwDevice.getL2GatewayIds().contains(input.key().getUuid())) {
@@ -283,11 +281,15 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
         String elanName = elanInstance.getElanInstanceName();
         Integer defaultVlan = input.getSegmentId();
         Uuid l2GwConnId = input.key().getUuid();
-        List<Devices> l2Devices = requireNonNullElse(l2Gateway.getDevices(), emptyList());
+        List<Devices> l2Devices = l2Gateway.getDevices();
 
         LOG.trace("Associating ELAN {} with L2Gw Conn Id {} having below L2Gw devices {}", elanName, l2GwConnId,
                 l2Devices);
 
+        if (l2Devices == null) {
+            return;
+        }
+
         for (Devices l2Device : l2Devices) {
             String l2DeviceName = l2Device.getDeviceName();
             // L2gateway can have more than one L2 Gw devices. Configure Logical Switch, VLAN mappings,...
index 3a6fce8d3c2ffb4b813f3c8308d0ccba58e931cf..334f871b103ffa0a6d2ca3e4a4078561d0d076fb 100755 (executable)
@@ -8,7 +8,6 @@
 package org.opendaylight.netvirt.elan.utils;
 
 import static java.util.Collections.emptyList;
-import static java.util.Objects.requireNonNull;
 import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
@@ -22,7 +21,6 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
-
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -31,13 +29,11 @@ import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
-
 import javax.annotation.CheckReturnValue;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.apache.commons.lang3.StringUtils;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
@@ -534,8 +530,7 @@ public class ElanUtils {
         if (!existingElanDpnInterfaces.isPresent()) {
             return dpIds;
         }
-        List<DpnInterfaces> dpnInterfaces =
-            requireNonNullElse(existingElanDpnInterfaces.get().getDpnInterfaces(), emptyList());
+        List<DpnInterfaces> dpnInterfaces = existingElanDpnInterfaces.get().nonnullDpnInterfaces();
         for (DpnInterfaces dpnInterface : dpnInterfaces) {
             dpIds.add(dpnInterface.getDpId());
         }
@@ -560,8 +555,7 @@ public class ElanUtils {
         if (!existingElanDpnInterfaces.isPresent()) {
             return false;
         }
-        List<DpnInterfaces> dpnInterfaces =
-            requireNonNullElse(existingElanDpnInterfaces.get().getDpnInterfaces(), emptyList());
+        List<DpnInterfaces> dpnInterfaces = existingElanDpnInterfaces.get().nonnullDpnInterfaces();
         for (DpnInterfaces dpnInterface : dpnInterfaces) {
             if (Objects.equals(dpnInterface.getDpId(), dpId)) {
                 return true;
@@ -816,7 +810,7 @@ public class ElanUtils {
                 LOG.debug("RPC Call to Get egress actions for interface {} returned with Errors {}", ifName,
                         rpcResult.getErrors());
             } else {
-                listAction = requireNonNullElse(rpcResult.getResult().getAction(), emptyList());
+                listAction = rpcResult.getResult().nonnullAction();
             }
         } catch (Exception e) {
             LOG.warn("Exception when egress actions for interface {}", ifName, e);
@@ -1738,10 +1732,4 @@ public class ElanUtils {
         return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:" + dpnId)))
                 .augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(new GroupId(groupId))).build();
     }
-
-    // Use Objects.requireNonNullElse instead with JDK9+
-    @Nonnull
-    public static <T> T requireNonNullElse(@Nullable T obj, @Nonnull T defaultObj) {
-        return obj != null ? obj : requireNonNull(defaultObj);
-    }
 }
index cf63fe76f2fc4a154f37bd0da047905186b8b12c..911e7cffcdcbb28074a846bc00328058232928a2 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netvirt.elan.utils;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
-import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.MapDifference;
@@ -396,7 +395,7 @@ public class TransportZoneNotificationUtil {
         }
 
         Subnets subnets = getOrAddSubnet(zoneSubnets, subnetIp);
-        for (Vteps existingVtep : requireNonNullElse(subnets.getVteps(), Collections.<Vteps>emptyList())) {
+        for (Vteps existingVtep : subnets.nonnullVteps()) {
             if (Objects.equals(existingVtep.getDpnId(), dpnId)) {
                 return false;
             }