fibmanager: drop nullToEmpty and reqNonNullOrElse 17/79917/4
authorStephen Kitt <skitt@redhat.com>
Fri, 25 Jan 2019 08:53:23 +0000 (09:53 +0100)
committerSam Hague <shague@redhat.com>
Mon, 28 Jan 2019 15:21:07 +0000 (15:21 +0000)
Change-Id: I00072529caa24f6a1c75507b5fdd2d71e6eb461e
Signed-off-by: Stephen Kitt <skitt@redhat.com>
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/BaseVrfEntryHandler.java
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/BgpRouteVrfEntryHandler.java
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/EvpnVrfEntryHandler.java
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/FibUtil.java
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/NexthopManager.java
fibmanager/impl/src/main/java/org/opendaylight/netvirt/fibmanager/VrfEntryListener.java

index 92d9a4637ed71c2ecff0943dc28cbeb88ea47df0..01cdccb6ccf084dc01b7434d14b4146ee11e9503 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.netvirt.fibmanager;
 
 import static java.util.stream.Collectors.toList;
 import static org.opendaylight.genius.mdsalutil.NWUtil.isIpv4Address;
-import static org.opendaylight.netvirt.fibmanager.FibUtil.nullToEmpty;
 
 import com.google.common.base.Optional;
 import java.math.BigInteger;
