Handle nullable lists 39/77539/4
authorStephen Kitt <skitt@redhat.com>
Mon, 5 Nov 2018 14:41:24 +0000 (15:41 +0100)
committerStephen Kitt <skitt@redhat.com>
Thu, 8 Nov 2018 09:09:46 +0000 (10:09 +0100)
... and a few other potential NPEs (with some drive-by clean-up, which
I can split out if necessary).

Change-Id: I84ed816ff938f25be2113068c4903a5e325ae216
Signed-off-by: Stephen Kitt <skitt@redhat.com>
59 files changed:
alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/genius/alivenessmonitor/internal/AlivenessMonitor.java
alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/genius/alivenessmonitor/internal/HwVtepTunnelsStateHandler.java
alivenessmonitor/alivenessmonitor-impl/src/main/java/org/opendaylight/genius/alivenessmonitor/utils/AlivenessMonitorUtil.java
arputil/arputil-impl/src/main/java/org/opendaylight/genius/arputil/internal/ArpUtilImpl.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/IdManager.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/IdPoolListener.java
idmanager/idmanager-impl/src/main/java/org/opendaylight/genius/idmanager/IdUtils.java
idmanager/idmanager-impl/src/test/java/org/opendaylight/genius/idmanager/test/IdManagerTest.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/IfmUtil.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/InterfacemgrProvider.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/commons/AlivenessMonitorUtils.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/commons/InterfaceManagerCommonUtils.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/CacheBridgeEntryConfigListener.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/CacheBridgeRefEntryListener.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/VlanMemberConfigListener.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/pmcounters/NodeConnectorStatsImpl.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/hwvtep/statehelpers/HwVTEPInterfaceStateUpdateHelper.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/ovs/confighelpers/OvsInterfaceConfigRemoveHelper.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/ovs/confighelpers/OvsInterfaceConfigUpdateHelper.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/ovs/confighelpers/OvsVlanMemberConfigRemoveHelper.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/ovs/confighelpers/OvsVlanMemberConfigUpdateHelper.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/ovs/statehelpers/OvsInterfaceStateUpdateHelper.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/ovs/utilities/SouthboundUtils.java
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/servicebindings/flowbased/listeners/FlowBasedServicesConfigListener.java
interfacemanager/interfacemanager-shell/src/main/java/org/opendaylight/genius/interfacemanager/shell/IfmCLIUtil.java
ipv6util/api/src/main/java/org/opendaylight/genius/ipv6util/api/Ipv6Util.java
ipv6util/impl/src/main/java/org/opendaylight/genius/ipv6util/nd/Ipv6NdUtilServiceImpl.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/cache/DpnTepStateCache.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/cli/ItmCliUtils.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/cli/TepCommandHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/cli/VtepSchemaShow.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmExternalTunnelAddWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmExternalTunnelDeleteWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmInternalTunnelAddWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmInternalTunnelDeleteWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmMonitorWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmTepRemoveWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmTunnelAggregationHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmTunnelStateAddHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/OvsdbTepAddConfigHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/OvsdbTepRemoveConfigHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/impl/ITMBatchingUtils.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/impl/ItmProvider.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/impl/ItmUtils.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/itmdirecttunnels/listeners/DpnTepStateListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/itmdirecttunnels/listeners/TerminationPointStateListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/itmdirecttunnels/listeners/TunnelInventoryStateListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/itmdirecttunnels/renderer/ovs/utilities/DirectTunnelUtils.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/InterfaceStateListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/TransportZoneListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/TunnelMonitorChangeListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/TunnelMonitorIntervalListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/VtepConfigSchemaListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/recovery/impl/ItmTepInstanceRecoveryHandler.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/rpc/ItmManagerRpcService.java
lockmanager/lockmanager-impl/src/main/java/org/opendaylight/genius/lockmanager/impl/LockManagerServiceImpl.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/NWUtil.java
mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/genius/mdsalutil/cache/DataObjectCache.java
mdsalutil/mdsalutil-api/src/test/java/org/opendaylight/genius/mdsalutil/interfaces/testutils/FlowAssertTestUtils.java

index 02e467b9f3d8a6b1a5d708ba3fd515f790ce068f..1ad31908407b6d69ff2a04e398b3dfe1da1c34f1 100644 (file)
@@ -12,6 +12,7 @@ import static org.opendaylight.genius.alivenessmonitor.utils.AlivenessMonitorUti
 import static org.opendaylight.genius.alivenessmonitor.utils.AlivenessMonitorUtil.getMonitorProfileId;
 import static org.opendaylight.genius.alivenessmonitor.utils.AlivenessMonitorUtil.getMonitorStateId;
 import static org.opendaylight.genius.alivenessmonitor.utils.AlivenessMonitorUtil.getMonitoringInfoId;
+import static org.opendaylight.genius.alivenessmonitor.utils.AlivenessMonitorUtil.nullToEmpty;
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
 
 import com.google.common.base.Optional;
