package org.opendaylight.netvirt.dhcpservice.api;
-import static java.util.Collections.emptyList;
-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
-import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class DHCPUtils {
str.deleteCharAt(str.lastIndexOf(":"));
return str.toString();
}
-
- // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3
- @Nonnull
- public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
- return input != null ? input : emptyList();
- }
}
protected void add(InstanceIdentifier<AllocationPool> key, AllocationPool dataObjectModification) {
String networkId = key.firstKeyOf(Network.class).getNetworkId();
dhcpAllocationPoolManager.createIdAllocationPool(networkId, dataObjectModification);
- Map<BigInteger, List<String>> elanDpnInterfacesByName = getDpnInterfacesByNetwork(networkId);
+ Map<BigInteger, List<String>> elanDpnInterfacesByName =
+ dhcpAllocationPoolManager.getElanDpnInterfacesByName(dataBroker, networkId);
for (Entry<BigInteger, List<String>> entry : elanDpnInterfacesByName.entrySet()) {
BigInteger dpnId = entry.getKey();
for (String interfaceName : entry.getValue()) {
protected void remove(InstanceIdentifier<AllocationPool> key, AllocationPool dataObjectModification) {
String networkId = key.firstKeyOf(Network.class).getNetworkId();
dhcpAllocationPoolManager.releaseIdAllocationPool(networkId, dataObjectModification);
- Map<BigInteger, List<String>> elanDpnInterfacesByName = getDpnInterfacesByNetwork(networkId);
+ Map<BigInteger, List<String>> elanDpnInterfacesByName =
+ dhcpAllocationPoolManager.getElanDpnInterfacesByName(dataBroker, networkId);
elanDpnInterfacesByName.values().forEach(interfaceNames -> interfaceNames.forEach(interfaceName -> {
DhcpAllocationPoolRemoveJob job = new DhcpAllocationPoolRemoveJob(txRunner, interfaceName);
jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), job,
// TODO Auto-generated method stub
}
-
- private Map<BigInteger, List<String>> getDpnInterfacesByNetwork(String networkId) {
- Map<BigInteger, List<String>> elanDpnInterfacesByName = dhcpAllocationPoolManager
- .getElanDpnInterfacesByName(dataBroker, networkId);
- return elanDpnInterfacesByName;
- }
}
*/
package org.opendaylight.netvirt.dhcpservice;
-import static org.opendaylight.netvirt.dhcpservice.api.DHCPUtils.nullToEmpty;
-
import com.google.common.base.Optional;
import java.math.BigInteger;
+import java.util.Collections;
import java.util.EventListener;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
}
}
- @Nullable
+ @Nonnull
public Map<BigInteger, List<String>> getElanDpnInterfacesByName(DataBroker broker, String elanInstanceName) {
InstanceIdentifier<ElanDpnInterfacesList> elanDpnIfacesIid = InstanceIdentifier.builder(ElanDpnInterfaces.class)
.child(ElanDpnInterfacesList.class, new ElanDpnInterfacesListKey(elanInstanceName)).build();
elanDpnIfacesIid);
if (!elanDpnIfacesOpc.isPresent()) {
LOG.warn("Could not find DpnInterfaces for elan {}", elanInstanceName);
- return null;
+ return Collections.emptyMap();
}
- return nullToEmpty(elanDpnIfacesOpc.get().getDpnInterfaces()).stream()
- .collect(Collectors.toMap(DpnInterfaces::getDpId, value -> nullToEmpty(value.getInterfaces())));
+ return elanDpnIfacesOpc.get().nonnullDpnInterfaces().stream()
+ .collect(Collectors.toMap(DpnInterfaces::getDpId,
+ value -> value.getInterfaces() != null ? value.getInterfaces() : Collections.emptyList()));
}
@Nullable
package org.opendaylight.netvirt.dhcpservice;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
-import static org.opendaylight.netvirt.dhcpservice.api.DHCPUtils.nullToEmpty;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
Optional<DesignatedSwitchesForExternalTunnels> designatedSwitchForTunnelOptional =
MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, instanceIdentifier);
if (designatedSwitchForTunnelOptional.isPresent()) {
- List<DesignatedSwitchForTunnel> list = nullToEmpty(
- designatedSwitchForTunnelOptional.get().getDesignatedSwitchForTunnel());
+ List<DesignatedSwitchForTunnel> list =
+ designatedSwitchForTunnelOptional.get().nonnullDesignatedSwitchForTunnel();
for (DesignatedSwitchForTunnel designatedSwitchForTunnel : list) {
Set<Pair<IpAddress, String>> setOfTunnelIpElanNamePair =
designatedDpnsToTunnelIpElanNameCache
InstanceIdentifier<Ports> inst = InstanceIdentifier.builder(Neutron.class).child(Ports.class).build();
Optional<Ports> optionalPorts = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst);
if (optionalPorts.isPresent()) {
- List<Port> list = nullToEmpty(optionalPorts.get().getPort());
+ List<Port> list = optionalPorts.get().nonnullPort();
for (Port port : list) {
if (NeutronUtils.isPortVnicTypeNormal(port)) {
continue;
MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, instanceIdentifier);
if (designatedSwitchForTunnelOptional.isPresent()) {
List<DesignatedSwitchForTunnel> list =
- nullToEmpty(designatedSwitchForTunnelOptional.get().getDesignatedSwitchForTunnel());
+ designatedSwitchForTunnelOptional.get().nonnullDesignatedSwitchForTunnel();
for (DesignatedSwitchForTunnel designatedSwitchForTunnel : list) {
if (dpId.equals(BigInteger.valueOf(designatedSwitchForTunnel.getDpId()))) {
return true;
public java.util.Optional<SubnetToDhcpPort> getSubnetDhcpPortData(String elanInstanceName) {
java.util.Optional<SubnetToDhcpPort> optSubnetDhcp = java.util.Optional.empty();
Uuid nwUuid = new Uuid(elanInstanceName);
- List<Uuid> subnets = nullToEmpty(DhcpServiceUtils.getSubnetIdsFromNetworkId(broker, nwUuid));
+ List<Uuid> subnets = DhcpServiceUtils.getSubnetIdsFromNetworkId(broker, nwUuid);
for (Uuid subnet : subnets) {
if (DhcpServiceUtils.isIpv4Subnet(broker, subnet)) {
optSubnetDhcp = DhcpServiceUtils.getSubnetDhcpPortData(broker, subnet.getValue());
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
-import static org.opendaylight.netvirt.dhcpservice.api.DHCPUtils.nullToEmpty;
import java.math.BigInteger;
import java.util.ArrayList;
protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) {
LOG.trace("Port changed to {}", update);
//With Ipv6 changes we can get ipv4 subnets later. The below check is to support such scenario.
- if (nullToEmpty(original.getFixedIps()).size() < nullToEmpty(update.getFixedIps()).size()) {
+ if (original.nonnullFixedIps().size() < update.nonnullFixedIps().size()) {
final String interfaceName = update.getUuid().getValue();
- List<FixedIps> updatedFixedIps = new ArrayList<>(nullToEmpty(update.getFixedIps()));
+ List<FixedIps> updatedFixedIps = new ArrayList<>(update.nonnullFixedIps());
// Need to check only the newly added fixed ip.
- updatedFixedIps.removeAll(nullToEmpty(original.getFixedIps()));
+ updatedFixedIps.removeAll(original.nonnullFixedIps());
Subnet subnet = dhcpManager.getNeutronSubnet(updatedFixedIps);
if (null == subnet || !subnet.isEnableDhcp()) {
LOG.trace("Subnet is null/not ipv4 or not enabled {}", subnet);
*/
package org.opendaylight.netvirt.dhcpservice;
-import static org.opendaylight.netvirt.dhcpservice.api.DHCPUtils.nullToEmpty;
-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@Nullable
private static String getIpv4Address(Port port) {
- for (FixedIps fixedIp : nullToEmpty(port.getFixedIps())) {
+ for (FixedIps fixedIp : port.nonnullFixedIps()) {
if (isIpv4Address(fixedIp.getIpAddress())) {
return fixedIp.getIpAddress().getIpv4Address().getValue();
}
package org.opendaylight.netvirt.dhcpservice;
import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
-import static org.opendaylight.netvirt.dhcpservice.api.DHCPUtils.nullToEmpty;
import com.google.common.base.Optional;
import java.math.BigInteger;
@Nonnull
private static List<BigInteger> extractDpnsFromNodes(Optional<Nodes> optionalNodes) {
return optionalNodes.toJavaUtil().map(
- nodes -> nullToEmpty(nodes.getNode()).stream().map(Node::getId).filter(Objects::nonNull).map(
+ nodes -> nodes.nonnullNode().stream().map(Node::getId).filter(Objects::nonNull).map(
MDSALUtil::getDpnIdFromNodeName).collect(
Collectors.toList())).orElse(Collections.emptyList());
}
Optional<ElanDpnInterfacesList> elanDpnOptional =
MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInstanceIdentifier);
if (elanDpnOptional.isPresent()) {
- List<DpnInterfaces> dpns = nullToEmpty(elanDpnOptional.get().getDpnInterfaces());
+ List<DpnInterfaces> dpns = elanDpnOptional.get().nonnullDpnInterfaces();
for (DpnInterfaces dpnInterfaces : dpns) {
elanDpns.add(dpnInterfaces.getDpId());
}
return null;
}
- @Nullable
+ @Nonnull
public static List<Uuid> getSubnetIdsFromNetworkId(DataBroker broker, Uuid networkId) {
InstanceIdentifier id = buildNetworkMapIdentifier(networkId);
Optional<NetworkMap> optionalNetworkMap = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id);
if (optionalNetworkMap.isPresent()) {
- return optionalNetworkMap.get().getSubnetIdList();
+ @Nullable List<Uuid> subnetIdList = optionalNetworkMap.get().getSubnetIdList();
+ if (subnetIdList != null) {
+ return subnetIdList;
+ }
}
- return null;
+ return Collections.emptyList();
}
static InstanceIdentifier<NetworkMap> buildNetworkMapIdentifier(Uuid networkId) {