Handle nullable lists in elanmanager 68/77068/2
authorStephen Kitt <skitt@redhat.com>
Tue, 16 Oct 2018 14:52:09 +0000 (16:52 +0200)
committerStephen Kitt <skitt@redhat.com>
Thu, 18 Oct 2018 14:07:25 +0000 (16:07 +0200)
Following YANGTOOLS-585, lists can be null (which is correctly
indicated with an @Nullable annotation). This patch deals with the
fallout.

Change-Id: I50cddb975389da42dc85bac65724576741cf6a5b
Signed-off-by: Stephen Kitt <skitt@redhat.com>
60 files changed:
elanmanager/api/src/main/java/org/opendaylight/netvirt/elanmanager/api/IL2gwService.java
elanmanager/api/src/main/java/org/opendaylight/netvirt/elanmanager/utils/ElanL2GwCacheUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/ElanAdd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/ElanDelete.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/ElanGet.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/ElanInterfaceAdd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/ElanInterfaceDelete.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/ElanInterfaceGet.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/ElanInterfaceUpdate.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/ElanMacTableFlush.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/ElanMacTableGet.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/ElanUpdate.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/StaticMacAdd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/StaticMacDelete.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/etree/EtreeAdd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/etree/EtreeDelete.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/etree/EtreeGet.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/etree/EtreeInterfaceAdd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/etree/EtreeInterfaceDelete.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/etree/EtreeInterfaceGet.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwUtilsCacheCli.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwValidateCli.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/NetworkL2gwDeviceInfoCli.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/utils/EvpnMacVrfUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/evpn/utils/EvpnUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanBridgeManager.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfaceClusteredListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanDpnInterfacesListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceStateClusteredListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanOvsdbNodeListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanPacketInHandler.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanServiceProvider.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/HwvtepHAUtil.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/BaseCommand.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/LocalMcastCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/LocalUcastCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/LogicalSwitchesCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/MergeCommand.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/PhysicalLocatorCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/RemoteMcastCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/RemoteUcastCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/SwitchesCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/TerminationPointCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/TunnelCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/commands/TunnelIpCmd.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/ha/handlers/NodeCopier.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ChildListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanGroupListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepPhysicalSwitchListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepTerminationPointListener.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayMulticastUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/ElanL2GatewayUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/statisitcs/ElanStatisticsImpl.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanDmacUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanEtreeUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanItmUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/ElanUtils.java
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/utils/TransportZoneNotificationUtil.java

index 598b730643a054383fa060aa3007f2280c4fe421..f6eb2d6f3a1a4ac00e55e0bcd6d3216b0cfc3429 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.netvirt.elanmanager.api;
 import java.util.List;
 import java.util.Set;
 
+import javax.annotation.Nullable;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
 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;