@@ -574,7 +575,7 @@ public class AlivenessMonitor extends AbstractClusteredSyncDataTreeChangeListene
         ListenableFuture<Void> updateFuture = Futures.transformAsync(readFuture, optEntry -> {
             if (optEntry.isPresent()) {
                 InterfaceMonitorEntry entry = optEntry.get();
-                List<Long> monitorIds1 = entry.getMonitorIds();
+                List<Long> monitorIds1 = new ArrayList<>(nullToEmpty(entry.getMonitorIds()));
                 monitorIds1.add(monitorId);
                 InterfaceMonitorEntry newEntry1 = new InterfaceMonitorEntryBuilder()
                          .withKey(new InterfaceMonitorEntryKey(interfaceName)).setMonitorIds(monitorIds1).build();
@@ -1114,7 +1115,7 @@ public class AlivenessMonitor extends AbstractClusteredSyncDataTreeChangeListene
         ListenableFuture<Void> updateFuture = Futures.transformAsync(readFuture, optEntry -> {
             if (optEntry.isPresent()) {
                 InterfaceMonitorEntry entry = optEntry.get();
-                List<Long> monitorIds = entry.getMonitorIds();
+                List<Long> monitorIds = new ArrayList<>(nullToEmpty(entry.getMonitorIds()));
                 monitorIds.remove(monitorId);
                 if (monitorIds.isEmpty()) {
                     tx.delete(LogicalDatastoreType.OPERATIONAL, getInterfaceMonitorMapId(interfaceName));
index bc110c1b0830d6900f57dfee4555f4035c6950a0..93c33218daf9b511cde46ea6d990927bb4a7b41c 100644 (file)
@@ -182,9 +182,9 @@ public class HwVtepTunnelsStateHandler extends AbstractSyncDataTreeChangeListene
             return livenessState;
         }
         for (BfdStatus bfdState : tunnelBfdStatus) {
-            if (bfdState.getBfdStatusKey().equalsIgnoreCase(AlivenessMonitorConstants.BFD_OP_STATE)) {
+            if (AlivenessMonitorConstants.BFD_OP_STATE.equalsIgnoreCase(bfdState.getBfdStatusKey())) {
                 String bfdOpState = bfdState.getBfdStatusValue();
-                if (bfdOpState.equalsIgnoreCase(AlivenessMonitorConstants.BFD_STATE_UP)) {
+                if (AlivenessMonitorConstants.BFD_STATE_UP.equalsIgnoreCase(bfdOpState)) {
                     livenessState = LivenessState.Up;
                 } else {
                     livenessState = LivenessState.Down;
@@ -240,7 +240,7 @@ public class HwVtepTunnelsStateHandler extends AbstractSyncDataTreeChangeListene
         Iterator<BfdParams> tunnelBfdParamsIterator = tunnelBfdParams.iterator();
         while (tunnelBfdParamsIterator.hasNext()) {
             BfdParams bfdParam = tunnelBfdParamsIterator.next();
-            if (bfdParam.getBfdParamKey().equals(AlivenessMonitorConstants.BFD_PARAM_ENABLE)) {
+            if (AlivenessMonitorConstants.BFD_PARAM_ENABLE.equals(bfdParam.getBfdParamKey())) {
                 tunnelBfdParamsIterator.remove();
                 break;
             }
index aeb29f37e5888423afc8ac9be58c1476c776454d..1e987b642b11b6863539357a4bfeef1d4a0c6dfc 100644 (file)
@@ -7,7 +7,11 @@
  */
 package org.opendaylight.genius.alivenessmonitor.utils;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.apache.commons.lang3.StringUtils;
 import org.opendaylight.genius.ipv6util.api.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
@@ -94,4 +98,10 @@ public final class AlivenessMonitorUtil {
         }
         return errorText.toString();
     }
+
+    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3.0.2
+    @Nonnull
+    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
+        return input != null ? input : new ArrayList<>(0);
+    }
 }
index 91683deca5f5f72e841b82f39721accaed61cd8a..c559577ebbd5c004a1596b708bc401b2d7c37b13 100644 (file)
@@ -27,6 +27,8 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
+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;
@@ -228,7 +230,7 @@ public class ArpUtilImpl extends AbstractLifecycle implements OdlArputilService,
         }
 
         int localErrorCount = 0;
-        for (InterfaceAddress interfaceAddress : arpReqInput.getInterfaceAddress()) {
+        for (InterfaceAddress interfaceAddress : nullToEmpty(arpReqInput.getInterfaceAddress())) {
             try {
                 interfaceName = interfaceAddress.getInterface();
                 srcIpBytes = getIpAddressBytes(interfaceAddress.getIpAddress());
@@ -561,4 +563,10 @@ public class ArpUtilImpl extends AbstractLifecycle implements OdlArputilService,
 
         return new BigInteger(nodeKeyString.substring(OPENFLOW_PFX.length()));
     }
+
+    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3.0.2
+    @Nonnull
+    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
+        return input != null ? input : new ArrayList<>(0);
+    }
 }
index 172bb94f0e2015c816a711d7ad7083d1980b69d7..ff6f6d19222ac5f9f045cfa61fff9bf9a685a5d6 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.genius.idmanager;
 import static java.util.Comparator.comparing;
 import static java.util.stream.Collectors.toCollection;
 import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+import static org.opendaylight.genius.idmanager.IdUtils.nullToEmpty;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
 import com.google.common.base.Optional;
@@ -22,6 +23,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.CompletableFuture;
@@ -154,9 +156,7 @@ public class IdManager implements IdManagerService, IdManagerMonitor {
         if (!idPoolsOptional.isPresent()) {
             return;
         }
-        IdPools idPools = idPoolsOptional.get();
-        List<IdPool> idPoolList = idPools.getIdPool();
-        idPoolList
+        nullToEmpty(idPoolsOptional.get().getIdPool())
                 .stream()
                 .filter(idPool -> idPool.getParentPoolName() != null
                         && !idPool.getParentPoolName().isEmpty()
@@ -175,8 +175,7 @@ public class IdManager implements IdManagerService, IdManagerMonitor {
         ReleasedIdsHolder releasedIdsHolder = idPool.getReleasedIdsHolder();
         ReleasedIdHolder releasedIdHolder = new ReleasedIdHolder(idUtils, releasedIdsHolder.getDelayedTimeSec());
         releasedIdHolder.setAvailableIdCount(releasedIdsHolder.getAvailableIdCount());
-        List<DelayedIdEntries> delayedEntries = releasedIdsHolder.getDelayedIdEntries();
-        List<DelayedIdEntry> delayedIdEntryInCache = delayedEntries
+        List<DelayedIdEntry> delayedIdEntryInCache = nullToEmpty(releasedIdsHolder.getDelayedIdEntries())
                 .stream()
                 .map(delayedIdEntry -> new DelayedIdEntry(delayedIdEntry
                         .getId(), delayedIdEntry.getReadyTimeSec()))
@@ -437,7 +436,7 @@ public class IdManager implements IdManagerService, IdManagerMonitor {
 
     private long getIdsFromOtherChildPools(ReleasedIdsHolderBuilder releasedIdsBuilderParent, IdPool parentIdPool)
             throws OperationFailedException {
-        List<ChildPools> childPoolsList = parentIdPool.getChildPools();
+        List<ChildPools> childPoolsList = nullToEmpty(parentIdPool.getChildPools());
         // Sorting the child pools on last accessed time so that the pool that
         // was not accessed for a long time comes first.
         childPoolsList.sort(comparing(ChildPools::getLastAccessTime));
@@ -446,7 +445,7 @@ public class IdManager implements IdManagerService, IdManagerMonitor {
             if (childPools.getLastAccessTime() + DEFAULT_IDLE_TIME > currentTime) {
                 break;
             }
-            if (!childPools.getChildPoolName().equals(idUtils.getLocalPoolName(parentIdPool.getPoolName()))) {
+            if (!Objects.equals(childPools.getChildPoolName(), idUtils.getLocalPoolName(parentIdPool.getPoolName()))) {
                 InstanceIdentifier<IdPool> idPoolInstanceIdentifier = idUtils
                         .getIdPoolInstance(childPools.getChildPoolName());
                 IdPool otherChildPool =
@@ -575,7 +574,7 @@ public class IdManager implements IdManagerService, IdManagerMonitor {
             return;
         }
         IdEntries existingIdEntry = existingIdEntryObject.get();
-        List<Long> idValuesList = existingIdEntry.getIdValue();
+        List<Long> idValuesList = nullToEmpty(existingIdEntry.getIdValue());
         IdLocalPool localIdPoolCache = localPool.get(parentPoolName);
         boolean isRemoved = idEntries.remove(existingIdEntry);
         LOG.debug("The entry {} is removed {}", existingIdEntry, isRemoved);
index 33c8b17b40f56fb91f274abd2d8d3230048e603d..536f0fc48c2cb8e5b80f319229ebd5a5029c2f9a 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.genius.idmanager;
 
+import java.util.Objects;
 import javax.annotation.Nonnull;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
@@ -55,11 +56,11 @@ public class IdPoolListener extends AbstractClusteredAsyncDataTreeChangeListener
     @Override
     public void update(@Nonnull InstanceIdentifier<IdPool> instanceIdentifier, @Nonnull IdPool originalIdPool,
                        @Nonnull IdPool updatedIdPool) {
-        if (!updatedIdPool.getAvailableIdsHolder().equals(originalIdPool.getAvailableIdsHolder()) || !updatedIdPool
-                .getReleasedIdsHolder().equals(originalIdPool.getReleasedIdsHolder())) {
+        if (!Objects.equals(updatedIdPool.getAvailableIdsHolder(), originalIdPool.getAvailableIdsHolder())
+                || !Objects.equals(updatedIdPool.getReleasedIdsHolder(), originalIdPool.getReleasedIdsHolder())) {
             String parentPoolName = updatedIdPool.getParentPoolName();
             String poolName = updatedIdPool.getPoolName();
-            if (parentPoolName != null && !parentPoolName.isEmpty()) {
+            if (poolName != null && parentPoolName != null && !parentPoolName.isEmpty()) {
                 if (!idUtils.getPoolUpdatedMap(poolName) && poolName.equals(idUtils.getLocalPoolName(parentPoolName))) {
                     LOG.info("Received update for pool {} : {} - {}", updatedIdPool.getPoolName(), originalIdPool,
                              updatedIdPool);
index ac60df711395d700eb7730fffd2b096b20681c61..2b16f36d4404685e45135d6984ec03533b8052c5 100644 (file)
@@ -23,6 +23,8 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicInteger;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.inject.Singleton;
 import org.opendaylight.genius.idmanager.ReleasedIdHolder.DelayedIdEntry;
 import org.opendaylight.genius.infra.Datastore.Configuration;
@@ -336,4 +338,10 @@ public class IdUtils {
     public String getUniqueKey(String parentPoolName, String idKey) {
         return parentPoolName + idKey;
     }
+
+    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3.0.2
+    @Nonnull
+    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
+        return input != null ? input : new ArrayList<>(0);
+    }
 }
index 474ad1fe8649dcc0f4778478badf629cad4ef7ef..23f7d02919be388e79d1881a5f1a5ef6fedeb742 100644 (file)
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.opendaylight.genius.idmanager.IdUtils.nullToEmpty;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.Sets;
@@ -406,7 +407,7 @@ public class IdManagerTest {
     private IdPool getUpdatedActualParentPool() throws ReadFailedException {
         IdPool idPoolParentFromDS = singleTxdataBroker.syncRead(LogicalDatastoreType.CONFIGURATION,
                 InstanceIdentifier.builder(IdPools.class).child(IdPool.class, new IdPoolKey(ID_POOL_NAME)).build());
-        List<ChildPools> childPool = idPoolParentFromDS.getChildPools();
+        List<ChildPools> childPool = nullToEmpty(idPoolParentFromDS.getChildPools());
         List<ChildPools> updatedChildPool = childPool.stream()
                 .map(child -> new ChildPoolsBuilder(child).setLastAccessTime(0L).build()).collect(Collectors.toList());
         List<IdEntries> idEntries = idPoolParentFromDS.getIdEntries();
index a90ea6413d8c2c5814e9c900c0a1a85ee0f5215c..7233e2bd0b251267b8b7db1102eec78c342ddaa7 100755 (executable)
@@ -25,6 +25,8 @@ import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.apache.commons.lang3.BooleanUtils;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
@@ -572,4 +574,10 @@ public final class IfmUtil {
     public static long getLogicalTunnelSelectGroupId(int lportTag) {
         return org.opendaylight.genius.interfacemanager.globals.IfmConstants.VXLAN_GROUPID_MIN + lportTag;
     }
+
+    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3.0.2
+    @Nonnull
+    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
+        return input != null ? input : new ArrayList<>(0);
+    }
 }
index 44552c392cc3cdfcf9da004c83597caf5ce9ca5e..8b7533242345fa6ba41ccd3e3d47e81110408022 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.genius.interfacemanager;
 
 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.interfacemanager.IfmUtil.nullToEmpty;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
@@ -499,7 +500,7 @@ public class InterfacemgrProvider implements AutoCloseable, IInterfaceManager {
         try {
             RpcResult<GetEndpointIpForDpnOutput> ipForDpnOutputRpcResult = output.get();
             if (ipForDpnOutputRpcResult.isSuccessful()) {
-                List<IpAddress> localIps = ipForDpnOutputRpcResult.getResult().getLocalIps();
+                List<IpAddress> localIps = nullToEmpty(ipForDpnOutputRpcResult.getResult().getLocalIps());
                 if (!localIps.isEmpty()) {
                     return localIps.get(0).getIpv4Address().getValue();
                 }
index 192f20802703629fbc343f392d8b22197d0cf66e..47e4ba90d8599a005cad2817f4842500d718ec4e 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import javax.inject.Inject;
@@ -198,7 +199,7 @@ public final class AlivenessMonitorUtils {
 
             // Delete old profile from Aliveness Manager
             IfTunnel ifTunnelOld = interfaceOld.augmentation(IfTunnel.class);
-            if (!ifTunnelNew.getMonitorInterval().equals(ifTunnelOld.getMonitorInterval())) {
+            if (!Objects.equals(ifTunnelNew.getMonitorInterval(), ifTunnelOld.getMonitorInterval())) {
                 LOG.debug("deleting older monitor profile for interface {}", interfaceName);
                 long profileId = allocateProfile(FAILURE_THRESHOLD, ifTunnelOld.getMonitorInterval(), MONITORING_WINDOW,
                         MonitorProtocolType.Lldp);
@@ -252,7 +253,7 @@ public final class AlivenessMonitorUtils {
         if (monitorIdInterfaceMap.isPresent()) {
             monitorIdInterfaceInstance = monitorIdInterfaceMap.get();
             existinginterfaceName = monitorIdInterfaceInstance.getInterfaceName();
-            if (!existinginterfaceName.equals(infName)) {
+            if (!Objects.equals(existinginterfaceName, infName)) {
                 monitorIdInterfaceInstance = monitorIdInterfaceBuilder.withKey(new MonitorIdInterfaceKey(monitorId))
                         .setInterfaceName(infName).build();
                 tx.merge(id, monitorIdInterfaceInstance, CREATE_MISSING_PARENTS);
index 564933e63ffcd31b8a2abd6c267d27dee9da5442..e33e0e5e8442db6fadf2e806e1459e9a2944735c 100644 (file)
@@ -756,7 +756,7 @@ public final class InterfaceManagerCommonUtils {
                 .build();
         tx.delete(intfid);
 
-        if (interfaceNameEntries.size() <= 1) {
+        if (interfaceNameEntries != null && interfaceNameEntries.size() <= 1) {
             tx.delete(dpnToInterfaceId);
         }
     }
index 3da2c9758b64f98546f6dec71425e2e7400ff594..096afc8d350874426a598edf03a874bd92672259 100644 (file)
@@ -61,7 +61,9 @@ public class CacheBridgeEntryConfigListener implements ClusteredDataTreeChangeLi
             final DataObjectModification<BridgeEntry> mod = change.getRootNode();
             switch (mod.getModificationType()) {
                 case DELETE:
-                    interfaceMetaUtils.removeFromBridgeEntryCache(mod.getDataBefore());
+                    if (mod.getDataBefore() != null) {
+                        interfaceMetaUtils.removeFromBridgeEntryCache(mod.getDataBefore());
+                    }
                     break;
                 case SUBTREE_MODIFIED:
                 case WRITE:
index a8329fe5ef108d7903ede778f598e407652f638e..37be03fbbd8af0566e36f8c4a9cddd663805d671 100644 (file)
@@ -68,7 +68,9 @@ public class CacheBridgeRefEntryListener implements ClusteredDataTreeChangeListe
                      * Removing for now, can consider this as future optimization.
                      *
                      */
-                    interfaceMetaUtils.removeFromBridgeRefEntryCache(mod.getDataBefore());
+                    if (mod.getDataBefore() != null) {
+                        interfaceMetaUtils.removeFromBridgeRefEntryCache(mod.getDataBefore());
+                    }
                     break;
                 case SUBTREE_MODIFIED:
                 case WRITE:
index 09235864776b42d8e56e8550712a85b1bfb1d8df..d3e35cddaffcf4e2ef9241a42f12481f70e7cb42 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.genius.interfacemanager.listeners;
 
+import java.util.Objects;
 import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -76,7 +77,7 @@ public class VlanMemberConfigListener extends AbstractSyncDataTreeChangeListener
         }
 
         String lowerLayerIf = parentRefs.getParentInterface();
-        if (lowerLayerIf.equals(removedInterface.getName())) {
+        if (Objects.equals(lowerLayerIf, removedInterface.getName())) {
             LOG.error("Attempt to remove Vlan Trunk-Member {} with same parent interface name.", removedInterface);
             return;
         }
@@ -115,7 +116,7 @@ public class VlanMemberConfigListener extends AbstractSyncDataTreeChangeListener
         }
 
         String lowerLayerIf = parentRefsNew.getParentInterface();
-        if (lowerLayerIf.equals(updatedInterface.getName())) {
+        if (Objects.equals(lowerLayerIf, updatedInterface.getName())) {
             LOG.error(
                     "Configuration Error. Attempt to update Vlan Trunk-Member {} with same parent " + "interface name.",
                     updatedInterface);
@@ -144,7 +145,7 @@ public class VlanMemberConfigListener extends AbstractSyncDataTreeChangeListener
         }
 
         String lowerLayerIf = parentRefs.getParentInterface();
-        if (lowerLayerIf.equals(added.getName())) {
+        if (Objects.equals(lowerLayerIf, added.getName())) {
             LOG.error("Attempt to add Vlan Trunk-Member {} with same parent interface name.", added);
             return;
         }
index a16e074cbb49547c8a98bef0282087df3ebbb4fe..3627b6a3bda20add7392705bbfaa7c460f8c5187 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.genius.interfacemanager.pmcounters;
 
+import static org.opendaylight.genius.interfacemanager.IfmUtil.nullToEmpty;
 import static org.opendaylight.infrautils.utils.concurrent.Executors.newListeningScheduledThreadPool;
 
 import com.google.common.base.Optional;
@@ -259,7 +260,7 @@ public class NodeConnectorStatsImpl extends AsyncClusteredDataTreeChangeListener
         List<NodeConnectorStatisticsAndPortNumberMap> ncStatsAndPortMapList = nodeConnectorStatisticsOutput
                         .getNodeConnectorStatisticsAndPortNumberMap();
         // Parse NodeConnectorStatistics and create/update counters for them
-        for (NodeConnectorStatisticsAndPortNumberMap ncStatsAndPortMap : ncStatsAndPortMapList) {
+        for (NodeConnectorStatisticsAndPortNumberMap ncStatsAndPortMap : nullToEmpty(ncStatsAndPortMapList)) {
             NodeConnectorId nodeConnector = ncStatsAndPortMap.getNodeConnectorId();
             LOG.trace("Create/update metric counter for NodeConnector: {} of node: {}", nodeConnector, dpid);
             port = nodeConnector.getValue();
@@ -327,7 +328,7 @@ public class NodeConnectorStatsImpl extends AsyncClusteredDataTreeChangeListener
         Map<Short, AtomicInteger> flowTableMap = new HashMap<>();
         // Get all flows for node from RPC result
         List<FlowAndStatisticsMapList> flowTableAndStatisticsMapList = flowStatsOutput.getFlowAndStatisticsMapList();
-        for (FlowAndStatisticsMapList flowAndStatisticsMap : flowTableAndStatisticsMapList) {
+        for (FlowAndStatisticsMapList flowAndStatisticsMap : nullToEmpty(flowTableAndStatisticsMapList)) {
             short tableId = flowAndStatisticsMap.getTableId();
             // populate map to maintain flow count per table
             flowTableMap.computeIfAbsent(tableId, key -> new AtomicInteger(0)).incrementAndGet();
index c3d4989ecb298c71785af5a8cfa673aff570d834..845a065f82606de031a097a637c57a0b4948814c 100644 (file)
@@ -54,9 +54,9 @@ public final class HwVTEPInterfaceStateUpdateHelper {
         OperStatus livenessState = OperStatus.Down;
         if (tunnelBfdStatus != null && !tunnelBfdStatus.isEmpty()) {
             for (BfdStatus bfdState : tunnelBfdStatus) {
-                if (bfdState.getBfdStatusKey().equalsIgnoreCase(SouthboundUtils.BFD_OP_STATE)) {
+                if (SouthboundUtils.BFD_OP_STATE.equalsIgnoreCase(bfdState.getBfdStatusKey())) {
                     String bfdOpState = bfdState.getBfdStatusValue();
-                    if (bfdOpState.equalsIgnoreCase(SouthboundUtils.BFD_STATE_UP)) {
+                    if (SouthboundUtils.BFD_STATE_UP.equalsIgnoreCase(bfdOpState)) {
                         livenessState = OperStatus.Up;
                     } else {
                         livenessState = OperStatus.Down;
index c50b82050bc3d283679bfa27cb7792f1115493dc..6f380bb9141b92a47216b4fd99b52035b1ddae5b 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.genius.interfacemanager.renderer.ovs.confighelpers;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.genius.interfacemanager.IfmUtil.nullToEmpty;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
@@ -253,7 +254,8 @@ public final class OvsInterfaceConfigRemoveHelper {
             futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
                 // FIXME: If the no. of child entries exceeds 100, perform txn
                 // updates in batches of 100.
-                for (InterfaceChildEntry interfaceChildEntry : interfaceParentEntry.getInterfaceChildEntry()) {
+                for (InterfaceChildEntry interfaceChildEntry : nullToEmpty(
+                        interfaceParentEntry.getInterfaceChildEntry())) {
                     LOG.debug("removing interface state for vlan trunk member {}",
                             interfaceChildEntry.getChildInterface());
                     interfaceManagerCommonUtils.deleteInterfaceStateInformation(interfaceChildEntry.getChildInterface(),
index 3bebf90f7d724937a4177451aed1c8f5385a7c97..a0aff54e0754481468d3f3e2d7de51b32331da5b 100644 (file)
@@ -120,8 +120,8 @@ public class OvsInterfaceConfigUpdateHelper {
         IfTunnel ifTunnelOld = interfaceOld.augmentation(IfTunnel.class);
         IfTunnel ifTunnelNew = interfaceNew.augmentation(IfTunnel.class);
         if (checkAugmentations(ifTunnelOld, ifTunnelNew)) {
-            if (!ifTunnelNew.getTunnelDestination().equals(ifTunnelOld.getTunnelDestination())
-                    || !ifTunnelNew.getTunnelSource().equals(ifTunnelOld.getTunnelSource())
+            if (!Objects.equals(ifTunnelNew.getTunnelDestination(), ifTunnelOld.getTunnelDestination())
+                    || !Objects.equals(ifTunnelNew.getTunnelSource(), ifTunnelOld.getTunnelSource())
                     || ifTunnelNew.getTunnelGateway() != null && ifTunnelOld.getTunnelGateway() != null
                             && !ifTunnelNew.getTunnelGateway().equals(ifTunnelOld.getTunnelGateway())) {
                 return true;
index 95c42c304caa0e9d07be0d4b415e7e74f1d9e1a3..758294751526171ad907ec3b56542e081d9e23b8 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.genius.interfacemanager.renderer.ovs.confighelpers;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.genius.interfacemanager.IfmUtil.nullToEmpty;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
@@ -69,7 +70,8 @@ public class OvsVlanMemberConfigRemoveHelper {
             // Configuration changes
             futures.add(txChain.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
                 // Delete the interface child information
-                List<InterfaceChildEntry> interfaceChildEntries = interfaceParentEntry.getInterfaceChildEntry();
+                List<InterfaceChildEntry> interfaceChildEntries =
+                    nullToEmpty(interfaceParentEntry.getInterfaceChildEntry());
                 InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(interfaceOld.getName());
                 InstanceIdentifier<InterfaceChildEntry> interfaceChildEntryIid = InterfaceMetaUtils
                     .getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
index 5390c253c7d90bffcb019674596631e4bed681c3..aab08017e71e8f441ffe5bf6f1254b68e0962f01 100644 (file)
@@ -84,7 +84,7 @@ public class OvsVlanMemberConfigUpdateHelper {
         }
 
         if (vlanIdModified(ifL2vlanOld.getVlanId(), ifL2vlanNew.getVlanId())
-                || !parentRefsOld.getParentInterface().equals(parentRefsNew.getParentInterface())) {
+                || !Objects.equals(parentRefsOld.getParentInterface(), parentRefsNew.getParentInterface())) {
             LOG.info("vlan-id modified for interface {}", interfaceNew.getName());
             futures.addAll(ovsVlanMemberConfigRemoveHelper.removeConfiguration(parentRefsOld, interfaceOld));
             futures.addAll(ovsVlanMemberConfigAddHelper.addConfiguration(parentRefsNew, interfaceNew));
index d9efd9b6183ec87aff35e54d8b1196c1351f5cd2..db91e3940a9e22b40dbaa6ed638161dbb43f0d70 100644 (file)
@@ -12,6 +12,7 @@ import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
 import com.google.common.util.concurrent.ListenableFuture;
 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;
@@ -61,7 +62,7 @@ public class OvsInterfaceStateUpdateHelper {
         MacAddress macAddressOld = flowCapableNodeConnectorOld.getHardwareAddress();
 
         boolean opstateModified = !operStatusNew.equals(operStatusOld);
-        boolean hardwareAddressModified = !macAddressNew.equals(macAddressOld);
+        boolean hardwareAddressModified = !Objects.equals(macAddressNew, macAddressOld);
 
         if (!opstateModified && !hardwareAddressModified) {
             LOG.debug("If State entry for port: {} Not Modified.", interfaceName);
index fb4a1717696e1424bcbd8b99dfd2e4e7c027b97f..d226464d684c20576ce0584d00964fec5ea2f543 100644 (file)
@@ -231,7 +231,7 @@ public class SouthboundUtils {
             options.put(TUNNEL_OPTIONS_REMOTE_IP, remoteIp.stringValue());
         }
         // Specific options for each type of tunnel
-        if (ifTunnel.getTunnelInterfaceType().equals(TunnelTypeMplsOverGre.class)) {
+        if (TunnelTypeMplsOverGre.class.equals(ifTunnel.getTunnelInterfaceType())) {
             String switchVersion = getSwitchVersion((InstanceIdentifier<Node>) bridgeIid);
             LOG.debug("Switch OVS Version: {}", switchVersion);
             if (org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils.compareDbVersionToMinVersion(
@@ -414,7 +414,7 @@ public class SouthboundUtils {
             return false;
         }
         for (InterfaceBfd interfaceBfd : interfaceBfds) {
-            if (interfaceBfd.getBfdKey().equalsIgnoreCase(SouthboundUtils.BFD_ENABLE_KEY)) {
+            if (SouthboundUtils.BFD_ENABLE_KEY.equalsIgnoreCase(interfaceBfd.getBfdKey())) {
                 return SouthboundUtils.BFD_ENABLE_VALUE.equalsIgnoreCase(interfaceBfd.getBfdValue());//checkBfdEnabled
             }
         }
index 2c4ff5a9a0787e541fedf94544674a6c4ddd9ff6..eccc93ffa4e1a324b2807103c83ff0e37fbe2b3f 100644 (file)
@@ -11,17 +11,16 @@ package org.opendaylight.genius.interfacemanager.servicebindings.flowbased.liste
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
 
 import com.google.common.util.concurrent.ListenableFuture;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Objects;
 import java.util.concurrent.Callable;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
@@ -141,35 +140,41 @@ public class FlowBasedServicesConfigListener implements ClusteredDataTreeChangeL
     private synchronized void onBoundServicesChanged(final DataObjectModification<BoundServices> dataObjectModification,
                                                      final InstanceIdentifier<ServicesInfo> rootIdentifier,
                                                      final DataObjectModification<ServicesInfo> rootNode) {
-        final List<BoundServices> boundServices = rootNode.getDataAfter().getBoundServices();
-        final ServicesInfoKey servicesInfoKey = rootNode.getDataAfter().key();
-        final BoundServices boundServicesBefore = dataObjectModification.getDataBefore();
-        final BoundServices boundServicesAfter =  dataObjectModification.getDataAfter();
+        if (rootNode.getDataAfter() != null) {
+            final List<BoundServices> boundServices = rootNode.getDataAfter().getBoundServices();
+            final ServicesInfoKey servicesInfoKey = rootNode.getDataAfter().key();
+            final BoundServices boundServicesBefore = dataObjectModification.getDataBefore();
+            final BoundServices boundServicesAfter =  dataObjectModification.getDataAfter();
 
-        switch (dataObjectModification.getModificationType()) {
-            case DELETE:
-                remove(servicesInfoKey, boundServicesBefore, boundServices);
-                break;
-            case SUBTREE_MODIFIED:
-                update(servicesInfoKey, getBoundServicesInstanceIdentifier(rootIdentifier,
-                        boundServicesBefore.key()), boundServicesBefore, boundServicesAfter, boundServices);
-                break;
-            case WRITE:
-                if (boundServicesBefore == null) {
-                    add(servicesInfoKey, boundServicesAfter, boundServices);
-                } else {
-                    update(servicesInfoKey, getBoundServicesInstanceIdentifier(rootIdentifier,
+            switch (dataObjectModification.getModificationType()) {
+                case DELETE:
+                    if (boundServicesBefore != null) {
+                        remove(servicesInfoKey, boundServicesBefore, boundServices);
+                    }
+                    break;
+                case SUBTREE_MODIFIED:
+                    if (boundServicesBefore != null) {
+                        update(servicesInfoKey, getBoundServicesInstanceIdentifier(rootIdentifier,
                             boundServicesBefore.key()), boundServicesBefore, boundServicesAfter, boundServices);
-                }
-                break;
-            default:
-                LOG.error("Unhandled Modificiation Type{} for {}", dataObjectModification.getModificationType(),
-                    rootIdentifier);
+                    }
+                    break;
+                case WRITE:
+                    if (boundServicesBefore == null) {
+                        add(servicesInfoKey, boundServicesAfter, boundServices);
+                    } else {
+                        update(servicesInfoKey, getBoundServicesInstanceIdentifier(rootIdentifier,
+                            boundServicesBefore.key()), boundServicesBefore, boundServicesAfter, boundServices);
+                    }
+                    break;
+                default:
+                    LOG.error("Unhandled Modificiation Type{} for {}", dataObjectModification.getModificationType(),
+                        rootIdentifier);
 
+            }
         }
     }
 
-    protected void remove(final ServicesInfoKey serviceKey, final BoundServices boundServiceOld,
+    protected void remove(@Nonnull final ServicesInfoKey serviceKey, @Nonnull  final BoundServices boundServiceOld,
                           final List<BoundServices> boundServicesList) {
         if (!entityOwnershipUtils.isEntityOwner(IfmConstants.INTERFACE_SERVICE_BINDING_ENTITY,
                 IfmConstants.INTERFACE_SERVICE_BINDING_ENTITY)) {
@@ -191,12 +196,13 @@ public class FlowBasedServicesConfigListener implements ClusteredDataTreeChangeL
                           BoundServices boundServiceOld, BoundServices boundServiceNew,
                           List<BoundServices> boundServicesList) {
         if (!Objects.equals(boundServiceOld, boundServiceNew)) {
-            /**
+            /*
              * In some cases ACL needs to change metadata passed from dispatcher tables to ACL tables dynamically.
              * For this update operation has been enhanced to support same. This is only supported for ACL for now
              * and the functionality will remain same for all other applications as it was earlier.
              */
-            if ((boundServiceNew.getServicePriority() == NwConstants.ACL_SERVICE_INDEX
+            if (boundServiceNew.getServicePriority() != null && (
+                boundServiceNew.getServicePriority() == NwConstants.ACL_SERVICE_INDEX
                     || boundServiceNew.getServicePriority() == NwConstants.EGRESS_ACL_SERVICE_INDEX)
                     && !Objects.equals(boundServiceOld, boundServiceNew)) {
                 LOG.info("Bound services flow update for service {}", boundServiceNew.getServiceName());
@@ -274,11 +280,11 @@ public class FlowBasedServicesConfigListener implements ClusteredDataTreeChangeL
         Class<? extends ServiceModeBase> serviceMode;
         FlowBasedServicesConfigRemovable flowBasedServicesConfigRemovable;
         BoundServices boundServicesNew;
-        List<BoundServices> boundServicesList;
+        @Nullable List<BoundServices> boundServicesList;
 
         RendererConfigRemoveWorker(String interfaceName, Class<? extends ServiceModeBase> serviceMode,
                                    FlowBasedServicesConfigRemovable flowBasedServicesConfigRemovable,
-                                   BoundServices boundServicesNew, List<BoundServices> boundServicesList) {
+                                   BoundServices boundServicesNew, @Nullable List<BoundServices> boundServicesList) {
             this.interfaceName = interfaceName;
             this.serviceMode = serviceMode;
             this.flowBasedServicesConfigRemovable = flowBasedServicesConfigRemovable;
index 5d13bf87cea6be6f1a5edabb58be417b4f026762..512b574e4dfe18abaf93cf6c288bf841872c17d9 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.interfacemanager.shell;
 
+import static org.opendaylight.genius.interfacemanager.IfmUtil.nullToEmpty;
+
 import java.math.BigInteger;
 import java.util.Formatter;
 
@@ -213,7 +215,7 @@ public final class IfmCLIUtil {
             String remoteIp = UNSET;
             String localIp = UNSET;
             String key = UNSET;
-            for (Options portOption: port.getOptions()) {
+            for (Options portOption: nullToEmpty(port.getOptions())) {
                 switch (portOption.getOption()) {
                     case "local_ip":
                         localIp = portOption.getValue();
index d0c9077ef3bea43543cb324ced03f49bf6aa69c3..173008c83e299d80ba19d32311d89b2890118855 100644 (file)
@@ -13,7 +13,11 @@ import com.google.common.net.InetAddresses;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.apache.commons.lang3.StringUtils;
 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.inet.types.rev130715.Ipv6Address;
@@ -282,4 +286,10 @@ public final class Ipv6Util {
             throw new IllegalArgumentException("Invalid ipv6Address=" + ipv6Address, e);
         }
     }
+
+    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3.0.2
+    @Nonnull
+    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
+        return input != null ? input : new ArrayList<>(0);
+    }
 }
index dd074c854204fb67342d782af39a8e4df5df258b..05924b791e15549324ca11a900d224b6b78e9369 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.genius.ipv6util.nd;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.opendaylight.genius.ipv6util.api.Ipv6Util.nullToEmpty;
 
 import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
@@ -67,7 +68,7 @@ public class Ipv6NdUtilServiceImpl implements Ipv6NdUtilService {
         int localErrorCount = 0;
 
         targetIpv6Address = ndInput.getTargetIpAddress();
-        for (InterfaceAddress interfaceAddress : ndInput.getInterfaceAddress()) {
+        for (InterfaceAddress interfaceAddress : nullToEmpty(ndInput.getInterfaceAddress())) {
             try {
                 interfaceName = interfaceAddress.getInterface();
                 srcIpv6Address = interfaceAddress.getSrcIpAddress();
index 3fe11eab42a72b8c675f4b1d7a2feb7ae6d93d42..10db60625b4d8d612fcb42447533310eba1e5f69 100644 (file)
@@ -7,11 +7,14 @@
  */
 package org.opendaylight.genius.itm.cache;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import javax.inject.Inject;
@@ -63,7 +66,7 @@ public class DpnTepStateCache extends DataObjectCache<BigInteger, DpnsTeps> {
 
     @Override
     protected void added(InstanceIdentifier<DpnsTeps> path, DpnsTeps dpnsTeps) {
-        for (RemoteDpns remoteDpns : dpnsTeps.getRemoteDpns()) {
+        for (RemoteDpns remoteDpns : nullToEmpty(dpnsTeps.getRemoteDpns())) {
             final String dpn = getDpnId(dpnsTeps.getSourceDpnId(), remoteDpns.getDestinationDpnId());
             DpnTepInterfaceInfo value = new DpnTepInterfaceInfoBuilder()
                     .setTunnelName(remoteDpns.getTunnelName())
@@ -78,7 +81,7 @@ public class DpnTepStateCache extends DataObjectCache<BigInteger, DpnsTeps> {
 
     @Override
     protected void removed(InstanceIdentifier<DpnsTeps> path, DpnsTeps dpnsTeps) {
-        for (RemoteDpns remoteDpns : dpnsTeps.getRemoteDpns()) {
+        for (RemoteDpns remoteDpns : nullToEmpty(dpnsTeps.getRemoteDpns())) {
             dpnTepInterfaceMap.remove(getDpnId(dpnsTeps.getSourceDpnId(), remoteDpns.getDestinationDpnId()));
             tunnelEndpointMap.remove(remoteDpns.getTunnelName());
         }
@@ -95,7 +98,7 @@ public class DpnTepStateCache extends DataObjectCache<BigInteger, DpnsTeps> {
                 Optional<DpnsTeps> dpnsTeps = super.get(srcDpnId);
                 if (dpnsTeps.isPresent()) {
                     DpnsTeps teps = dpnsTeps.get();
-                    teps.getRemoteDpns().forEach(remoteDpns -> {
+                    nullToEmpty(teps.getRemoteDpns()).forEach(remoteDpns -> {
                         DpnTepInterfaceInfo value = new DpnTepInterfaceInfoBuilder()
                                 .setTunnelName(remoteDpns.getTunnelName())
                                 .setIsMonitoringEnabled(remoteDpns.isMonitoringEnabled())
@@ -117,16 +120,15 @@ public class DpnTepStateCache extends DataObjectCache<BigInteger, DpnsTeps> {
     public void removeTepFromDpnTepInterfaceConfigDS(BigInteger srcDpnId) throws TransactionCommitFailedException {
         Collection<DpnsTeps> dpnsTeps = this.getAllPresent();
         for (DpnsTeps dpnTep : dpnsTeps) {
-            if (!dpnTep.getSourceDpnId().equals(srcDpnId)) {
-                List<RemoteDpns> remoteDpns = dpnTep.getRemoteDpns();
-                for (RemoteDpns remoteDpn : remoteDpns) {
-                    if (remoteDpn.getDestinationDpnId().equals(srcDpnId)) {
+            if (!Objects.equals(dpnTep.getSourceDpnId(), srcDpnId)) {
+                for (RemoteDpns remoteDpns : nullToEmpty(dpnTep.getRemoteDpns())) {
+                    if (Objects.equals(remoteDpns.getDestinationDpnId(), srcDpnId)) {
                         // Remote the SrcDpnId from the remote List. Remove it from COnfig DS. 4
                         // This will be reflected in cache by the ClusteredDTCN. Not removing it here !
                         //Caution :- Batching Delete !!
                         InstanceIdentifier<RemoteDpns> remoteDpnII =
                                 buildRemoteDpnsInstanceIdentifier(dpnTep.getSourceDpnId(),
-                                        remoteDpn.getDestinationDpnId());
+                                        remoteDpns.getDestinationDpnId());
                         SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION,
                                 remoteDpnII);
                         break;
index 9383b9cdaede7d1604e1b629ff305fdb4e74b0a9..006f736cc513d93e6e4a0f401d38816b33b9d05a 100644 (file)
@@ -33,11 +33,10 @@ public final class ItmCliUtils {
         if (StringUtils.isNotBlank(dpnIds)) {
             final String[] arrDpnIds = StringUtils.split(dpnIds, ',');
             for (String dpn : arrDpnIds) {
-                if (StringUtils.isNumeric(StringUtils.trim(dpn))) {
-                    lstDpnIds.add(new BigInteger(StringUtils.trim(dpn)));
-                } else {
-                    Preconditions.checkArgument(false, String.format("DPN ID [%s] is not a numeric value.", dpn));
-                }
+                String trimmedDpn = StringUtils.trim(dpn);
+                Preconditions.checkArgument(StringUtils.isNumeric(trimmedDpn),
+                    "DPN ID [" + dpn + "] is not a numeric value.");
+                lstDpnIds.add(new BigInteger(trimmedDpn));
             }
         }
         return lstDpnIds;
index 4968b7d44695879b5d9c0db8ec28cbc3edb4f20a..7479466816a4efa13c3be631143118ba88356462 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.itm.cli;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import java.math.BigInteger;
@@ -17,13 +19,13 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicInteger;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.net.util.SubnetUtils;
 import org.apache.felix.service.command.CommandSession;
@@ -227,7 +229,7 @@ public class TepCommandHelper {
         // Checking for duplicates in config DS
         for (TransportZone tz : allTransportZonesAsMap.values()) {
             boolean isGreType = false;
-            if (tz.getTunnelType().equals(TunnelTypeGre.class)) {
+            if (TunnelTypeGre.class.equals(tz.getTunnelType())) {
                 isGreType = true;
             }
             for (Subnets sub : ItmUtils.emptyIfNull(tz.getSubnets())) {
@@ -242,17 +244,13 @@ public class TepCommandHelper {
         if (ItmUtils.isEmpty(vtepList)) {
             return;
         }
-        if (vtepList.contains(inputVtep)) {
-            Preconditions.checkArgument(false, "VTEP already exists");
-        }
+        Preconditions.checkArgument(!vtepList.contains(inputVtep), "VTEP already exists");
         BigInteger dpnId = inputVtep.getDpnId();
         if (isConfiguredTepGreType && isGreType) {
             for (Vteps vtep : vtepList) {
-                if (vtep.getDpnId().equals(dpnId)) {
-                    String errMsg = "DPN [" + dpnId + "] already configured with GRE TEP."
-                            + " Mutiple GRE TEP's on a single DPN are not allowed.";
-                    Preconditions.checkArgument(false, errMsg);
-                }
+                Preconditions.checkArgument(!Objects.equals(vtep.getDpnId(), dpnId),
+                    "DPN [" + dpnId + "] already configured with GRE TEP."
+                        + " Mutiple GRE TEP's on a single DPN are not allowed.");
             }
         }
     }
@@ -289,7 +287,7 @@ public class TepCommandHelper {
          * StringUtils.equalsIgnoreCase(ITMConstants.TUNNEL_TYPE_GRE,
          * tzone.getTunnelType())) { return true; }
          */
-        return tzone != null && tzone.getTunnelType().equals(TunnelTypeGre.class);
+        return tzone != null && TunnelTypeGre.class.equals(tzone.getTunnelType());
     }
 
     /**
@@ -335,7 +333,7 @@ public class TepCommandHelper {
             Map<SubnetObject, List<Vteps>> subVtepMapTemp = transportZonesHashMap.get(tzone);
             for (List<Vteps> vtepList : subVtepMapTemp.values()) {
                 for (Vteps vtep : vtepList) {
-                    if (vtep.getDpnId().equals(dpnId)) {
+                    if (Objects.equals(vtep.getDpnId(), dpnId)) {
                         return true;
                     }
                 }
@@ -358,7 +356,7 @@ public class TepCommandHelper {
                     continue;
                 }
                 for (Vteps vtep : sub.getVteps()) {
-                    if (vtep.getDpnId().equals(dpnId)) {
+                    if (Objects.equals(vtep.getDpnId(), dpnId)) {
                         return true;
                     }
                 }
@@ -469,7 +467,7 @@ public class TepCommandHelper {
                     for (Vteps vtep : sub.getVteps()) {
                         flag = true;
                         String strTunnelType ;
-                        if (tz.getTunnelType().equals(TunnelTypeGre.class)) {
+                        if (TunnelTypeGre.class.equals(tz.getTunnelType())) {
                             strTunnelType = ITMConstants.TUNNEL_TYPE_GRE;
                         } else {
                             strTunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
@@ -597,7 +595,7 @@ public class TepCommandHelper {
             Optional<Vteps> vtepOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, vpath, dataBroker);
             if (vtepOptional.isPresent()) {
                 vtepCli = vtepOptional.get();
-                if (vtepCli.getIpAddress().equals(ipAddressObj)) {
+                if (Objects.equals(vtepCli.getIpAddress(), ipAddressObj)) {
                     InstanceIdentifier<Subnets> spath =
                             InstanceIdentifier
                                     .builder(TransportZones.class)
@@ -607,7 +605,8 @@ public class TepCommandHelper {
                             dataBroker);
                     if (subOptional.isPresent()) {
                         subCli = subOptional.get();
-                        if (subCli.getGatewayIp().equals(gatewayIpObj) && subCli.getVlanId().equals(vlanId)) {
+                        if (Objects.equals(subCli.getGatewayIp(), gatewayIpObj) && Objects.equals(subCli.getVlanId(),
+                                vlanId)) {
                             vtepDelCommitList.add(vtepCli);
                         } else if (session != null) {
                             session.getConsole().println("vtep with this vlan or gateway doesnt exist");
@@ -637,8 +636,8 @@ public class TepCommandHelper {
                 Optional<TransportZones> transportZonesOptional =
                         ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
                 if (transportZonesOptional.isPresent()) {
-                    TransportZones transportZones = transportZonesOptional.get();
-                    for (TransportZone tz : transportZones.getTransportZone()) {
+                    List<TransportZone> transportZones = nullToEmpty(transportZonesOptional.get().getTransportZone());
+                    for (TransportZone tz : transportZones) {
                         if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
                             continue;
                         }
@@ -651,7 +650,7 @@ public class TepCommandHelper {
                                                 .child(TransportZone.class, tz.key())
                                                 .child(Subnets.class, sub.key())
                                                 .child(Vteps.class, vtep.key()).build();
-                                if (sub.getVteps().remove(vtep)) {
+                                if (sub.getVteps() != null && sub.getVteps().remove(vtep)) {
                                     vtepPaths.add(vpath);
                                     if (sub.getVteps().size() == 0 || sub.getVteps() == null) {
                                         subDelList.add(sub);
@@ -662,7 +661,7 @@ public class TepCommandHelper {
                         }
                     }
 
-                    for (TransportZone tz : transportZones.getTransportZone()) {
+                    for (TransportZone tz : transportZones) {
                         if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
                             continue;
                         }
@@ -682,13 +681,12 @@ public class TepCommandHelper {
                     }
 
                     for (TransportZone tz : tzDelList) {
-                        if (transportZones.getTransportZone().remove(tz)) {
+                        if (transportZones.remove(tz)) {
                             InstanceIdentifier<T> tpath =
                                     (InstanceIdentifier<T>) InstanceIdentifier.builder(TransportZones.class)
                                             .child(TransportZone.class, tz.key()).build();
                             tzPaths.add(tpath);
-                            if (transportZones.getTransportZone() == null
-                                    || transportZones.getTransportZone().size() == 0) {
+                            if (transportZones.isEmpty()) {
                                 ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
                                     tx -> tx.delete(LogicalDatastoreType.CONFIGURATION, path)), LOG,
                                     "Error deleting {}", path);
@@ -730,7 +728,7 @@ public class TepCommandHelper {
 
         for (StateTunnelList tunnelInst : tunnelLists) {
            // Display only the internal tunnels
-            if (tunnelInst.getDstInfo().getTepDeviceType().equals(TepTypeInternal.class)) {
+            if (TepTypeInternal.class.equals(tunnelInst.getDstInfo().getTepDeviceType())) {
                 String tunnelInterfaceName = tunnelInst.getTunnelInterfaceName();
                 LOG.trace("tunnelInterfaceName::: {}", tunnelInterfaceName);
                 String tunnelState = ITMConstants.TUNNEL_STATE_UNKNOWN;
@@ -741,7 +739,7 @@ public class TepCommandHelper {
                 }
                 Class<? extends TunnelTypeBase> tunType = tunnelInst.getTransportType();
                 String tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
-                if (tunType.equals(TunnelTypeVxlan.class)) {
+                if (TunnelTypeVxlan.class.equals(tunType)) {
                     tunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
                 } else if (tunType.equals(TunnelTypeGre.class)) {
                     tunnelType = ITMConstants.TUNNEL_TYPE_GRE;
@@ -813,7 +811,7 @@ public class TepCommandHelper {
             } else {
                 tunnelType = StringUtils.upperCase(tunnelType);
                 tunType = ItmUtils.TUNNEL_TYPE_MAP.get(tunnelType);
-                if (transportZoneFromConfigDS.getTunnelType().equals(tunType)) {
+                if (Objects.equals(transportZoneFromConfigDS.getTunnelType(), tunType)) {
                     // default-TZ already exists and tunnel-type is not changed during
                     // controller restart, then nothing to do now. Just return.
                     return;
@@ -864,17 +862,17 @@ public class TepCommandHelper {
         }
 
         if (tzoneFromConfigDs != null) {
-            if (!tzoneFromConfigDs.getTunnelType().equals(tunType)  && ItmUtils.isNotEmpty(tzoneFromConfigDs
+            if (!Objects.equals(tzoneFromConfigDs.getTunnelType(), tunType) && ItmUtils.isNotEmpty(tzoneFromConfigDs
                     .getSubnets())) {
                 // for default-TZ, such error message is not needed to be thrown.
                 // it needs to be handled in different way, by deleting default-TZ
                 // with old tunnel-type and then add default-TZ with new tunnel-type
                 if (!transportZoneName.equals(ITMConstants.DEFAULT_TRANSPORT_ZONE)) {
-                    String errorMsg = "Changing the tunnel type from " + tzoneFromConfigDs.getTunnelType()
-                        + " to " + strTunnelType
-                        + " is not allowed for already configured transport zone [" + transportZoneName
-                        + "].";
-                    Preconditions.checkArgument(false, errorMsg);
+                    throw new IllegalArgumentException(
+                        "Changing the tunnel type from " + tzoneFromConfigDs.getTunnelType()
+                            + " to " + strTunnelType
+                            + " is not allowed for already configured transport zone [" + transportZoneName
+                            + "].");
                 } else {
                     // delete already existing default TZ
                     ItmUtils.deleteTransportZoneFromConfigDS(ITMConstants.DEFAULT_TRANSPORT_ZONE, dataBroker);
index cddf1652d973e7797b16c1a6f8cf408f76708988..89ce784de878911dcc8f77deec4bebb2a7bdd082 100644 (file)
@@ -123,7 +123,7 @@ public class VtepSchemaShow extends OsgiCommandSupport {
 
         Class<? extends TunnelTypeBase> tunType = schema.getTunnelType();
 
-        if (tunType.equals(TunnelTypeGre.class)) {
+        if (TunnelTypeGre.class.equals(tunType)) {
             strTunnelType = ITMConstants.TUNNEL_TYPE_GRE;
         } else {
             strTunnelType = ITMConstants.TUNNEL_TYPE_VXLAN;
index f62568e25b6924d4e879770707a916cc1da4e3aa..301290df1c79d145d73c3ea27634fa6fbf051f1f 100644 (file)
@@ -15,6 +15,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import org.apache.commons.net.util.SubnetUtils;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -165,7 +166,7 @@ public class ItmExternalTunnelAddWorker {
                     if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
                         for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
                             //dont mesh if hwVteps and OVS-tep have same ip-address
-                            if (hwVtepDS.getIpAddress().equals(tep.getIpAddress())) {
+                            if (Objects.equals(hwVtepDS.getIpAddress(), tep.getIpAddress())) {
                                 continue;
                             }
                             final String cssID = dpn.getDPNID().toString();
@@ -212,7 +213,7 @@ public class ItmExternalTunnelAddWorker {
                     for (Subnets sub : tzone.getSubnets()) {
                         if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
                             for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
-                                if (hwVtepDS.getIpAddress().equals(hwTep.getHwIp())) {
+                                if (Objects.equals(hwVtepDS.getIpAddress(), hwTep.getHwIp())) {
                                     continue;//dont mesh with self
                                 }
                                 LOG.trace("wire up {} and {}",hwTep, hwVtepDS);
@@ -236,7 +237,7 @@ public class ItmExternalTunnelAddWorker {
                         }
                         if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
                             for (Vteps vtep : sub.getVteps()) {
-                                if (vtep.getIpAddress().equals(hwTep.getHwIp())) {
+                                if (Objects.equals(vtep.getIpAddress(), hwTep.getHwIp())) {
                                     continue;
                                 }
                                 //TOR-OVS
index 3846241cfb724914e1ef7fb0d3c2cb6d3c0001bf..7c200497eee14b3b0a6a3fe9390aa3bbfb94ff9c 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.itm.confighelpers;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
@@ -14,6 +16,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -132,7 +135,7 @@ public final class ItmExternalTunnelDeleteWorker {
             for (DPNTEPsInfo dpn : cfgdDpnList) {
                 if (dpn.getTunnelEndPoints() != null) {
                     for (TunnelEndPoints srcTep : dpn.getTunnelEndPoints()) {
-                        for (TzMembership zone : srcTep.getTzMembership()) {
+                        for (TzMembership zone : nullToEmpty(srcTep.getTzMembership())) {
                             deleteTunnelsInTransportZone(zone.getZoneName(), dpn, srcTep, cfgdhwVteps, dataBroker,
                                     writeTransaction);
                         }
@@ -161,7 +164,7 @@ public final class ItmExternalTunnelDeleteWorker {
                                 LOG.trace("hwtepDS exists {}", hwVtepDS);
                                 // do i need to check node-id?
                                 // for mlag case and non-m-lag case, isnt it enough to just check ipaddress?
-                                if (hwVtepDS.getIpAddress().equals(hwTep.getHwIp())) {
+                                if (Objects.equals(hwVtepDS.getIpAddress(), hwTep.getHwIp())) {
                                     continue;// dont delete tunnels with self
                                 }
                                 // TOR-TOR
index 3e1a7a6f71191ff92ee31dbb74c5989ddf7a8627..1a15db2645d7a81871be474353a5e0f801554935 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.genius.itm.confighelpers;
 import static java.util.Collections.singletonList;
 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.itm.impl.ItmUtils.nullToEmpty;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -18,6 +19,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.Callable;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -157,11 +159,12 @@ public final class ItmInternalTunnelAddWorker {
         List<TunnelEndPoints> srcEndPts = srcDpn.getTunnelEndPoints();
         List<TunnelEndPoints> dstEndPts = dstDpn.getTunnelEndPoints();
 
-        for (TunnelEndPoints srcte : srcEndPts) {
-            for (TunnelEndPoints dstte : dstEndPts) {
+        for (TunnelEndPoints srcte : nullToEmpty(srcEndPts)) {
+            for (TunnelEndPoints dstte : nullToEmpty(dstEndPts)) {
                 // Compare the Transport zones
-                if (!srcDpn.getDPNID().equals(dstDpn.getDPNID())) {
-                    if (!ItmUtils.getIntersection(srcte.getTzMembership(), dstte.getTzMembership()).isEmpty()) {
+                if (!Objects.equals(srcDpn.getDPNID(), dstDpn.getDPNID())) {
+                    if (!ItmUtils.getIntersection(nullToEmpty(srcte.getTzMembership()),
+                            nullToEmpty(dstte.getTzMembership())).isEmpty()) {
                         // wire them up
                         wireUpBidirectionalTunnel(tx, srcte, dstte, srcDpn.getDPNID(), dstDpn.getDPNID(),
                                 mdsalManager);
@@ -228,7 +231,7 @@ public final class ItmInternalTunnelAddWorker {
         String gateway = srcte.getIpAddress().getIpv4Address() != null ? "0.0.0.0" : "::";
         IpAddress gatewayIpObj = IpAddressBuilder.getDefaultInstance(gateway);
         IpAddress gwyIpAddress =
-                srcte.getSubnetMask().equals(dstte.getSubnetMask()) ? gatewayIpObj : srcte.getGwIpAddress() ;
+                Objects.equals(srcte.getSubnetMask(), dstte.getSubnetMask()) ? gatewayIpObj : srcte.getGwIpAddress();
         LOG.debug(" Creating Trunk Interface with parameters trunk I/f Name - {}, parent I/f name - {}, "
                 + "source IP - {}, destination IP - {} gateway IP - {}",
                 trunkInterfaceName, srcte.getInterfaceName(), srcte.getIpAddress(), dstte.getIpAddress(), gwyIpAddress);
@@ -318,7 +321,7 @@ public final class ItmInternalTunnelAddWorker {
             String trunkInterfaceName, String parentInterfaceName) throws ExecutionException, InterruptedException,
             OperationFailedException {
         IpAddress gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
-        IpAddress gwyIpAddress = srcte.getSubnetMask().equals(dstte.getSubnetMask())
+        IpAddress gwyIpAddress = Objects.equals(srcte.getSubnetMask(), dstte.getSubnetMask())
                 ? gatewayIpObj : srcte.getGwIpAddress() ;
         LOG.debug("Creating Trunk Interface with parameters trunk I/f Name - {}, parent I/f name - {}, source IP - {},"
                         + " destination IP - {} gateway IP - {}", trunkInterfaceName, parentInterfaceName,
index 5f5b8489bb43bd36e9472b5ffcbd78acb2414c42..340277d81bf778b2c2e845b0cf00ffafd1d17b9d 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.genius.itm.confighelpers;
 
 import static java.util.Collections.singletonList;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -16,6 +17,7 @@ import java.math.BigInteger;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -127,9 +129,9 @@ public class ItmInternalTunnelDeleteWorker {
                     continue;
                 }
                 LOG.debug("Entries in meshEndPointCache {} for DPN Id{} ", meshedEndPtCache.size(), srcDpn.getDPNID());
-                for (TunnelEndPoints srcTep : srcDpn.getTunnelEndPoints()) {
+                for (TunnelEndPoints srcTep : nullToEmpty(srcDpn.getTunnelEndPoints())) {
                     LOG.trace("Processing srcTep {}", srcTep);
-                    List<TzMembership> srcTZones = srcTep.getTzMembership();
+                    List<TzMembership> srcTZones = nullToEmpty(srcTep.getTzMembership());
                     boolean tepDeleteFlag = false;
                     // First, take care of tunnel removal, so run through all other DPNS other than srcDpn
                     // In the tep received from Delete DCN, the membership list will always be 1
@@ -137,9 +139,10 @@ public class ItmInternalTunnelDeleteWorker {
                     // Hence if a tunnel is shared across TZs, compare the original membership list between end points
                     // to decide if tunnel to be deleted.
                     for (DPNTEPsInfo dstDpn : meshedDpnList) {
-                        if (!srcDpn.getDPNID().equals(dstDpn.getDPNID())) {
-                            for (TunnelEndPoints dstTep : dstDpn.getTunnelEndPoints()) {
-                                if (!ItmUtils.getIntersection(dstTep.getTzMembership(), srcTZones).isEmpty()) {
+                        if (!Objects.equals(srcDpn.getDPNID(), dstDpn.getDPNID())) {
+                            for (TunnelEndPoints dstTep : nullToEmpty(dstDpn.getTunnelEndPoints())) {
+                                if (!ItmUtils.getIntersection(nullToEmpty(dstTep.getTzMembership()),
+                                        srcTZones).isEmpty()) {
                                     List<TzMembership> originalTzMembership =
                                             ItmUtils.getOriginalTzMembership(srcTep, srcDpn.getDPNID(), meshedDpnList);
                                     if (ItmUtils.getIntersection(dstTep.getTzMembership(),
@@ -171,10 +174,10 @@ public class ItmInternalTunnelDeleteWorker {
                     }
                     for (DPNTEPsInfo dstDpn : meshedDpnList) {
                         // Second, take care of Tep TZ membership and identify if tep can be removed
-                        if (srcDpn.getDPNID().equals(dstDpn.getDPNID())) {
+                        if (Objects.equals(srcDpn.getDPNID(), dstDpn.getDPNID())) {
                             // Same DPN, so remove the TZ membership
-                            for (TunnelEndPoints dstTep : dstDpn.getTunnelEndPoints()) {
-                                if (dstTep.getIpAddress().equals(srcTep.getIpAddress())) {
+                            for (TunnelEndPoints dstTep : nullToEmpty(dstDpn.getTunnelEndPoints())) {
+                                if (Objects.equals(dstTep.getIpAddress(), srcTep.getIpAddress())) {
                                     // Remove the deleted TZ membership from the TEP
                                     LOG.debug("Removing TZ list {} from Existing TZ list {} ", srcTZones,
                                             dstTep.getTzMembership());
@@ -336,12 +339,15 @@ public class ItmInternalTunnelDeleteWorker {
             boolean emptyTunnelGroup = true;
             boolean foundLogicGroupIface = false;
             for (InternalTunnel tunl : tunnels) {
-                if (tunl.getSourceDPN().equals(srcDpnId) && tunl.getDestinationDPN().equals(dstDpnId)) {
-                    if (tunl.getTransportType().isAssignableFrom(TunnelTypeVxlan.class)
+                if (Objects.equals(tunl.getSourceDPN(), srcDpnId) && Objects.equals(tunl.getDestinationDPN(),
+                        dstDpnId)) {
+                    if (tunl.getTransportType() != null && tunl.getTransportType().isAssignableFrom(
+                            TunnelTypeVxlan.class)
                             && tunl.getTunnelInterfaceNames() != null && !tunl.getTunnelInterfaceNames().isEmpty()) {
                         emptyTunnelGroup = false;
                         break;
-                    } else if (tunl.getTransportType().isAssignableFrom(TunnelTypeLogicalGroup.class)) {
+                    } else if (tunl.getTransportType() != null && tunl.getTransportType().isAssignableFrom(
+                            TunnelTypeLogicalGroup.class)) {
                         foundLogicGroupIface = true;
                     }
                 }
@@ -457,7 +463,8 @@ public class ItmInternalTunnelDeleteWorker {
 
         ovsBridgeEntryOptional = ovsBridgeEntryCache.get(dpId);
         if (ovsBridgeEntryOptional.isPresent()) {
-            List<OvsBridgeTunnelEntry> bridgeTunnelEntries = ovsBridgeEntryOptional.get().getOvsBridgeTunnelEntry();
+            List<OvsBridgeTunnelEntry> bridgeTunnelEntries =
+                nullToEmpty(ovsBridgeEntryOptional.get().getOvsBridgeTunnelEntry());
             deleteBridgeInterfaceEntry(bridgeEntryKey, bridgeTunnelEntries, bridgeEntryIid, interfaceName);
             // IfIndex needs to be removed only during State Clean up not Config
             // TunnelMetaUtils.removeLportTagInterfaceMap(idManager, defaultOperationalShardTransaction, interfaceName);
index 0abd475b3258414b687dd68fc617e69a5ed9fce0..e61909a46b3285b2750f77d9c90f47bdf18d8544 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.itm.confighelpers;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
 
@@ -119,12 +121,11 @@ public class ItmMonitorWorker implements Callable<List<ListenableFuture<Void>>>
         }
     }
 
-    private void toggleForDirectEnabled(DpnsTeps dpnTeps, WriteTransaction transaction) throws ReadFailedException,
-        InterruptedException, ExecutionException {
+    private void toggleForDirectEnabled(DpnsTeps dpnTeps, WriteTransaction transaction) throws ReadFailedException {
         List<RemoteDpns> remoteDpnTepNewList = new ArrayList<>();
         RemoteDpns remoteDpnNew = null;
         Optional<OvsBridgeRefEntry> ovsBridgeRefEntry = ovsBridgeRefEntryCache.get(dpnTeps.getSourceDpnId());
-        for (RemoteDpns remoteDpn : dpnTeps.getRemoteDpns()) {
+        for (RemoteDpns remoteDpn : nullToEmpty(dpnTeps.getRemoteDpns())) {
             if (enabled != null) {
                 LOG.debug("toggleMonitoring: tunnelInterfaceName: {}, monitorEnable = {} ",
                     remoteDpn.getTunnelName(), enabled);
@@ -144,7 +145,7 @@ public class ItmMonitorWorker implements Callable<List<ListenableFuture<Void>>>
 
     public void updateMonitoringDS(BigInteger sourceDpnId,List<RemoteDpns> remoteDpnTepNewList,
                                    WriteTransaction transaction) {
-        InstanceIdentifier<DpnsTeps> iid = directTunnelUtils.createDpnTepsInstanceIdentifier(sourceDpnId);
+        InstanceIdentifier<DpnsTeps> iid = DirectTunnelUtils.createDpnTepsInstanceIdentifier(sourceDpnId);
         DpnsTepsBuilder builder = new DpnsTepsBuilder().withKey(new DpnsTepsKey(sourceDpnId))
             .setRemoteDpns(remoteDpnTepNewList);
         LOG.debug("DirectTunnelUtils - Builder remoteDPNs: {}", builder.getRemoteDpns());
index 794d4a328ccfb161b494671a34686f0d557d04e3..5d62b903b5a80b881814003aae69ff93093209a8 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.itm.confighelpers;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -63,7 +65,7 @@ public class ItmTepRemoveWorker implements Callable<List<ListenableFuture<Void>>
         if (dcGatewayIpList != null && !dcGatewayIpList.isEmpty()) {
             List<DPNTEPsInfo>  dpnDeleteList = new ArrayList<>();
             for (DPNTEPsInfo dpnTEPInfo : delDpnList) {
-                List<TunnelEndPoints> tunnelEndPointsList = dpnTEPInfo.getTunnelEndPoints();
+                List<TunnelEndPoints> tunnelEndPointsList = nullToEmpty(dpnTEPInfo.getTunnelEndPoints());
                 if (tunnelEndPointsList.size() == 1) {
                     dpnDeleteList.add(dpnTEPInfo);
                 } else {
index fb1eeccfee88fa03920505be732a99db6ff42a5e..fd15e4188777e982724a5a82f28bfb8ca2dd15ca 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.genius.itm.confighelpers;
 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.genius.itm.impl.ItmUtils.nullToEmpty;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -19,6 +20,7 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import javax.inject.Inject;
@@ -186,8 +188,8 @@ public class ItmTunnelAggregationHelper {
     }
 
     private Bucket createBucket(String interfaceName, IfTunnel ifTunnel, int bucketId, int portNumber) {
-        List<ActionInfo> listActionInfo = interfaceManager.getInterfaceEgressActions(interfaceName);
-        if (listActionInfo == null || listActionInfo.isEmpty()) {
+        List<ActionInfo> listActionInfo = nullToEmpty(interfaceManager.getInterfaceEgressActions(interfaceName));
+        if (listActionInfo.isEmpty()) {
             LOG.warn("MULTIPLE_VxLAN_TUNNELS: could not build Egress bucket for {}", interfaceName);
         }
         Integer portWeight = ifTunnel.getWeight() != null ? ifTunnel.getWeight() : DEFAULT_WEIGHT;
@@ -324,7 +326,7 @@ public class ItmTunnelAggregationHelper {
 
     private OperStatus getAggregatedOperStatus(Interface ifaceState, InterfaceParentEntry parentEntry) {
         String logicalTunnelName = parentEntry.getParentInterface();
-        if (!logicalTunnelName.equals(ifaceState.getName()) && ifaceState.getOperStatus() == OperStatus.Up) {
+        if (!Objects.equals(logicalTunnelName, ifaceState.getName()) && ifaceState.getOperStatus() == OperStatus.Up) {
             return OperStatus.Up;
         }
 
@@ -336,7 +338,7 @@ public class ItmTunnelAggregationHelper {
         }
         for (InterfaceChildEntry interfaceChildEntry : interfaceChildEntries) {
             String curChildInterface = interfaceChildEntry.getChildInterface();
-            if (!curChildInterface.equals(ifaceState.getName())) {
+            if (!Objects.equals(curChildInterface, ifaceState.getName())) {
                 InterfaceInfo ifInfo = interfaceManager.getInterfaceInfoFromOperationalDataStore(curChildInterface);
                 if (ifInfo != null && InterfaceInfo.InterfaceOpState.UP.equals(ifInfo.getOpState())) {
                     return OperStatus.Up;
index 43cf8a30482daff273599cb3216b848ac0ee4b29..bf9421d6a24cec66c9c4bf1d207e2b5ff1b09b12 100644 (file)
@@ -38,7 +38,7 @@ public final class ItmTunnelStateAddHelper {
         InstanceIdentifier<StateTunnelList> stListId = ItmUtils.buildStateTunnelListId(tlKey);
         StateTunnelList tunnelStateList;
         TunnelOperStatus tunnelOperStatus;
-        boolean tunnelState = iface.getOperStatus().equals(Interface.OperStatus.Up);
+        boolean tunnelState = Interface.OperStatus.Up.equals(iface.getOperStatus());
         switch (iface.getOperStatus()) {
             case Up:
                 tunnelOperStatus = TunnelOperStatus.Up;
index 5dda198309ff53f5c2253da3111121920549efa1..a3aaa917bd16bdaeafd67d547cfd060c0201e05b 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.genius.itm.confighelpers;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -140,7 +141,7 @@ public final class OvsdbTepAddConfigHelper {
                 Vteps oldVtep = null;
 
                 for (Vteps vtep : vtepList) {
-                    if (vtep.getDpnId().equals(dpnId)) {
+                    if (Objects.equals(vtep.getDpnId(), dpnId)) {
                         vtepFound = true;
                         oldVtep = vtep;
                         // get portName of existing vtep
@@ -265,7 +266,7 @@ public final class OvsdbTepAddConfigHelper {
                 UnknownVteps oldVtep = null;
 
                 for (UnknownVteps vtep : vtepList) {
-                    if (vtep.getDpnId().equals(dpid)) {
+                    if (Objects.equals(vtep.getDpnId(), dpid)) {
                         vtepFound = true;
                         oldVtep = vtep;
                         break;
index fe5bfb5de7ebb89a7279cc9f6eab97f699a43193..043eba2c39551c585816e0f054ea9c94696b19bb 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.genius.itm.confighelpers;
 
 import java.math.BigInteger;
 import java.util.List;
+import java.util.Objects;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -123,7 +124,7 @@ public final class OvsdbTepRemoveConfigHelper {
                 Vteps oldVtep = null;
 
                 for (Vteps vtep : vtepList) {
-                    if (vtep.getDpnId().equals(dpnId)) {
+                    if (Objects.equals(vtep.getDpnId(), dpnId)) {
                         vtepFound = true;
                         oldVtep = vtep;
                         break;
@@ -199,7 +200,7 @@ public final class OvsdbTepRemoveConfigHelper {
                 UnknownVteps foundVtep = null;
 
                 for (UnknownVteps vtep : vtepList) {
-                    if (vtep.getDpnId().equals(dpnId)) {
+                    if (Objects.equals(vtep.getDpnId(), dpnId)) {
                         vtepFound = true;
                         foundVtep = vtep;
                         break;
index 4e5c968451f19460969f56d9221e4200a98e143b..48acd6c0220c3f9cd532d67145c7330784bd674e 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.genius.itm.impl;
 
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.utils.batching.ActionableResource;
@@ -87,15 +88,15 @@ public final class ITMBatchingUtils {
         getQueue(entityType).add(actResource);
     }
 
+    @Nonnull
     public static BlockingQueue<ActionableResource> getQueue(EntityType entityType) {
         switch (entityType) {
             case DEFAULT_OPERATIONAL : return DEFAULT_OPERATIONAL_SHARD_BUFFER_Q;
             case DEFAULT_CONFIG : return DEFAULT_CONFIG_SHARD_BUFFER_Q;
             case TOPOLOGY_CONFIG: return TOPOLOGY_CONFIG_SHARD_BUFFER_Q;
-            default : {
-                LOG.debug("entity type is neither operational or config, getQueue operation failed");
-                return null;
-            }
+            default:
+                throw new IllegalArgumentException(
+                    "Entity type " + entityType + " is neither operational or config, getQueue operation failed");
         }
     }
 
index 94fb258f4a461c2f34b5375d633edec105df9253..e4f4856dc5c8d4a2d40a107b436ed253709144e3 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.itm.impl;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -21,7 +23,6 @@ import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
-
 import org.apache.aries.blueprint.annotation.service.Service;
 import org.apache.felix.service.command.CommandSession;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -332,9 +333,7 @@ public class ItmProvider implements AutoCloseable, IITMProvider /*,ItmStateServi
 
         String schemaName = validatedSchema.getSchemaName();
         VtepConfigSchema existingSchema = getVtepConfigSchema(schemaName);
-        if (existingSchema != null) {
-            Preconditions.checkArgument(false, String.format("VtepConfigSchema [%s] already exists!", schemaName));
-        }
+        Preconditions.checkArgument(existingSchema == null, "VtepConfigSchema [" + schemaName + "] already exists!");
         MDSALUtil.syncWrite(this.dataBroker, LogicalDatastoreType.CONFIGURATION,
                 ItmUtils.getVtepConfigSchemaIdentifier(schemaName), validatedSchema);
         LOG.debug("Vtep config schema {} added to config DS", schemaName);
@@ -364,12 +363,12 @@ public class ItmProvider implements AutoCloseable, IITMProvider /*,ItmStateServi
             builder.setDpnIds(schema.getDpnIds());
         } else {*/
         if (lstDpnsForAdd != null && !lstDpnsForAdd.isEmpty()) {
-            List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(schema.getDpnIds());
+            List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(nullToEmpty(schema.getDpnIds()));
             originalDpnList.addAll(lstDpnsForAdd) ;
             builder.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(originalDpnList));
         }
         if (lstDpnsForDelete != null && !lstDpnsForDelete.isEmpty()) {
-            List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(schema.getDpnIds());
+            List<BigInteger> originalDpnList = ItmUtils.getDpnIdList(nullToEmpty(schema.getDpnIds()));
             originalDpnList.removeAll(lstDpnsForDelete) ;
             builder.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(originalDpnList));
             // schema.setDpnIds(ItmUtils.getDpnIdsListFromBigInt(ItmUtils.getDpnIdList(schema.getDpnIds())
index 5242babeaa38f28e59348f86ee1f596de36a1973..05e0c464c0eb9371dd868f9bd2e05a405b56c6bf 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.itm.impl;
 
+import static java.util.Collections.emptyList;
+
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.BiMap;
@@ -23,9 +25,11 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.net.util.SubnetUtils;
 import org.apache.commons.net.util.SubnetUtils.SubnetInfo;
@@ -542,10 +546,13 @@ public final class ItmUtils {
                                                                   List<VtepConfigSchema> existingSchemas) {
         VtepConfigSchema validSchema = validateVtepConfigSchema(schema);
         for (VtepConfigSchema existingSchema : emptyIfNull(existingSchemas)) {
-            if (!StringUtils.equalsIgnoreCase(schema.getSchemaName(), existingSchema.getSchemaName())
-                    && schema.getSubnet().equals(existingSchema.getSubnet())) {
+            if (!(!StringUtils.equalsIgnoreCase(schema.getSchemaName(), existingSchema.getSchemaName())
+                    && Objects.equals(schema.getSubnet(), existingSchema.getSubnet()))) {
                 String subnetCidr = getSubnetCidrAsString(schema.getSubnet());
-                Preconditions.checkArgument(false, "VTEP schema with subnet [" + subnetCidr
+                Preconditions.checkArgument(
+                    !(!StringUtils.equalsIgnoreCase(schema.getSchemaName(), existingSchema.getSchemaName())
+                        && Objects.equals(schema.getSubnet(), existingSchema.getSubnet())),
+                    "VTEP schema with subnet [" + subnetCidr
                         + "] already exists. Multiple VTEP schemas with same subnet is not allowed.");
             }
         }
@@ -553,11 +560,10 @@ public final class ItmUtils {
             String tzone = validSchema.getTransportZoneName();
             List<BigInteger> lstDpns = getConflictingDpnsAlreadyConfiguredWithTz(validSchema.getSchemaName(), tzone,
                     getDpnIdList(validSchema.getDpnIds()), existingSchemas);
-            if (!lstDpns.isEmpty()) {
-                Preconditions.checkArgument(false, "DPN's " + lstDpns + " already configured for transport zone "
-                                + tzone + ". Only one end point per transport Zone per Dpn is allowed.");
-            }
-            if (schema.getTunnelType().equals(TunnelTypeGre.class)) {
+            Preconditions.checkArgument(lstDpns.isEmpty(),
+                "DPN's " + lstDpns + " already configured for transport zone "
+                    + tzone + ". Only one end point per transport Zone per Dpn is allowed.");
+            if (TunnelTypeGre.class.equals(schema.getTunnelType())) {
                 validateForSingleGreTep(validSchema.getSchemaName(), getDpnIdList(validSchema.getDpnIds()),
                         existingSchemas);
             }
@@ -572,11 +578,8 @@ public final class ItmUtils {
                     && !StringUtils.equalsIgnoreCase(schemaName, existingSchema.getSchemaName())) {
                 List<BigInteger> lstConflictingDpns = new ArrayList<>(getDpnIdList(existingSchema.getDpnIds()));
                 lstConflictingDpns.retainAll(emptyIfNull(lstDpnsForAdd));
-                if (!lstConflictingDpns.isEmpty()) {
-                    String errMsg = "DPN's " + lstConflictingDpns
-                            + " already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.";
-                    Preconditions.checkArgument(false, errMsg);
-                }
+                Preconditions.checkArgument(lstConflictingDpns.isEmpty(), "DPN's " + lstConflictingDpns
+                    + " already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.");
             }
         }
     }
@@ -594,10 +597,9 @@ public final class ItmUtils {
         IpAddress gatewayIp = schema.getGatewayIp();
         if (gatewayIp != null) {
             String strGatewayIp = gatewayIp.stringValue();
-            if (!strGatewayIp.equals(ITMConstants.DUMMY_IP_ADDRESS) && !subnetUtils.getInfo().isInRange(strGatewayIp)) {
-                Preconditions.checkArgument(false, "Gateway IP address " + strGatewayIp
-                        + " is not in subnet range " + subnetCidr);
-            }
+            Preconditions.checkArgument(
+                ITMConstants.DUMMY_IP_ADDRESS.equals(strGatewayIp) || subnetUtils.getInfo().isInRange(strGatewayIp),
+                "Gateway IP address " + strGatewayIp + " is not in subnet range " + subnetCidr);
         }
         ItmUtils.getExcludeIpAddresses(schema.getExcludeIpFilter(), subnetUtils.getInfo());
         return new VtepConfigSchemaBuilder(schema).setTunnelType(schema.getTunnelType()).build();
@@ -623,7 +625,7 @@ public final class ItmUtils {
         for (VtepConfigSchema schema : emptyIfNull(existingSchemas)) {
             if (!StringUtils.equalsIgnoreCase(schemaName, schema.getSchemaName())
                     && StringUtils.equals(schema.getTransportZoneName(), tzone)) {
-                lstConflictingDpns = new ArrayList<>(getDpnIdList(schema.getDpnIds()));
+                lstConflictingDpns = new ArrayList<>(getDpnIdList(nullToEmpty(schema.getDpnIds())));
                 lstConflictingDpns.retainAll(lstDpns);
                 if (!lstConflictingDpns.isEmpty()) {
                     break;
@@ -723,40 +725,32 @@ public final class ItmUtils {
                                                                List<BigInteger> lstDpnsForDelete,
                                                                IITMProvider itmProvider) {
         Preconditions.checkArgument(StringUtils.isNotBlank(schemaName));
-        if ((lstDpnsForAdd == null || lstDpnsForAdd.isEmpty())
-                && (lstDpnsForDelete == null || lstDpnsForDelete.isEmpty())) {
-            Preconditions.checkArgument(false,
-                    "DPN ID list for add | delete is null or empty in schema " + schemaName);
-        }
+        Preconditions.checkArgument(lstDpnsForAdd != null && !lstDpnsForAdd.isEmpty() && lstDpnsForDelete != null
+                && !lstDpnsForDelete.isEmpty(),
+            "DPN ID list for add | delete is null or empty in schema " + schemaName);
         VtepConfigSchema schema = itmProvider.getVtepConfigSchema(schemaName);
-        if (schema == null) {
-            Preconditions.checkArgument(false, "Specified VTEP Schema [" + schemaName
-                    + "] doesn't exists!");
-        }
-        List<BigInteger> existingDpnIds = getDpnIdList(schema.getDpnIds());
+        Preconditions.checkArgument(schema != null, "Specified VTEP Schema [" + schemaName + "] doesn't exist!");
+        List<BigInteger> existingDpnIds = getDpnIdList(nullToEmpty(schema.getDpnIds()));
         if (isNotEmpty(lstDpnsForAdd)) {
             List<BigInteger> lstAlreadyExistingDpns = new ArrayList<>(existingDpnIds);
             lstAlreadyExistingDpns.retainAll(lstDpnsForAdd);
             Preconditions.checkArgument(lstAlreadyExistingDpns.isEmpty(),
                     "DPN ID's " + lstAlreadyExistingDpns
                             + " already exists in VTEP schema [" + schemaName + "]");
-            if (schema.getTunnelType().equals(TunnelTypeGre.class)) {
+            if (TunnelTypeGre.class.equals(schema.getTunnelType())) {
                 validateForSingleGreTep(schema.getSchemaName(), lstDpnsForAdd, itmProvider.getAllVtepConfigSchemas());
             }
         }
         if (isNotEmpty(lstDpnsForDelete)) {
-            if (existingDpnIds.isEmpty()) {
-                String builder = "DPN ID's " + lstDpnsForDelete
-                        + " specified for delete from VTEP schema [" + schemaName
-                        + "] are not configured in the schema.";
-                Preconditions.checkArgument(false, builder);
-            } else if (!existingDpnIds.containsAll(lstDpnsForDelete)) {
+            Preconditions.checkArgument(!existingDpnIds.isEmpty(), "DPN ID's " + lstDpnsForDelete
+                + " specified for delete from VTEP schema [" + schemaName
+                + "] are not configured in the schema.");
+            if (!existingDpnIds.containsAll(lstDpnsForDelete)) {
                 List<BigInteger> lstConflictingDpns = new ArrayList<>(lstDpnsForDelete);
                 lstConflictingDpns.removeAll(existingDpnIds);
-                String builder = "DPN ID's " + lstConflictingDpns
-                        + " specified for delete from VTEP schema [" + schemaName
-                        + "] are not configured in the schema.";
-                Preconditions.checkArgument(false, builder);
+                throw new IllegalArgumentException("DPN ID's " + lstConflictingDpns
+                    + " specified for delete from VTEP schema [" + schemaName
+                    + "] are not configured in the schema.");
             }
         }
         return schema;
@@ -767,7 +761,7 @@ public final class ItmUtils {
     }
 
     public static <T> List<T> emptyIfNull(List<T> list) {
-        return list == null ? Collections.emptyList() : list;
+        return list == null ? emptyList() : list;
     }
 
     public static <T> boolean isEmpty(Collection<T> collection) {
@@ -921,8 +915,8 @@ public final class ItmUtils {
                 }
             }
             if (hwVtepsExist) {
-                for (HwVtep hwVtep : hwVteps) {
-                    for (HwVtep hwVtepOther : hwVteps) {
+                for (HwVtep hwVtep : nullToEmpty(hwVteps)) {
+                    for (HwVtep hwVtepOther : nullToEmpty(hwVteps)) {
                         if (!hwVtep.getHwIp().equals(hwVtepOther.getHwIp())) {
                             tunnels.add(getExtTunnel(hwVtep.getNodeId(), hwVtepOther.getNodeId(),
                                     tunType, dataBroker));
@@ -1009,11 +1003,9 @@ public final class ItmUtils {
     }
 
     public static List<TunnelEndPoints> getTEPsForDpn(BigInteger srcDpn, Collection<DPNTEPsInfo> dpnList) {
-        List<TunnelEndPoints> tunnelEndPoints = new ArrayList<>();
         for (DPNTEPsInfo dpn : dpnList) {
-            if (dpn.getDPNID().equals(srcDpn)) {
-                tunnelEndPoints.addAll(dpn.getTunnelEndPoints());
-                return tunnelEndPoints ;
+            if (Objects.equals(dpn.getDPNID(), srcDpn)) {
+                return new ArrayList<>(nullToEmpty(dpn.getTunnelEndPoints()));
             }
         }
         return null;
@@ -1028,7 +1020,7 @@ public final class ItmUtils {
             result = tunnelList.get().getInternalTunnel();
         }
         if (result == null) {
-            result = Collections.emptyList();
+            result = emptyList();
         }
         return result;
     }
@@ -1059,7 +1051,7 @@ public final class ItmUtils {
             result = tunnelList.get().getExternalTunnel();
         }
         if (result == null) {
-            result = Collections.emptyList();
+            result = emptyList();
         }
         return result;
     }
@@ -1075,7 +1067,7 @@ public final class ItmUtils {
         } else if (tunType.equals(TunnelTypeLogicalGroup.class)) {
             tunnelType = ITMConstants.TUNNEL_TYPE_LOGICAL_GROUP_VXLAN;
         }
-        return tunnelType ;
+        return tunnelType;
     }
 
 
@@ -1317,7 +1309,7 @@ public final class ItmUtils {
 
     public static List<TzMembership> removeTransportZoneMembership(TunnelEndPoints endPts, List<TzMembership> zones) {
         LOG.trace(" RemoveTransportZoneMembership TEPs {}, Membership to be removed {} ", endPts, zones);
-        List<TzMembership> existingTzList = new ArrayList<>(endPts.getTzMembership()) ;
+        List<TzMembership> existingTzList = new ArrayList<>(nullToEmpty(endPts.getTzMembership())) ;
         for (TzMembership membership : zones) {
             existingTzList.remove(new TzMembershipBuilder().setZoneName(membership.getZoneName()).build());
         }
@@ -1325,21 +1317,23 @@ public final class ItmUtils {
         return existingTzList;
     }
 
+    @Nonnull
     public static List<TzMembership> getOriginalTzMembership(TunnelEndPoints srcTep, BigInteger dpnId,
                                                              Collection<DPNTEPsInfo> meshedDpnList) {
         LOG.trace("Original Membership for source DPN {}, source TEP {}", dpnId, srcTep);
         for (DPNTEPsInfo dstDpn : meshedDpnList) {
             if (dpnId.equals(dstDpn.getDPNID())) {
                 List<TunnelEndPoints> endPts = dstDpn.getTunnelEndPoints();
-                for (TunnelEndPoints tep : endPts) {
-                    if (tep.getIpAddress().equals(srcTep.getIpAddress())) {
-                        LOG.debug("Original Membership size {}", tep.getTzMembership().size()) ;
-                        return tep.getTzMembership();
+                for (TunnelEndPoints tep : nullToEmpty(endPts)) {
+                    if (Objects.equals(tep.getIpAddress(), srcTep.getIpAddress())) {
+                        List<TzMembership> tzMemberships = nullToEmpty(tep.getTzMembership());
+                        LOG.debug("Original Membership size {}", tzMemberships.size()) ;
+                        return tzMemberships;
                     }
                 }
             }
         }
-        return null ;
+        return emptyList();
     }
 
     public static StateTunnelList buildStateTunnelList(StateTunnelListKey tlKey, String name, boolean state,
@@ -1498,4 +1492,10 @@ public final class ItmUtils {
         }
         return tunType ;
     }
+
+    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3.0.2
+    @Nonnull
+    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
+        return input != null ? input : new ArrayList<>(0);
+    }
 }
index 0bb9fda6b626e6a861da757a638f42b110f674f2..40b3926880b62e0f1924abf1a14196452c9c63f6 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.itm.itmdirecttunnels.listeners;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -54,7 +56,7 @@ public class DpnTepStateListener extends AbstractTunnelListenerBase<DpnsTeps> {
         if (!entityOwner()) {
             return;
         }
-        for (RemoteDpns remoteDpns : dpnsTeps.getRemoteDpns()) {
+        for (RemoteDpns remoteDpns : nullToEmpty(dpnsTeps.getRemoteDpns())) {
             //Process the unprocessed NodeConnector for the Tunnel, if present in the UnprocessedNodeConnectorCache
             // This may run in all node as its ClusteredDTCN but cache will be populated in only the Entity owner
             String tunnelName = remoteDpns.getTunnelName();
index 2f1325fc9419cfe956415cdcc77b4ab1c3d1c3aa..e96264b576dadf17be5bb0169627508ca34f79ab 100644 (file)
@@ -147,7 +147,7 @@ public class TerminationPointStateListener
         List<InterfaceBfdStatus> tunnelBfdStatus = terminationPoint.getInterfaceBfdStatus();
         if (tunnelBfdStatus != null && !tunnelBfdStatus.isEmpty()) {
             for (InterfaceBfdStatus bfdState : tunnelBfdStatus) {
-                if (bfdState.getBfdStatusKey().equalsIgnoreCase(DirectTunnelUtils.BFD_OP_STATE)) {
+                if (DirectTunnelUtils.BFD_OP_STATE.equalsIgnoreCase(bfdState.getBfdStatusKey())) {
                     String bfdOpState = bfdState.getBfdStatusValue();
                     return DirectTunnelUtils.BFD_STATE_UP.equalsIgnoreCase(bfdOpState)
                             ? Interface.OperStatus.Up : Interface.OperStatus.Down;
index d8ca326f2c1b4b21a26feb6107c6d5fafb59dc5c..e6db3e1f70fec9dcf74aa682d38c1638662db8e5 100644 (file)
@@ -15,6 +15,7 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.Callable;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -190,7 +191,7 @@ public class TunnelInventoryStateListener extends AbstractTunnelListenerBase<Flo
         if (!operStatusNew.equals(operStatusOld)) {
             opstateModified = true;
         }
-        if (!macAddressNew.equals(macAddressOld)) {
+        if (!Objects.equals(macAddressNew, macAddressOld)) {
             hardwareAddressModified = true;
         }
 
index 661238c06696ceaf48f1376e22b8622e3c813aa3..f74ed8a570d8e699b7ba2ac531ecb4741aed23fb 100644 (file)
@@ -401,7 +401,7 @@ public final class DirectTunnelUtils {
         options.put(DirectTunnelUtils.TUNNEL_OPTIONS_TOS, DirectTunnelUtils.TUNNEL_OPTIONS_TOS_VALUE_INHERIT);
 
         // Specific options for each type of tunnel
-        if (ifTunnel.getTunnelInterfaceType().equals(TunnelTypeVxlanGpe.class)) {
+        if (TunnelTypeVxlanGpe.class.equals(ifTunnel.getTunnelInterfaceType())) {
             options.put(DirectTunnelUtils.TUNNEL_OPTIONS_EXTS, DirectTunnelUtils.TUNNEL_OPTIONS_VALUE_GPE);
             options.put(DirectTunnelUtils.TUNNEL_OPTIONS_NSI, DirectTunnelUtils.TUNNEL_OPTIONS_VALUE_FLOW);
             options.put(DirectTunnelUtils.TUNNEL_OPTIONS_NSP, DirectTunnelUtils.TUNNEL_OPTIONS_VALUE_FLOW);
index e2e87d46ec5ac84d80701da0f7b94743a8e7d75c..3204bb5ed62ded93710666ff89d502654242bbe3 100644 (file)
@@ -127,7 +127,7 @@ public class InterfaceStateListener extends AbstractSyncDataTreeChangeListener<I
         Optional<StateTunnelList> tunnelsState = tunnelStateCache.get(stListId);
         StateTunnelListBuilder stlBuilder;
         TunnelOperStatus tunnelOperStatus;
-        boolean tunnelState = updated.getOperStatus().equals(Interface.OperStatus.Up);
+        boolean tunnelState = OperStatus.Up.equals(updated.getOperStatus());
         switch (updated.getOperStatus()) {
             case Up:
                 tunnelOperStatus = TunnelOperStatus.Up;
index bbeeb7f5dfd0c49b87a8cb4d1c1700d3a807424f..879c2af53f5f192264c9ef301ce44780673f332e 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 import javax.annotation.Nonnull;
 import javax.inject.Inject;
@@ -161,11 +162,11 @@ public class TransportZoneListener extends AbstractSyncDataTreeChangeListener<Tr
         // do not entertain request and skip tunnels remove operation
         // if def-tz removal request is due to def-tz-enabled flag is disabled or
         // due to change in def-tz-tunnel-type, then allow def-tz tunnels deletion
-        if (transportZone.getZoneName().equalsIgnoreCase(ITMConstants.DEFAULT_TRANSPORT_ZONE)) {
+        if (ITMConstants.DEFAULT_TRANSPORT_ZONE.equalsIgnoreCase(transportZone.getZoneName())) {
             // Get TunnelTypeBase object for tunnel-type configured in config file
             Class<? extends TunnelTypeBase> tunType = ItmUtils.getTunnelType(itmConfig.getDefTzTunnelType());
 
-            if (!itmConfig.isDefTzEnabled() || !transportZone.getTunnelType().equals(tunType)) {
+            if (!itmConfig.isDefTzEnabled() || !Objects.equals(transportZone.getTunnelType(), tunType)) {
                 allowTunnelDeletion = true;
             } else {
                 // this is case when def-tz removal request is from Northbound.
index 7143d89e7fb5e18dbed07908b3acdb3907bebd33..f2461fc6b0e2bace9b4453badac9b316fd03e244 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.itm.listeners;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import com.google.common.base.Optional;
 import javax.annotation.Nonnull;
 import javax.inject.Inject;
@@ -71,8 +73,7 @@ public class TunnelMonitorChangeListener
             monitorProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
         }
         if (transportZonesOptional.isPresent()) {
-            TransportZones transportZones = transportZonesOptional.get();
-            for (TransportZone tzone : transportZones.getTransportZone()) {
+            for (TransportZone tzone : nullToEmpty(transportZonesOptional.get().getTransportZone())) {
                 LOG.debug("Remove - TunnelMonitorToggleWorker with tzone = {}, Enable = {}, MonitorProtocol = {}",
                         tzone.getZoneName(),dataObjectModification.isEnabled(), monitorProtocol);
                 if (interfaceManager.isItmDirectTunnelsEnabled()) {
@@ -116,8 +117,7 @@ public class TunnelMonitorChangeListener
 
         }
         if (transportZonesOptional.isPresent()) {
-            TransportZones tzones = transportZonesOptional.get();
-            for (TransportZone tzone : tzones.getTransportZone()) {
+            for (TransportZone tzone : nullToEmpty(transportZonesOptional.get().getTransportZone())) {
                 LOG.debug("Update - TunnelMonitorToggleWorker with tzone = {}, Enable = {}, MonitorProtocol = {}",
                         tzone.getZoneName(),dataObjectModificationAfter.isEnabled(), monitorProtocol);
                 if (interfaceManager.isItmDirectTunnelsEnabled()) {
@@ -148,8 +148,7 @@ public class TunnelMonitorChangeListener
             monitorProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
         }
         if (transportZonesOptional.isPresent()) {
-            TransportZones tzones = transportZonesOptional.get();
-            for (TransportZone tzone : tzones.getTransportZone()) {
+            for (TransportZone tzone : nullToEmpty(transportZonesOptional.get().getTransportZone())) {
                 LOG.debug("Add: TunnelMonitorToggleWorker with tzone = {} monitoringEnabled {} and "
                         + "monitoringProtocol {}",tzone.getZoneName(),dataObjectModification.isEnabled(),
                         dataObjectModification.getMonitorProtocol());
index ddfb838bfad2cd3ee8f1ca8553161c1b6cde7be4..251b6a9f72d653bf1024d0ed4df1a4edf4f6deae 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.itm.listeners;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import com.google.common.base.Optional;
 import javax.annotation.Nonnull;
 import javax.inject.Inject;
@@ -64,8 +66,7 @@ public class TunnelMonitorIntervalListener extends AbstractSyncDataTreeChangeLis
         Optional<TransportZones> transportZonesOptional = ItmUtils
                 .read(LogicalDatastoreType.CONFIGURATION, path, broker);
         if (transportZonesOptional.isPresent()) {
-            TransportZones tzones = transportZonesOptional.get();
-            for (TransportZone tzone : tzones.getTransportZone()) {
+            for (TransportZone tzone : nullToEmpty(transportZonesOptional.get().getTransportZone())) {
                 //if you remove configuration, the last configured interval is only set i.e no change
                 LOG.debug("Remove:Calling TunnelMonitorIntervalWorker with tzone = {} and {}", tzone.getZoneName(),
                           dataObjectModification.getInterval());
@@ -92,8 +93,7 @@ public class TunnelMonitorIntervalListener extends AbstractSyncDataTreeChangeLis
         Optional<TransportZones> transportZonesOptional = ItmUtils
                 .read(LogicalDatastoreType.CONFIGURATION, path, broker);
         if (transportZonesOptional.isPresent()) {
-            TransportZones tzones = transportZonesOptional.get();
-            for (TransportZone tzone : tzones.getTransportZone()) {
+            for (TransportZone tzone : nullToEmpty(transportZonesOptional.get().getTransportZone())) {
                 LOG.debug("Update:Calling TunnelMonitorIntervalWorker with tzone = {} and {}", tzone.getZoneName(),
                           dataObjectModificationAfter.getInterval());
                 if (interfaceManager.isItmDirectTunnelsEnabled()) {
@@ -118,8 +118,7 @@ public class TunnelMonitorIntervalListener extends AbstractSyncDataTreeChangeLis
         Optional<TransportZones> transportZonesOptional = ItmUtils
                 .read(LogicalDatastoreType.CONFIGURATION, path, broker);
         if (transportZonesOptional.isPresent()) {
-            TransportZones tzones = transportZonesOptional.get();
-            for (TransportZone tzone : tzones.getTransportZone()) {
+            for (TransportZone tzone : nullToEmpty(transportZonesOptional.get().getTransportZone())) {
                 LOG.debug("Add:Calling TunnelMonitorIntervalWorker with tzone = {} and {}", tzone.getZoneName(),
                           dataObjectModification.getInterval());
                 if (interfaceManager.isItmDirectTunnelsEnabled()) {
index 50a9ff6fa0e982570cfb1315859df04185fb7023..5817a65746c31b90d97d502f5c738542fc553b46 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.genius.itm.listeners;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -92,7 +94,7 @@ public class VtepConfigSchemaListener extends AbstractAsyncDataTreeChangeListene
     public void remove(@Nonnull InstanceIdentifier<VtepConfigSchema> instanceIdentifier,
                        @Nonnull VtepConfigSchema vtepConfigSchema) {
         LOG.trace("Received notification for VTEP config schema [{}] deleted.", vtepConfigSchema.getSchemaName());
-        List<BigInteger> lstDpnIds = ItmUtils.getDpnIdList(vtepConfigSchema.getDpnIds());
+        List<BigInteger> lstDpnIds = ItmUtils.getDpnIdList(nullToEmpty(vtepConfigSchema.getDpnIds()));
         if (!lstDpnIds.isEmpty()) {
             deleteVteps(vtepConfigSchema, lstDpnIds);
         }
@@ -178,7 +180,7 @@ public class VtepConfigSchemaListener extends AbstractAsyncDataTreeChangeListene
             delnAddRequired = true;
         } else if (!StringUtils.equalsIgnoreCase(original.getTransportZoneName(), updated.getTransportZoneName())) {
             delnAddRequired = true;
-        } else if (!original.getTunnelType().equals(updated.getTunnelType())) {
+        } else if (!Objects.equals(original.getTunnelType(), updated.getTunnelType())) {
             delnAddRequired = true;
         }
         return delnAddRequired;
@@ -271,7 +273,7 @@ public class VtepConfigSchemaListener extends AbstractAsyncDataTreeChangeListene
         // Check this later
         String tunType ;
         Class<? extends TunnelTypeBase> tunnelType = schema.getTunnelType() ;
-        if (tunnelType.equals(TunnelTypeVxlan.class)) {
+        if (TunnelTypeVxlan.class.equals(tunnelType)) {
             tunType = ITMConstants.TUNNEL_TYPE_VXLAN;
         } else {
             tunType = ITMConstants.TUNNEL_TYPE_GRE;
index a35c117ed4a6d5ff1636d090b5011cfe51563702..f2e668afdc0fe90f4050259d304842042966ab32 100644 (file)
@@ -7,9 +7,12 @@
  */
 package org.opendaylight.genius.itm.recovery.impl;
 
+import static org.opendaylight.genius.itm.impl.ItmUtils.nullToEmpty;
+
 import java.time.Duration;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicInteger;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -146,9 +149,9 @@ public class ItmTepInstanceRecoveryHandler implements ServiceRecoveryInterface {
                 jobCoordinator.enqueueJob(tzName, tepRemoveWorker);
                 AtomicInteger eventCallbackCount = new AtomicInteger(0);
                 AtomicInteger eventRegistrationCount = new AtomicInteger(0);
-                tunnelList.stream().filter(internalTunnel -> internalTunnel
-                        .getDestinationDPN().equals(dpnTepsToRecover.getDPNID()) || internalTunnel.getSourceDPN()
-                        .equals(dpnTepsToRecover.getDPNID())).forEach(internalTunnel -> {
+                tunnelList.stream().filter(internalTunnel -> Objects.equals(internalTunnel
+                        .getDestinationDPN(), dpnTepsToRecover.getDPNID()) || Objects.equals(
+                        internalTunnel.getSourceDPN(), dpnTepsToRecover.getDPNID())).forEach(internalTunnel -> {
                             eventRegistrationCount.incrementAndGet();
                             interfaceListToRecover.add(String.valueOf(internalTunnel.getTunnelInterfaceNames())); });
 
@@ -196,7 +199,7 @@ public class ItmTepInstanceRecoveryHandler implements ServiceRecoveryInterface {
             return null;
         }
 
-        for (Subnets sub : transportZone.getSubnets()) {
+        for (Subnets sub : nullToEmpty(transportZone.getSubnets())) {
             if (sub.getVteps() == null || sub.getVteps().isEmpty()) {
                 LOG.error("Transport Zone {} subnet {} has no vteps", transportZone.getZoneName(), sub.getPrefix());
             }
index de3ad07e423b9209b25772c925ac0fbbdf520626..e2aca26ed3ef72bc23924fdaa454c9aff2fb6071 100644 (file)
@@ -683,7 +683,7 @@ public class ItmManagerRpcService implements ItmRpcService {
                     return result;
                 }
                 for (TransportZone tzone : transportZones.getTransportZone()) {
-                    if (!tzone.getTunnelType().equals(TunnelTypeVxlan.class)) {
+                    if (!TunnelTypeVxlan.class.equals(tzone.getTunnelType())) {
                         continue;
                     }
                     foundVxlanTzone = true;
@@ -763,7 +763,7 @@ public class ItmManagerRpcService implements ItmRpcService {
                     return result;
                 }
                 for (TransportZone tzone : transportZones.getTransportZone()) {
-                    if (!tzone.getTunnelType().equals(TunnelTypeVxlan.class)) {
+                    if (!TunnelTypeVxlan.class.equals(tzone.getTunnelType())) {
                         continue;
                     }
                     String transportZone = tzone.getZoneName();
index e9845f238ae856a78f443684bee2983fcef6ede0..7ae4b7ef56b1feb05b0c789b9c536f032cc8f182 100644 (file)
@@ -11,6 +11,7 @@ import com.google.common.base.Optional;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
+import java.util.Objects;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
@@ -219,7 +220,7 @@ public class LockManagerServiceImpl implements LockManagerService {
                 } else {
                     String lockDataOwner = result.get().getLockOwner();
                     String currentOwner = lockData.getLockOwner();
-                    if (currentOwner.equals(lockDataOwner)) {
+                    if (Objects.equals(currentOwner, lockDataOwner)) {
                         return true;
                     }
                 }
index af50c72808482f27473eda4f96505fc481c2f84a..04a13c6be550b1dc1c6dd65570757cf503aacc99 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.genius.mdsalutil;
 
+import static org.opendaylight.genius.ipv6util.api.Ipv6Util.nullToEmpty;
+
 import com.google.common.base.Optional;
 import com.google.common.net.InetAddresses;
 import com.google.common.primitives.Ints;
@@ -167,9 +169,7 @@ public final class NWUtil {
         if (!nodesOptional.isPresent()) {
             return result;
         }
-        Nodes nodes = nodesOptional.get();
-        List<Node> nodeList = nodes.getNode();
-        for (Node node : nodeList) {
+        for (Node node : nullToEmpty(nodesOptional.get().getNode())) {
             NodeId nodeId = node.getId();
             if (nodeId != null) {
                 BigInteger dpnId = MDSALUtil.getDpnIdFromNodeName(nodeId);
index 8ac981d9fb02268f8bbb0f2f09bc41535418b056..4070d85e948d9d7e5e09b49e2dd5a3dcc33ac01a 100644 (file)
@@ -88,7 +88,7 @@ public class DataObjectCache<K, V extends DataObject> implements AutoCloseable {
                     case WRITE:
                     case SUBTREE_MODIFIED:
                         V dataAfter = rootNode.getDataAfter();
-                        cache.put(keyFunction.apply(path, dataAfter), Optional.of(dataAfter));
+                        cache.put(keyFunction.apply(path, dataAfter), Optional.fromNullable(dataAfter));
                         added(path, dataAfter);
                         break;
                     case DELETE:
index 92222fc8a6da929821213423b78999bf03597d1e..1147170b4ab6ce3a3e2df560f2fe9bd24a059a96 100644 (file)
@@ -11,7 +11,9 @@ import static org.opendaylight.mdsal.binding.testutils.AssertDataObjects.assertE
 
 import java.util.ArrayList;
 import java.util.Comparator;
-
+import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
@@ -20,7 +22,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru
 /**
  * This class is a place holder for various openflow flow/group related test utilities.
  *
- * @autor Faseela K
+ * @author Faseela K
  */
 public class FlowAssertTestUtils {
 
@@ -41,11 +43,18 @@ public class FlowAssertTestUtils {
         FlowBuilder flowBuilder = new FlowBuilder(flow);
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         if (flow.getInstructions() != null) {
-            ArrayList<Instruction> instructionList = new ArrayList<>(flow.getInstructions().getInstruction());
+            ArrayList<Instruction> instructionList =
+                new ArrayList<>(nullToEmpty(flow.getInstructions().getInstruction()));
             instructionList.sort(Comparator.comparing(o -> o.key().toString()));
             instructionsBuilder.setInstruction(instructionList);
             flowBuilder.setInstructions(instructionsBuilder.build());
         }
         return flowBuilder.build();
     }
+
+    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3.0.2
+    @Nonnull
+    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
+        return input != null ? input : new ArrayList<>(0);
+    }
 }