*/
package org.opendaylight.netvirt.dhcpservice.jobs;
-import com.google.common.util.concurrent.FutureCallback;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
import com.google.common.util.concurrent.ListenableFuture;
-import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
-import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import java.util.concurrent.ExecutionException;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.genius.infra.Datastore;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
+import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager;
import org.opendaylight.netvirt.dhcpservice.DhcpManager;
import org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710._interface.name.mac.addresses.InterfaceNameMacAddressKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class DhcpInterfaceRemoveJob implements Callable<List<ListenableFuture<Void>>> {
+public class DhcpInterfaceRemoveJob implements Callable<List<? extends ListenableFuture<?>>> {
private static final Logger LOG = LoggerFactory.getLogger(DhcpInterfaceRemoveJob.class);
- private static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
- @Override
- public void onSuccess(Void result) {
- LOG.debug("Success in Datastore write operation");
- }
-
- @Override
- public void onFailure(Throwable error) {
- LOG.error("Error in Datastore write operation", error);
- }
- };
-
private final DhcpManager dhcpManager;
private final DhcpExternalTunnelManager dhcpExternalTunnelManager;
private final DataBroker dataBroker;
private final ManagedNewTransactionRunner txRunner;
private final Interface interfaceDel;
- private final BigInteger dpnId;
+ private final Uint64 dpnId;
private final IInterfaceManager interfaceManager;
private final IElanService elanService;
private final Port port;
public DhcpInterfaceRemoveJob(DhcpManager dhcpManager, DhcpExternalTunnelManager dhcpExternalTunnelManager,
DataBroker dataBroker,
- Interface interfaceDel, BigInteger dpnId, IInterfaceManager interfaceManager,
+ Interface interfaceDel, Uint64 dpnId, IInterfaceManager interfaceManager,
IElanService elanService, Port port) {
this.dhcpManager = dhcpManager;
this.dhcpExternalTunnelManager = dhcpExternalTunnelManager;
}
@Override
- public List<ListenableFuture<Void>> call() {
+ public List<ListenableFuture<Void>> call() throws ExecutionException, InterruptedException {
String interfaceName = interfaceDel.getName();
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
if (iface != null) {
- IfTunnel tunnelInterface = iface.getAugmentation(IfTunnel.class);
+ IfTunnel tunnelInterface = iface.augmentation(IfTunnel.class);
if (tunnelInterface != null && !tunnelInterface.isInternal()) {
IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
- List<BigInteger> dpns = DhcpServiceUtils.getListOfDpns(dataBroker);
+ List<Uint64> dpns = DhcpServiceUtils.getListOfDpns(dataBroker);
if (dpns.contains(dpnId)) {
return dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp, dpnId);
}
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
// Support for VM migration use cases.
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> DhcpServiceUtils.unbindDhcpService(interfaceName, tx)));
java.util.Optional<String> subnetId = DhcpServiceUtils.getNeutronSubnetId(port);
if (subnetId.isPresent()) {
subnetId.get());
if (subnetToDhcp.isPresent()) {
LOG.trace("Removing ArpResponder flow for last interface {} on DPN {}", interfaceName, dpnId);
- ArpResponderInput arpInput = new ArpResponderInput.ArpReponderInputBuilder().setDpId(dpnId)
+ ArpResponderInput arpInput = new ArpResponderInput.ArpReponderInputBuilder().setDpId(dpnId.toJava())
.setInterfaceName(interfaceName).setSpa(subnetToDhcp.get().getPortFixedip())
.setLportTag(interfaceDel.getIfIndex()).buildForRemoveFlow();
elanService.removeArpResponderFlow(arpInput);
return futures;
}
- private List<ListenableFuture<Void>> unInstallDhcpEntries(String interfaceName, BigInteger dpId) {
- return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(
- tx -> dhcpManager.unInstallDhcpEntries(dpId, getAndRemoveVmMacAddress(tx, interfaceName), tx)));
+ private List<ListenableFuture<Void>> unInstallDhcpEntries(String interfaceName, Uint64 dpId)
+ throws ExecutionException, InterruptedException {
+ String vmMacAddress = txRunner.applyWithNewReadWriteTransactionAndSubmit(OPERATIONAL,
+ tx -> getAndRemoveVmMacAddress(tx, interfaceName)).get();
+ return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ tx -> dhcpManager.unInstallDhcpEntries(dpId, vmMacAddress, tx)));
}
@Nullable
- private String getAndRemoveVmMacAddress(ReadWriteTransaction tx, String interfaceName) throws ReadFailedException {
+ private String getAndRemoveVmMacAddress(TypedReadWriteTransaction<Datastore.Operational> tx, String interfaceName)
+ throws ExecutionException, InterruptedException {
InstanceIdentifier<InterfaceNameMacAddress> instanceIdentifier =
InstanceIdentifier.builder(InterfaceNameMacAddresses.class)
.child(InterfaceNameMacAddress.class, new InterfaceNameMacAddressKey(interfaceName)).build();
- return tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).checkedGet().toJavaUtil().map(
+ return tx.read(instanceIdentifier).get().map(
interfaceNameMacAddress -> {
String vmMacAddress = interfaceNameMacAddress.getMacAddress();
LOG.trace("Entry for interface found in InterfaceNameVmMacAddress map {}, {}", interfaceName,
vmMacAddress);
- tx.delete(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
+ tx.delete(instanceIdentifier);
return vmMacAddress;
}).orElseGet(() -> {
LOG.trace("Entry for interface {} missing in InterfaceNameVmMacAddress map", interfaceName);