@@ -26,7 +27,7 @@ public interface IL2gwService {
     void addL2GatewayConnection(L2gatewayConnection input);
 
     void addL2GatewayConnection(L2gatewayConnection input,
-                                String l2GwDeviceName,
+                                @Nullable String l2GwDeviceName,
                                 L2gateway l2Gateway);
 
     List<L2gatewayConnection> getAssociatedL2GwConnections(Set<Uuid> l2GatewayIds);
index 78672153246e7aeebd7e68a58575698ee1a86c38..79ad578a54c1729e669ee9b00c0c43fbfafaa325 100644 (file)
@@ -12,6 +12,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import javax.annotation.Nullable;
 import org.opendaylight.genius.utils.cache.CacheUtil;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice;
 
@@ -47,7 +48,7 @@ public final class ElanL2GwCacheUtils {
         cachedMap.values().forEach(deviceMap -> deviceMap.remove(deviceName));
     }
 
-
+    @Nullable
     public static L2GatewayDevice removeL2GatewayDeviceFromCache(String elanName, String l2gwDeviceNodeId) {
         ConcurrentMap<String, ConcurrentMap<String, L2GatewayDevice>> cachedMap =
                 (ConcurrentMap<String, ConcurrentMap<String, L2GatewayDevice>>) CacheUtil.getCache(
@@ -60,6 +61,7 @@ public final class ElanL2GwCacheUtils {
         }
     }
 
+    @Nullable
     public static L2GatewayDevice getL2GatewayDeviceFromCache(String elanName, String l2gwDeviceNodeId) {
         ConcurrentMap<String, ConcurrentMap<String, L2GatewayDevice>> cachedMap =
                 (ConcurrentMap<String, ConcurrentMap<String, L2GatewayDevice>>) CacheUtil.getCache(
@@ -83,6 +85,7 @@ public final class ElanL2GwCacheUtils {
         return result;
     }
 
+    @Nullable
     public static List<L2GatewayDevice> getAllElanDevicesFromCache() {
         ConcurrentMap<String, ConcurrentMap<String, L2GatewayDevice>> cachedMap =
                 (ConcurrentMap<String, ConcurrentMap<String, L2GatewayDevice>>) CacheUtil.getCache(
index 59d5420765a89e789e6fcf22a652ebdf01ab5882..26b0d5896be951f34f2d7dfe110e139f5afe081c 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.cli;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -32,6 +33,7 @@ public class ElanAdd extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         if (macTimeOut == -1) {
             macTimeOut = 30;
index 046e8e28bf7ac3ce03c6824f554567493a9896ca..8ea21c3f21baf6e4f76e012f3ebf1c65f62402cb 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.cli;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -28,6 +29,7 @@ public class ElanDelete extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing the Deletion of ElanInstance command for elanName: {}", elanName);
         boolean isSuccess = elanProvider.deleteElanInstance(elanName);
index 9e80f213bbb8c82d6fff4fe43493cde79a5bbba3..608659c03f0c4d5e6c2279f2ea2cdec825864ca9 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.cli;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -31,6 +32,7 @@ public class ElanGet extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing Get ElanInstance command for elanName: {}", elanName);
         if (elanName != null) {
index 6627903752418cc1a89121a94ae78307a301ede6..9e6fd8e6cf160598521c0b55738fd071998d99f1 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.cli;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -36,6 +37,7 @@ public class ElanInterfaceAdd extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing create ElanInterface command for elanName:{}, interfaceName:{}, staticMacAddresses:{},"
                 + "elanInterfaceDescr:{}",elanName, interfaceName, staticMacAddresses, elanInterfaceDescr);
index 653609552958447fd15aa2a08c0a6b3d77c1b106..8d00ee71e94fb2d804cdb754e361167a1198f561 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.cli;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -29,6 +30,7 @@ public class ElanInterfaceDelete  extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Deleting ElanInterface command for elanName:{}, interfaceName:{}", elanName, interfaceName);
         elanProvider.deleteElanInterface(interfaceName);
index 60b858f5b56f25fe10aba042a526da2c3342a541..46ea6c79d7f0e6b1ec096805df0e2980d9e4a638 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.cli;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -38,6 +39,7 @@ public class ElanInterfaceGet extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing Get ElanInterface command for the corresponding Elan Instance for {}", elanName);
         if (elanName != null) {
index 2405cd04349911ff48991686dfaa36bba67773b4..714665450b1bb603854a17334c2ed1e8440b5c0d 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.cli;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -36,6 +37,7 @@ public class ElanInterfaceUpdate extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing elanInterface update command for elanName:{}, interfaceName:{}, staticMacAddresses:{},"
                 + "elanInterfaceDescr:{}", elanName, interfaceName, staticMacAddresses, elanInterfaceDescr);
index ba603f567e57a765131555bf24f7d00f58a5fe28..3cf3ecbef333181da967bd304c07d0cc90aa953b 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.cli;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -28,6 +29,7 @@ public class ElanMacTableFlush extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing mac table flush command for {}", elanName);
         elanProvider.flushMACTable(elanName);
index 516af9339d439a7fa9b80b23de3ca38be1a98cfe..326860c50e7f78d308c8b476ef222ba4b71dc910 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netvirt.elan.cli;
 import java.text.SimpleDateFormat;
 import java.util.Collection;
 import java.util.Date;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -33,6 +34,7 @@ public class ElanMacTableGet extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing elan mac table get command for {}", elanName);
         Collection<MacEntry> macTables = elanProvider.getElanMacTable(elanName);
index 57f2ecfc8a337abf399cf3fee6519742ec0c8147..8aca18544fe086c623409c6c8b2a6da3cebfa44d 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.cli;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -31,6 +32,7 @@ public class ElanUpdate  extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Updating elanInstance update command for elanName:{}, macTimeOut:{}, elanDescr:{}",
                 elanName, macTimeOut, elanDescr);
index 22aeedae41d89166b6c29a79f03a1c18dd366ea0..1938999f551a4f079186e474f64862ac78d01a48 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.cli;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -32,6 +33,7 @@ public class StaticMacAdd extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing static mac add command for elanName:{}, interfaceName:{}, staticMacAddress:{}",
                 elanName, interfaceName, staticMacAddress);
index aab6bec29b7fbafad1937de253a6d10c5dcd9173..03b4991681c77d5b1089f279a4987b4590cfee00 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.cli;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -32,6 +33,7 @@ public class StaticMacDelete  extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing static mac delete command for elanName:{}, interfaceName:{}, staticMacAddress:{}",
                 elanName, interfaceName, staticMacAddress);
index 1c71ec5ae514ff24141c6930979f3746ba9450cf..e8d5dc712e5d7c0ac7bc7391b3d73ae8df92bf8f 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.cli.etree;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -32,6 +33,7 @@ public class EtreeAdd extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         if (macTimeOut == -1) {
             macTimeOut = 30;
index 02d91d6773d710f6d93c38519edb40070ce63d8b..a1a11d3f66182ccaef93fe7bdbde34ce647f4ad6 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.cli.etree;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -28,6 +29,7 @@ public class EtreeDelete extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing the Deletion of EtreeInstance command {}", etreeName);
         boolean isSuccess = elanProvider.deleteEtreeInstance(etreeName);
index b93bc924eb1a9ab7ec67b642bc22e09eee653c09..9b2737f213376a3be74983997acd888360182ff9 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.cli.etree;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -32,6 +33,7 @@ public class EtreeGet extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing Get EtreeInstance command for {}", etreeName);
         if (etreeName != null) {
index 633b6e269b67cc54ff84d978454020385c4e8a1d..44c9b6bbb9e0b249de7e35bf687d126e5d7afe54 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.cli.etree;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -41,6 +42,7 @@ public class EtreeInterfaceAdd extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         EtreeInterfaceType inputType = null;
         for (EtreeInterfaceType type : EtreeInterfaceType.values()) {
index 81273ea4f21721f08c700048f974a56899a2a0f9..2484a555dd8f6c39ac12f6c362740be230cca36c 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.cli.etree;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -31,6 +32,7 @@ public class EtreeInterfaceDelete extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Deleting EtreeInterface command etreeName:{}, interfaceName:{}", etreeName, interfaceName);
         ElanInterface existingInterface =
index 2331afc197b7efbbe98526f8211b6464242e4ab2..41666e313270365e83022072c44bb01b3b0531f6 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.cli.etree;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -40,6 +41,7 @@ public class EtreeInterfaceGet extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Executing Get EtreeInterface command for the corresponding Etree Instance {}", etreeName);
         if (etreeName != null) {
index e141348cf195aac0f552f2ff79a68ee2e24675c8..6b035924dff9c9c831221ad82d56caea13424f90 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Collection;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentMap;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.commands.Option;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -50,6 +51,7 @@ public class L2GwUtilsCacheCli extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() throws IOException {
         if (cacheName == null) {
             session.getConsole().println("Available caches");
index 75f007f3641be9b680ce953c1911bdf18ad5a04d..00c9598aa2305eb01586af5da6306fe2e7aa730d 100644 (file)
@@ -8,6 +8,9 @@
 
 package org.opendaylight.netvirt.elan.cli.l2gw;
 
+import static java.util.Collections.emptyList;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
+
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.collect.Sets;
@@ -23,6 +26,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.stream.Collectors;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -109,6 +113,7 @@ public class L2GwValidateCli extends OsgiCommandSupport {
 
     @Override
     @SuppressFBWarnings("DM_DEFAULT_ENCODING")
+    @Nullable
     public Object doExecute() throws Exception {
         try {
             pw = new PrintWriter(new FileOutputStream(new File("l2gw.validation.txt")));
@@ -132,13 +137,15 @@ public class L2GwValidateCli extends OsgiCommandSupport {
             Optional<Topology> configTopoOptional = tx.read(LogicalDatastoreType.CONFIGURATION, topoId).checkedGet();
 
             if (operationalTopoOptional.isPresent()) {
-                for (Node node : operationalTopoOptional.get().getNode()) {
+                for (Node node : requireNonNullElse(operationalTopoOptional.get().getNode(),
+                        Collections.<Node>emptyList())) {
                     InstanceIdentifier<Node> nodeIid = topoId.child(Node.class, node.key());
                     operationalNodes.put(nodeIid, node);
                 }
             }
             if (configTopoOptional.isPresent()) {
-                for (Node node : configTopoOptional.get().getNode()) {
+                for (Node node : requireNonNullElse(configTopoOptional.get().getNode(),
+                        Collections.<Node>emptyList())) {
                     InstanceIdentifier<Node> nodeIid = topoId.child(Node.class, node.key());
                     configNodes.put(nodeIid, node);
                 }
@@ -171,6 +178,7 @@ public class L2GwValidateCli extends OsgiCommandSupport {
         return false;
     }
 
+    @Nullable
     private DataObject getData(Map<InstanceIdentifier<Node>, Map<InstanceIdentifier, DataObject>> dataMap,
                                InstanceIdentifier<Node> nodeIid, InstanceIdentifier dataIid) {
         if (dataMap.containsKey(nodeIid)) {
@@ -385,7 +393,7 @@ public class L2GwValidateCli extends OsgiCommandSupport {
 
             L2gateway l2gateway = uuidToL2Gateway.get(l2gatewayConnection.getL2gatewayId());
             String logicalSwitchName = l2gatewayConnection.getNetworkId().getValue();
-            List<Devices> devices = l2gateway.getDevices();
+            List<Devices> devices = requireNonNullElse(l2gateway.getDevices(), emptyList());
 
             for (Devices device : devices) {
 
@@ -549,8 +557,8 @@ public class L2GwValidateCli extends OsgiCommandSupport {
             }
             VlanBindings expectedBindings = !expectedVlans.isEmpty() ? expectedVlans.get(0) : null;
             boolean foundBindings = false;
-            List<VlanBindings> vlanBindingses = configTerminationPoint.augmentation(
-                    HwvtepPhysicalPortAugmentation.class).getVlanBindings();
+            List<VlanBindings> vlanBindingses = requireNonNullElse(configTerminationPoint.augmentation(
+                    HwvtepPhysicalPortAugmentation.class).getVlanBindings(), emptyList());
             for (VlanBindings actual : vlanBindingses) {
                 if (actual.equals(expectedBindings)) {
                     foundBindings = true;
index a1368692d9ec0c84d31b5e2c11069475136d5d82..95f0c3801da76be8913706f7378c16c3b5012184 100644 (file)
@@ -8,13 +8,18 @@
 
 package org.opendaylight.netvirt.elan.cli.l2gw;
 
+import static java.util.Collections.emptyList;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
+
 import com.google.common.base.Optional;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.commands.Option;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -90,6 +95,7 @@ public class NetworkL2gwDeviceInfoCli extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         List<Node> nodes = new ArrayList<>();
         Set<String> networks = new HashSet<>();
@@ -97,7 +103,7 @@ public class NetworkL2gwDeviceInfoCli extends OsgiCommandSupport {
             Optional<Topology> topologyOptional = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
                     createHwvtepTopologyInstanceIdentifier());
             if (topologyOptional.isPresent()) {
-                nodes = topologyOptional.get().getNode();
+                nodes = requireNonNullElse(topologyOptional.get().getNode(), emptyList());
             }
         } else {
             Optional<Node> nodeOptional = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
@@ -251,7 +257,8 @@ public class NetworkL2gwDeviceInfoCli extends OsgiCommandSupport {
             if (elanName.equals(lsFromLocalMac)) {
                 String mac = localMac.getMacEntryKey().getValue();
                 List<String> locatorsets = new ArrayList<>();
-                for (LocatorSet locatorSet : localMac.getLocatorSet()) {
+                for (LocatorSet locatorSet : requireNonNullElse(localMac.getLocatorSet(),
+                        Collections.<LocatorSet>emptyList())) {
                     locatorsets.add(getLocatorValue(locatorSet.getLocatorRef()));
                 }
                 session.getConsole().println(mac + GAP + locatorsets.toString());
@@ -278,7 +285,8 @@ public class NetworkL2gwDeviceInfoCli extends OsgiCommandSupport {
             if (elanName.equals(lsFromremoteMac)) {
                 String mac = remoteMac.getMacEntryKey().getValue();
                 List<String> locatorsets = new ArrayList<>();
-                for (LocatorSet locatorSet : remoteMac.getLocatorSet()) {
+                for (LocatorSet locatorSet : requireNonNullElse(remoteMac.getLocatorSet(),
+                        Collections.<LocatorSet>emptyList())) {
                     locatorsets.add(getLocatorValue(locatorSet.getLocatorRef()));
                 }
                 session.getConsole().println(mac + GAP + locatorsets.toString());
@@ -317,6 +325,7 @@ public class NetworkL2gwDeviceInfoCli extends OsgiCommandSupport {
 
     }
 
+    @Nullable
     String getLocatorValue(HwvtepPhysicalLocatorRef locatorRef) {
         if (locatorRef == null) {
             return null;
@@ -325,6 +334,7 @@ public class NetworkL2gwDeviceInfoCli extends OsgiCommandSupport {
                 .firstKeyOf(TerminationPoint.class).getTpId().getValue();
     }
 
+    @Nullable
     String getLogicalSwitchValue(HwvtepLogicalSwitchRef logicalSwitchRef) {
         if (logicalSwitchRef == null) {
             return null;
@@ -333,12 +343,13 @@ public class NetworkL2gwDeviceInfoCli extends OsgiCommandSupport {
                 .firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
     }
 
+    @Nullable
     Node getPSnode(Node hwvtepNode, LogicalDatastoreType datastoreType) {
-        if (hwvtepNode.augmentation(HwvtepGlobalAugmentation.class) != null
-                && hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).getSwitches() != null) {
-            for (Switches switches : hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).getSwitches()) {
-                NodeId psNodeId = switches.getSwitchRef().getValue().firstKeyOf(Node.class).getNodeId();
-                return HwvtepUtils.getHwVtepNode(dataBroker, datastoreType, psNodeId);
+        if (hwvtepNode.augmentation(HwvtepGlobalAugmentation.class) != null) {
+            List<Switches> switches = hwvtepNode.augmentation(HwvtepGlobalAugmentation.class).getSwitches();
+            if (switches != null) {
+                return HwvtepUtils.getHwVtepNode(dataBroker, datastoreType,
+                    switches.iterator().next().getSwitchRef().getValue().firstKeyOf(Node.class).getNodeId());
             }
         }
         return null;
index 7fc05c284fa71c68992bed0be00bc3bdaa170325..e3916b03e6c2fc327e59c7795cc541eac9603c3b 100644 (file)
@@ -266,6 +266,7 @@ public class EvpnMacVrfUtils {
         }
     }
 
+    @Nullable
     public String getRoutePathNexthopIp(MacVrfEntry macVrfEntry) {
         if (macVrfEntry.getRoutePaths() == null || macVrfEntry.getRoutePaths().isEmpty()) {
             LOG.debug("RoutePaths is null or empty for macvrfentry {}", macVrfEntry);
index 5eada5cd57cc83c45eb2a31262f4ea8f110ecff9..1c0f2ca23a057391d6d9a97f4f10663113636b78 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netvirt.elan.evpn.utils;
 
+import static java.util.Collections.emptyList;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.Futures;
@@ -23,6 +25,7 @@ import java.util.function.BiConsumer;
 import java.util.function.BiPredicate;
 import java.util.function.Function;
 import java.util.function.Predicate;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -143,6 +146,7 @@ public class EvpnUtils {
         });
     }
 
+    @Nullable
     public String getEndpointIpAddressForDPN(BigInteger dpnId) {
 
         Future<RpcResult<GetDpnEndpointIpsOutput>> result = itmRpcService.getDpnEndpointIps(
@@ -176,6 +180,7 @@ public class EvpnUtils {
                 : interfaceManager.getInterfaceInfoFromOperationalDataStore(ifName).getMacAddress());
     }
 
+    @Nullable
     public String getL3vpnNameFromElan(ElanInstance elanInfo) {
         if (elanInfo == null) {
             LOG.debug("getL3vpnNameFromElan :elanInfo is NULL");
@@ -185,6 +190,7 @@ public class EvpnUtils {
         return evpnAugmentation != null ? evpnAugmentation.getL3vpnName() : null;
     }
 
+    @Nullable
     public static String getEvpnNameFromElan(ElanInstance elanInfo) {
         if (elanInfo == null) {
             LOG.debug("getEvpnNameFromElan :elanInfo is NULL");
@@ -194,6 +200,7 @@ public class EvpnUtils {
         return evpnAugmentation != null ? evpnAugmentation.getEvpnName() : null;
     }
 
+    @Nullable
     public String getEvpnRd(ElanInstance elanInfo) {
         String evpnName = getEvpnNameFromElan(elanInfo);
         if (evpnName == null) {
@@ -353,9 +360,10 @@ public class EvpnUtils {
             LOG.info("No External Tunnel Configured while programming the l2vni table.");
             return tunnelInterfaceNameList;
         }
-        List<ExternalTunnel> externalTunnels = externalTunnelListOptional.get().getExternalTunnel();
+        List<ExternalTunnel> externalTunnels =
+            requireNonNullElse(externalTunnelListOptional.get().getExternalTunnel(), emptyList());
 
-        dcGatewayIps
+        requireNonNullElse(dcGatewayIps, Collections.<DcGatewayIp>emptyList())
                 .forEach(dcIp -> externalTunnels
                 .stream()
                 .filter(externalTunnel -> externalTunnel.getDestinationDevice()
index a298366140647d007fe797d1754160bf1aa34fda..cef926b432ee0c018fc9817e6d63cec5333b0a35 100644 (file)
@@ -18,6 +18,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Random;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -214,6 +215,7 @@ public class ElanBridgeManager implements IElanBridgeManager {
 
     }
 
+    @Nullable
     private List<ManagedNodeEntry> getManagedNodeEntries(Node node) {
         OvsdbNodeAugmentation ovsdbNode = southboundUtils.extractNodeAugmentation(node);
         if (ovsdbNode == null) {
@@ -311,7 +313,7 @@ public class ElanBridgeManager implements IElanBridgeManager {
      * @param mac mac address to set on the bridge or null
      * @return true if no errors occurred
      */
-    public boolean addBridge(Node ovsdbNode, String bridgeName, String mac) {
+    public boolean addBridge(Node ovsdbNode, String bridgeName, @Nullable String mac) {
         boolean rv = true;
         if (southboundUtils.getBridgeFromConfig(ovsdbNode, bridgeName) == null) {
             Class<? extends DatapathTypeBase> dpType = null;
@@ -398,6 +400,7 @@ public class ElanBridgeManager implements IElanBridgeManager {
      * @param physicalNetworkName name of physical network
      * @return physical network name
      */
+    @Nullable
     public String getProviderMappingValue(Node node, String physicalNetworkName) {
         Map<String, String> providerMappings = getOpenvswitchOtherConfigMap(node, PROVIDER_MAPPINGS_KEY);
         String providerMappingValue = providerMappings.get(physicalNetworkName);
@@ -567,6 +570,7 @@ public class ElanBridgeManager implements IElanBridgeManager {
      * {@inheritDoc}.
      */
     @Override
+    @Nullable
     public Node getBridgeNode(BigInteger dpId) {
         List<Node> ovsdbNodes = southboundUtils.getOvsdbNodes();
         if (null == ovsdbNodes) {
@@ -588,6 +592,7 @@ public class ElanBridgeManager implements IElanBridgeManager {
         return null;
     }
 
+    @Nullable
     public String getProviderInterfaceName(BigInteger dpId, String physicalNetworkName) {
         Node brNode;
 
@@ -600,6 +605,7 @@ public class ElanBridgeManager implements IElanBridgeManager {
         return getProviderInterfaceName(brNode, physicalNetworkName);
     }
 
+    @Nullable
     public String getProviderInterfaceName(Node bridgeNode, String physicalNetworkName) {
         if (physicalNetworkName == null) {
             return null;
@@ -625,10 +631,10 @@ public class ElanBridgeManager implements IElanBridgeManager {
     }
 
     public boolean hasDatapathID(Node node) {
-        return southboundUtils.getDataPathId(node) > 0 ? true : false;
+        return southboundUtils.getDataPathId(node) > 0;
     }
 
-    public Boolean isBridgeOnOvsdbNode(Node ovsdbNode, String bridgename) {
+    public boolean isBridgeOnOvsdbNode(Node ovsdbNode, String bridgename) {
         return southboundUtils.isBridgeOnOvsdbNode(ovsdbNode, bridgename);
     }
 
index 8e843eac716090bdbb27a72ca8bb6d28d5d0ed98..6b69e7193d544816d6295594aab369a709e8ace7 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.netvirt.elan.internal;
 
-import java.util.Collections;
+import static java.util.Collections.emptyList;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
+
+import java.util.List;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -84,7 +87,7 @@ public class ElanDpnInterfaceClusteredListener
         elanClusterUtils.runOnlyInOwnerNode(elanName, "updating mcast mac upon tunnel event",
             () -> {
                 elanL2GatewayMulticastUtils.updateRemoteMcastMacOnElanL2GwDevices(elanName);
-                return Collections.emptyList();
+                return emptyList();
             });
     }
 
@@ -120,8 +123,9 @@ public class ElanDpnInterfaceClusteredListener
     @Override
     protected void update(InstanceIdentifier<DpnInterfaces> identifier, DpnInterfaces original,
                           final DpnInterfaces dpnInterfaces) {
-        LOG.debug("dpninterfaces update fired new size {}", dpnInterfaces.getInterfaces().size());
-        if (dpnInterfaces.getInterfaces().isEmpty()) {
+        List<String> interfaces = requireNonNullElse(dpnInterfaces.getInterfaces(), emptyList());
+        LOG.debug("dpninterfaces update fired new size {}", interfaces.size());
+        if (interfaces.isEmpty()) {
             elanInstanceDpnsCache.remove(getElanName(identifier), dpnInterfaces);
             LOG.debug("dpninterfaces last dpn interface on this elan {} ", dpnInterfaces.key());
             // this is the last dpn interface on this elan
@@ -146,7 +150,7 @@ public class ElanDpnInterfaceClusteredListener
                     elanL2GatewayMulticastUtils.updateRemoteMcastMacOnElanL2GwDevices(elanName);
                 }
             }
-            return null;
+            return emptyList();
         });
     }
 
index 5b17290e75ad10a64199f40134594826d16ded39..23650aa7a5785196178e5e11e770346be4a72985 100644 (file)
@@ -8,8 +8,10 @@
 
 package org.opendaylight.netvirt.elan.internal;
 
+import static java.util.Collections.emptyList;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
+
 import java.math.BigInteger;
-import java.util.Collections;
 import java.util.List;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -76,13 +78,13 @@ public class ElanDpnInterfacesListener
         ElanInstance elanInstance = elanInstanceCache.get(elanInstanceName).orNull();
 
         if (elanInstance != null && !elanInstance.isExternal() && ElanUtils.isVlan(elanInstance)) {
-            List<String> interfaces = update.getInterfaces();
+            List<String> interfaces = requireNonNullElse(update.getInterfaces(), emptyList());
             // trigger deletion for vlan provider intf on the DPN for the vlan provider network
             if (interfaces.size() == 1 && interfaceManager.isExternalInterface(interfaces.get(0))) {
                 LOG.debug("deleting vlan prv intf for elan {}, dpn {}", elanInstanceName, dpnId);
                 jobCoordinator.enqueueJob(dpnId.toString(), () -> {
                     elanService.deleteExternalElanNetwork(elanInstance, dpnId);
-                    return Collections.emptyList();
+                    return emptyList();
                 });
             }
         }
@@ -102,7 +104,7 @@ public class ElanDpnInterfacesListener
                 LOG.debug("creating vlan member intf for elan {}, dpn {}",
                         elanInstance.getPhysicalNetworkName(), dpnId);
                 elanService.createExternalElanNetwork(elanInstance, dpnId);
-                return Collections.emptyList();
+                return emptyList();
             });
         }
     }
index a4d46200853d29ae4af755728e729712bfd1febd..b64e2c1031e4f9fe2b1776ad06172c3099627c26 100644 (file)
@@ -7,10 +7,12 @@
  */
 package org.opendaylight.netvirt.elan.internal;
 
+import static java.util.Collections.emptyList;
 import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
 import static org.opendaylight.netvirt.elan.utils.ElanUtils.isVxlanNetworkOrVxlanSegment;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -264,7 +266,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 return;
             }
             futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, flowTx -> {
-                List<String> elanInterfaces = elanState.getElanInterfaces();
+                List<String> elanInterfaces = requireNonNullElse(elanState.getElanInterfaces(), emptyList());
                 if (elanInterfaces.isEmpty()) {
                     holder.isLastElanInterface = true;
                 }
@@ -367,7 +369,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         if (elanState == null) {
             return elanState;
         }
-        List<String> elanInterfaces = elanState.getElanInterfaces();
+        List<String> elanInterfaces = requireNonNullElse(elanState.getElanInterfaces(), emptyList());
         boolean isRemoved = elanInterfaces.remove(interfaceName);
         if (!isRemoved) {
             return elanState;
@@ -486,7 +488,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
             for (DpnInterfaces dpnInterface : dpnInterfaces) {
                 BigInteger currentDpId = dpnInterface.getDpId();
                 if (!currentDpId.equals(dpId)) {
-                    for (String elanInterface : dpnInterface.getInterfaces()) {
+                    for (String elanInterface : requireNonNullElse(dpnInterface.getInterfaces(),
+                            Collections.<String>emptyList())) {
                         ElanInterfaceMac macs = elanUtils.getElanInterfaceMacByInterfaceName(elanInterface);
                         if (macs == null || macs.getMacEntry() == null) {
                             continue;
@@ -641,7 +644,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         }
         for (DpnInterfaces dpnInterfaces : dpnInterfaceLists) {
             BigInteger dstDpId = interfaceInfo.getDpId();
-            if (dpnInterfaces.getDpId().equals(dstDpId)) {
+            if (Objects.equals(dpnInterfaces.getDpId(), dstDpId)) {
                 continue;
             }
             List<String> remoteElanInterfaces = dpnInterfaces.getInterfaces();
@@ -717,7 +720,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                             holder.dpnInterfaces =
                                 createElanInterfacesList(elanInstanceName, interfaceName, holder.dpId, operTx);
                         } else {
-                            List<String> elanInterfaces = existingElanDpnInterfaces.get().getInterfaces();
+                            List<String> elanInterfaces =
+                                requireNonNullElse(existingElanDpnInterfaces.get().getInterfaces(), emptyList());
                             elanInterfaces.add(interfaceName);
                             holder.dpnInterfaces = updateElanDpnInterfacesList(elanInstanceName, holder.dpId,
                                 elanInterfaces, operTx);
@@ -731,7 +735,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                         elanL2GatewayUtils.installElanL2gwDevicesLocalMacsInDpn(holder.dpId, elanInstance,
                             interfaceName);
                     } else {
-                        List<String> elanInterfaces = existingElanDpnInterfaces.get().getInterfaces();
+                        List<String> elanInterfaces =
+                            requireNonNullElse(existingElanDpnInterfaces.get().getInterfaces(), emptyList());
                         elanInterfaces.add(interfaceName);
                         if (elanInterfaces.size() == 1) { // 1st dpn interface
                             elanL2GatewayUtils.installElanL2gwDevicesLocalMacsInDpn(holder.dpId, elanInstance,
@@ -880,13 +885,14 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         }
         DpnInterfaces dpnInterfaces = existingElanDpnInterfaces.get();
         int dummyInterfaceCount =  0;
-        if (dpnInterfaces.getInterfaces().contains(routerPortUuid)) {
+        List<String> interfaces = requireNonNullElse(dpnInterfaces.getInterfaces(), emptyList());
+        if (interfaces.contains(routerPortUuid)) {
             dummyInterfaceCount++;
         }
-        if (dpnInterfaces.getInterfaces().contains(elanInstanceName)) {
+        if (interfaces.contains(elanInstanceName)) {
             dummyInterfaceCount++;
         }
-        return dpnInterfaces.getInterfaces().size() - dummyInterfaceCount == 0;
+        return interfaces.size() - dummyInterfaceCount == 0;
     }
 
     private InstanceIdentifier<MacEntry> getMacEntryOperationalDataPath(String elanName, PhysAddress physAddress) {
@@ -1008,7 +1014,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         int bucketId = 0;
         ElanDpnInterfacesList elanDpns = elanUtils.getElanDpnInterfacesList(elanInfo.getElanInstanceName());
         if (elanDpns != null) {
-            List<DpnInterfaces> dpnInterfaces = elanDpns.getDpnInterfaces();
+            List<DpnInterfaces> dpnInterfaces = requireNonNullElse(elanDpns.getDpnInterfaces(), emptyList());
             for (DpnInterfaces dpnInterface : dpnInterfaces) {
                 List<Bucket> remoteListBucketInfo = new ArrayList<>();
                 if (elanUtils.isDpnPresent(dpnInterface.getDpId()) && !Objects.equals(dpnInterface.getDpId(), dpId)
@@ -1125,7 +1131,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                     }
                 })));
         }
-        return Collections.emptyList();
+        return emptyList();
     }
 
     private void createDropBucket(List<Bucket> listBucket) {
@@ -1149,7 +1155,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         long groupId = ElanUtils.getElanLocalBCGId(elanInfo.getElanTag());
 
         List<String> interfaces = new ArrayList<>();
-        if (newDpnInterface != null) {
+        if (newDpnInterface != null && newDpnInterface.getInterfaces() != null) {
             interfaces = newDpnInterface.getInterfaces();
         }
         for (String ifName : interfaces) {
@@ -1182,7 +1188,7 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
             int bucketId = 0;
 
             List<String> interfaces = new ArrayList<>();
-            if (newDpnInterface != null) {
+            if (newDpnInterface != null && newDpnInterface.getInterfaces() != null) {
                 interfaces = newDpnInterface.getInterfaces();
             }
             for (String ifName : interfaces) {
@@ -1565,7 +1571,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         if (dpnInterfaceLists == null) {
             return;
         }
-        List<ElanDpnInterfacesList> elanDpnIf = dpnInterfaceLists.getElanDpnInterfacesList();
+        List<ElanDpnInterfacesList> elanDpnIf =
+            requireNonNullElse(dpnInterfaceLists.getElanDpnInterfacesList(), emptyList());
         for (ElanDpnInterfacesList elanDpns : elanDpnIf) {
             int cnt = 0;
             String elanName = elanDpns.getElanInstanceName();
@@ -1586,9 +1593,9 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
             DpnInterfaces dstDpnIf = null;
             for (DpnInterfaces dpnIf : dpnInterfaces) {
                 BigInteger dpnIfDpId = dpnIf.getDpId();
-                if (dpnIfDpId.equals(srcDpId)) {
+                if (Objects.equals(dpnIfDpId, srcDpId)) {
                     cnt++;
-                } else if (dpnIfDpId.equals(dstDpId)) {
+                } else if (Objects.equals(dpnIfDpId, dstDpId)) {
                     cnt++;
                     dstDpnIf = dpnIf;
                 }
@@ -1615,10 +1622,10 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                             if (isOperational(interfaceInfo)) {
                                 return installDMacAddressTables(elanInfo, interfaceInfo, srcDpId);
                             }
-                            return Collections.emptyList();
+                            return emptyList();
                         }, ElanConstants.JOB_MAX_RETRIES);
                     }
-                    return Collections.emptyList();
+                    return emptyList();
                 }, ElanConstants.JOB_MAX_RETRIES);
             }
 
@@ -1657,7 +1664,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
         if (dpnInterfaceLists == null) {
             return;
         }
-        List<ElanDpnInterfacesList> elanDpnIf = dpnInterfaceLists.getElanDpnInterfacesList();
+        List<ElanDpnInterfacesList> elanDpnIf =
+            requireNonNullElse(dpnInterfaceLists.getElanDpnInterfacesList(), emptyList());
         for (ElanDpnInterfacesList elanDpns : elanDpnIf) {
             String elanName = elanDpns.getElanInstanceName();
             ElanInstance elanInfo = elanInstanceCache.get(elanName).orNull();
index eae199f0956d79c4f768416849bf4c47d1e6b293..8d1865ac9278ba59d647c698d624be0a4edef4db 100644 (file)
@@ -69,7 +69,7 @@ public class ElanInterfaceStateClusteredListener extends
     @Override
     protected void add(InstanceIdentifier<Interface> identifier, final Interface intrf) {
         if (intrf.getType() != null && intrf.getType().equals(Tunnel.class)) {
-            if (intrf.getOperStatus().equals(Interface.OperStatus.Up)) {
+            if (Interface.OperStatus.Up.equals(intrf.getOperStatus())) {
                 final String interfaceName = intrf.getName();
 
                 elanClusterUtils.runOnlyInOwnerNode("external tunnel update", () -> {
index 327ae36c68ee52c96f754e22cc886c1dcf45d5a1..06d90a9beb9c8e2ba27c5236f7b18cd6b817c810 100644 (file)
@@ -81,7 +81,7 @@ public class ElanOvsdbNodeListener extends AsyncDataTreeChangeListenerBase<Node,
     @Override
     protected void update(InstanceIdentifier<Node> identifier, Node original, Node update) {
         LOG.debug("ElanOvsdbNodeListener.update, updated node detected. original: {} new: {}", original, update);
-        Boolean integrationBridgeExist = bridgeMgr.isBridgeOnOvsdbNode(update, bridgeMgr.getIntegrationBridgeName());
+        boolean integrationBridgeExist = bridgeMgr.isBridgeOnOvsdbNode(update, bridgeMgr.getIntegrationBridgeName());
         // ignore updates where the bridge was deleted
         if (!(bridgeMgr.isBridgeOnOvsdbNode(original, bridgeMgr.getIntegrationBridgeName())
                 && !integrationBridgeExist)) {
index 07767fdc309b394c3e97361dac48393b6bdc9564..bf51464c02e9e7b2355824ade87624d65d85db12 100755 (executable)
@@ -18,6 +18,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import java.util.Objects;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
@@ -171,7 +172,7 @@ public class ElanPacketInHandler implements PacketProcessingListener {
                                                final boolean isVlanOrFlatProviderIface) {
         jobCoordinator.enqueueJob(ElanUtils.getElanMacKey(elanTag, macAddress),
             () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
-                if (oldMacEntry != null && oldMacEntry.getInterface().equals(interfaceName)) {
+                if (oldMacEntry != null && Objects.equals(oldMacEntry.getInterface(), interfaceName)) {
                     // This should never occur because of ovs temporary mac learning
                     elanManagerCounters.unknownSmacPktinForwardingEntriesRemoved();
                 } else if (oldMacEntry != null && !isVlanOrFlatProviderIface) {
@@ -226,7 +227,7 @@ public class ElanPacketInHandler implements PacketProcessingListener {
 
     private void macMigrationFlowsCleanup(String interfaceName, ElanInstance elanInstance, MacEntry macEntry,
                                           boolean isVlanOrFlatProviderIface) {
-        if (macEntry != null && !macEntry.getInterface().equals(interfaceName)
+        if (macEntry != null && !Objects.equals(macEntry.getInterface(), interfaceName)
                 && !isVlanOrFlatProviderIface) {
             tryAndRemoveInvalidMacEntry(elanInstance.getElanInstanceName(), macEntry);
             elanManagerCounters.unknownSmacPktinFlowsRemovedForRelearned();
index 2faa3844af54c48f07a40ccc97152f1d5b2fc912..e5420d19bb9ea1ff86552fd17b9717735df45b25 100644 (file)
@@ -8,6 +8,9 @@
 
 package org.opendaylight.netvirt.elan.internal;
 
+import static java.util.Collections.emptyList;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
+
 import com.google.common.base.Optional;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
@@ -17,10 +20,12 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.Future;
 import java.util.function.BiFunction;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -130,6 +135,7 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
         candidateRegistration = registerCandidate(entityOwnershipService);
     }
 
+    @Nullable
     private static EntityOwnershipCandidateRegistration registerCandidate(
             EntityOwnershipService entityOwnershipService) {
         try {
@@ -235,6 +241,7 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
     }
 
     @Override
+    @Nullable
     public EtreeInterface getEtreeInterfaceByElanInterfaceName(String elanInterface) {
         return elanInterfaceCache.getEtreeInterface(elanInterface).orNull();
     }
@@ -243,7 +250,7 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
             String description) {
         boolean isEqual = false;
         if (existingElanInstance.getMacTimeout() == macTimeOut
-                && existingElanInstance.getDescription().equals(description)) {
+                && Objects.equals(existingElanInstance.getDescription(), description)) {
             isEqual = true;
         }
         return isEqual;
@@ -261,17 +268,15 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
 
     @Override
     public boolean deleteElanInstance(String elanInstanceName) {
-        boolean isSuccess = false;
         Optional<ElanInstance> existingElanInstance = elanInstanceCache.get(elanInstanceName);
         if (!existingElanInstance.isPresent()) {
             LOG.debug("Elan Instance is not present for {}", elanInstanceName);
-            return isSuccess;
+            return false;
         }
         LOG.debug("Deletion of the existing Elan Instance {}", existingElanInstance);
         ElanUtils.delete(broker, LogicalDatastoreType.CONFIGURATION,
                 ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName));
-        isSuccess = true;
-        return isSuccess;
+        return true;
     }
 
     @Override
@@ -301,8 +306,8 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
     }
 
     @Override
-    public void addElanInterface(String elanInstanceName, String interfaceName, List<String> staticMacAddresses,
-            String description) {
+    public void addElanInterface(String elanInstanceName, String interfaceName,
+            @Nullable List<String> staticMacAddresses, @Nullable String description) {
         Optional<ElanInstance> existingElanInstance = elanInstanceCache.get(elanInstanceName);
         if (existingElanInstance.isPresent()) {
             ElanInterfaceBuilder elanInterfaceBuilder = new ElanInterfaceBuilder()
@@ -420,6 +425,7 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
     }
 
     @Override
+    @Nullable
     public ElanInstance getElanInstance(String elanName) {
         return elanInstanceCache.get(elanName).orNull();
     }
@@ -429,7 +435,7 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
         InstanceIdentifier<ElanInstances> elanInstancesIdentifier = InstanceIdentifier.builder(ElanInstances.class)
                 .build();
         return ElanUtils.read(broker, LogicalDatastoreType.CONFIGURATION, elanInstancesIdentifier).toJavaUtil().map(
-                ElanInstances::getElanInstance).orElse(Collections.emptyList());
+                ElanInstances::getElanInstance).orElse(emptyList());
     }
 
     @Override
@@ -443,9 +449,10 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
         if (!elanInterfacesOptional.isPresent()) {
             return elanInterfaces;
         }
-        List<ElanInterface> elanInterfaceList = elanInterfacesOptional.get().getElanInterface();
+        List<ElanInterface> elanInterfaceList =
+            requireNonNullElse(elanInterfacesOptional.get().getElanInterface(), emptyList());
         for (ElanInterface elanInterface : elanInterfaceList) {
-            if (elanInterface.getElanInstanceName().equals(elanInstanceName)) {
+            if (Objects.equals(elanInterface.getElanInstanceName(), elanInstanceName)) {
                 elanInterfaces.add(elanInterface.getName());
             }
         }
@@ -661,6 +668,7 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
     }
 
     @Override
+    @Nullable
     public ElanInterface getElanInterfaceByElanInterfaceName(String interfaceName) {
         return elanInterfaceCache.get(interfaceName).orNull();
     }
@@ -722,13 +730,13 @@ public class ElanServiceProvider extends AbstractLifecycle implements IElanServi
         ElanInstance elanInstance = getElanInstance(elanInstanceName);
         if (elanInstance == null) {
             LOG.debug("No ELAN instance found for {}", elanInstanceName);
-            return Collections.emptyList();
+            return emptyList();
         }
 
         Long elanTag = elanInstance.getElanTag();
         if (elanTag == null) {
             LOG.debug("No ELAN tag found for {}", elanInstanceName);
-            return Collections.emptyList();
+            return emptyList();
         }
         return Collections.singletonList(
                 new NxMatchRegister(ElanConstants.ELAN_REG_ID, elanTag, MetaDataUtil.getElanMaskForReg()));
index 4124b82e9ca8258901bd4668baf75922e135b883..8f05dd0eb355a6d98f129822c76c12f58f63f7a0 100644 (file)
@@ -21,6 +21,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@@ -203,7 +204,7 @@ public final class HwvtepHAUtil {
         return physicalLocatorRef;
     }
 
-    public static boolean isEmptyList(List list) {
+    public static boolean isEmptyList(@Nullable List list) {
         return list == null || list.isEmpty();
     }
 
@@ -211,6 +212,7 @@ public final class HwvtepHAUtil {
         return collection == null || collection.isEmpty();
     }
 
+    @Nullable
     public static Node getOriginal(DataObjectModification<Node> mod) {
         Node node = null;
         switch (mod.getModificationType()) {
@@ -229,6 +231,7 @@ public final class HwvtepHAUtil {
         return node;
     }
 
+    @Nullable
     public static Node getUpdated(DataObjectModification<Node> mod) {
         Node node = null;
         switch (mod.getModificationType()) {
@@ -246,6 +249,7 @@ public final class HwvtepHAUtil {
         return node;
     }
 
+    @Nullable
     public static Node getCreated(DataObjectModification<Node> mod) {
         if (mod.getModificationType() == DataObjectModification.ModificationType.WRITE
                 && mod.getDataBefore() == null) {
@@ -254,6 +258,7 @@ public final class HwvtepHAUtil {
         return null;
     }
 
+    @Nullable
     public static Node getRemoved(DataObjectModification<Node> mod) {
         if (mod.getModificationType() == DataObjectModification.ModificationType.DELETE) {
             return mod.getDataBefore();
@@ -261,6 +266,7 @@ public final class HwvtepHAUtil {
         return null;
     }
 
+    @Nullable
     public static String getPsName(Node psNode) {
         String psNodeId = psNode.getNodeId().getValue();
         if (psNodeId.contains(PHYSICALSWITCH)) {
@@ -269,6 +275,7 @@ public final class HwvtepHAUtil {
         return null;
     }
 
+    @Nullable
     public static String getPsName(InstanceIdentifier<Node> psNodeIid) {
         String psNodeId = psNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
         if (psNodeId.contains(PHYSICALSWITCH)) {
@@ -285,6 +292,7 @@ public final class HwvtepHAUtil {
         return convertToInstanceIdentifier(psNodeId);
     }
 
+    @Nullable
     public static InstanceIdentifier<Node> convertPsPath(Node psNode, InstanceIdentifier<Node> nodePath) {
         String psNodeId = psNode.getNodeId().getValue();
         if (psNodeId.contains(PHYSICALSWITCH)) {
@@ -304,6 +312,7 @@ public final class HwvtepHAUtil {
         return nodeBuilder;
     }
 
+    @Nullable
     public static String getHAIdFromManagerOtherConfig(Node node) {
         if (node.augmentation(HwvtepGlobalAugmentation.class) == null) {
             return null;
@@ -311,9 +320,9 @@ public final class HwvtepHAUtil {
         HwvtepGlobalAugmentation globalAugmentation = node.augmentation(HwvtepGlobalAugmentation.class);
         if (globalAugmentation != null) {
             List<Managers> managers = globalAugmentation.getManagers();
-            if (managers != null && managers.size() > 0 && managers.get(0).getManagerOtherConfigs() != null) {
+            if (managers != null && !managers.isEmpty() && managers.get(0).getManagerOtherConfigs() != null) {
                 for (ManagerOtherConfigs configs : managers.get(0).getManagerOtherConfigs()) {
-                    if (configs.getOtherConfigKey().equals(HA_ID)) {
+                    if (HA_ID.equals(configs.getOtherConfigKey())) {
                         return configs.getOtherConfigValue();
                     }
                 }
@@ -342,7 +351,7 @@ public final class HwvtepHAUtil {
                 return childNodeIds;
             }
             for (ManagerOtherConfigs otherConfigs : managers.getManagerOtherConfigs()) {
-                if (otherConfigs.getOtherConfigKey().equals(HA_CHILDREN)) {
+                if (HA_CHILDREN.equals(otherConfigs.getOtherConfigKey())) {
                     String nodeIdsVal = otherConfigs.getOtherConfigValue();
                     if (nodeIdsVal != null) {
                         String[] parts = nodeIdsVal.split(",");
index f3f430a8ea7d08f457de4a3f3dd5b9c3cb215b87..74cee2f4eec8143ee10454679919bc511e6b18e4 100644 (file)
@@ -11,6 +11,7 @@ import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 public abstract class BaseCommand<T> {
 
@@ -19,10 +20,11 @@ public abstract class BaseCommand<T> {
      * @param updated Updated List
      * @param original Origina list to be compared with
      * @param comparator based on which diff will be returned
-     * @param <T> T extends DataObject
+     * @param <U> U extends DataObject
      * @return List of diff based on comparator
      */
-    public <T> List<T> diffOf(List<T> updated, final List<T> original, final Comparator comparator) {
+    public <U> List<U> diffOf(@Nullable List<U> updated, @Nullable final List<U> original,
+            final Comparator<U> comparator) {
         if (updated == null) {
             return new ArrayList<>();
         }
@@ -30,10 +32,10 @@ public abstract class BaseCommand<T> {
             return new ArrayList<>(updated);
         }
 
-        List<T> result = new ArrayList<>();
-        for (T ele : updated) {
+        List<U> result = new ArrayList<>();
+        for (U ele : updated) {
             boolean present = false;
-            for (T orig : original) {
+            for (U orig : original) {
                 if (0 == comparator.compare(ele, orig)) {
                     present = true;
                     break;
index 962e65f00e6aee794c454df7c2a42ed4d7f240d6..913dd6bc83f420fb7f0023b165a087fa8d3c24f9 100644 (file)
@@ -7,8 +7,13 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
+
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
+import javax.annotation.Nullable;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
@@ -31,6 +36,7 @@ public class LocalMcastCmd
     }
 
     @Override
+    @Nullable
     public List<LocalMcastMacs> getData(HwvtepGlobalAugmentation node) {
         if (node != null) {
             return node.getLocalMcastMacs();
@@ -55,7 +61,7 @@ public class LocalMcastCmd
     public LocalMcastMacs transform(InstanceIdentifier<Node> nodePath, LocalMcastMacs src) {
         LocalMcastMacsBuilder ucmlBuilder = new LocalMcastMacsBuilder(src);
         List<LocatorSet> locatorSet = new ArrayList<>();
-        for (LocatorSet locator : src.getLocatorSet()) {
+        for (LocatorSet locator : requireNonNullElse(src.getLocatorSet(), Collections.<LocatorSet>emptyList())) {
             locatorSet.add(new LocatorSetBuilder().setLocatorRef(HwvtepHAUtil.buildLocatorRef(nodePath,
                     HwvtepHAUtil.getTepIpVal(locator.getLocatorRef()))).build());
         }
@@ -86,7 +92,7 @@ public class LocalMcastCmd
                 .getHwvtepNodeName();
         InstanceIdentifier<?> origMacRefIdentifier = orig.getLogicalSwitchRef().getValue();
         HwvtepNodeName origMacNodeName = origMacRefIdentifier.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName();
-        if (updated.getMacEntryKey().equals(orig.getMacEntryKey())
+        if (Objects.equals(updated.getMacEntryKey(), orig.getMacEntryKey())
                 && updatedMacNodeName.equals(origMacNodeName)) {
             List<LocatorSet> updatedLocatorSet = updated.getLocatorSet();
             List<LocatorSet> origLocatorSet = orig.getLocatorSet();
index 1599816d225b316374fc5052c4aaad431fc27283..4aefc90907d976e9caff2e75385a190d848bfd01 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
@@ -30,6 +31,7 @@ public class LocalUcastCmd
     }
 
     @Override
+    @Nullable
     public List<LocalUcastMacs> getData(HwvtepGlobalAugmentation node) {
         if (node != null) {
             return node.getLocalUcastMacs();
index 94de5168fbaac2a7a415b161dd4eb20af4b73335..f97783026498d43434f161331033a8d7a7db50a2 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
@@ -24,6 +25,7 @@ public class LogicalSwitchesCmd extends MergeCommand<LogicalSwitches,
     }
 
     @Override
+    @Nullable
     public List<LogicalSwitches> getData(HwvtepGlobalAugmentation node) {
         if (node != null) {
             return node.getLogicalSwitches();
index 44a8bdcd80bd8bf892454890dfd2f1113f4a9b03..d75f76bd1f3e3105a6a0bd5f753e1908aeef3abc 100644 (file)
@@ -18,6 +18,7 @@ import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -186,7 +187,7 @@ public abstract class MergeCommand<T extends DataObject, Y extends Builder, Z ex
         transformUpdate(existingData, updatedData, origData, nodePath, OPERATIONAL, tx);
     }
 
-    boolean areSameSize(List objA, List objB) {
+    boolean areSameSize(@Nullable List objA, @Nullable List objB) {
         if (HwvtepHAUtil.isEmptyList(objA) && HwvtepHAUtil.isEmptyList(objB)) {
             return true;
         }
@@ -217,6 +218,7 @@ public abstract class MergeCommand<T extends DataObject, Y extends Builder, Z ex
         }
     }
 
+    @Nullable
     public abstract List<T> getData(Z node);
 
     public abstract void setData(Y builder, List<T> data);
index b03e8a201859e8dfa12eed4f85eafa2b6784102f..e7234f8e08d7978aca812570d83185822f28535c 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
 import java.util.List;
+import java.util.Objects;
+import javax.annotation.Nullable;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
@@ -21,6 +23,7 @@ public class PhysicalLocatorCmd extends MergeCommand<TerminationPoint, NodeBuild
     }
 
     @Override
+    @Nullable
     public List<TerminationPoint> getData(Node node) {
         if (node != null) {
             return node.getTerminationPoint();
@@ -59,7 +62,7 @@ public class PhysicalLocatorCmd extends MergeCommand<TerminationPoint, NodeBuild
                 updated.augmentation(HwvtepPhysicalLocatorAugmentation.class);
         HwvtepPhysicalLocatorAugmentation origPhysicalLocator =
                 orig.augmentation(HwvtepPhysicalLocatorAugmentation.class);
-        return updatedPhysicalLocator.getDstIp().equals(origPhysicalLocator.getDstIp())
+        return Objects.equals(updatedPhysicalLocator.getDstIp(), origPhysicalLocator.getDstIp())
                 && updatedPhysicalLocator.getEncapsulationType() == origPhysicalLocator.getEncapsulationType();
     }
 
index 763825bc0499c4fe20252b5a45f3545187b9dd2e..6e2b024804c0c67c3151f64952301a46178549b2 100644 (file)
@@ -7,8 +7,13 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
+
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
+import javax.annotation.Nullable;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
@@ -31,6 +36,7 @@ public class RemoteMcastCmd extends
     }
 
     @Override
+    @Nullable
     public List<RemoteMcastMacs> getData(HwvtepGlobalAugmentation augmentation) {
         if (augmentation != null) {
             return augmentation.getRemoteMcastMacs();
@@ -55,7 +61,7 @@ public class RemoteMcastCmd extends
     public RemoteMcastMacs transform(InstanceIdentifier<Node> nodePath, RemoteMcastMacs src) {
         RemoteMcastMacsBuilder ucmlBuilder = new RemoteMcastMacsBuilder(src);
         List<LocatorSet> locatorSet = new ArrayList<>();
-        for (LocatorSet locator : src.getLocatorSet()) {
+        for (LocatorSet locator : requireNonNullElse(src.getLocatorSet(), Collections.<LocatorSet>emptyList())) {
             locatorSet.add(new LocatorSetBuilder().setLocatorRef(HwvtepHAUtil.buildLocatorRef(nodePath,
                     HwvtepHAUtil.getTepIpVal(locator.getLocatorRef()))).build());
         }
@@ -87,7 +93,7 @@ public class RemoteMcastCmd extends
                 .getHwvtepNodeName();
         InstanceIdentifier<?> origMacRefIdentifier = orig.getLogicalSwitchRef().getValue();
         HwvtepNodeName origMacNodeName = origMacRefIdentifier.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName();
-        if (updated.getMacEntryKey().equals(orig.getMacEntryKey())
+        if (Objects.equals(updated.getMacEntryKey(), orig.getMacEntryKey())
                 && updatedMacNodeName.equals(origMacNodeName)) {
             List<LocatorSet> updatedLocatorSet = updated.getLocatorSet();
             List<LocatorSet> origLocatorSet = orig.getLocatorSet();
index f73e37d8d64121598afc232d8eaef8fb5ff700db..d8abdfe01dd7f2f1a927b1949275df8f212b42f0 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
 import java.util.List;
+import java.util.Objects;
+import javax.annotation.Nullable;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
@@ -28,6 +30,7 @@ public class RemoteUcastCmd extends MergeCommand<RemoteUcastMacs,
     }
 
     @Override
+    @Nullable
     public List<RemoteUcastMacs> getData(HwvtepGlobalAugmentation node) {
         if (node != null) {
             return node.getRemoteUcastMacs();
@@ -78,7 +81,7 @@ public class RemoteUcastCmd extends MergeCommand<RemoteUcastMacs,
                 .getHwvtepNodeName();
         InstanceIdentifier<?> origMacRefIdentifier = orig.getLogicalSwitchRef().getValue();
         HwvtepNodeName origMacNodeName = origMacRefIdentifier.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName();
-        return updated.getMacEntryKey().equals(orig.getMacEntryKey())
+        return Objects.equals(updated.getMacEntryKey(), orig.getMacEntryKey())
                 && updatedMacNodeName.equals(origMacNodeName);
     }
 
index 1ff791928525fcd662dccadd83e1ada7a89b4e29..1b9670188f9ef2e9914ccf25a9dda86b05606cdc 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
@@ -24,6 +25,7 @@ public class SwitchesCmd extends MergeCommand<Switches, HwvtepGlobalAugmentation
     }
 
     @Override
+    @Nullable
     public List<Switches> getData(HwvtepGlobalAugmentation node) {
         if (node != null) {
             return node.getSwitches();
index e2e80a8430f43cda67c344e79419c23ff499ce15..db1cf06eacb746f0e36c34adaee4de6ebd063246 100644 (file)
@@ -11,6 +11,7 @@ import java.io.Serializable;
 import java.util.Comparator;
 import java.util.List;
 import java.util.stream.Collectors;
+import javax.annotation.Nullable;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalPortAugmentationBuilder;
@@ -29,6 +30,7 @@ public class TerminationPointCmd extends MergeCommand<TerminationPoint, NodeBuil
     }
 
     @Override
+    @Nullable
     public List<TerminationPoint> getData(Node node) {
         if (node != null) {
             return node.getTerminationPoint();
index d5a15c29956cf84736fe8185146d16ec28481a1b..2d7cfc2e200bef94d35eb295607afa8d4162529a 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
 import java.util.List;
+import javax.annotation.Nullable;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
@@ -27,6 +28,7 @@ public class TunnelCmd  extends MergeCommand<Tunnels, PhysicalSwitchAugmentation
     }
 
     @Override
+    @Nullable
     public List<Tunnels> getData(PhysicalSwitchAugmentation node) {
         if (node != null) {
             return node.getTunnels();
index 66aa92e752886373b15dd6e8eb7c4acad9a6ac84..e64c5a55fb741029fc510c02f83615634d0980a4 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
 import java.util.List;
 import java.util.Objects;
+import javax.annotation.Nullable;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIps;
@@ -23,6 +24,7 @@ public class TunnelIpCmd extends
     }
 
     @Override
+    @Nullable
     public List<TunnelIps> getData(PhysicalSwitchAugmentation node) {
         if (node != null) {
             return node.getTunnelIps();
index d03465597f28491c2f0cf35afc115862bafa7d42..1c31257b4cf10868233c17a4457057149be2cb76 100644 (file)
@@ -166,7 +166,7 @@ public class NodeCopier implements INodeCopier {
                                      */
                                     HwvtepHAUtil.deleteNodeIfPresent(tx, dstPsPath);
                                 }
-                            }), LOG, "Failed to read source node {}", srcPsNodeOptional.get());
+                            }), LOG, "Failed to read source node {}", srcPsPath);
                     });
                 }
 
index b4eba7e3055a1c658ef99a7ad6e778899a12e5bc..3a3e6b296853a84ca8f5d3027ce6ea79be034dff 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Nullable;
 import javax.annotation.PreDestroy;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
@@ -204,6 +205,7 @@ public abstract class ChildListener<P extends DataObject, C extends DataObject,
         }
     }
 
+    @Nullable
     protected DataObjectModification.ModificationType getModificationType(
             final DataObjectModification<? extends DataObject> mod) {
         try {
index d313171cf5dfc7bb197eabd41625cd6be4abf18a..c7a78ddc121b3d1e79c5a261855faff63a4312be 100644 (file)
@@ -12,6 +12,7 @@ import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import java.math.BigInteger;
 import java.util.List;
 import java.util.concurrent.ConcurrentMap;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -41,7 +42,6 @@ import org.slf4j.LoggerFactory;
 public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<Group, ElanGroupListener> {
 
     private static final Logger LOG = LoggerFactory.getLogger(ElanGroupListener.class);
-    private final DataBroker broker;
     private final ManagedNewTransactionRunner txRunner;
     private final ElanClusterUtils elanClusterUtils;
     private final ElanUtils elanUtils;
@@ -52,13 +52,12 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
     public ElanGroupListener(DataBroker db, ElanClusterUtils elanClusterUtils, ElanUtils elanUtils,
             ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils, ElanInstanceCache elanInstanceCache) {
         super(Group.class, ElanGroupListener.class);
-        broker = db;
         this.txRunner = new ManagedNewTransactionRunnerImpl(db);
         this.elanClusterUtils = elanClusterUtils;
         this.elanUtils = elanUtils;
         this.elanL2GatewayMulticastUtils = elanL2GatewayMulticastUtils;
         this.elanInstanceCache = elanInstanceCache;
-        registerListener(LogicalDatastoreType.CONFIGURATION, broker);
+        registerListener(LogicalDatastoreType.CONFIGURATION, db);
         LOG.trace("ElanGroupListener registered");
     }
 
@@ -74,6 +73,7 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
     }
 
 
+    @Nullable
     ElanInstance getElanInstanceFromGroupId(Group update) {
         for (ElanInstance elanInstance : elanInstanceCache.getAllPresent()) {
             if (elanInstance.getElanTag() != null) {
@@ -87,6 +87,7 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
         return null;
     }
 
+    @Nullable
     private BigInteger getDpnId(String node) {
         //openflow:1]
         String[] temp = node.split(":");
@@ -97,7 +98,7 @@ public class ElanGroupListener extends AsyncClusteredDataTreeChangeListenerBase<
     }
 
     @Override
-    protected void update(InstanceIdentifier<Group> identifier, Group original, Group update) {
+    protected void update(InstanceIdentifier<Group> identifier, @Nullable Group original, Group update) {
         LOG.trace("received group updated {}", update.key().getGroupId());
         final BigInteger dpnId = getDpnId(identifier.firstKeyOf(Node.class).getId().getValue());
         if (dpnId == null) {
index 2a16e8ebee10ca3fda88d313ba94f70244ee6196..525031420de81f3c534bd790fd49491eddd0b066 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Objects;
 import java.util.Set;
 import java.util.function.BiPredicate;
 import java.util.function.Predicate;
+import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -360,6 +361,7 @@ public class HwvtepPhysicalSwitchListener
         return psNodeId;
     }
 
+    @Nullable
     private InstanceIdentifier<Node> getManagedByNodeIid(InstanceIdentifier<PhysicalSwitchAugmentation> identifier) {
         String psNodeId = identifier.firstKeyOf(Node.class).getNodeId().getValue();
         if (psNodeId.contains(HwvtepHAUtil.PHYSICALSWITCH)) {
@@ -369,6 +371,7 @@ public class HwvtepPhysicalSwitchListener
         return null;
     }
 
+    @Nullable
     private String getPsName(InstanceIdentifier<PhysicalSwitchAugmentation> identifier) {
         String psNodeId = identifier.firstKeyOf(Node.class).getNodeId().getValue();
         if (psNodeId.contains(HwvtepHAUtil.PHYSICALSWITCH)) {
index 1717446ea4499c0906e4623cea0b443cc8815f2c..452f2d581becfa7297a17cbc00f7b944d1fae80c 100644 (file)
@@ -7,12 +7,15 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.listeners;
 
+import static java.util.Collections.emptyList;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -144,7 +147,7 @@ public class HwvtepTerminationPointListener
         } else {
             LOG.error("{} entry not in config datastore", psNodeId);
         }
-        return Collections.emptyList();
+        return emptyList();
     }
 
     private List<ListenableFuture<Void>> handlePortDeleted(InstanceIdentifier<TerminationPoint> identifier) {
@@ -164,12 +167,13 @@ public class HwvtepTerminationPointListener
             } else {
                 String logicalSwitchName = ElanL2GatewayUtils.getLogicalSwitchFromElan(
                         l2GwConn.getNetworkId().getValue());
-                List<Devices> l2Devices = l2Gateway.getDevices();
+                List<Devices> l2Devices = requireNonNullElse(l2Gateway.getDevices(), emptyList());
                 for (Devices l2Device : l2Devices) {
                     String l2DeviceName = l2Device.getDeviceName();
                     if (l2DeviceName != null && l2DeviceName.equals(psName)) {
-                        for (Interfaces deviceInterface : l2Device.getInterfaces()) {
-                            if (deviceInterface.getInterfaceName().equals(newPortId)) {
+                        for (Interfaces deviceInterface : requireNonNullElse(l2Device.getInterfaces(),
+                                Collections.<Interfaces>emptyList())) {
+                            if (Objects.equals(deviceInterface.getInterfaceName(), newPortId)) {
                                 if (deviceInterface.getSegmentationIds() != null
                                         && !deviceInterface.getSegmentationIds().isEmpty()) {
                                     for (Integer vlanId : deviceInterface.getSegmentationIds()) {
index a5bde9463507ee19c69b4569add41511c5deea4f..97dfa4922d9790e4c5bbaa0a664db8d34c498835 100644 (file)
@@ -10,16 +10,19 @@ package org.opendaylight.netvirt.elan.l2gw.utils;
 import static java.util.Collections.emptyList;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.netvirt.elan.utils.ElanUtils.isVxlanNetworkOrVxlanSegment;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentMap;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -230,14 +233,14 @@ public class ElanL2GatewayMulticastUtils {
         setupElanBroadcastGroups(elanInfo, null, dpnId, confTx);
     }
 
-    public void setupElanBroadcastGroups(ElanInstance elanInfo, DpnInterfaces dpnInterfaces, BigInteger dpnId,
+    public void setupElanBroadcastGroups(ElanInstance elanInfo, @Nullable DpnInterfaces dpnInterfaces, BigInteger dpnId,
             TypedWriteTransaction<Datastore.Configuration> confTx) {
         setupStandardElanBroadcastGroups(elanInfo, dpnInterfaces, dpnId, confTx);
         setupLeavesEtreeBroadcastGroups(elanInfo, dpnInterfaces, dpnId, confTx);
     }
 
-    public void setupStandardElanBroadcastGroups(ElanInstance elanInfo, DpnInterfaces dpnInterfaces, BigInteger dpnId,
-            TypedWriteTransaction<Datastore.Configuration> confTx) {
+    public void setupStandardElanBroadcastGroups(ElanInstance elanInfo, @Nullable DpnInterfaces dpnInterfaces,
+            BigInteger dpnId, TypedWriteTransaction<Datastore.Configuration> confTx) {
         List<Bucket> listBucket = new ArrayList<>();
         int bucketId = 0;
         int actionKey = 0;
@@ -256,8 +259,8 @@ public class ElanL2GatewayMulticastUtils {
         mdsalManager.addGroup(confTx, dpnId, group);
     }
 
-    public void setupLeavesEtreeBroadcastGroups(ElanInstance elanInfo, DpnInterfaces dpnInterfaces, BigInteger dpnId,
-            TypedWriteTransaction<Datastore.Configuration> confTx) {
+    public void setupLeavesEtreeBroadcastGroups(ElanInstance elanInfo, @Nullable DpnInterfaces dpnInterfaces,
+            BigInteger dpnId, TypedWriteTransaction<Datastore.Configuration> confTx) {
         EtreeInstance etreeInstance = elanInfo.augmentation(EtreeInstance.class);
         if (etreeInstance != null) {
             long etreeLeafTag = etreeInstance.getEtreeLeafTagVal().getValue();
@@ -280,10 +283,12 @@ public class ElanL2GatewayMulticastUtils {
         }
     }
 
+    @Nullable
     private DpnInterfaces getDpnInterfaces(ElanDpnInterfacesList elanDpns, BigInteger dpnId) {
         if (elanDpns != null) {
-            for (DpnInterfaces dpnInterface : elanDpns.getDpnInterfaces()) {
-                if (dpnInterface.getDpId().equals(dpnId)) {
+            for (DpnInterfaces dpnInterface : requireNonNullElse(elanDpns.getDpnInterfaces(),
+                    Collections.<DpnInterfaces>emptyList())) {
+                if (Objects.equals(dpnInterface.getDpId(), dpnId)) {
                     return dpnInterface;
                 }
             }
@@ -313,8 +318,8 @@ public class ElanL2GatewayMulticastUtils {
     }
 
     @Nonnull
-    public List<Bucket> getRemoteBCGroupBuckets(ElanInstance elanInfo, DpnInterfaces dpnInterfaces, BigInteger dpnId,
-                                                int bucketId, long elanTag) {
+    public List<Bucket> getRemoteBCGroupBuckets(ElanInstance elanInfo, @Nullable DpnInterfaces dpnInterfaces,
+                                                BigInteger dpnId, int bucketId, long elanTag) {
         List<Bucket> listBucketInfo = new ArrayList<>();
         ElanDpnInterfacesList elanDpns = elanUtils.getElanDpnInterfacesList(elanInfo.getElanInstanceName());
 
@@ -396,7 +401,8 @@ public class ElanL2GatewayMulticastUtils {
             long elanTagOrVni) {
         List<Bucket> listBucketInfo = new ArrayList<>();
         if (elanDpns != null) {
-            for (DpnInterfaces dpnInterface : elanDpns.getDpnInterfaces()) {
+            for (DpnInterfaces dpnInterface : requireNonNullElse(elanDpns.getDpnInterfaces(),
+                    Collections.<DpnInterfaces>emptyList())) {
                 if (elanUtils.isDpnPresent(dpnInterface.getDpId()) && !Objects.equals(dpnInterface.getDpId(), dpnId)
                         && dpnInterface.getInterfaces() != null && !dpnInterface.getInterfaces().isEmpty()) {
                     try {
index 3d22638c90ec388580602e4a89d073c65f6c66bf..6be28a03701c3fa2a45ac8dcd6ebf5cf8110bd5c 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.l2gw.utils;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
@@ -32,6 +33,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -74,6 +76,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpc
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.DeviceVteps;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddL2GwDeviceInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.AddL2GwDeviceOutput;
@@ -207,7 +210,7 @@ public class ElanL2GatewayUtils {
                     HwvtepSouthboundUtils.createPhysicalLocatorInstanceIdentifier(nodeId, expectedPhyLocatorAug));
             if (remoteMcastMac.getLocatorSet() != null) {
                 for (LocatorSet locatorSet : remoteMcastMac.getLocatorSet()) {
-                    if (locatorSet.getLocatorRef().equals(expectedPhyLocRef)) {
+                    if (Objects.equals(locatorSet.getLocatorRef(), expectedPhyLocRef)) {
                         LOG.trace("matched phyLocRef: {}", expectedPhyLocRef);
                         return true;
                     }
@@ -274,6 +277,7 @@ public class ElanL2GatewayUtils {
         return HwvtepUtils.deleteRemoteUcastMacs(broker, nodeId, logicalSwitchName, lstMac);
     }
 
+    @Nullable
     public ElanInstance getElanInstanceForUcastLocalMac(LocalUcastMacs localUcastMac) {
         Optional<LogicalSwitches> lsOpc = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL,
                 (InstanceIdentifier<LogicalSwitches>) localUcastMac.getLogicalSwitchRef().getValue());
@@ -361,7 +365,7 @@ public class ElanL2GatewayUtils {
     }
 
     public void installL2GwUcastMacInElan(final ElanInstance elan, final L2GatewayDevice extL2GwDevice,
-            final String macToBeAdded, final LocalUcastMacs localUcastMacs, String interfaceName) {
+            final String macToBeAdded, final LocalUcastMacs localUcastMacs, @Nullable String interfaceName) {
         final String extDeviceNodeId = extL2GwDevice.getHwvtepNodeId();
         final String elanInstanceName = elan.getElanInstanceName();
         final Collection<DpnInterfaces> elanDpns = getElanDpns(elanInstanceName);
@@ -771,6 +775,7 @@ public class ElanL2GatewayUtils {
      *            the interface name
      * @return the dpid from interface
      */
+    @Nullable
     public BigInteger getDpidFromInterface(String interfaceName) {
         BigInteger dpId = null;
         Future<RpcResult<GetDpidFromInterfaceOutput>> output = interfaceManagerRpcService
@@ -935,6 +940,7 @@ public class ElanL2GatewayUtils {
         return interfaceInstanceIdentifierBuilder.build();
     }
 
+    @Nullable
     public static Interface getInterfaceFromConfigDS(InterfaceKey interfaceKey, DataBroker dataBroker) {
         InstanceIdentifier<Interface> interfaceId = getInterfaceIdentifier(interfaceKey);
         try {
@@ -1004,7 +1010,8 @@ public class ElanL2GatewayUtils {
                 return;
             }
             String psNodeId = globalNodeId + HwvtepHAUtil.PHYSICALSWITCH + psName;
-            tzonesoptional.get().getTransportZone().stream()
+            requireNonNullElse(tzonesoptional.get().getTransportZone(),
+                Collections.<TransportZone>emptyList()).stream()
                 .filter(transportZone -> transportZone.getSubnets() != null)
                 .flatMap(transportZone -> transportZone.getSubnets().stream())
                 .filter(subnet -> subnet.getDeviceVteps() != null)
@@ -1046,16 +1053,17 @@ public class ElanL2GatewayUtils {
             }
             JdkFutures.addErrorLogging(
                 new ManagedNewTransactionRunnerImpl(dataBroker).callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
-                    tx -> {
-                        optionalElan.get().getElanInstance().stream()
-                        .flatMap(elan -> elan.getExternalTeps().stream()
-                                .map(externalTep -> ElanL2GatewayMulticastUtils.buildExternalTepPath(
-                                        elan.getElanInstanceName(), externalTep.getTepIp())))
+                    tx -> requireNonNullElse(optionalElan.get().getElanInstance(),
+                        Collections.<ElanInstance>emptyList()).stream()
+                        .flatMap(elan -> requireNonNullElse(elan.getExternalTeps(),
+                            Collections.<ExternalTeps>emptyList()).stream()
+                            .map(externalTep -> ElanL2GatewayMulticastUtils.buildExternalTepPath(
+                                elan.getElanInstanceName(), externalTep.getTepIp())))
                         .filter(externalTepIid -> Objects.equals(
-                                deviceVteps.getIpAddress(), externalTepIid.firstKeyOf(ExternalTeps.class).getTepIp()))
+                            deviceVteps.getIpAddress(), externalTepIid.firstKeyOf(ExternalTeps.class).getTepIp()))
                         .peek(externalTepIid -> LOG.info("Deleting stale external tep {}", externalTepIid))
-                        .forEach(externalTepIid -> tx.delete(externalTepIid));
-                    }), LOG, "Failed to delete stale external teps {}", deviceVteps);
+                        .forEach(tx::delete)), LOG,
+                "Failed to delete stale external teps {}", deviceVteps);
             Thread.sleep(10000);//TODO remove the sleep currently it waits for interfacemgr to finish the cleanup
         } catch (ReadFailedException | InterruptedException e) {
             LOG.error("Failed to delete stale l2gw tep {}", deviceVteps, e);
index 15adbcff05b09c05e56a8e0cf29fbd2ab1ef9fd2..6e3a42cdc743093b7b53bb2d74716a450265ae8b 100644 (file)
@@ -8,7 +8,9 @@
 
 package org.opendaylight.netvirt.elan.l2gw.utils;
 
+import static java.util.Collections.emptyList;
 import static org.opendaylight.netvirt.elan.utils.ElanUtils.isVxlanNetworkOrVxlanSegment;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
@@ -16,11 +18,12 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -105,9 +108,10 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
     }
 
     public static boolean isGatewayAssociatedToL2Device(L2GatewayDevice l2GwDevice) {
-        return l2GwDevice.getL2GatewayIds().size() > 0;
+        return !l2GwDevice.getL2GatewayIds().isEmpty();
     }
 
+    @Nullable
     public static L2gateway getNeutronL2gateway(DataBroker broker, Uuid l2GatewayId) {
         LOG.debug("getNeutronL2gateway for {}", l2GatewayId.getValue());
         InstanceIdentifier<L2gateway> inst = InstanceIdentifier.create(Neutron.class).child(L2gateways.class)
@@ -119,7 +123,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
     public static List<L2gateway> getL2gatewayList(DataBroker broker) {
         InstanceIdentifier<L2gateways> inst = InstanceIdentifier.create(Neutron.class).child(L2gateways.class);
         return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst).toJavaUtil().map(
-                L2gateways::getL2gateway).orElse(Collections.emptyList());
+                L2gateways::getL2gateway).orElse(emptyList());
     }
 
     @Nonnull
@@ -127,7 +131,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
         InstanceIdentifier<L2gatewayConnections> inst = InstanceIdentifier.create(Neutron.class)
                 .child(L2gatewayConnections.class);
         return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst).toJavaUtil().map(
-                L2gatewayConnections::getL2gatewayConnection).orElse(Collections.emptyList());
+                L2gatewayConnections::getL2gatewayConnection).orElse(emptyList());
     }
 
     /**
@@ -145,7 +149,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
         List<L2gatewayConnection> l2GwConnections = new ArrayList<>();
         for (Uuid l2GatewayId : l2GatewayIds) {
             for (L2gatewayConnection l2GwConn : allL2GwConns) {
-                if (l2GwConn.getL2gatewayId().equals(l2GatewayId)) {
+                if (Objects.equals(l2GwConn.getL2gatewayId(), l2GatewayId)) {
                     l2GwConnections.add(l2GwConn);
                 }
             }
@@ -184,8 +188,8 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
     }
 
     public void addL2GatewayConnection(final L2gatewayConnection input,
-                                       final String l2GwDeviceName ,
-                                       L2gateway l2Gateway) {
+                                       @Nullable final String l2GwDeviceName ,
+                                       @Nullable L2gateway l2Gateway) {
         LOG.info("Adding L2gateway Connection with ID: {}", input.key().getUuid());
 
         Uuid networkUuid = input.getNetworkId();
@@ -224,7 +228,8 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
 
     private void disAssociateHwvtepsFromElan(String elanName, L2gatewayConnection input) {
         Integer defaultVlan = input.getSegmentId();
-        List<L2GatewayDevice> l2Devices = ElanL2GwCacheUtils.getAllElanDevicesFromCache();
+        List<L2GatewayDevice> l2Devices =
+            requireNonNullElse(ElanL2GwCacheUtils.getAllElanDevicesFromCache(), emptyList());
         List<Devices> l2gwDevicesToBeDeleted = new ArrayList<>();
         for (L2GatewayDevice elanL2gwDevice : l2Devices) {
             if (elanL2gwDevice.getL2GatewayIds().contains(input.key().getUuid())) {
@@ -238,7 +243,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
             if (l2Gateway == null) {
                 LOG.error("Failed to find the l2gateway for the connection {}", input.getUuid());
                 return;
-            } else {
+            } else if (l2Gateway.getDevices() != null) {
                 l2gwDevicesToBeDeleted.addAll(l2Gateway.getDevices());
             }
         }
@@ -274,11 +279,11 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
     }
 
     private void associateHwvtepsToElan(ElanInstance elanInstance,
-            L2gateway l2Gateway, L2gatewayConnection input, String l2GwDeviceName) {
+            L2gateway l2Gateway, L2gatewayConnection input, @Nullable String l2GwDeviceName) {
         String elanName = elanInstance.getElanInstanceName();
         Integer defaultVlan = input.getSegmentId();
         Uuid l2GwConnId = input.key().getUuid();
-        List<Devices> l2Devices = l2Gateway.getDevices();
+        List<Devices> l2Devices = requireNonNullElse(l2Gateway.getDevices(), emptyList());
 
         LOG.trace("Associating ELAN {} with L2Gw Conn Id {} having below L2Gw devices {}", elanName, l2GwConnId,
                 l2Devices);
@@ -409,7 +414,7 @@ public class L2GatewayConnectionUtils implements AutoCloseable {
         List<L2gatewayConnection> l2GwConnections = new ArrayList<>();
         List<L2gatewayConnection> allL2GwConns = getAllL2gatewayConnections(broker);
         for (L2gatewayConnection l2GwConn : allL2GwConns) {
-            if (l2GwConn.getL2gatewayId().equals(l2GatewayId)) {
+            if (Objects.equals(l2GwConn.getL2gatewayId(), l2GatewayId)) {
                 l2GwConnections.add(l2GwConn);
             }
         }
index a0cae369a140130d0cc13fd4630d4dcc84df425b..d79b270e067ccc8a96e796de9dcd0819160f46e2 100755 (executable)
@@ -10,6 +10,7 @@ package org.opendaylight.netvirt.elan.statisitcs;
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
@@ -84,6 +85,7 @@ public class ElanStatisticsImpl implements ElanStatisticsService {
                 .withResult(queryforElanInterfaceStatistics(tableId, elanInstanceName, interfaceInfo)).build());
     }
 
+    @Nullable
     private GetElanInterfaceStatisticsOutput queryforElanInterfaceStatistics(short tableId, String elanInstanceName,
             InterfaceInfo interfaceInfo) {
 //        BigInteger dpId = interfaceInfo.getDpId();
index 8068ee67a2191ad4b3d16c8534e390ae6a8aa6f4..e373f55166512834f157c2f0b1eaf8a48a6ccf9a 100644 (file)
@@ -15,6 +15,7 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -305,15 +306,15 @@ public class ElanDmacUtils {
 
     private ListenableFuture<Void> buildEtreeDmacFlowForExternalRemoteMacWithBatch(
             BigInteger dpnId, String extDeviceNodeId, Long vni, String macAddress, String displayName,
-            String interfaceName, EtreeLeafTagName etreeLeafTag) {
+            @Nullable String interfaceName, EtreeLeafTagName etreeLeafTag) {
 
         boolean isRoot;
         if (interfaceName == null) {
             isRoot = true;
         } else {
             Optional<EtreeInterface> etreeInterface = elanInterfaceCache.getEtreeInterface(interfaceName);
-            isRoot = etreeInterface.isPresent() ? etreeInterface.get().getEtreeInterfaceType()
-                    == EtreeInterface.EtreeInterfaceType.Root : false;
+            isRoot = etreeInterface.isPresent()
+                && etreeInterface.get().getEtreeInterfaceType() == EtreeInterface.EtreeInterfaceType.Root;
         }
         if (isRoot) {
             Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId,
@@ -337,7 +338,7 @@ public class ElanDmacUtils {
 
     public List<ListenableFuture<Void>> installDmacFlowsToExternalRemoteMacInBatch(
             BigInteger dpnId, String extDeviceNodeId, Long elanTag, Long vni, String macAddress, String displayName,
-            String interfaceName) {
+            @Nullable String interfaceName) {
 
         Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId, elanTag, vni, macAddress,
                 displayName);
@@ -355,7 +356,7 @@ public class ElanDmacUtils {
 
     private List<ListenableFuture<Void>> installEtreeDmacFlowsToExternalRemoteMacInBatch(
             BigInteger dpnId, String extDeviceNodeId, Long elanTag, Long vni, String macAddress, String displayName,
-            String interfaceName) {
+            @Nullable String interfaceName) {
 
         EtreeLeafTagName etreeLeafTag = elanEtreeUtils.getEtreeLeafTagByElanTag(elanTag);
         if (etreeLeafTag != null) {
index 3ee407e19513a925f8b227e5fcd5aa69b51141d7..33c6da02564f305a39856cd26306832092bf940d 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.utils;
 
 import com.google.common.base.Optional;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -25,6 +26,7 @@ public class ElanEtreeUtils {
         this.broker = broker;
     }
 
+    @Nullable
     public EtreeLeafTagName getEtreeLeafTagByElanTag(long elanTag) {
         InstanceIdentifier<ElanTagName> elanId = ElanUtils.getElanInfoEntriesOperationalDataPath(elanTag);
         Optional<ElanTagName> existingElanInfo = ElanUtils.read(broker,
index db9fd89eca802d2acb709211bfda67377a57f20f..defc7821d16732634c47ba2cb8699aa57a9490e8 100644 (file)
@@ -12,6 +12,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -203,7 +204,7 @@ public class ElanItmUtils {
      * @return the list
      */
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public List<Action> buildItmEgressActions(String interfaceName, Long tunnelKey, boolean internal) {
+    public List<Action> buildItmEgressActions(String interfaceName, @Nullable Long tunnelKey, boolean internal) {
         try {
             if (internal && interfaceManager.isItmDirectTunnelsEnabled()) {
                 GetEgressActionsForTunnelInput getEgressActInputItm = new GetEgressActionsForTunnelInputBuilder()
index ff832a637f956acd1bec517e9deb05db9a775211..3a6fce8d3c2ffb4b813f3c8308d0ccba58e931cf 100755 (executable)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netvirt.elan.utils;
 
+import static java.util.Collections.emptyList;
+import static java.util.Objects.requireNonNull;
 import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
@@ -26,6 +28,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
@@ -331,6 +334,7 @@ public class ElanUtils {
     }
 
     // elan-state Operational container
+    @Nullable
     public static Elan getElanByName(DataBroker broker, String elanInstanceName) {
         InstanceIdentifier<Elan> elanIdentifier = getElanInstanceOperationalDataPath(elanInstanceName);
         return MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, elanIdentifier).orNull();
@@ -347,18 +351,14 @@ public class ElanUtils {
     }
 
     // grouping of forwarding-entries
+    @Nullable
     public MacEntry getInterfaceMacEntriesOperationalDataPath(String interfaceName, PhysAddress physAddress) {
         InstanceIdentifier<MacEntry> existingMacEntryId = getInterfaceMacEntriesIdentifierOperationalDataPath(
                 interfaceName, physAddress);
         return read(broker, LogicalDatastoreType.OPERATIONAL, existingMacEntryId).orNull();
     }
 
-    public MacEntry getInterfaceMacEntriesOperationalDataPathFromId(InstanceIdentifier identifier) {
-        Optional<MacEntry> existingInterfaceMacEntry = read(broker,
-                LogicalDatastoreType.OPERATIONAL, identifier);
-        return existingInterfaceMacEntry.orNull();
-    }
-
+    @Nullable
     public MacEntry getInterfaceMacEntriesOperationalDataPathFromId(TypedReadTransaction<Operational> tx,
             InstanceIdentifier<MacEntry> identifier) throws ExecutionException, InterruptedException {
         return tx.read(identifier).get().orNull();
@@ -384,12 +384,7 @@ public class ElanUtils {
         return tx.read(macId).get();
     }
 
-    public MacEntry getMacEntryFromElanMacId(InstanceIdentifier identifier) {
-        Optional<MacEntry> existingInterfaceMacEntry = read(broker,
-                LogicalDatastoreType.OPERATIONAL, identifier);
-        return existingInterfaceMacEntry.orNull();
-    }
-
+    @Nullable
     public MacEntry getMacEntryFromElanMacId(TypedReadTransaction<Operational> tx,
             InstanceIdentifier<MacEntry> identifier) throws ExecutionException, InterruptedException {
         return tx.read(identifier).get().orNull();
@@ -445,7 +440,7 @@ public class ElanUtils {
 
     /**
      * Returns the list of Interfaces that belong to an Elan on an specific DPN.
-     * Data retrieved from Elan's operational DS: elan-dpn-interfaces container
+     * Data retrieved from Elan's operational DS: elan-dpn-interfaces container.
      *
      * @param elanInstanceName
      *            name of the Elan to which the interfaces must belong to
@@ -453,6 +448,7 @@ public class ElanUtils {
      *            Id of the DPN where the interfaces are located
      * @return the elan interface Info
      */
+    @Nullable
     public DpnInterfaces getElanInterfaceInfoByElanDpn(String elanInstanceName, BigInteger dpId) {
         InstanceIdentifier<DpnInterfaces> elanDpnInterfacesId = getElanDpnInterfaceOperationalDataPath(elanInstanceName,
                 dpId);
@@ -478,6 +474,7 @@ public class ElanUtils {
     }
 
     // elan-tag-name-map Operational Container
+    @Nullable
     public ElanTagName getElanInfoByElanTag(long elanTag) {
         InstanceIdentifier<ElanTagName> elanId = getElanInfoEntriesOperationalDataPath(elanTag);
         Optional<ElanTagName> existingElanInfo = read(broker,
@@ -506,11 +503,13 @@ public class ElanUtils {
                 .child(ElanDpnInterfacesList.class, new ElanDpnInterfacesListKey(elanInstanceName)).build();
     }
 
+    @Nullable
     public ElanDpnInterfacesList getElanDpnInterfacesList(String elanName) {
         InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanName);
         return read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId).orNull();
     }
 
+    @Nullable
     public ElanDpnInterfaces getElanDpnInterfacesList() {
         InstanceIdentifier<ElanDpnInterfaces> elanDpnInterfaceId = InstanceIdentifier.builder(ElanDpnInterfaces.class)
                 .build();
@@ -535,7 +534,8 @@ public class ElanUtils {
         if (!existingElanDpnInterfaces.isPresent()) {
             return dpIds;
         }
-        List<DpnInterfaces> dpnInterfaces = existingElanDpnInterfaces.get().getDpnInterfaces();
+        List<DpnInterfaces> dpnInterfaces =
+            requireNonNullElse(existingElanDpnInterfaces.get().getDpnInterfaces(), emptyList());
         for (DpnInterfaces dpnInterface : dpnInterfaces) {
             dpIds.add(dpnInterface.getDpId());
         }
@@ -560,15 +560,17 @@ public class ElanUtils {
         if (!existingElanDpnInterfaces.isPresent()) {
             return false;
         }
-        List<DpnInterfaces> dpnInterfaces = existingElanDpnInterfaces.get().getDpnInterfaces();
+        List<DpnInterfaces> dpnInterfaces =
+            requireNonNullElse(existingElanDpnInterfaces.get().getDpnInterfaces(), emptyList());
         for (DpnInterfaces dpnInterface : dpnInterfaces) {
-            if (dpnInterface.getDpId().equals(dpId)) {
+            if (Objects.equals(dpnInterface.getDpId(), dpId)) {
                 return true;
             }
         }
         return false;
     }
 
+    @Nullable
     public ElanForwardingTables getElanForwardingList() {
         InstanceIdentifier<ElanForwardingTables> elanForwardingTableId = InstanceIdentifier
                 .builder(ElanForwardingTables.class).build();
@@ -586,6 +588,7 @@ public class ElanUtils {
      *            the elan name
      * @return the elan mac table
      */
+    @Nullable
     public MacTable getElanMacTable(String elanName) {
         return getElanMacTable(broker, elanName);
     }
@@ -800,7 +803,8 @@ public class ElanUtils {
      * @return the egress actions for interface
      */
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public List<Action> getEgressActionsForInterface(String ifName, Long tunnelKey) {
+    @Nonnull
+    public List<Action> getEgressActionsForInterface(String ifName, @Nullable Long tunnelKey) {
         List<Action> listAction = new ArrayList<>();
         try {
             GetEgressActionsForInterfaceInput getEgressActionInput = new GetEgressActionsForInterfaceInputBuilder()
@@ -812,8 +816,7 @@ public class ElanUtils {
                 LOG.debug("RPC Call to Get egress actions for interface {} returned with Errors {}", ifName,
                         rpcResult.getErrors());
             } else {
-                List<Action> actions = rpcResult.getResult().getAction();
-                listAction = actions;
+                listAction = requireNonNullElse(rpcResult.getResult().getAction(), emptyList());
             }
         } catch (Exception e) {
             LOG.warn("Exception when egress actions for interface {}", ifName, e);
@@ -843,7 +846,7 @@ public class ElanUtils {
         List<DpnInterfaces> elanDpns = getInvolvedDpnsInElan(elanInstanceName);
         for (DpnInterfaces elanDpn : elanDpns) {
 
-            if (elanDpn.getDpId().equals(dpId)) {
+            if (Objects.equals(elanDpn.getDpId(), dpId)) {
                 continue;
             }
 
@@ -877,7 +880,7 @@ public class ElanUtils {
     public List<DpnInterfaces> getElanDPNByName(String elanInstanceName) {
         InstanceIdentifier<ElanDpnInterfacesList> elanIdentifier = getElanDpnOperationDataPath(elanInstanceName);
         return MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, elanIdentifier).toJavaUtil().map(
-                ElanDpnInterfacesList::getDpnInterfaces).orElse(Collections.emptyList());
+                ElanDpnInterfacesList::getDpnInterfaces).orElse(emptyList());
     }
 
     private void setupLocalDmacFlow(long elanTag, BigInteger dpId, String ifName, String macAddress,
@@ -1296,6 +1299,7 @@ public class ElanUtils {
      *            the datastore type
      * @return the external tunnel
      */
+    @Nullable
     public ExternalTunnel getExternalTunnel(String sourceDevice, String destinationDevice,
             LogicalDatastoreType datastoreType) {
         Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
@@ -1313,6 +1317,7 @@ public class ElanUtils {
      *            the datastore type
      * @return the external tunnel
      */
+    @Nullable
     public ExternalTunnel getExternalTunnel(String interfaceName, LogicalDatastoreType datastoreType) {
         ExternalTunnel externalTunnel = null;
         List<ExternalTunnel> externalTunnels = getAllExternalTunnels(datastoreType);
@@ -1335,7 +1340,7 @@ public class ElanUtils {
     public List<ExternalTunnel> getAllExternalTunnels(LogicalDatastoreType datastoreType) {
         InstanceIdentifier<ExternalTunnelList> iid = InstanceIdentifier.builder(ExternalTunnelList.class).build();
         return read(broker, datastoreType, iid).toJavaUtil().map(ExternalTunnelList::getExternalTunnel).orElse(
-                Collections.emptyList());
+                emptyList());
     }
 
     public static List<MatchInfo> buildMatchesForElanTagShFlagAndDstMac(long elanTag, boolean shFlag, String macAddr) {
@@ -1375,6 +1380,7 @@ public class ElanUtils {
      *            the data broker
      * @return the interface state from oper ds
      */
+    @Nullable
     public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
         .ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceStateFromOperDS(
             String interfaceName, DataBroker dataBroker) {
@@ -1435,7 +1441,7 @@ public class ElanUtils {
                 && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId() != 0;
     }
 
-    private static boolean isVxlanSegment(ElanInstance elanInstance) {
+    private static boolean isVxlanSegment(@Nullable ElanInstance elanInstance) {
         if (elanInstance != null) {
             List<ElanSegments> elanSegments = elanInstance.getElanSegments();
             if (elanSegments != null) {
@@ -1451,7 +1457,7 @@ public class ElanUtils {
         return false;
     }
 
-    public static boolean isVxlanNetworkOrVxlanSegment(ElanInstance elanInstance) {
+    public static boolean isVxlanNetworkOrVxlanSegment(@Nullable ElanInstance elanInstance) {
         return isVxlan(elanInstance) || isVxlanSegment(elanInstance);
     }
 
@@ -1524,6 +1530,7 @@ public class ElanUtils {
                 matches, instructions);
     }
 
+    @Nullable
     public String getExternalElanInterface(String elanInstanceName, BigInteger dpnId) {
         DpnInterfaces dpnInterfaces = getElanInterfaceInfoByElanDpn(elanInstanceName, dpnId);
         if (dpnInterfaces == null || dpnInterfaces.getInterfaces() == null) {
@@ -1656,7 +1663,7 @@ public class ElanUtils {
     public List<MacEntry> getElanMacEntries(String elanName) {
         MacTable macTable = getElanMacTable(elanName);
         if (macTable == null) {
-            return Collections.emptyList();
+            return emptyList();
         }
         return macTable.getMacEntry();
     }
@@ -1704,6 +1711,7 @@ public class ElanUtils {
                 NwConstants.ARP_RESPONDER_TABLE)), LOG, "Error removing ARP responder flow");
     }
 
+    @Nullable
     public static String getRouterPordIdFromElanInstance(DataBroker dataBroker, String elanInstanceName) {
         Optional<Subnetmaps> subnetMapsData =
                 read(dataBroker, LogicalDatastoreType.CONFIGURATION, buildSubnetMapsWildCardPath());
@@ -1730,6 +1738,10 @@ public class ElanUtils {
         return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:" + dpnId)))
                 .augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(new GroupId(groupId))).build();
     }
-}
-
 
+    // Use Objects.requireNonNullElse instead with JDK9+
+    @Nonnull
+    public static <T> T requireNonNullElse(@Nullable T obj, @Nonnull T defaultObj) {
+        return obj != null ? obj : requireNonNull(defaultObj);
+    }
+}
index c4c6898a8cfa8da151a60b73ed349add1f3d250f..cf63fe76f2fc4a154f37bd0da047905186b8b12c 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netvirt.elan.utils;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.MapDifference;
@@ -20,6 +21,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
@@ -394,8 +396,8 @@ public class TransportZoneNotificationUtil {
         }
 
         Subnets subnets = getOrAddSubnet(zoneSubnets, subnetIp);
-        for (Vteps existingVtep : subnets.getVteps()) {
-            if (existingVtep.getDpnId().equals(dpnId)) {
+        for (Vteps existingVtep : requireNonNullElse(subnets.getVteps(), Collections.<Vteps>emptyList())) {
+            if (Objects.equals(existingVtep.getDpnId(), dpnId)) {
                 return false;
             }
         }
@@ -425,7 +427,7 @@ public class TransportZoneNotificationUtil {
         IpPrefix subnetPrefix = IpPrefixBuilder.getDefaultInstance(subnetIp);
 
         for (Subnets subnet : subnets) {
-            if (subnet.getPrefix().equals(subnetPrefix)) {
+            if (Objects.equals(subnet.getPrefix(), subnetPrefix)) {
                 return subnet;
             }
         }
@@ -444,6 +446,7 @@ public class TransportZoneNotificationUtil {
         return subnetsBuilder.build();
     }
 
+    @Nullable
     private String getDpnLocalIp(BigInteger dpId) throws ReadFailedException {
         Optional<Node> node = getPortsNode(dpId);