Handle nullable lists in neutronvpn 30/77030/2
authorStephen Kitt <skitt@redhat.com>
Tue, 16 Oct 2018 08:40:44 +0000 (10:40 +0200)
committerSam Hague <shague@redhat.com>
Tue, 16 Oct 2018 20:47:15 +0000 (20:47 +0000)
Following YANGTOOLS-585, lists can be null (which is correctly
indicated with an @Nullable annotation). This patch deals with the
fallout.

Change-Id: I8b730d8b7af405cf430534c90d3fb0990c32850d
Signed-off-by: Stephen Kitt <skitt@redhat.com>
15 files changed:
neutronvpn/api/src/main/java/org/opendaylight/netvirt/neutronvpn/api/l2gw/L2GatewayDevice.java
neutronvpn/api/src/main/java/org/opendaylight/netvirt/neutronvpn/api/utils/NeutronUtils.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronExternalSubnetHandler.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronFloatingToFixedIpMappingChangeListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronHostConfigChangeListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronNetworkChangeListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronPortChangeListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronSubnetGwMacResolver.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnNatManager.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/evpn/manager/NeutronEvpnManager.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/evpn/utils/NeutronEvpnUtils.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/l2gw/L2GatewayListener.java
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/l2gw/L2GwTransportZoneListener.java

