From 80232aad799e602e9fa8b4f4a3baeb5ba013f19f Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Fri, 25 Jan 2019 09:53:22 +0100 Subject: [PATCH] elanmanager: drop nullToEmpty and reqNonNullOrElse Change-Id: Ibef665d4f6701219282a4b30533b03a72b376d05 Signed-off-by: Stephen Kitt --- .../elanmanager/utils/ElanL2GwCacheUtils.java | 6 ++-- .../elan/cli/l2gw/L2GwValidateCli.java | 15 +++----- .../cli/l2gw/NetworkL2gwDeviceInfoCli.java | 12 ++----- .../netvirt/elan/evpn/utils/EvpnUtils.java | 10 ++---- .../ElanDpnInterfaceClusteredListener.java | 7 ++-- .../internal/ElanDpnInterfacesListener.java | 6 ++-- .../elan/internal/ElanInterfaceManager.java | 36 ++++++++++--------- .../elan/internal/ElanServiceProvider.java | 4 +-- .../elan/l2gw/ha/commands/LocalMcastCmd.java | 5 +-- .../elan/l2gw/ha/commands/RemoteMcastCmd.java | 5 +-- .../l2gw/listeners/ElanGroupListener.java | 2 +- .../HwvtepTerminationPointListener.java | 6 ++-- .../utils/ElanL2GatewayMulticastUtils.java | 8 ++--- .../elan/l2gw/utils/ElanL2GatewayUtils.java | 11 ++---- .../l2gw/utils/L2GatewayConnectionUtils.java | 10 +++--- .../netvirt/elan/utils/ElanUtils.java | 18 ++-------- .../utils/TransportZoneNotificationUtil.java | 3 +- 17 files changed, 61 insertions(+), 103 deletions(-) diff --git a/elanmanager/api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java b/elanmanager/api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java index 79ad578a54..953774572f 100644 --- a/elanmanager/api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java +++ b/elanmanager/api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java @@ -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 getAllElanDevicesFromCache() { ConcurrentMap> cachedMap = (ConcurrentMap>) CacheUtil.getCache( ElanL2GwCacheUtils.L2GATEWAY_CONN_CACHE_NAME); if (cachedMap == null || cachedMap.isEmpty()) { - return null; + return Collections.emptyList(); } List l2GwDevices = new ArrayList<>(); diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwValidateCli.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwValidateCli.java index 00c9598aa2..189a4b7ae9 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwValidateCli.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwValidateCli.java @@ -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 configTopoOptional = tx.read(LogicalDatastoreType.CONFIGURATION, topoId).checkedGet(); if (operationalTopoOptional.isPresent()) { - for (Node node : requireNonNullElse(operationalTopoOptional.get().getNode(), - Collections.emptyList())) { + for (Node node : operationalTopoOptional.get().nonnullNode()) { InstanceIdentifier nodeIid = topoId.child(Node.class, node.key()); operationalNodes.put(nodeIid, node); } } if (configTopoOptional.isPresent()) { - for (Node node : requireNonNullElse(configTopoOptional.get().getNode(), - Collections.emptyList())) { + for (Node node : configTopoOptional.get().nonnullNode()) { InstanceIdentifier 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 = requireNonNullElse(l2gateway.getDevices(), emptyList()); + List 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 vlanBindingses = requireNonNullElse(configTerminationPoint.augmentation( - HwvtepPhysicalPortAugmentation.class).getVlanBindings(), emptyList()); + List vlanBindingses = configTerminationPoint.augmentation( + HwvtepPhysicalPortAugmentation.class).nonnullVlanBindings(); for (VlanBindings actual : vlanBindingses) { if (actual.equals(expectedBindings)) { foundBindings = true; diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/NetworkL2gwDeviceInfoCli.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/NetworkL2gwDeviceInfoCli.java index 95f0c3801d..23f8989360 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/NetworkL2gwDeviceInfoCli.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/NetworkL2gwDeviceInfoCli.java @@ -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 topologyOptional = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, createHwvtepTopologyInstanceIdentifier()); if (topologyOptional.isPresent()) { - nodes = requireNonNullElse(topologyOptional.get().getNode(), emptyList()); + nodes.addAll(topologyOptional.get().nonnullNode()); } } else { Optional 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 locatorsets = new ArrayList<>(); - for (LocatorSet locatorSet : requireNonNullElse(localMac.getLocatorSet(), - Collections.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 locatorsets = new ArrayList<>(); - for (LocatorSet locatorSet : requireNonNullElse(remoteMac.getLocatorSet(), - Collections.emptyList())) { + for (LocatorSet locatorSet : remoteMac.nonnullLocatorSet()) { locatorsets.add(getLocatorValue(locatorSet.getLocatorRef())); } session.getConsole().println(mac + GAP + locatorsets.toString()); diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/utils/EvpnUtils.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/utils/EvpnUtils.java index 1c0f2ca23a..5f5652ae28 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/utils/EvpnUtils.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/utils/EvpnUtils.java @@ -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 dcGatewayIps = dcGatewayIpListOptional.get().getDcGatewayIp(); + List dcGatewayIps = dcGatewayIpListOptional.get().nonnullDcGatewayIp(); Optional externalTunnelListOptional = getExternalTunnelList(); if (!externalTunnelListOptional.isPresent()) { LOG.info("No External Tunnel Configured while programming the l2vni table."); return tunnelInterfaceNameList; } - List externalTunnels = - requireNonNullElse(externalTunnelListOptional.get().getExternalTunnel(), emptyList()); + List externalTunnels = externalTunnelListOptional.get().nonnullExternalTunnel(); - requireNonNullElse(dcGatewayIps, Collections.emptyList()) - .forEach(dcIp -> externalTunnels + dcGatewayIps.forEach(dcIp -> externalTunnels .stream() .filter(externalTunnel -> externalTunnel.getDestinationDevice() .contains(dcIp.getIpAddress().getIpv4Address().toString())) diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfaceClusteredListener.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfaceClusteredListener.java index 6b69e7193d..ed44101926 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfaceClusteredListener.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfaceClusteredListener.java @@ -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 identifier, DpnInterfaces original, final DpnInterfaces dpnInterfaces) { - List interfaces = requireNonNullElse(dpnInterfaces.getInterfaces(), emptyList()); - LOG.debug("dpninterfaces update fired new size {}", interfaces.size()); - if (interfaces.isEmpty()) { + List 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 diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfacesListener.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfacesListener.java index 23650aa7a5..b825ac6ca0 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfacesListener.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfacesListener.java @@ -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 interfaces = requireNonNullElse(update.getInterfaces(), emptyList()); + List 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); diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java index 62255cec3e..27f6aa7442 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java @@ -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 { - List elanInterfaces = requireNonNullElse(elanState.getElanInterfaces(), emptyList()); - if (elanInterfaces.isEmpty()) { + @Nullable List elanInterfaces = elanState.getElanInterfaces(); + if (elanInterfaces == null || elanInterfaces.isEmpty()) { holder.isLastElanInterface = true; } if (interfaceInfo != null) { @@ -371,8 +371,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase elanInterfaces = requireNonNullElse(elanState.getElanInterfaces(), emptyList()); - boolean isRemoved = elanInterfaces.remove(interfaceName); + List elanInterfaces = elanState.getElanInterfaces(); + boolean isRemoved = elanInterfaces != null && elanInterfaces.remove(interfaceName); if (!isRemoved) { return elanState; } @@ -493,9 +493,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase { for (DpnInterfaces dpnInterface : dpnInterfaces) { BigInteger currentDpId = dpnInterface.getDpId(); - if (!currentDpId.equals(dpId)) { - for (String elanInterface : requireNonNullElse(dpnInterface.getInterfaces(), - Collections.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 existingInterfaces = existingElanDpnInterfaces.get().getInterfaces(); List 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 existingInterfaces = existingElanDpnInterfaces.get().getInterfaces(); List 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 interfaces = requireNonNullElse(dpnInterfaces.getInterfaces(), emptyList()); + List 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 getMacEntryOperationalDataPath(String elanName, PhysAddress physAddress) { @@ -1025,7 +1029,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase dpnInterfaces = requireNonNullElse(elanDpns.getDpnInterfaces(), emptyList()); + List dpnInterfaces = elanDpns.nonnullDpnInterfaces(); for (DpnInterfaces dpnInterface : dpnInterfaces) { List remoteListBucketInfo = new ArrayList<>(); if (elanUtils.isDpnPresent(dpnInterface.getDpId()) && !Objects.equals(dpnInterface.getDpId(), dpId) @@ -1582,8 +1586,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase elanDpnIf = - requireNonNullElse(dpnInterfaceLists.getElanDpnInterfacesList(), emptyList()); + List elanDpnIf = dpnInterfaceLists.nonnullElanDpnInterfacesList(); for (ElanDpnInterfacesList elanDpns : elanDpnIf) { int cnt = 0; String elanName = elanDpns.getElanInstanceName(); @@ -1675,8 +1678,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase elanDpnIf = - requireNonNullElse(dpnInterfaceLists.getElanDpnInterfacesList(), emptyList()); + List elanDpnIf = dpnInterfaceLists.nonnullElanDpnInterfacesList(); for (ElanDpnInterfacesList elanDpns : elanDpnIf) { String elanName = elanDpns.getElanInstanceName(); ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull(); diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanServiceProvider.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanServiceProvider.java index e5420d19bb..44a4e463d7 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanServiceProvider.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanServiceProvider.java @@ -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 elanInterfaceList = - requireNonNullElse(elanInterfacesOptional.get().getElanInterface(), emptyList()); + List elanInterfaceList = elanInterfacesOptional.get().nonnullElanInterface(); for (ElanInterface elanInterface : elanInterfaceList) { if (Objects.equals(elanInterface.getElanInstanceName(), elanInstanceName)) { elanInterfaces.add(elanInterface.getName()); diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/LocalMcastCmd.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/LocalMcastCmd.java index 913dd6bc83..0ffecc6b13 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/LocalMcastCmd.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/LocalMcastCmd.java @@ -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 nodePath, LocalMcastMacs src) { LocalMcastMacsBuilder ucmlBuilder = new LocalMcastMacsBuilder(src); List locatorSet = new ArrayList<>(); - for (LocatorSet locator : requireNonNullElse(src.getLocatorSet(), Collections.emptyList())) { + for (LocatorSet locator : src.nonnullLocatorSet()) { locatorSet.add(new LocatorSetBuilder().setLocatorRef(HwvtepHAUtil.buildLocatorRef(nodePath, HwvtepHAUtil.getTepIpVal(locator.getLocatorRef()))).build()); } diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/RemoteMcastCmd.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/RemoteMcastCmd.java index 6e2b024804..02c16e2aa7 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/RemoteMcastCmd.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/RemoteMcastCmd.java @@ -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 nodePath, RemoteMcastMacs src) { RemoteMcastMacsBuilder ucmlBuilder = new RemoteMcastMacsBuilder(src); List locatorSet = new ArrayList<>(); - for (LocatorSet locator : requireNonNullElse(src.getLocatorSet(), Collections.emptyList())) { + for (LocatorSet locator : src.nonnullLocatorSet()) { locatorSet.add(new LocatorSetBuilder().setLocatorRef(HwvtepHAUtil.buildLocatorRef(nodePath, HwvtepHAUtil.getTepIpVal(locator.getLocatorRef()))).build()); } diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java index c7a78ddc12..f610b45ec7 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java @@ -106,7 +106,7 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase< } List allDevices = ElanL2GwCacheUtils.getAllElanDevicesFromCache(); - if (allDevices == null || allDevices.isEmpty()) { + if (allDevices.isEmpty()) { LOG.trace("no elan devices present in cache {}", update.key().getGroupId()); return; } diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepTerminationPointListener.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepTerminationPointListener.java index 452f2d581b..fbbaee87d3 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepTerminationPointListener.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepTerminationPointListener.java @@ -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 l2Devices = requireNonNullElse(l2Gateway.getDevices(), emptyList()); + List l2Devices = l2Gateway.nonnullDevices(); for (Devices l2Device : l2Devices) { String l2DeviceName = l2Device.getDeviceName(); if (l2DeviceName != null && l2DeviceName.equals(psName)) { - for (Interfaces deviceInterface : requireNonNullElse(l2Device.getInterfaces(), - Collections.emptyList())) { + for (Interfaces deviceInterface : l2Device.nonnullInterfaces()) { if (Objects.equals(deviceInterface.getInterfaceName(), newPortId)) { if (deviceInterface.getSegmentationIds() != null && !deviceInterface.getSegmentationIds().isEmpty()) { diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayMulticastUtils.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayMulticastUtils.java index 97dfa4922d..c258e8772e 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayMulticastUtils.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayMulticastUtils.java @@ -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.emptyList())) { + for (DpnInterfaces dpnInterface : elanDpns.nonnullDpnInterfaces()) { if (Objects.equals(dpnInterface.getDpId(), dpnId)) { return dpnInterface; } @@ -401,8 +398,7 @@ public class ElanL2GatewayMulticastUtils { long elanTagOrVni) { List listBucketInfo = new ArrayList<>(); if (elanDpns != null) { - for (DpnInterfaces dpnInterface : requireNonNullElse(elanDpns.getDpnInterfaces(), - Collections.emptyList())) { + for (DpnInterfaces dpnInterface : elanDpns.nonnullDpnInterfaces()) { if (elanUtils.isDpnPresent(dpnInterface.getDpId()) && !Objects.equals(dpnInterface.getDpId(), dpnId) && dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty()) { try { diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayUtils.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayUtils.java index 6be28a0370..0b69b50b6f 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayUtils.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayUtils.java @@ -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.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.emptyList()).stream() - .flatMap(elan -> requireNonNullElse(elan.getExternalTeps(), - Collections.emptyList()).stream() + tx -> optionalElan.get().nonnullElanInstance().stream() + .flatMap(elan -> elan.nonnullExternalTeps().stream() .map(externalTep -> ElanL2GatewayMulticastUtils.buildExternalTepPath( elan.getElanInstanceName(), externalTep.getTepIp()))) .filter(externalTepIid -> Objects.equals( diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java index 6e3a42cdc7..8cb813b52c 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java @@ -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 l2Devices = - requireNonNullElse(ElanL2GwCacheUtils.getAllElanDevicesFromCache(), emptyList()); + List l2Devices = ElanL2GwCacheUtils.getAllElanDevicesFromCache(); List 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 l2Devices = requireNonNullElse(l2Gateway.getDevices(), emptyList()); + List 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,... diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java index 3a6fce8d3c..334f871b10 100755 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java @@ -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 = - requireNonNullElse(existingElanDpnInterfaces.get().getDpnInterfaces(), emptyList()); + List 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 = - requireNonNullElse(existingElanDpnInterfaces.get().getDpnInterfaces(), emptyList()); + List 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 requireNonNullElse(@Nullable T obj, @Nonnull T defaultObj) { - return obj != null ? obj : requireNonNull(defaultObj); - } } diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/TransportZoneNotificationUtil.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/TransportZoneNotificationUtil.java index cf63fe76f2..911e7cffcd 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/TransportZoneNotificationUtil.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/TransportZoneNotificationUtil.java @@ -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.emptyList())) { + for (Vteps existingVtep : subnets.nonnullVteps()) { if (Objects.equals(existingVtep.getDpnId(), dpnId)) { return false; } -- 2.36.6