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;
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();
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));
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;
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;
}
*/
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;
}
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);
+ }
}
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;
}
int localErrorCount = 0;
- for (InterfaceAddress interfaceAddress : arpReqInput.getInterfaceAddress()) {
+ for (InterfaceAddress interfaceAddress : nullToEmpty(arpReqInput.getInterfaceAddress())) {
try {
interfaceName = interfaceAddress.getInterface();
srcIpBytes = getIpAddressBytes(interfaceAddress.getIpAddress());
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);
+ }
}
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;
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;
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()
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()))
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));
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 =
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);
*/
package org.opendaylight.genius.idmanager;
+import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
@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);
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;
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);
+ }
}
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;
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();
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;
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);
+ }
}
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;
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();
}
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;
// 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);
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);
.build();
tx.delete(intfid);
- if (interfaceNameEntries.size() <= 1) {
+ if (interfaceNameEntries != null && interfaceNameEntries.size() <= 1) {
tx.delete(dpnToInterfaceId);
}
}
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:
* 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:
*/
package org.opendaylight.genius.interfacemanager.listeners;
+import java.util.Objects;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
}
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;
}
}
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);
}
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;
}
*/
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;
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();
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();
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;
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;
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(),
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;
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;
// 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);
}
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));
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;
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);
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(
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
}
}
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;
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)) {
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());
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;
*/
package org.opendaylight.genius.interfacemanager.shell;
+import static org.opendaylight.genius.interfacemanager.IfmUtil.nullToEmpty;
+
import java.math.BigInteger;
import java.util.Formatter;
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();
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;
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);
+ }
}
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;
int localErrorCount = 0;
targetIpv6Address = ndInput.getTargetIpAddress();
- for (InterfaceAddress interfaceAddress : ndInput.getInterfaceAddress()) {
+ for (InterfaceAddress interfaceAddress : nullToEmpty(ndInput.getInterfaceAddress())) {
try {
interfaceName = interfaceAddress.getInterface();
srcIpv6Address = interfaceAddress.getSrcIpAddress();
*/
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;
@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())
@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());
}
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())
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;
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;
*/
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;
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;
// 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())) {
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.");
}
}
}
* 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());
}
/**
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;
}
}
continue;
}
for (Vteps vtep : sub.getVteps()) {
- if (vtep.getDpnId().equals(dpnId)) {
+ if (Objects.equals(vtep.getDpnId(), dpnId)) {
return true;
}
}
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;
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)
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");
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;
}
.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);
}
}
- for (TransportZone tz : transportZones.getTransportZone()) {
+ for (TransportZone tz : transportZones) {
if (tz.getSubnets() == null || tz.getSubnets().isEmpty()) {
continue;
}
}
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);
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;
}
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;
} 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;
}
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);
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;
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;
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();
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);
}
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
*/
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;
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;
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);
}
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
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;
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;
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);
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);
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,
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;
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;
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
// 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(),
}
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());
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;
}
}
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);
*/
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;
}
}
- 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);
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());
*/
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;
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 {
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;
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;
}
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;
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;
}
}
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;
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;
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;
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
UnknownVteps oldVtep = null;
for (UnknownVteps vtep : vtepList) {
- if (vtep.getDpnId().equals(dpid)) {
+ if (Objects.equals(vtep.getDpnId(), dpid)) {
vtepFound = true;
oldVtep = vtep;
break;
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;
Vteps oldVtep = null;
for (Vteps vtep : vtepList) {
- if (vtep.getDpnId().equals(dpnId)) {
+ if (Objects.equals(vtep.getDpnId(), dpnId)) {
vtepFound = true;
oldVtep = vtep;
break;
UnknownVteps foundVtep = null;
for (UnknownVteps vtep : vtepList) {
- if (vtep.getDpnId().equals(dpnId)) {
+ if (Objects.equals(vtep.getDpnId(), dpnId)) {
vtepFound = true;
foundVtep = vtep;
break;
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;
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");
}
}
*/
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;
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;
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);
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())
*/
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;
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;
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.");
}
}
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);
}
&& !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.");
}
}
}
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();
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;
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;
}
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) {
}
}
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));
}
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;
result = tunnelList.get().getInternalTunnel();
}
if (result == null) {
- result = Collections.emptyList();
+ result = emptyList();
}
return result;
}
result = tunnelList.get().getExternalTunnel();
}
if (result == null) {
- result = Collections.emptyList();
+ result = emptyList();
}
return result;
}
} else if (tunType.equals(TunnelTypeLogicalGroup.class)) {
tunnelType = ITMConstants.TUNNEL_TYPE_LOGICAL_GROUP_VXLAN;
}
- return tunnelType ;
+ return tunnelType;
}
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());
}
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,
}
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);
+ }
}
*/
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;
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();
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;
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;
if (!operStatusNew.equals(operStatusOld)) {
opstateModified = true;
}
- if (!macAddressNew.equals(macAddressOld)) {
+ if (!Objects.equals(macAddressNew, macAddressOld)) {
hardwareAddressModified = true;
}
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);
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;
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;
// 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.
*/
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;
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()) {
}
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()) {
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());
*/
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;
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());
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()) {
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()) {
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;
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);
}
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;
// 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;
*/
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;
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())); });
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());
}
return result;
}
for (TransportZone tzone : transportZones.getTransportZone()) {
- if (!tzone.getTunnelType().equals(TunnelTypeVxlan.class)) {
+ if (!TunnelTypeVxlan.class.equals(tzone.getTunnelType())) {
continue;
}
foundVxlanTzone = true;
return result;
}
for (TransportZone tzone : transportZones.getTransportZone()) {
- if (!tzone.getTunnelType().equals(TunnelTypeVxlan.class)) {
+ if (!TunnelTypeVxlan.class.equals(tzone.getTunnelType())) {
continue;
}
String transportZone = tzone.getZoneName();
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;
} else {
String lockDataOwner = result.get().getLockOwner();
String currentOwner = lockData.getLockOwner();
- if (currentOwner.equals(lockDataOwner)) {
+ if (Objects.equals(currentOwner, lockDataOwner)) {
return true;
}
}
*/
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;
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);
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:
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;
/**
* This class is a place holder for various openflow flow/group related test utilities.
*
- * @autor Faseela K
+ * @author Faseela K
*/
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);
+ }
}