index 988f626dbac966686335b15ba715d75d9073d68a..00c1f4115c35b53389beb0df4d0be9a34c465e4a 100644 (file)
@@ -19,6 +19,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
@@ -94,6 +95,7 @@ public class L2GatewayDevice {
      *
      * @return the tunnel ip
      */
+    @Nullable
     public IpAddress getTunnelIp() {
         if (!tunnelIps.isEmpty()) {
             return tunnelIps.iterator().next();
index 92ca17d78ba2caaf878ceaceccbbcf529cc232d3..332129e2d34af7928511a0cf26d3160fe6f50420 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.netvirt.neutronvpn.api.utils;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.Preconditions;
 import java.util.Collections;
 import java.util.List;
@@ -15,6 +17,8 @@ import java.util.Locale;
 import java.util.Objects;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
@@ -219,7 +223,8 @@ public final class NeutronUtils {
         }
     }
 
-    public static List<Uuid> getVpnMapRouterIdsListUuid(List<RouterIds> routerIds) {
+    @Nonnull
+    public static List<Uuid> getVpnMapRouterIdsListUuid(@Nullable List<RouterIds> routerIds) {
         if (routerIds == null) {
             return Collections.emptyList();
         }
@@ -227,4 +232,9 @@ public final class NeutronUtils {
             routerId -> routerId.getRouterId()).collect(Collectors.toList());
     }
 
+    // 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 b45b55754e695305cc738fe690164ca96b0d63f9..c3dc1dcfb537d40cfaf16d54ac931ea875d6fc8e 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netvirt.neutronvpn;
 
 import java.util.List;
 
+import javax.annotation.Nullable;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -37,7 +38,7 @@ public class NeutronExternalSubnetHandler implements AutoCloseable {
         LOG.info("{} close", getClass().getSimpleName());
     }
 
-    public void handleExternalSubnetAdded(Network network, Uuid subnetId, List<Uuid> routerIds) {
+    public void handleExternalSubnetAdded(Network network, Uuid subnetId, @Nullable List<Uuid> routerIds) {
         Uuid networkId = network.getUuid();
         if (NeutronvpnUtils.getIsExternal(network) && NeutronvpnUtils.isFlatOrVlanNetwork(network)) {
             LOG.info("Added external subnet {} part of external network {} will create NAT external subnet",
index c1d6176fb169b0ca2b2cc75eab9ad1dbef2567b7..d7fadd8eb19d47dc70c15291c1e6e34ca52edd66 100644 (file)
@@ -8,10 +8,13 @@
 package org.opendaylight.netvirt.neutronvpn;
 
 import static org.opendaylight.netvirt.neutronvpn.NeutronvpnUtils.buildfloatingIpIdToPortMappingIdentifier;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -205,11 +208,12 @@ public class NeutronFloatingToFixedIpMappingChangeListener extends AsyncDataTree
                             routerPortsIdentifierBuilder.build());
             if (optionalRouterPorts.isPresent()) {
                 RouterPorts routerPorts = optionalRouterPorts.get();
-                List<Ports> portsList = routerPorts.getPorts();
+                List<Ports> portsList = requireNonNullElse(routerPorts.getPorts(), Collections.emptyList());
                 List<InternalToExternalPortMap> intExtPortMap = new ArrayList<>();
                 for (Ports ports : portsList) {
-                    if (ports.getPortName().equals(fixedNeutronPortName)) {
-                        intExtPortMap = ports.getInternalToExternalPortMap();
+                    if (Objects.equals(ports.getPortName(), fixedNeutronPortName)) {
+                        intExtPortMap =
+                            requireNonNullElse(ports.getInternalToExternalPortMap(), Collections.emptyList());
                         break;
                     }
                 }
@@ -218,7 +222,7 @@ public class NeutronFloatingToFixedIpMappingChangeListener extends AsyncDataTree
                             fixedNeutronPortName, isLockAcquired);
                 } else {
                     for (InternalToExternalPortMap intToExtMap : intExtPortMap) {
-                        if (intToExtMap.getInternalIp().equals(fixedIpAddress)) {
+                        if (Objects.equals(intToExtMap.getInternalIp(), fixedIpAddress)) {
                             InstanceIdentifier<InternalToExternalPortMap> intExtPortMapIdentifier =
                                     routerPortsIdentifierBuilder.child(Ports
                                     .class, new PortsKey(fixedNeutronPortName)).child(InternalToExternalPortMap.class,
@@ -264,7 +268,7 @@ public class NeutronFloatingToFixedIpMappingChangeListener extends AsyncDataTree
                         List<Ports> portsList = routerPorts.getPorts();
                         if (portsList != null && !portsList.isEmpty()) {
                             for (Ports ports : portsList) {
-                                if (ports.getPortName().equals(fixedNeutronPortName)) {
+                                if (Objects.equals(ports.getPortName(), fixedNeutronPortName)) {
                                     String routerName = routerPorts.getRouterId();
                                     InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts>
                                         routerPortsIdentifierBuilder = floatingIpInfoIdentifierBuilder
index 12a62a44967a58a883a6cadb294fd86b9bc34790..0475f8347e7323bb0fcfaf11033e0f0634946ca5 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netvirt.neutronvpn;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
+import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -163,6 +164,7 @@ public class NeutronHostConfigChangeListener
         return hostconfigBuilder.build();
     }
 
+    @Nullable
     private String getExternalId(Node node, String key) {
         OvsdbNodeAugmentation ovsdbNode = getOvsdbNodeAugmentation(node);
         if (ovsdbNode != null && ovsdbNode.getOpenvswitchExternalIds() != null) {
@@ -175,6 +177,7 @@ public class NeutronHostConfigChangeListener
         return null;
     }
 
+    @Nullable
     private OvsdbNodeAugmentation getOvsdbNodeAugmentation(Node node) {
         OvsdbNodeAugmentation ovsdbNode = southboundUtils.extractOvsdbNode(node);
         if (ovsdbNode == null) {
index b8262d74b9150b31fa88603f85d177d286290ce3..97af8e286174ca8a493bda1ac51452046da8a22a 100644 (file)
@@ -13,6 +13,7 @@ import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -214,8 +215,9 @@ public class NeutronNetworkChangeListener
         return 0L;
     }
 
+    @Nullable
     private Class<? extends SegmentTypeBase> elanSegmentTypeFromNetworkType(
-            Class<? extends NetworkTypeBase> networkType) {
+            @Nullable Class<? extends NetworkTypeBase> networkType) {
         if (networkType == null) {
             return null;
         }
index c015a5de9e70eadf9b4fa7351ac5746976386ed6..db11a13578ae05d02c5d2802d42533c597df7493 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.neutronvpn;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Strings;
@@ -25,6 +26,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
+import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.inject.Singleton;
 import org.apache.commons.lang3.ObjectUtils;
@@ -267,9 +269,9 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         }
     }
 
-    private void handleFloatingIpPortUpdated(Port original, Port update) {
-        if ((original == null || original.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING))
-            && !update.getDeviceId().equals(NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING)) {
+    private void handleFloatingIpPortUpdated(@Nullable Port original, Port update) {
+        if ((original == null || NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equals(original.getDeviceId()))
+            && !NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equals(update.getDeviceId())) {
             // populate floating-ip uuid and floating-ip port attributes (uuid, mac and subnet id for the ONLY
             // fixed IP) to be used by NAT, depopulated in NATService once mac is retrieved in the removal path
             addToFloatingIpPortInfo(new Uuid(update.getDeviceId()), update.getUuid(), update.getFixedIps().get(0)
@@ -294,9 +296,9 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                 listVpnIds.add(vpnId);
                 Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
                 List<Subnetmap> subnetMapList = new ArrayList<>();
-                List<FixedIps> portIps = routerPort.getFixedIps();
                 boolean portIsIpv6 = false;
-                for (FixedIps portIP : portIps) {
+                for (FixedIps portIP : requireNonNullElse(routerPort.getFixedIps(),
+                        Collections.<FixedIps>emptyList())) {
                     // NOTE:  Please donot change the order of calls to updateSubnetNodeWithFixedIP
                     // and addSubnetToVpn here
                     if (internetVpnId != null
@@ -323,7 +325,8 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
                     nvpnManager.createVpnInterface(listVpnIds, routerPort, null);
                 }
                 IpVersionChoice ipVersion = IpVersionChoice.UNDEFINED;
-                for (FixedIps portIP : routerPort.getFixedIps()) {
+                for (FixedIps portIP : requireNonNullElse(routerPort.getFixedIps(),
+                        Collections.<FixedIps>emptyList())) {
                     String ipValue = portIP.getIpAddress().stringValue();
                     ipVersion = NeutronvpnUtils.getIpVersionFromString(ipValue);
                     if (ipVersion.isIpVersionChosen(IpVersionChoice.IPV4)) {
@@ -366,7 +369,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             elanService.removeKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
             Uuid vpnId = ObjectUtils.defaultIfNull(neutronvpnUtils.getVpnForRouter(routerId, true),
                     routerId);
-            List<FixedIps> portIps = routerPort.getFixedIps();
+            List<FixedIps> portIps = requireNonNullElse(routerPort.getFixedIps(), Collections.emptyList());
             boolean vpnInstanceInternetIpVersionRemoved = false;
             Uuid vpnInstanceInternetUuid = null;
             for (FixedIps portIP : portIps) {
@@ -516,6 +519,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId, builder.build());
     }
 
+    @Nullable
     private String getPortHostId(final Port port) {
         if (port != null) {
             PortBindingExtension portBinding = port.augmentation(PortBindingExtension.class);
@@ -526,6 +530,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         return null;
     }
 
+    @Nullable
     private Hostconfig getHostConfig(final Port port) {
         String hostId = getPortHostId(port);
         if (hostId == null) {
@@ -538,7 +543,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             LOG.error("failed to read host config from host {}", hostId, e);
             return null;
         }
-        return hostConfig.isPresent() ? hostConfig.get() : null;
+        return hostConfig.orNull();
     }
 
     private boolean isPortBound(final Port port) {
@@ -565,13 +570,14 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
         return false;
     }
 
+    @Nullable
     private Map<String, JsonElement> unmarshal(final String profile) {
         if (null == profile) {
             return null;
         }
         Gson gson = new Gson();
         JsonObject jsonObject = gson.fromJson(profile, JsonObject.class);
-        Map<String, JsonElement> map = new HashMap();
+        Map<String, JsonElement> map = new HashMap<>();
         for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) {
             map.put(entry.getKey(), entry.getValue());
         }
@@ -608,7 +614,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     private void handleNeutronPortCreated(final Port port) {
         final String portName = port.getUuid().getValue();
         final Uuid portId = port.getUuid();
-        final List<FixedIps> portIpAddrsList = port.getFixedIps();
+        final List<FixedIps> portIpAddrsList = requireNonNullElse(port.getFixedIps(), Collections.emptyList());
         if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
             return;
         }
@@ -669,7 +675,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
     private void handleNeutronPortDeleted(final Port port) {
         final String portName = port.getUuid().getValue();
         final Uuid portId = port.getUuid();
-        final List<FixedIps> portIpsList = port.getFixedIps();
+        final List<FixedIps> portIpsList = requireNonNullElse(port.getFixedIps(), Collections.emptyList());
         jobCoordinator.enqueueJob("PORT- " + portName,
             () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
                 if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
@@ -812,6 +818,7 @@ public class NeutronPortChangeListener extends AsyncDataTreeChangeListenerBase<P
             })));
     }
 
+    @Nullable
     private InterfaceAclBuilder handlePortSecurityUpdated(Port portOriginal,
             Port portUpdated, boolean origSecurityEnabled, boolean updatedSecurityEnabled,
             InterfaceBuilder interfaceBuilder) {
index f7566dfc0dd45deb0ce9e3eb152f1e2a20a1fc1a..3f9ee75d05e464e3ea2f3e950856374a9a15bfa5 100644 (file)
@@ -16,6 +16,7 @@ import java.util.List;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
@@ -164,6 +165,7 @@ public class NeutronSubnetGwMacResolver {
         }
     }
 
+    @Nullable
     private Port getRouterExtGatewayPort(Router router) {
         if (router == null) {
             LOG.trace("Router is null");
@@ -179,6 +181,7 @@ public class NeutronSubnetGwMacResolver {
         return neutronvpnUtils.getNeutronPort(extPortId);
     }
 
+    @Nullable
     private String getExternalInterface(Router router) {
         ExternalGatewayInfo extGatewayInfo = router.getExternalGatewayInfo();
         String routerName = router.getUuid().getValue();
@@ -202,6 +205,7 @@ public class NeutronSubnetGwMacResolver {
         return elanService.getExternalElanInterface(extNetworkId.getValue(), primarySwitch);
     }
 
+    @Nullable
     private IpAddress getExternalGwIpAddress(Uuid subnetId) {
         if (subnetId == null) {
             LOG.error("Subnet id is null");
index 35ac3c895df3a04b8be9d21cc6e19d0eff6b9190..00a145aeed9492c9a01898bce8a4a8e172ee020e 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netvirt.neutronvpn;
 import static java.util.Collections.singletonList;
 import static org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.syncReadOptional;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -47,7 +48,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
-import org.opendaylight.genius.infra.Datastore;
+import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.infra.TypedWriteTransaction;
@@ -255,7 +256,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
     protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId,
-                                       NetworkAttributes.NetworkType networkType, long segmentationId) {
+                                       @Nullable NetworkAttributes.NetworkType networkType, long segmentationId) {
         try {
             InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
             synchronized (subnetId.getValue().intern()) {
@@ -288,9 +289,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    protected Subnetmap updateSubnetNode(Uuid subnetId, Uuid routerId, Uuid vpnId, Uuid internetvpnId) {
-        Subnetmap subnetmap = null;
-        SubnetmapBuilder builder = null;
+    @Nullable
+    protected Subnetmap updateSubnetNode(Uuid subnetId, @Nullable Uuid routerId, Uuid vpnId,
+            @Nullable Uuid internetvpnId) {
         InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
                 .child(Subnetmap.class, new SubnetmapKey(subnetId))
                 .build();
@@ -299,13 +300,12 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 Optional<Subnetmap> sn =
                         SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
                                 id);
-                if (sn.isPresent()) {
-                    builder = new SubnetmapBuilder(sn.get());
-                    LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
-                } else {
+                if (!sn.isPresent()) {
                     LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
                     return null;
                 }
+                LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
+                SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
                 if (routerId != null) {
                     builder.setRouterId(routerId);
                 }
@@ -314,21 +314,20 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 }
                 builder.setInternetVpnId(internetvpnId);
 
-                subnetmap = builder.build();
+                Subnetmap subnetmap = builder.build();
                 LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
                 SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
+                return subnetmap;
             }
         } catch (ReadFailedException | TransactionCommitFailedException e) {
             LOG.error("Subnet map update failed for node {}", subnetId.getValue(), e);
+            return null;
         }
-        return subnetmap;
     }
 
-    protected void updateSubnetNodeWithFixedIp(Uuid subnetId, Uuid routerId,
-                                               Uuid routerInterfacePortId, String fixedIp,
-                                               String routerIntfMacAddress, Uuid vpnId) {
-        Subnetmap subnetmap = null;
-        SubnetmapBuilder builder = null;
+    protected void updateSubnetNodeWithFixedIp(Uuid subnetId, @Nullable Uuid routerId,
+                                               @Nullable Uuid routerInterfacePortId, @Nullable String fixedIp,
+                                               @Nullable String routerIntfMacAddress, @Nullable Uuid vpnId) {
         InstanceIdentifier<Subnetmap> id =
             InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
         try {
@@ -336,15 +335,14 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 Optional<Subnetmap> sn =
                         SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
                                 id);
-                if (sn.isPresent()) {
-                    builder = new SubnetmapBuilder(sn.get());
-                    LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}",
-                        subnetId.getValue());
-                } else {
+                if (!sn.isPresent()) {
                     LOG.error("WithRouterFixedIP: subnetmap node for subnet {} does not exist, returning ",
                         subnetId.getValue());
                     return;
                 }
+                LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}",
+                    subnetId.getValue());
+                SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
                 builder.setRouterId(routerId);
                 builder.setRouterInterfacePortId(routerInterfacePortId);
                 builder.setRouterIntfMacAddress(routerIntfMacAddress);
@@ -352,7 +350,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                 if (vpnId != null) {
                     builder.setVpnId(vpnId);
                 }
-                subnetmap = builder.build();
+                Subnetmap subnetmap = builder.build();
                 LOG.debug("WithRouterFixedIP Creating/Updating subnetMap node for Router FixedIp: {} ",
                     subnetId.getValue());
                 SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
@@ -363,7 +361,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    protected Subnetmap updateSubnetmapNodeWithPorts(Uuid subnetId, Uuid portId, Uuid directPortId) {
+    protected Subnetmap updateSubnetmapNodeWithPorts(Uuid subnetId, @Nullable Uuid portId,
+            @Nullable Uuid directPortId) {
         Subnetmap subnetmap = null;
         InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,
                 new SubnetmapKey(subnetId)).build();
@@ -410,8 +409,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         return subnetmap;
     }
 
-    protected Subnetmap removeFromSubnetNode(Uuid subnetId, Uuid networkId, Uuid routerId,
-                                            Uuid vpnId, Uuid portId) {
+    protected Subnetmap removeFromSubnetNode(Uuid subnetId, @Nullable Uuid networkId, @Nullable Uuid routerId,
+                                            Uuid vpnId, @Nullable Uuid portId) {
         Subnetmap subnetmap = null;
         InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
                 .child(Subnetmap.class, new SubnetmapKey(subnetId))
@@ -453,7 +452,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         return subnetmap;
     }
 
-    protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, Uuid portId, Uuid directPortId) {
+    @Nullable
+    protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, @Nullable Uuid portId,
+            @Nullable Uuid directPortId) {
         Subnetmap subnetmap = null;
         InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class,
                 new SubnetmapKey(subnetId)).build();
@@ -639,7 +640,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    protected void updateVpnMaps(Uuid vpnId, String name, Uuid router, Uuid tenantId, List<Uuid> networks) {
+    protected void updateVpnMaps(Uuid vpnId, @Nullable String name, @Nullable Uuid router, @Nullable Uuid tenantId,
+            @Nullable List<Uuid> networks) {
         VpnMapBuilder builder;
         boolean isLockAcquired = false;
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
@@ -694,7 +696,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    private void clearFromVpnMaps(Uuid vpnId, Uuid routerId, List<Uuid> networkIds) {
+    private void clearFromVpnMaps(Uuid vpnId, @Nullable Uuid routerId, @Nullable List<Uuid> networkIds) {
         boolean isLockAcquired = false;
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
                 .child(VpnMap.class, new VpnMapKey(vpnId))
@@ -788,15 +790,15 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     protected Adjacencies createPortIpAdjacencies(Port port, Boolean isRouterInterface,
-                                                  TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn,
-                                                  Subnetmap sn, VpnInterface vpnIface) {
+                                                  TypedWriteTransaction<Configuration> wrtConfigTxn,
+                                                  @Nullable Subnetmap sn, @Nullable VpnInterface vpnIface) {
         List<Adjacency> adjList = new ArrayList<>();
         if (vpnIface != null) {
             adjList = vpnIface.augmentation(Adjacencies.class).getAdjacency();
         }
         String infName = port.getUuid().getValue();
         LOG.trace("neutronVpnManager: create config adjacencies for Port: {}", infName);
-        for (FixedIps ip : port.getFixedIps()) {
+        for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
             String ipValue = ip.getIpAddress().stringValue();
             String ipPrefix = ip.getIpAddress().getIpv4Address() != null ? ipValue + "/32" : ipValue + "/128";
             if (sn != null && !FibHelper.doesPrefixBelongToSubnet(ipPrefix, sn.getSubnetIp(), false)) {
@@ -838,7 +840,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     protected void createVpnInterface(Collection<Uuid> vpnIds, Port port,
-                                      TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+                                      @Nullable TypedWriteTransaction<Configuration> wrtConfigTxn) {
         boolean isRouterInterface = false;
         if (port.getDeviceOwner() != null) {
             isRouterInterface = NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(port.getDeviceOwner());
@@ -850,7 +852,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     protected void withdrawPortIpFromVpnIface(Uuid vpnId, Uuid internetVpnId,
-                       Port port, Subnetmap sn, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+                       Port port, Subnetmap sn, TypedWriteTransaction<Configuration> wrtConfigTxn) {
         String infName = port.getUuid().getValue();
         InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
         Optional<VpnInterface> optionalVpnInterface = null;
@@ -869,7 +871,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
         LOG.trace("withdraw adjacencies for Port: {} subnet {}", port.getUuid().getValue(),
                 sn != null ? sn.getSubnetIp() : "null");
-        List<Adjacency> vpnAdjsList = optionalVpnInterface.get().augmentation(Adjacencies.class).getAdjacency();
+        List<Adjacency> vpnAdjsList =
+            requireNonNullElse(optionalVpnInterface.get().augmentation(Adjacencies.class).getAdjacency(),
+                Collections.emptyList());
         List<Adjacency> updatedAdjsList = new ArrayList<>();
         boolean isIpFromAnotherSubnet = false;
         for (Adjacency adj : vpnAdjsList) {
@@ -893,8 +897,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                           String.valueOf(adjString), wrtConfigTxn);
                 }
             } else {
-                if (port.getDeviceOwner()
-                    .equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF) && sn.getRouterId() != null) {
+                if (NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(port.getDeviceOwner())
+                        && sn.getRouterId() != null) {
                     Router rtr = neutronvpnUtils.getNeutronRouter(sn.getRouterId());
                     if (rtr != null && rtr.getRoutes() != null) {
                         List<Routes> extraRoutesToRemove = new ArrayList<>();
@@ -931,7 +935,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
     protected void deleteVpnInterface(String infName, @Nullable String vpnId,
-                                      TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+                                      @Nullable TypedWriteTransaction<Configuration> wrtConfigTxn) {
         if (wrtConfigTxn == null) {
             ListenableFutures.addErrorLogging(
                     txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
@@ -977,7 +981,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     protected void removeInternetVpnFromVpnInterface(Uuid vpnId, Port port,
-                                             TypedWriteTransaction<Datastore.Configuration> writeConfigTxn,
+                                             TypedWriteTransaction<Configuration> writeConfigTxn,
                                              Subnetmap sm) {
         if (vpnId == null || port == null) {
             return;
@@ -1022,8 +1026,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                                 mipToQuery, infName, vpnId.getValue());
                     }
                 }
-                List<FixedIps> ips = port.getFixedIps();
-                for (FixedIps ip : ips) {
+                for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
                     String ipValue = ip.getIpAddress().stringValue();
                     //skip IPv4 address
                     if (!NeutronvpnUtils.getIpVersionFromString(ipValue).isIpVersionChosen(IpVersionChoice.IPV6)) {
@@ -1048,9 +1051,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    protected void updateVpnInterface(Uuid vpnId, Uuid oldVpnId, Port port, boolean isBeingAssociated,
+    protected void updateVpnInterface(Uuid vpnId, @Nullable Uuid oldVpnId, Port port, boolean isBeingAssociated,
                                       boolean isSubnetIp,
-                                      TypedWriteTransaction<Datastore.Configuration> writeConfigTxn) {
+                                      TypedWriteTransaction<Configuration> writeConfigTxn) {
         if (vpnId == null || port == null) {
             return;
         }
@@ -1104,8 +1107,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                     Adjacencies adjacencies = new AdjacenciesBuilder().setAdjacency(adjacencyList).build();
                     vpnIfBuilder.addAugmentation(Adjacencies.class, adjacencies);
                 }
-                List<FixedIps> ips = port.getFixedIps();
-                for (FixedIps ip : ips) {
+                for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
                     String ipValue = ip.getIpAddress().stringValue();
                     if (oldVpnId != null) {
                         neutronvpnUtils.removeVpnPortFixedIpToPort(oldVpnId.getValue(),
@@ -1127,8 +1129,9 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    public void createL3InternalVpn(Uuid vpn, String name, Uuid tenant, List<String> rd, List<String> irt,
-                                    List<String> ert, Uuid router, List<Uuid> networks) {
+    public void createL3InternalVpn(Uuid vpn, @Nullable String name, @Nullable Uuid tenant, @Nullable List<String> rd,
+            @Nullable List<String> irt, @Nullable List<String> ert, @Nullable Uuid router,
+            @Nullable List<Uuid> networks) {
 
         IpVersionChoice ipVersChoices = neutronvpnUtils.getIpVersionChoicesFromRouterUuid(router);
 
@@ -1172,7 +1175,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
      * @throws Exception if association of L3VPN failed
      */
     public void createVpn(Uuid vpnId, String name, Uuid tenantId, List<String> rdList, List<String> irtList,
-                    List<String> ertList,  @Nullable List<Uuid> routerIdsList, List<Uuid> networkList,
+                    List<String> ertList,  @Nullable List<Uuid> routerIdsList, @Nullable List<Uuid> networkList,
                     VpnInstance.Type type, long l3vni) throws Exception {
 
         IpVersionChoice ipVersChoices = IpVersionChoice.UNDEFINED;
@@ -1380,7 +1383,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
                         SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION,
                                 vpnsIdentifier);
                 if (optionalVpns.isPresent() && !optionalVpns.get().getVpnInstance().isEmpty()) {
-                    for (VpnInstance vpn : optionalVpns.get().getVpnInstance()) {
+                    for (VpnInstance vpn : requireNonNullElse(optionalVpns.get().getVpnInstance(),
+                            Collections.<VpnInstance>emptyList())) {
                         // eliminating implicitly created (router and VLAN provider external network specific) VPNs
                         // from getL3VPN output
                         if (vpn.getIpv4Family().getRouteDistinguisher() != null) {
@@ -1501,10 +1505,8 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
 
         int failurecount = 0;
         int warningcount = 0;
-        List<Uuid> vpns = input.getId();
+        List<Uuid> vpns = requireNonNullElse(input.getId(), Collections.emptyList());
         for (Uuid vpn : vpns) {
-            RpcError error;
-            String msg;
             try {
                 LOG.debug("L3VPN delete RPC: VpnID {}", vpn.getValue());
                 InstanceIdentifier<VpnInstance> vpnIdentifier =
@@ -1638,7 +1640,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
-    protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet, Uuid internetVpnId) {
+    protected void removeSubnetFromVpn(final Uuid vpnId, Uuid subnet, @Nullable Uuid internetVpnId) {
         Preconditions.checkArgument(vpnId != null || internetVpnId != null,
                 "removeSubnetFromVpn: at least one VPN must be not null");
         LOG.debug("Removing subnet {} from vpn {}/{}", subnet.getValue(),
@@ -1762,6 +1764,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         }
     }
 
+    @Nullable
     private Subnetmap updateVpnForSubnet(Uuid oldVpnId, Uuid newVpnId, Uuid subnet, boolean isBeingAssociated) {
         LOG.debug("Moving subnet {} from oldVpn {} to newVpn {} ", subnet.getValue(),
                 oldVpnId.getValue(), newVpnId.getValue());
@@ -2727,8 +2730,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             List<String> fixedIPList = new ArrayList<>();
             Port port = neutronvpnUtils.getNeutronPort(portId);
             if (port != null) {
-                List<FixedIps> fixedIPs = port.getFixedIps();
-                for (FixedIps ip : fixedIPs) {
+                for (FixedIps ip : requireNonNullElse(port.getFixedIps(), Collections.<FixedIps>emptyList())) {
                     fixedIPList.add(ip.getIpAddress().stringValue());
                 }
             } else {
@@ -2891,6 +2893,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
         return neutronvpnUtils.getNeutronSubnet(subnetId);
     }
 
+    @Nullable
     protected IpAddress getNeutronSubnetGateway(Uuid subnetId) {
         Subnet sn = neutronvpnUtils.getNeutronSubnet(subnetId);
         if (null != sn) {
@@ -2935,7 +2938,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
 
         Optional<Ports> ports = syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, portidentifier);
         if (ports.isPresent() && ports.get().getPort() != null) {
-            for (Port port : ports.get().getPort()) {
+            for (Port port : requireNonNullElse(ports.get().getPort(), Collections.<Port>emptyList())) {
                 List<FixedIps> fixedIPs = port.getFixedIps();
                 if (fixedIPs != null && !fixedIPs.isEmpty()) {
                     List<String> ipList = new ArrayList<>();
@@ -2989,9 +2992,10 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
             result.add("");
             result.add("------------------------------------------------------------------------------------");
             result.add("");
-            List<L3vpnInstances> vpnList = rpcResult.getResult().getL3vpnInstances();
-            for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn
-                    .rev150602.VpnInstance vpn : vpnList) {
+            for (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnInstance vpn :
+                    requireNonNullElse(rpcResult.getResult().getL3vpnInstances(),
+                        Collections.<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602
+                            .VpnInstance>emptyList())) {
                 String tenantId = vpn.getTenantId() != null ? vpn.getTenantId().getValue()
                         : "\"                 " + "                  \"";
                 result.add(String.format(" %-37s %-37s %-7s ", vpn.getId().getValue(), tenantId,
@@ -3069,15 +3073,16 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     private void createExternalVpnInterface(Uuid vpnId, String infName,
-                                            TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+                                            TypedWriteTransaction<Configuration> wrtConfigTxn) {
         writeVpnInterfaceToDs(Collections.singletonList(vpnId), infName, null, vpnId /* external network id */,
                 false /* not a router iface */, wrtConfigTxn);
     }
 
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
-    private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName, Adjacencies adjacencies,
-            Uuid networkUuid, Boolean isRouterInterface, TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+    private void writeVpnInterfaceToDs(@Nonnull Collection<Uuid> vpnIdList, String infName,
+            @Nullable Adjacencies adjacencies, Uuid networkUuid, Boolean isRouterInterface,
+            TypedWriteTransaction<Configuration> wrtConfigTxn) {
         if (vpnIdList.isEmpty() || infName == null) {
             LOG.error("vpnid is empty or interface({}) is null", infName);
             return;
@@ -3124,7 +3129,7 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
     }
 
     private void updateVpnInterfaceWithAdjacencies(Uuid vpnId, String infName, Adjacencies adjacencies,
-                                                   TypedWriteTransaction<Datastore.Configuration> wrtConfigTxn) {
+                                                   TypedWriteTransaction<Configuration> wrtConfigTxn) {
         if (vpnId == null || infName == null) {
             LOG.error("vpn id or interface is null");
             return;
index c800f4988b48015206ad30b560c57e2a460bb6dc..200d13288785e72e8705da889ffa5a6db7bbd5a9 100644 (file)
@@ -7,14 +7,18 @@
  */
 package org.opendaylight.netvirt.neutronvpn;
 
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
+
 import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
+import javax.annotation.Nullable;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -90,7 +94,7 @@ public class NeutronvpnNatManager implements AutoCloseable {
         LOG.info("{} close", getClass().getSimpleName());
     }
 
-    public void handleExternalNetworkForRouter(Router original, Router update) {
+    public void handleExternalNetworkForRouter(@Nullable Router original, Router update) {
         Uuid routerId = update.getUuid();
         Uuid origExtNetId = null;
         Uuid updExtNetId = null;
@@ -470,7 +474,8 @@ public class NeutronvpnNatManager implements AutoCloseable {
             builder.setEnableSnat(update.getExternalGatewayInfo().isEnableSnat());
 
             ArrayList<ExternalIps> externalIps = new ArrayList<>();
-            for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
+            for (ExternalFixedIps fixedIps : requireNonNullElse(update.getExternalGatewayInfo().getExternalFixedIps(),
+                    Collections.<ExternalFixedIps>emptyList())) {
                 addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
             }
             builder.setExternalIps(externalIps);
@@ -630,7 +635,7 @@ public class NeutronvpnNatManager implements AutoCloseable {
         }
     }
 
-    public void updateOrAddExternalSubnet(Uuid networkId, Uuid subnetId, List<Uuid> routerIds) {
+    public void updateOrAddExternalSubnet(Uuid networkId, Uuid subnetId, @Nullable List<Uuid> routerIds) {
         Optional<Subnets> optionalExternalSubnets = neutronvpnUtils.getOptionalExternalSubnets(subnetId);
         if (optionalExternalSubnets.isPresent()) {
             LOG.trace("Will update external subnet {} with networkId {} and routerIds {}",
@@ -656,7 +661,7 @@ public class NeutronvpnNatManager implements AutoCloseable {
         }
     }
 
-    public void updateExternalSubnet(Uuid networkId, Uuid subnetId, List<Uuid> routerIds) {
+    public void updateExternalSubnet(Uuid networkId, Uuid subnetId, @Nullable List<Uuid> routerIds) {
         InstanceIdentifier<Subnets> subnetsIdentifier = InstanceIdentifier.builder(ExternalSubnets.class)
                 .child(Subnets.class, new SubnetsKey(subnetId)).build();
         try {
@@ -701,7 +706,7 @@ public class NeutronvpnNatManager implements AutoCloseable {
         }
     }
 
-    private static Subnets createSubnets(Uuid subnetId, Uuid networkId, List<Uuid> routerIds) {
+    private static Subnets createSubnets(Uuid subnetId, Uuid networkId, @Nullable List<Uuid> routerIds) {
         SubnetsBuilder subnetsBuilder = new SubnetsBuilder();
         subnetsBuilder.withKey(new SubnetsKey(subnetId));
         subnetsBuilder.setId(subnetId);
index ba804acc39d21e73afdb1a2071f28eddd7380493..cacacf9844b29132bda550ebc5368a916bf2111d 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.netvirt.neutronvpn;
 
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableBiMap;
@@ -33,6 +34,7 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.apache.commons.lang3.StringUtils;
@@ -208,6 +210,7 @@ public class NeutronvpnUtils {
         this.ipV6InternetDefRt = ipV6InternetDefRt;
     }
 
+    @Nullable
     protected Subnetmap getSubnetmap(Uuid subnetId) {
         InstanceIdentifier<Subnetmap> id = buildSubnetMapIdentifier(subnetId);
         Optional<Subnetmap> sn = read(LogicalDatastoreType.CONFIGURATION, id);
@@ -219,6 +222,7 @@ public class NeutronvpnUtils {
         return null;
     }
 
+    @Nullable
     public VpnMap getVpnMap(Uuid id) {
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
                 new VpnMapKey(id)).build();
@@ -230,12 +234,13 @@ public class NeutronvpnUtils {
         return null;
     }
 
+    @Nullable
     protected Uuid getVpnForNetwork(Uuid network) {
         InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
         Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
         if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
-            List<VpnMap> allMaps = optionalVpnMaps.get().getVpnMap();
-            for (VpnMap vpnMap : allMaps) {
+            for (VpnMap vpnMap : requireNonNullElse(optionalVpnMaps.get().getVpnMap(),
+                    Collections.<VpnMap>emptyList())) {
                 List<Uuid> netIds = vpnMap.getNetworkIds();
                 if (netIds != null && netIds.contains(network)) {
                     return vpnMap.getVpnId();
@@ -246,6 +251,7 @@ public class NeutronvpnUtils {
         return null;
     }
 
+    @Nullable
     protected Uuid getVpnForSubnet(Uuid subnetId) {
         InstanceIdentifier<Subnetmap> subnetmapIdentifier = buildSubnetMapIdentifier(subnetId);
         Optional<Subnetmap> optionalSubnetMap = read(LogicalDatastoreType.CONFIGURATION,
@@ -257,6 +263,7 @@ public class NeutronvpnUtils {
         return null;
     }
 
+    @Nullable
     protected Uuid getNetworkForSubnet(Uuid subnetId) {
         InstanceIdentifier<Subnetmap> subnetmapIdentifier = buildSubnetMapIdentifier(subnetId);
         Optional<Subnetmap> optionalSubnetMap = read(LogicalDatastoreType.CONFIGURATION,
@@ -269,7 +276,8 @@ public class NeutronvpnUtils {
     }
 
     // @param external vpn - true if external vpn being fetched, false for internal vpn
-    protected Uuid getVpnForRouter(Uuid routerId, boolean externalVpn) {
+    @Nullable
+    protected Uuid getVpnForRouter(@Nullable Uuid routerId, boolean externalVpn) {
         if (routerId == null) {
             return null;
         }
@@ -277,31 +285,21 @@ public class NeutronvpnUtils {
         InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
         Optional<VpnMaps> optionalVpnMaps = read(LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
         if (optionalVpnMaps.isPresent() && optionalVpnMaps.get().getVpnMap() != null) {
-            List<VpnMap> allMaps = optionalVpnMaps.get().getVpnMap();
-            for (VpnMap vpnMap : allMaps) {
+            for (VpnMap vpnMap : requireNonNullElse(optionalVpnMaps.get().getVpnMap(),
+                    Collections.<VpnMap>emptyList())) {
                 List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.vpnmap
                     .RouterIds> routerIdsList = vpnMap.getRouterIds();
                 if (routerIdsList == null || routerIdsList.isEmpty()) {
                     continue;
                 }
-                boolean isInternetBgpVpn = false;
-                //Skip router vpnId fetching from internet BGP-VPN
+                // Skip router vpnId fetching from internet BGP-VPN
                 if (vpnMap.getNetworkIds() != null && !vpnMap.getNetworkIds().isEmpty()) {
-                    for (Uuid netId: vpnMap.getNetworkIds()) {
-                        Network network = getNeutronNetwork(netId);
-                        if (getIsExternal(network)) {
-                            isInternetBgpVpn = true;
-                        }
-                        /* If first network is not a external network then no need iterate
-                         * whole network list from the VPN
-                         */
-                        break;
+                    // We only need to check the first network; if it’s not an external network there’s no
+                    // need to check the rest of the VPN’s network list
+                    if (getIsExternal(getNeutronNetwork(vpnMap.getNetworkIds().iterator().next()))) {
+                        continue;
                     }
                 }
-                if (isInternetBgpVpn) {
-                    //skip further processing
-                    continue;
-                }
                 List<Uuid> rtrIdsList = routerIdsList.stream().map(routerIds -> routerIds.getRouterId())
                         .collect(Collectors.toList());
                 if (rtrIdsList.contains(routerId)) {
@@ -321,6 +319,7 @@ public class NeutronvpnUtils {
         return null;
     }
 
+    @Nullable
     protected List<Uuid> getRouterIdListforVpn(Uuid vpnId) {
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
                 new VpnMapKey(vpnId)).build();
@@ -333,6 +332,7 @@ public class NeutronvpnUtils {
         return null;
     }
 
+    @Nullable
     protected List<Uuid> getNetworksForVpn(Uuid vpnId) {
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
                 new VpnMapKey(vpnId)).build();
@@ -361,6 +361,7 @@ public class NeutronvpnUtils {
         return subnets;
     }
 
+    @Nullable
     protected String getNeutronPortNameFromVpnPortFixedIp(String vpnName, String fixedIp) {
         InstanceIdentifier<VpnPortipToPort> id = buildVpnPortipToPortIdentifier(vpnName, fixedIp);
         Optional<VpnPortipToPort> vpnPortipToPortData = read(LogicalDatastoreType.CONFIGURATION, id);
@@ -372,6 +373,7 @@ public class NeutronvpnUtils {
         return null;
     }
 
+    @Nullable
     protected List<Uuid> getSubnetIdsFromNetworkId(Uuid networkId) {
         InstanceIdentifier<NetworkMap> id = buildNetworkMapIdentifier(networkId);
         Optional<NetworkMap> optionalNetworkMap = read(LogicalDatastoreType.CONFIGURATION, id);
@@ -382,6 +384,7 @@ public class NeutronvpnUtils {
         return null;
     }
 
+    @Nullable
     protected List<Uuid> getPortIdsFromSubnetId(Uuid subnetId) {
         InstanceIdentifier<Subnetmap> id = buildSubnetMapIdentifier(subnetId);
         Optional<Subnetmap> optionalSubnetmap = read(LogicalDatastoreType.CONFIGURATION, id);
@@ -470,8 +473,9 @@ public class NeutronvpnUtils {
      * @param port2SecurityGroups the port 2 security groups
      * @return the security groups delta
      */
-    protected static List<Uuid> getSecurityGroupsDelta(List<Uuid> port1SecurityGroups,
-            List<Uuid> port2SecurityGroups) {
+    @Nullable
+    protected static List<Uuid> getSecurityGroupsDelta(@Nullable List<Uuid> port1SecurityGroups,
+            @Nullable List<Uuid> port2SecurityGroups) {
         if (port1SecurityGroups == null) {
             return null;
         }
@@ -531,10 +535,11 @@ public class NeutronvpnUtils {
      * @param port2AllowedAddressPairs the port 2 allowed address pairs
      * @return the allowed address pairs delta
      */
+    @Nullable
     protected static List<AllowedAddressPairs> getAllowedAddressPairsDelta(
-        List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes
+        @Nullable List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes
             .AllowedAddressPairs> port1AllowedAddressPairs,
-        List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes
+        @Nullable List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes
             .AllowedAddressPairs> port2AllowedAddressPairs) {
         if (port1AllowedAddressPairs == null) {
             return null;
@@ -758,6 +763,7 @@ public class NeutronvpnUtils {
         }
     }
 
+    @Nullable
     protected List<SubnetInfo> getSubnetInfo(Port port) {
         List<FixedIps> portFixedIps = port.getFixedIps();
         if (portFixedIps == null) {
@@ -832,6 +838,7 @@ public class NeutronvpnUtils {
 
     // TODO Clean up the exception handling and the console output
     @SuppressWarnings({"checkstyle:IllegalCatch", "checkstyle:RegexpSinglelineJava"})
+    @Nullable
     protected Short getIPPrefixFromPort(Port port) {
         try {
             Uuid subnetUUID = port.getFixedIps().get(0).getSubnetId();
@@ -1110,6 +1117,7 @@ public class NeutronvpnUtils {
         return providerExtension != null ? providerExtension.getNetworkType() : null;
     }
 
+    @Nullable
     static ProviderTypes getProviderNetworkType(Network network) {
         if (network == null) {
             LOG.error("Error in getting provider network type since network is null");
@@ -1180,8 +1188,8 @@ public class NeutronvpnUtils {
         Optional<InterVpnLinks> interVpnLinksOpData = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION,
                 interVpnLinksIid);
         if (interVpnLinksOpData.isPresent()) {
-            List<InterVpnLink> allInterVpnLinks = interVpnLinksOpData.get().getInterVpnLink();
-            for (InterVpnLink interVpnLink : allInterVpnLinks) {
+            for (InterVpnLink interVpnLink : requireNonNullElse(interVpnLinksOpData.get().getInterVpnLink(),
+                    Collections.<InterVpnLink>emptyList())) {
                 if (interVpnLink.getFirstEndpoint().getIpAddress().getValue().equals(endpointIp)
                         || interVpnLink.getSecondEndpoint().getIpAddress().getValue().equals(endpointIp)) {
                     return Optional.of(interVpnLink);
@@ -1199,8 +1207,8 @@ public class NeutronvpnUtils {
             MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, routerDpnId);
         if (neutronRouterDpnsOpt.isPresent()) {
             NeutronRouterDpns neutronRouterDpns = neutronRouterDpnsOpt.get();
-            List<RouterDpnList> routerDpnLists = neutronRouterDpns.getRouterDpnList();
-            for (RouterDpnList routerDpnList : routerDpnLists) {
+            for (RouterDpnList routerDpnList : requireNonNullElse(neutronRouterDpns.getRouterDpnList(),
+                    Collections.<RouterDpnList>emptyList())) {
                 if (routerDpnList.getDpnVpninterfacesList() != null) {
                     for (DpnVpninterfacesList dpnInterfaceList : routerDpnList.getDpnVpninterfacesList()) {
                         if (dpnInterfaceList.getDpnId().equals(dpid)) {
@@ -1213,6 +1221,7 @@ public class NeutronvpnUtils {
         return ret;
     }
 
+    @Nullable
     protected Integer getUniqueRDId(String poolName, String idKey) {
         AllocateIdInput getIdInput = new AllocateIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
         try {
@@ -1408,6 +1417,7 @@ public class NeutronvpnUtils {
      *
      * @return the route-distinguisher of the VPN
      */
+    @Nullable
     public String getVpnRd(String vpnName) {
         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
             .instance.to.vpn.id.VpnInstance> id = getVpnInstanceToVpnIdIdentifier(vpnName);
@@ -1450,6 +1460,7 @@ public class NeutronvpnUtils {
         return IpVersionChoice.UNDEFINED;
     }
 
+    @Nullable
     public VpnInstanceOpDataEntry getVpnInstanceOpDataEntryFromVpnId(String vpnName) {
         String primaryRd = getVpnRd(vpnName);
         if (primaryRd == null) {
@@ -1504,7 +1515,8 @@ public class NeutronvpnUtils {
         Optional<Subnetmaps> allSubnetMaps = read(LogicalDatastoreType.CONFIGURATION, subnetMapsId);
         // calculate and store in list IpVersion for each subnetMap, belonging to current VpnInstance
         List<IpVersionChoice> snIpVersions = new ArrayList<>();
-        for (Subnetmap snMap: allSubnetMaps.get().getSubnetmap()) {
+        for (Subnetmap snMap : requireNonNullElse(allSubnetMaps.get().getSubnetmap(),
+                Collections.<Subnetmap>emptyList())) {
             if (snMap.getId().equals(sm.getId())) {
                 continue;
             }
@@ -1582,6 +1594,7 @@ public class NeutronvpnUtils {
      * @param vpnId the Uuid of the VPN
      * @return the VpnInstance or null if unfindable
      */
+    @Nullable
     public VpnInstance getVpnInstance(DataBroker broker, Uuid vpnId) {
         if (broker == null || vpnId == null) {
             return null;
@@ -1622,6 +1635,7 @@ public class NeutronvpnUtils {
      * @param subnetUuid Uuid of subnet where you are finding a link to an external network
      * @return Uuid of externalVpn or null if it is not found
      */
+    @Nullable
     public Uuid getInternetvpnUuidBoundToSubnetRouter(@Nonnull Uuid subnetUuid) {
         Subnetmap subnetmap = getSubnetmap(subnetUuid);
         Uuid routerUuid = subnetmap.getRouterId();
@@ -1647,7 +1661,7 @@ public class NeutronvpnUtils {
             Uuid extNwVpnId = getVpnForNetwork(extNet.getUuid());
             rtrList.addAll(getRouterIdListforVpn(extNwVpnId));
         }
-        if (rtrList == null || rtrList.isEmpty()) {
+        if (rtrList.isEmpty()) {
             return subList;
         }
         for (Uuid rtrId: rtrList) {
@@ -1810,14 +1824,15 @@ public class NeutronvpnUtils {
                         LogicalDatastoreType.OPERATIONAL, id);
         List<BigInteger> dpns = new ArrayList<>();
         if (routerDpnListData.isPresent()) {
-            List<DpnVpninterfacesList> dpnVpninterfacesList = routerDpnListData.get().getDpnVpninterfacesList();
-            for (DpnVpninterfacesList dpnVpnInterface : dpnVpninterfacesList) {
+            for (DpnVpninterfacesList dpnVpnInterface : requireNonNullElse(
+                    routerDpnListData.get().getDpnVpninterfacesList(), Collections.<DpnVpninterfacesList>emptyList())) {
                 dpns.add(dpnVpnInterface.getDpnId());
             }
         }
         return dpns;
     }
 
+    @Nullable
     public List<Uuid> getRouterIdsfromVpnInstance(String vpnName) {
         // returns only router, attached to IPv4 networks
         InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
@@ -1841,6 +1856,7 @@ public class NeutronvpnUtils {
         return routerInstanceIdentifier;
     }
 
+    @Nullable
     List<Subnetmap> getSubnetmapListFromNetworkId(Uuid networkId) {
         List<Uuid> subnetIdList = getSubnetIdsFromNetworkId(networkId);
         if (subnetIdList != null) {
@@ -1861,6 +1877,7 @@ public class NeutronvpnUtils {
         return null;
     }
 
+    @Nullable
     public long getVpnId(String vpnName) {
         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn
                 .instance.to.vpn.id.VpnInstance> id = getVpnInstanceToVpnIdIdentifier(vpnName);
index 33ef39844b375a6dc457beeae6b7afdd627f9bc3..0892699d9f71b2fe213c50d260eaa0766bde98e0 100644 (file)
@@ -7,10 +7,13 @@
  */
 package org.opendaylight.netvirt.neutronvpn.evpn.manager;
 
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
+
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.function.Consumer;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -67,16 +70,13 @@ public class NeutronEvpnManager {
         SettableFuture<RpcResult<CreateEVPNOutput>> result = SettableFuture.create();
         List<RpcError> errorList = new ArrayList<>();
         int failurecount = 0;
-        int warningcount = 0;
         List<String> existingRDs = neutronvpnUtils.getExistingRDs();
 
-        List<Evpn> vpns = input.getEvpn();
-        for (Evpn vpn : vpns) {
+        for (Evpn vpn : requireNonNullElse(input.getEvpn(), Collections.<Evpn>emptyList())) {
             if (vpn.getRouteDistinguisher() == null || vpn.getImportRT() == null || vpn.getExportRT() == null) {
                 errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input",
                         formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to absence of RD/iRT/eRT input",
                                 vpn.getId().getValue())));
-                warningcount++;
                 continue;
             }
             VpnInstance.Type vpnInstanceType = VpnInstance.Type.L2;
@@ -84,7 +84,6 @@ public class NeutronEvpnManager {
                 errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-input",
                         formatAndLog(LOG::warn, "Creation of EVPN failed for VPN {} due to multiple RD input {}",
                                 vpn.getId().getValue(), vpn.getRouteDistinguisher())));
-                warningcount++;
                 continue;
             }
             if (existingRDs.contains(vpn.getRouteDistinguisher().get(0))) {
@@ -93,7 +92,6 @@ public class NeutronEvpnManager {
                                 "Creation of EVPN failed for VPN {} as another VPN with the same RD {} is already "
                                         + "configured",
                                 vpn.getId().getValue(), vpn.getRouteDistinguisher().get(0))));
-                warningcount++;
                 continue;
             }
             try {
@@ -163,10 +161,10 @@ public class NeutronEvpnManager {
                     .class, new VpnMapKey(vpnId)).build();
             EvpnInstancesBuilder evpn = new EvpnInstancesBuilder();
             List<String> rd = vpnInstance.getIpv4Family().getRouteDistinguisher();
-            List<VpnTarget> vpnTargetList = vpnInstance.getIpv4Family().getVpnTargets().getVpnTarget();
             List<String> ertList = new ArrayList<>();
             List<String> irtList = new ArrayList<>();
-            for (VpnTarget vpnTarget : vpnTargetList) {
+            for (VpnTarget vpnTarget : requireNonNullElse(vpnInstance.getIpv4Family().getVpnTargets().getVpnTarget(),
+                    Collections.<VpnTarget>emptyList())) {
                 if (vpnTarget.getVrfRTType() == VpnTarget.VrfRTType.ExportExtcommunity) {
                     ertList.add(vpnTarget.getVrfRTValue());
                 }
@@ -202,40 +200,30 @@ public class NeutronEvpnManager {
     }
 
     public ListenableFuture<RpcResult<DeleteEVPNOutput>> deleteEVPN(DeleteEVPNInput input) {
-        DeleteEVPNOutputBuilder opBuilder = new DeleteEVPNOutputBuilder();
-        SettableFuture<RpcResult<DeleteEVPNOutput>> result = SettableFuture.create();
         List<RpcError> errorList = new ArrayList<>();
 
-        int failurecount = 0;
-        int warningcount = 0;
-        List<Uuid> vpns = input.getId();
-        for (Uuid vpn : vpns) {
-            RpcError error;
-            String msg;
+        for (Uuid vpn : requireNonNullElse(input.getId(), Collections.<Uuid>emptyList())) {
             VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpn.getValue());
             if (vpnInstance != null) {
                 neutronvpnManager.removeVpn(vpn);
             } else {
                 errorList.add(RpcResultBuilder.newWarning(RpcError.ErrorType.PROTOCOL, "invalid-value",
                         formatAndLog(LOG::warn, "EVPN with vpnid: {} does not exist", vpn.getValue())));
-                warningcount++;
             }
         }
-        if (failurecount != 0) {
-            result.set(RpcResultBuilder.<DeleteEVPNOutput>failed().withRpcErrors(errorList).build());
-        } else {
-            List<String> errorResponseList = new ArrayList<>();
-            if (!errorList.isEmpty()) {
-                for (RpcError rpcError : errorList) {
-                    errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag()
-                            + ", ErrorMessage: " + rpcError.getMessage());
-                }
-            } else {
-                errorResponseList.add("Deletion of EVPN operation successful");
+        List<String> errorResponseList = new ArrayList<>();
+        if (!errorList.isEmpty()) {
+            for (RpcError rpcError : errorList) {
+                errorResponseList.add("ErrorType: " + rpcError.getErrorType() + ", ErrorTag: " + rpcError.getTag()
+                        + ", ErrorMessage: " + rpcError.getMessage());
             }
-            opBuilder.setResponse(errorResponseList);
-            result.set(RpcResultBuilder.success(opBuilder.build()).build());
+        } else {
+            errorResponseList.add("Deletion of EVPN operation successful");
         }
+        DeleteEVPNOutputBuilder opBuilder = new DeleteEVPNOutputBuilder();
+        opBuilder.setResponse(errorResponseList);
+        SettableFuture<RpcResult<DeleteEVPNOutput>> result = SettableFuture.create();
+        result.set(RpcResultBuilder.success(opBuilder.build()).build());
         return result;
     }
 
index 86e6b97034fa78a87271690e76a8a4d8cdb68053..2162185cc7c479cddcf2c02313311a6c39e4b2ba 100644 (file)
@@ -11,6 +11,7 @@ import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
 import com.google.common.base.Optional;
 import java.util.Collections;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -58,6 +59,7 @@ public class NeutronEvpnUtils {
         this.jobCoordinator = jobCoordinator;
     }
 
+    @Nullable
     public VpnInstance getVpnInstance(Uuid vpnId) {
         return VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
     }
index cf3aa3cc6306bf3a57aac1006b3a53688da82ad1..9174fe4d20254712cd4ca29d6444a542b7fd9afb 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.neutronvpn.l2gw;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.neutronvpn.api.utils.NeutronUtils.requireNonNullElse;
 
 import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.FutureCallback;
@@ -91,8 +92,7 @@ public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<
     protected void add(final InstanceIdentifier<L2gateway> identifier, final L2gateway input) {
         LOG.info("Adding L2gateway with ID: {}", input.getUuid());
 
-        List<Devices> l2Devices = input.getDevices();
-        for (Devices l2Device : l2Devices) {
+        for (Devices l2Device : requireNonNullElse(input.getDevices(), Collections.<Devices>emptyList())) {
             LOG.trace("Adding L2gateway device: {}", l2Device);
             addL2Device(l2Device, input);
         }
@@ -112,8 +112,7 @@ public class L2GatewayListener extends AsyncClusteredDataTreeChangeListenerBase<
         }), new FutureCallback<Void>() {
             @Override
             public void onSuccess(Void result) {
-                List<Devices> l2Devices = input.getDevices();
-                for (Devices l2Device : l2Devices) {
+                for (Devices l2Device : requireNonNullElse(input.getDevices(), Collections.<Devices>emptyList())) {
                     LOG.trace("Removing L2gateway device: {}", l2Device);
                     removeL2Device(l2Device, input);
                 }
index fe2ad15c475b3493e25808a7aa3fed0066b2d4b2..c01289b612e18471dc243f790f6208744fb04fa3 100644 (file)
@@ -109,7 +109,7 @@ public class L2GwTransportZoneListener
     @Override
     protected void add(InstanceIdentifier<TransportZone> key, TransportZone tzNew) {
         LOG.trace("Received Transport Zone Add Event: {}", tzNew);
-        if (tzNew.getTunnelType().equals(TunnelTypeVxlan.class)) {
+        if (TunnelTypeVxlan.class.equals(tzNew.getTunnelType())) {
             AddL2GwDevicesToTransportZoneJob job =
                     new AddL2GwDevicesToTransportZoneJob(itmRpcService, tzNew, l2GatewayCache);
             jobCoordinator.enqueueJob(job.getJobKey(), job);