@@ -159,7 +158,7 @@ public class BaseVrfEntryHandler implements AutoCloseable {
     @Nonnull
     protected List<AdjacencyResult> resolveAdjacency(final BigInteger remoteDpnId, final long vpnId,
                                                      final VrfEntry vrfEntry, String rd) {
-        List<RoutePaths> routePaths = nullToEmpty(vrfEntry.getRoutePaths());
+        List<RoutePaths> routePaths = vrfEntry.nonnullRoutePaths();
         FibHelper.sortIpAddress(routePaths);
         List<AdjacencyResult> adjacencyList = new ArrayList<>();
         List<String> prefixIpList;
@@ -187,15 +186,16 @@ public class BaseVrfEntryHandler implements AutoCloseable {
                     prefixIpList = Collections.singletonList(vrfEntry.getDestPrefix());
                 } else {
                     List<String> prefixIpListLocal = new ArrayList<>();
-                    vpnExtraRoutes.forEach(route -> nullToEmpty(route.getNexthopIpList()).forEach(extraRouteIp -> {
-                        String ipPrefix;
-                        if (isIpv4Address(extraRouteIp)) {
-                            ipPrefix = extraRouteIp + NwConstants.IPV4PREFIX;
-                        } else {
-                            ipPrefix = extraRouteIp + NwConstants.IPV6PREFIX;
-                        }
-                        prefixIpListLocal.add(ipPrefix);
-                    }));
+                    vpnExtraRoutes.stream().filter(route -> route.getNexthopIpList() != null).forEach(
+                        route -> route.getNexthopIpList().forEach(extraRouteIp -> {
+                            String ipPrefix;
+                            if (isIpv4Address(extraRouteIp)) {
+                                ipPrefix = extraRouteIp + NwConstants.IPV4PREFIX;
+                            } else {
+                                ipPrefix = extraRouteIp + NwConstants.IPV6PREFIX;
+                            }
+                            prefixIpListLocal.add(ipPrefix);
+                        }));
                     prefixIpList = prefixIpListLocal;
                 }
             } else {
index 214aca0772fd75a1f69a1636bb9a07512ea55966..1c0d62db6d9a6cdec85f4052a68e6e69de4f7a67 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.netvirt.fibmanager;
 
 import static java.util.stream.Collectors.toList;
-import static org.opendaylight.netvirt.fibmanager.FibUtil.nullToEmpty;
 
 import com.google.common.base.Optional;
 import java.math.BigInteger;
@@ -255,7 +254,7 @@ public class BgpRouteVrfEntryHandler extends BaseVrfEntryHandler
                                              String rd,
                                              List<NexthopManager.AdjacencyResult> adjacencyResults,
                                              List<SubTransaction> subTxns) {
-        if (nullToEmpty(vrfEntry.getRoutePaths()).size() > 2) {
+        if (vrfEntry.nonnullRoutePaths().size() > 2) {
             LOG.error("DC-GW can advertise only 2 bestPaths for prefix {}", vrfEntry.getDestPrefix());
             return;
         }
@@ -370,7 +369,7 @@ public class BgpRouteVrfEntryHandler extends BaseVrfEntryHandler
             final BigInteger dpnId, final long vpnId, final String rd,
             final String remoteNextHopIp, final Optional<VrfTables> vrfTable,
             WriteTransaction writeCfgTxn, List<SubTransaction> subTxns) {
-        return vrfEntry -> nullToEmpty(vrfEntry.getRoutePaths()).stream()
+        return vrfEntry -> vrfEntry.nonnullRoutePaths().stream()
                 .filter(routes -> !routes.getNexthopAddress().isEmpty()
                         && remoteNextHopIp.trim().equals(routes.getNexthopAddress().trim()))
                 .findFirst()
@@ -386,7 +385,7 @@ public class BgpRouteVrfEntryHandler extends BaseVrfEntryHandler
             final BigInteger dpnId, final long vpnId,
             final String remoteNextHopIp, final Optional<VrfTables> vrfTable,
             WriteTransaction writeCfgTxn, List<SubTransaction> subTxns) {
-        return vrfEntry -> nullToEmpty(vrfEntry.getRoutePaths()).stream()
+        return vrfEntry -> vrfEntry.nonnullRoutePaths().stream()
                 .filter(routes -> !routes.getNexthopAddress().isEmpty()
                         && remoteNextHopIp.trim().equals(routes.getNexthopAddress().trim()))
                 .findFirst()
index f091ba6bd057dde433d3892484ec76af90b8e523..55bfef2d55791ffd4251d22b6d2aba8dc94f042f 100644 (file)
@@ -8,16 +8,13 @@
 package org.opendaylight.netvirt.fibmanager;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
-import static org.opendaylight.netvirt.fibmanager.FibUtil.nullToEmpty;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
-
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-
 import java.util.Objects;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -149,8 +146,8 @@ public class EvpnVrfEntryHandler extends BaseVrfEntryHandler implements IVrfEntr
         if (localNextHopInfo == null) {
             //Handle extra routes and imported routes
             Routes extraRoute = getVpnToExtraroute(vpnId, rd, vrfEntry.getDestPrefix());
-            if (extraRoute != null) {
-                for (String nextHopIp : nullToEmpty(extraRoute.getNexthopIpList())) {
+            if (extraRoute != null && extraRoute.getNexthopIpList() != null) {
+                for (String nextHopIp : extraRoute.getNexthopIpList()) {
                     LOG.info("NextHop IP for destination {} is {}", vrfEntry.getDestPrefix(), nextHopIp);
                     if (nextHopIp != null) {
                         localNextHopInfo = getFibUtil().getPrefixToInterface(vpnId, nextHopIp + "/32");
index c4442e04422699e6bae13387acfc9134ef9a9ba4..840b60268f99afc36630cc2eb9fedf93ea4848e5 100644 (file)
@@ -8,7 +8,6 @@
 
 package org.opendaylight.netvirt.fibmanager;
 
-import static java.util.Collections.emptyList;
 import static java.util.stream.Collectors.joining;
 import static java.util.stream.Collectors.toList;
 import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
@@ -25,7 +24,6 @@ import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.locks.ReentrantLock;
-import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -730,7 +728,8 @@ public class FibUtil {
     public static void removeOrUpdateNextHopInfo(BigInteger dpnId, String nextHopKey, String groupId,
             Nexthops nexthops, TypedWriteTransaction<Operational> tx) {
         InstanceIdentifier<Nexthops> nextHopsId = getNextHopsIdentifier(nextHopKey);
-        List<String> targetDeviceIds = new ArrayList<>(nullToEmpty(nexthops.getTargetDeviceId()));
+        List<String> targetDeviceIds =
+            nexthops.getTargetDeviceId() != null ? new ArrayList<>(nexthops.getTargetDeviceId()) : new ArrayList<>();
         targetDeviceIds.remove(dpnId.toString());
         if (targetDeviceIds.isEmpty()) {
             tx.delete(nextHopsId);
@@ -908,10 +907,4 @@ public class FibUtil {
         }
         return false;
     }
-
-    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3
-    @Nonnull
-    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
-        return input != null ? input : emptyList();
-    }
 }
index 8ff25aa5bc4389b14405266c0108fac717e4b579..7fb4ee76df9f64be944424904fda976a2364c542 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.netvirt.fibmanager;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
 import static org.opendaylight.genius.mdsalutil.NWUtil.isIpv4Address;
-import static org.opendaylight.netvirt.fibmanager.FibUtil.nullToEmpty;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -271,7 +270,7 @@ public class NexthopManager implements AutoCloseable {
                             ifName, rpcResult.getErrors());
                     return Collections.emptyList();
                 } else {
-                    actions = rpcResult.getResult().getAction();
+                    actions = rpcResult.getResult().nonnullAction();
                 }
             } else {
                 RpcResult<GetEgressActionsForInterfaceOutput> rpcResult = odlInterfaceRpcService
@@ -282,11 +281,11 @@ public class NexthopManager implements AutoCloseable {
                             ifName, rpcResult.getErrors());
                     return Collections.emptyList();
                 } else {
-                    actions = rpcResult.getResult().getAction();
+                    actions = rpcResult.getResult().nonnullAction();
                 }
             }
             List<ActionInfo> listActionInfo = new ArrayList<>();
-            for (Action action : nullToEmpty(actions)) {
+            for (Action action : actions) {
                 actionKey = action.key().getOrder() + actionKey;
                 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action
                     actionClass = action.getAction();
@@ -536,7 +535,7 @@ public class NexthopManager implements AutoCloseable {
         Optional<VpnNexthops> vpnNexthops = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
         if (vpnNexthops.isPresent()) {
             // get nexthops list for vpn
-            List<VpnNexthop> nexthops = nullToEmpty(vpnNexthops.get().getVpnNexthop());
+            List<VpnNexthop> nexthops = vpnNexthops.get().nonnullVpnNexthop();
             for (VpnNexthop nexthop : nexthops) {
                 if (Objects.equals(nexthop.getIpAddress(), ipAddress)) {
                     // return nexthop
@@ -600,12 +599,12 @@ public class NexthopManager implements AutoCloseable {
             if (FibUtil.lockCluster(lockManager, nextHopLockStr, WAIT_TIME_TO_ACQUIRE_LOCK)) {
                 VpnNexthop nh = getVpnNexthop(vpnId, primaryIpAddress);
                 if (nh != null) {
-                    List<IpAdjacencies> prefixesList = new ArrayList<>(nullToEmpty(nh.getIpAdjacencies()));
+                    List<IpAdjacencies> prefixesList = new ArrayList<>(nh.nonnullIpAdjacencies());
                     IpAdjacencies prefix = new IpAdjacenciesBuilder().setIpAdjacency(currDestIpPrefix).build();
                     prefixesList.remove(prefix);
                     if (prefixesList.isEmpty()) { //remove the group only if there are no more flows using this group
                         GroupEntity groupEntity = MDSALUtil.buildGroupEntity(dpnId, nh.getEgressPointer(),
-                                primaryIpAddress, GroupTypes.GroupAll, Collections.EMPTY_LIST);
+                                primaryIpAddress, GroupTypes.GroupAll, Collections.emptyList());
                         // remove Group ...
                         mdsalApiManager.removeGroup(groupEntity);
                         //update MD-SAL DS
@@ -925,34 +924,37 @@ public class NexthopManager implements AutoCloseable {
 
     private List<BucketInfo> getBucketsForLocalNexthop(Long vpnId, BigInteger dpnId,
             VrfEntry vrfEntry, Routes routes) {
+        @Nullable List<String> nexthopIpList = routes.getNexthopIpList();
         if (LOG.isDebugEnabled()) {
             LOG.debug("NexthopManager.getBucketsForLocalNexthop invoked with vpnId {} dpnId {} "
                             + " vrfEntry.routePaths {}, routes.nexthopList {}", vpnId, dpnId, vrfEntry.getRoutePaths(),
-                    routes.getNexthopIpList());
+                nexthopIpList);
         }
         List<BucketInfo> listBucketInfo = new CopyOnWriteArrayList<>();
-        nullToEmpty(routes.getNexthopIpList()).parallelStream().forEach(nextHopIp -> {
-            String localNextHopIP;
-            if (isIpv4Address(nextHopIp)) {
-                localNextHopIP = nextHopIp + NwConstants.IPV4PREFIX;
-            } else {
-                localNextHopIP = nextHopIp + NwConstants.IPV6PREFIX;
-            }
-            Prefixes localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, localNextHopIP);
-            if (localNextHopInfo != null) {
-                long groupId = getLocalNextHopGroup(vpnId, localNextHopIP);
-                if (groupId == FibConstants.INVALID_GROUP_ID) {
-                    LOG.error("Unable to allocate groupId for vpnId {} , prefix {} , interface {}", vpnId,
-                            vrfEntry.getDestPrefix(), localNextHopInfo.getVpnInterfaceName());
-                    return;
+        if (nexthopIpList != null) {
+            nexthopIpList.parallelStream().forEach(nextHopIp -> {
+                String localNextHopIP;
+                if (isIpv4Address(nextHopIp)) {
+                    localNextHopIP = nextHopIp + NwConstants.IPV4PREFIX;
+                } else {
+                    localNextHopIP = nextHopIp + NwConstants.IPV6PREFIX;
                 }
-                List<ActionInfo> actionsInfos =
+                Prefixes localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, localNextHopIP);
+                if (localNextHopInfo != null) {
+                    long groupId = getLocalNextHopGroup(vpnId, localNextHopIP);
+                    if (groupId == FibConstants.INVALID_GROUP_ID) {
+                        LOG.error("Unable to allocate groupId for vpnId {} , prefix {} , interface {}", vpnId,
+                            vrfEntry.getDestPrefix(), localNextHopInfo.getVpnInterfaceName());
+                        return;
+                    }
+                    List<ActionInfo> actionsInfos =
                         Collections.singletonList(new ActionGroup(groupId));
-                BucketInfo bucket = new BucketInfo(actionsInfos);
-                bucket.setWeight(1);
-                listBucketInfo.add(bucket);
-            }
-        });
+                    BucketInfo bucket = new BucketInfo(actionsInfos);
+                    bucket.setWeight(1);
+                    listBucketInfo.add(bucket);
+                }
+            });
+        }
         LOG.trace("LOCAL: listbucket {}, vpnId {}, dpnId {}, routes {}", listBucketInfo, vpnId, dpnId, routes);
         return listBucketInfo;
     }
@@ -961,86 +963,88 @@ public class NexthopManager implements AutoCloseable {
             List<Routes> vpnExtraRoutes) {
         List<BucketInfo> listBucketInfo = new ArrayList<>();
         Map<String, List<ActionInfo>> egressActionMap = new HashMap<>();
-        vpnExtraRoutes.forEach(vpnExtraRoute -> nullToEmpty(vpnExtraRoute.getNexthopIpList()).forEach(nextHopIp -> {
-            String nextHopPrefixIp;
-            if (isIpv4Address(nextHopIp)) {
-                nextHopPrefixIp = nextHopIp + NwConstants.IPV4PREFIX;
-            } else {
-                nextHopPrefixIp = nextHopIp + NwConstants.IPV6PREFIX;
-            }
-            List<String> tepIpAddresses = fibUtil.getNextHopAddresses(rd, nextHopPrefixIp);
-            if (tepIpAddresses.isEmpty()) {
-                return;
-            }
-            // There would be only one nexthop address for a VM ip which would be the tep Ip
-            String tepIp = tepIpAddresses.get(0);
-            AdjacencyResult adjacencyResult = getRemoteNextHopPointer(dpnId, vpnId,
+        vpnExtraRoutes.stream().filter(vpnExtraRoute -> vpnExtraRoute.getNexthopIpList() != null).forEach(
+            vpnExtraRoute -> vpnExtraRoute.getNexthopIpList().forEach(nextHopIp -> {
+                String nextHopPrefixIp;
+                if (isIpv4Address(nextHopIp)) {
+                    nextHopPrefixIp = nextHopIp + NwConstants.IPV4PREFIX;
+                } else {
+                    nextHopPrefixIp = nextHopIp + NwConstants.IPV6PREFIX;
+                }
+                List<String> tepIpAddresses = fibUtil.getNextHopAddresses(rd, nextHopPrefixIp);
+                if (tepIpAddresses.isEmpty()) {
+                    return;
+                }
+                // There would be only one nexthop address for a VM ip which would be the tep Ip
+                String tepIp = tepIpAddresses.get(0);
+                AdjacencyResult adjacencyResult = getRemoteNextHopPointer(dpnId, vpnId,
                     vrfEntry.getDestPrefix(), tepIp, TunnelTypeVxlan.class);
-            if (adjacencyResult == null) {
-                return;
-            }
-            String egressInterface = adjacencyResult.getInterfaceName();
-            if (!FibUtil.isTunnelInterface(adjacencyResult)) {
-                return;
-            }
-            Class<? extends TunnelTypeBase> tunnelType = VpnExtraRouteHelper.getTunnelType(itmManager, egressInterface);
-            StateTunnelList ifState = null;
-            try {
-                ifState = fibUtil.getTunnelState(egressInterface);
-                if (ifState == null || ifState.getOperState() != TunnelOperStatus.Up) {
-                    LOG.trace("Tunnel is not up for interface {}", egressInterface);
+                if (adjacencyResult == null) {
                     return;
                 }
-            } catch (ReadFailedException e) {
-                LOG.error("getBucketsForRemoteNexthop: error in fetching tunnel state for interface {}",
+                String egressInterface = adjacencyResult.getInterfaceName();
+                if (!FibUtil.isTunnelInterface(adjacencyResult)) {
+                    return;
+                }
+                Class<? extends TunnelTypeBase> tunnelType =
+                    VpnExtraRouteHelper.getTunnelType(itmManager, egressInterface);
+                StateTunnelList ifState = null;
+                try {
+                    ifState = fibUtil.getTunnelState(egressInterface);
+                    if (ifState == null || ifState.getOperState() != TunnelOperStatus.Up) {
+                        LOG.trace("Tunnel is not up for interface {}", egressInterface);
+                        return;
+                    }
+                } catch (ReadFailedException e) {
+                    LOG.error("getBucketsForRemoteNexthop: error in fetching tunnel state for interface {}",
                         egressInterface, e);
-                return;
-            }
-            if (!TunnelTypeVxlan.class.equals(tunnelType)) {
-                return;
-            }
-            Long label = FibUtil.getLabelFromRoutePaths(vrfEntry).get();
-            Prefixes prefixInfo = fibUtil.getPrefixToInterface(vpnId, nextHopPrefixIp);
-            if (prefixInfo == null) {
-                LOG.error("No prefix info found for prefix {} in rd {} for VPN {}", nextHopPrefixIp, rd,
+                    return;
+                }
+                if (!TunnelTypeVxlan.class.equals(tunnelType)) {
+                    return;
+                }
+                Long label = FibUtil.getLabelFromRoutePaths(vrfEntry).get();
+                Prefixes prefixInfo = fibUtil.getPrefixToInterface(vpnId, nextHopPrefixIp);
+                if (prefixInfo == null) {
+                    LOG.error("No prefix info found for prefix {} in rd {} for VPN {}", nextHopPrefixIp, rd,
                         vpnId);
-                return;
-            }
-            BigInteger tunnelId;
-            if (FibUtil.isVxlanNetwork(prefixInfo.getNetworkType())) {
-                tunnelId = BigInteger.valueOf(prefixInfo.getSegmentationId());
-            } else {
-                LOG.warn("Network is not of type VXLAN for prefix {}."
+                    return;
+                }
+                BigInteger tunnelId;
+                if (FibUtil.isVxlanNetwork(prefixInfo.getNetworkType())) {
+                    tunnelId = BigInteger.valueOf(prefixInfo.getSegmentationId());
+                } else {
+                    LOG.warn("Network is not of type VXLAN for prefix {}."
                         + "Going with default Lport Tag.", prefixInfo.toString());
-                tunnelId = BigInteger.valueOf(label);
-            }
-            List<ActionInfo> actionInfos = new ArrayList<>();
-            actionInfos.add(new ActionSetFieldTunnelId(tunnelId));
-            String ifName = prefixInfo.getVpnInterfaceName();
-            String vpnName = fibUtil.getVpnNameFromId(vpnId);
-            if (vpnName == null) {
-                return;
-            }
-            String macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, nextHopPrefixIp);
-            actionInfos.add(new ActionSetFieldEthernetDestination(actionInfos.size(),
+                    tunnelId = BigInteger.valueOf(label);
+                }
+                List<ActionInfo> actionInfos = new ArrayList<>();
+                actionInfos.add(new ActionSetFieldTunnelId(tunnelId));
+                String ifName = prefixInfo.getVpnInterfaceName();
+                String vpnName = fibUtil.getVpnNameFromId(vpnId);
+                if (vpnName == null) {
+                    return;
+                }
+                String macAddress = fibUtil.getMacAddressFromPrefix(ifName, vpnName, nextHopPrefixIp);
+                actionInfos.add(new ActionSetFieldEthernetDestination(actionInfos.size(),
                     new MacAddress(macAddress)));
-            List<ActionInfo> egressActions;
-            if (egressActionMap.containsKey(egressInterface)) {
-                egressActions = egressActionMap.get(egressInterface);
-            } else {
-                egressActions = getEgressActionsForInterface(egressInterface, actionInfos.size(), true);
-                egressActionMap.put(egressInterface, egressActions);
-            }
-            if (egressActions.isEmpty()) {
-                LOG.error("Failed to retrieve egress action for prefix {} route-paths {}"
-                        + " interface {}." + " Aborting remote FIB entry creation.",
+                List<ActionInfo> egressActions;
+                if (egressActionMap.containsKey(egressInterface)) {
+                    egressActions = egressActionMap.get(egressInterface);
+                } else {
+                    egressActions = getEgressActionsForInterface(egressInterface, actionInfos.size(), true);
+                    egressActionMap.put(egressInterface, egressActions);
+                }
+                if (egressActions.isEmpty()) {
+                    LOG.error("Failed to retrieve egress action for prefix {} route-paths {}"
+                            + " interface {}." + " Aborting remote FIB entry creation.",
                         vrfEntry.getDestPrefix(), vrfEntry.getRoutePaths(), egressInterface);
-            }
-            actionInfos.addAll(egressActions);
-            BucketInfo bucket = new BucketInfo(actionInfos);
-            bucket.setWeight(1);
-            listBucketInfo.add(bucket);
-        }));
+                }
+                actionInfos.addAll(egressActions);
+                BucketInfo bucket = new BucketInfo(actionInfos);
+                bucket.setWeight(1);
+                listBucketInfo.add(bucket);
+            }));
         LOG.trace("LOCAL: listbucket {}, rd {}, dpnId {}, routes {}", listBucketInfo, rd, dpnId, vpnExtraRoutes);
         return listBucketInfo;
     }
@@ -1097,7 +1101,7 @@ public class NexthopManager implements AutoCloseable {
                 LOG.warn("RPC Call to Get egress actions for interface {} returned with Errors {}",
                         interfaceName, rpcResult.getErrors());
             } else {
-                actions = nullToEmpty(rpcResult.getResult().getAction());
+                actions = rpcResult.getResult().nonnullAction();
             }
         } catch (InterruptedException | ExecutionException e) {
             LOG.warn("Exception when egress actions for interface {}", interfaceName, e);
@@ -1127,25 +1131,27 @@ public class NexthopManager implements AutoCloseable {
                 if (!dpnLbNextHops.isPresent()) {
                     return;
                 }
-                List<String> nextHopKeys = nullToEmpty(dpnLbNextHops.get().getNexthopKey());
-                for (String nextHopKey : nextHopKeys) {
-                    Optional<Nexthops> optionalNextHops = fibUtil.getNexthops(nextHopKey);
-                    if (!optionalNextHops.isPresent()) {
-                        return;
-                    }
-                    Nexthops nexthops = optionalNextHops.get();
-                    final String groupId = nexthops.getGroupId();
-                    final long groupIdValue = Long.parseLong(groupId);
-                    if (noOfDcGws > 1) {
-                        mdsalApiManager.removeBucket(confTx, dpnId, groupIdValue, bucketId);
-                    } else {
-                        LOG.trace("Removed LB group {} on dpn {}", groupIdValue, dpnId);
-                        mdsalApiManager.removeGroup(confTx, dpnId, groupIdValue);
-                        removeNextHopPointer(nextHopKey);
-                    }
-                    // When the DC-GW is removed from configuration.
-                    if (noOfDcGws != availableDcGws.size()) {
-                        FibUtil.removeOrUpdateNextHopInfo(dpnId, nextHopKey, groupId, nexthops, operTx);
+                List<String> nextHopKeys = dpnLbNextHops.get().getNexthopKey();
+                if (nextHopKeys != null) {
+                    for (String nextHopKey : nextHopKeys) {
+                        Optional<Nexthops> optionalNextHops = fibUtil.getNexthops(nextHopKey);
+                        if (!optionalNextHops.isPresent()) {
+                            return;
+                        }
+                        Nexthops nexthops = optionalNextHops.get();
+                        final String groupId = nexthops.getGroupId();
+                        final long groupIdValue = Long.parseLong(groupId);
+                        if (noOfDcGws > 1) {
+                            mdsalApiManager.removeBucket(confTx, dpnId, groupIdValue, bucketId);
+                        } else {
+                            LOG.trace("Removed LB group {} on dpn {}", groupIdValue, dpnId);
+                            mdsalApiManager.removeGroup(confTx, dpnId, groupIdValue);
+                            removeNextHopPointer(nextHopKey);
+                        }
+                        // When the DC-GW is removed from configuration.
+                        if (noOfDcGws != availableDcGws.size()) {
+                            FibUtil.removeOrUpdateNextHopInfo(dpnId, nextHopKey, groupId, nexthops, operTx);
+                        }
                     }
                 }
                 FibUtil.removeDpnIdToNextHopInfo(destinationIp, dpnId, operTx);
@@ -1167,22 +1173,24 @@ public class NexthopManager implements AutoCloseable {
             if (!dpnLbNextHops.isPresent()) {
                 return;
             }
-            List<String> nextHopKeys = nullToEmpty(dpnLbNextHops.get().getNexthopKey());
-            for (String nextHopKey : nextHopKeys) {
-                Optional<Nexthops> optionalNextHops = fibUtil.getNexthops(nextHopKey);
-                if (!optionalNextHops.isPresent()) {
-                    return;
-                }
-                Nexthops nexthops = optionalNextHops.get();
-                final String groupId = nexthops.getGroupId();
-                final long groupIdValue = Long.parseLong(groupId);
-                if (isTunnelUp) {
-                    Bucket bucket = buildBucketForDcGwLbGroup(destinationIp, dpnId, bucketId, tunnelType);
-                    LOG.trace("Added bucket {} to group {} on dpn {}.", bucket, groupId, dpnId);
-                    mdsalApiManager.addBucket(confTx, dpnId, groupIdValue, bucket);
-                } else {
-                    LOG.trace("Removed bucketId {} from group {} on dpn {}.", bucketId, groupId, dpnId);
-                    mdsalApiManager.removeBucket(confTx, dpnId, groupIdValue, bucketId);
+            List<String> nextHopKeys = dpnLbNextHops.get().getNexthopKey();
+            if (nextHopKeys != null) {
+                for (String nextHopKey : nextHopKeys) {
+                    Optional<Nexthops> optionalNextHops = fibUtil.getNexthops(nextHopKey);
+                    if (!optionalNextHops.isPresent()) {
+                        return;
+                    }
+                    Nexthops nexthops = optionalNextHops.get();
+                    final String groupId = nexthops.getGroupId();
+                    final long groupIdValue = Long.parseLong(groupId);
+                    if (isTunnelUp) {
+                        Bucket bucket = buildBucketForDcGwLbGroup(destinationIp, dpnId, bucketId, tunnelType);
+                        LOG.trace("Added bucket {} to group {} on dpn {}.", bucket, groupId, dpnId);
+                        mdsalApiManager.addBucket(confTx, dpnId, groupIdValue, bucket);
+                    } else {
+                        LOG.trace("Removed bucketId {} from group {} on dpn {}.", bucketId, groupId, dpnId);
+                        mdsalApiManager.removeBucket(confTx, dpnId, groupIdValue, bucketId);
+                    }
                 }
             }
         }), LOG, "Error updating load-balancing group");
index 02983c613e33dfa022f981adb78b4bef2ab05ff7..543166393206baab6cea37ed5aa7b97c9174b2a7 100755 (executable)
@@ -11,7 +11,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.genius.mdsalutil.NWUtil.isIpv4Address;
-import static org.opendaylight.netvirt.fibmanager.FibUtil.nullToEmpty;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -37,6 +36,7 @@ import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
@@ -505,7 +505,8 @@ public class VrfEntryListener extends AsyncDataTreeChangeListenerBase<VrfEntry,
         LabelRouteInfoBuilder builder = new LabelRouteInfoBuilder(lri);
         if (!isPresentInList) {
             LOG.debug("vpnName {} is not present in LRI with label {}..", vpnInstanceName, lri.getLabel());
-            List<String> vpnInstanceNames = new ArrayList<>(nullToEmpty(lri.getVpnInstanceList()));
+            List<String> vpnInstanceNames =
+                lri.getVpnInstanceList() != null ? new ArrayList<>(lri.getVpnInstanceList()) : new ArrayList<>();
             vpnInstanceNames.add(vpnInstanceName);
             builder.setVpnInstanceList(vpnInstanceNames);
             MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, lriId, builder.build());
@@ -817,7 +818,8 @@ public class VrfEntryListener extends AsyncDataTreeChangeListenerBase<VrfEntry,
                                     fibUtil.getVpnInstanceOpData(rd);
                             if (vpnInstanceOpDataEntryOptional.isPresent()) {
                                 String vpnInstanceName = vpnInstanceOpDataEntryOptional.get().getVpnInstanceName();
-                                if (nullToEmpty(lri.getVpnInstanceList()).contains(vpnInstanceName)) {
+                                if (lri.getVpnInstanceList() != null && lri.getVpnInstanceList().contains(
+                                       vpnInstanceName)) {
                                     localNextHopInfo = updateVpnReferencesInLri(lri, vpnInstanceName, true);
                                     localNextHopIP = lri.getPrefix();
                                 } else {
@@ -1258,8 +1260,8 @@ public class VrfEntryListener extends AsyncDataTreeChangeListenerBase<VrfEntry,
             List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
             String usedRd = usedRds.isEmpty() ? primaryRd : usedRds.get(0);
             Routes extraRoute = baseVrfEntryHandler.getVpnToExtraroute(vpnId, usedRd, vrfEntry.getDestPrefix());
-            if (extraRoute != null) {
-                for (String nextHopIp : nullToEmpty(extraRoute.getNexthopIpList())) {
+            if (extraRoute != null && extraRoute.getNexthopIpList() != null) {
+                for (String nextHopIp : extraRoute.getNexthopIpList()) {
                     LOG.debug("NextHop IP for destination {} is {}", vrfEntry.getDestPrefix(), nextHopIp);
                     if (nextHopIp != null) {
                         String ipPrefix;
@@ -1448,8 +1450,9 @@ public class VrfEntryListener extends AsyncDataTreeChangeListenerBase<VrfEntry,
             return;
         }
 
-        if (nullToEmpty(optAdjacencies.get().getAdjacency()).size() <= 2
-                && nullToEmpty(optAdjacencies.get().getAdjacency()).stream().allMatch(adjacency ->
+        @NonNull List<Adjacency> adjacencies = optAdjacencies.get().nonnullAdjacency();
+        if (adjacencies.size() <= 2
+                && adjacencies.stream().allMatch(adjacency ->
                 adjacency.getAdjacencyType() == Adjacency.AdjacencyType.PrimaryAdjacency
                         && adjacency.isMarkedForDeletion() != null
                         && adjacency.isMarkedForDeletion()
@@ -1677,7 +1680,7 @@ public class VrfEntryListener extends AsyncDataTreeChangeListenerBase<VrfEntry,
                 lock.lock();
                 try {
                     futures.add(retryingTxRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
-                        for (final VrfEntry vrfEntry : nullToEmpty(vrfTable.get().getVrfEntry())) {
+                        for (final VrfEntry vrfEntry : vrfTable.get().nonnullVrfEntry()) {
                             SubnetRoute subnetRoute = vrfEntry.augmentation(SubnetRoute.class);
                             if (subnetRoute != null) {
                                 long elanTag = subnetRoute.getElantag();
@@ -1757,7 +1760,7 @@ public class VrfEntryListener extends AsyncDataTreeChangeListenerBase<VrfEntry,
                     final ReentrantLock lock = lockFor(vpnInstance);
                     lock.lock();
                     try {
-                        nullToEmpty(vrfTable.get().getVrfEntry()).stream()
+                        vrfTable.get().nonnullVrfEntry().stream()
                             .filter(vrfEntry -> RouteOrigin.BGP == RouteOrigin.value(vrfEntry.getOrigin()))
                             .forEach(bgpRouteVrfEntryHandler.getConsumerForCreatingRemoteFib(dpnId, vpnId,
                                 rd, remoteNextHopIp, vrfTable, TransactionAdapter.toWriteTransaction(tx), txnObjects));
@@ -1850,7 +1853,7 @@ public class VrfEntryListener extends AsyncDataTreeChangeListenerBase<VrfEntry,
                     try {
                         futures.add(retryingTxRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
                             String vpnName = fibUtil.getVpnNameFromId(vpnInstance.getVpnId());
-                            for (final VrfEntry vrfEntry : nullToEmpty(vrfTable.get().getVrfEntry())) {
+                            for (final VrfEntry vrfEntry : vrfTable.get().nonnullVrfEntry()) {
                                 /* parentRd is only filled for external PNF cases where the interface on the external
                                  * network VPN are used to cleanup the flows. For all other cases, use "rd" for
                                  * #fibUtil.isInterfacePresentInDpn().
@@ -1970,7 +1973,7 @@ public class VrfEntryListener extends AsyncDataTreeChangeListenerBase<VrfEntry,
                     try {
                         return Collections.singletonList(
                             txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
-                                tx -> nullToEmpty(vrfTable.get().getVrfEntry()).stream()
+                                tx -> vrfTable.get().nonnullVrfEntry().stream()
                                     .filter(vrfEntry -> RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP)
                                     .forEach(bgpRouteVrfEntryHandler.getConsumerForDeletingRemoteFib(dpnId, vpnId,
                                         remoteNextHopIp, vrfTable, TransactionAdapter.toWriteTransaction(tx),