*/
package org.opendaylight.netvirt.dhcpservice;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
import org.apache.commons.lang3.tuple.Pair;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TransactionAdapter;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.NwConstants;
jobCoordinator.enqueueJob(getJobKey(tunnelIpDpnKey), () -> {
if (entityOwnershipUtils.isEntityOwner(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
HwvtepSouthboundConstants.ELAN_ENTITY_NAME)) {
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- dpns.remove(designatedDpnId);
- for (BigInteger dpn : dpns) {
- installDhcpDropAction(dpn, vmMacAddress, tx);
- }
- installDhcpEntries(designatedDpnId, vmMacAddress, tx);
- }));
+ return Collections.singletonList(
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ dpns.remove(designatedDpnId);
+ for (BigInteger dpn : dpns) {
+ installDhcpDropAction(dpn, vmMacAddress, tx);
+ }
+ installDhcpEntries(designatedDpnId, vmMacAddress, tx);
+ }));
} else {
LOG.trace("Exiting installDhcpEntries since this cluster node is not the owner for dpn");
}
updateLocalCache(tunnelIp, elanInstanceName, vmMacAddress);
}
- public void installDhcpFlowsForVms(BigInteger designatedDpnId, Set<String> listVmMacAddress, WriteTransaction tx) {
+ public void installDhcpFlowsForVms(BigInteger designatedDpnId, Set<String> listVmMacAddress,
+ TypedWriteTransaction<Configuration> tx) {
for (String vmMacAddress : listVmMacAddress) {
installDhcpEntries(designatedDpnId, vmMacAddress, tx);
}
}
List<String> vmMacs = getAllVmMacs();
LOG.trace("Installing drop actions to this new DPN {} VMs {}", dpId, vmMacs);
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (String vmMacAddress : vmMacs) {
installDhcpDropAction(dpId, vmMacAddress, tx);
}
if (setOfTunnelIpElanNamePairs == null || setOfTunnelIpElanNamePairs.isEmpty()) {
LOG.trace("No tunnelIpElanName to handle for dpn {}. Returning", dpnId);
} else {
- ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
if (!dpnId.equals(DhcpMConstants.INVALID_DPID)) {
List<String> listOfVms = getAllVmMacs();
for (String vmMacAddress : listOfVms) {
}
public void updateCacheAndInstallNewFlows(List<BigInteger> listOfDpns, Pair<IpAddress, String> pair,
- WriteTransaction tx) {
+ TypedWriteTransaction<Configuration> tx) {
BigInteger newDesignatedDpn = chooseDpn(pair.getLeft(), pair.getRight(), listOfDpns);
if (newDesignatedDpn.equals(DhcpMConstants.INVALID_DPID)) {
return;
}
private void changeExistingFlowToDrop(Pair<IpAddress, String> tunnelIpElanNamePair, BigInteger dpnId,
- WriteTransaction tx) {
+ TypedWriteTransaction<Configuration> tx) {
Set<String> setOfVmMacAddress = tunnelIpElanNameToVmMacCache.get(tunnelIpElanNamePair);
if (setOfVmMacAddress == null || setOfVmMacAddress.isEmpty()) {
return;
writeDesignatedSwitchForExternalTunnel(DhcpMConstants.INVALID_DPID, tunnelIp, elanInstanceName);
}
- private void installDhcpEntries(BigInteger dpnId, String vmMacAddress, WriteTransaction tx) {
+ private void installDhcpEntries(BigInteger dpnId, String vmMacAddress, TypedWriteTransaction<Configuration> tx) {
DhcpServiceUtils.setupDhcpFlowEntry(dpnId, NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL,
vmMacAddress, NwConstants.ADD_FLOW, mdsalUtil, dhcpServiceCounters, tx);
}
}
- public void unInstallDhcpEntries(BigInteger dpnId, String vmMacAddress, WriteTransaction tx) {
+ public void unInstallDhcpEntries(BigInteger dpnId, String vmMacAddress, TypedWriteTransaction<Configuration> tx) {
DhcpServiceUtils.setupDhcpFlowEntry(dpnId, NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL,
vmMacAddress, NwConstants.DEL_FLOW, mdsalUtil, dhcpServiceCounters, tx);
}
- private void installDhcpDropAction(BigInteger dpn, String vmMacAddress, WriteTransaction tx) {
+ private void installDhcpDropAction(BigInteger dpn, String vmMacAddress, TypedWriteTransaction<Configuration> tx) {
DhcpServiceUtils.setupDhcpDropAction(dpn, NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL,
vmMacAddress, NwConstants.ADD_FLOW, mdsalUtil, dhcpServiceCounters, tx);
}
}
}
}
- return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
for (Pair<IpAddress, String> tunnelElanPair : tunnelElanPairSet) {
IpAddress tunnelIpInDpn = tunnelElanPair.getLeft();
String elanInstanceName = tunnelElanPair.getRight();
return null;
}
- private WriteTransaction putRemoteMcastMac(WriteTransaction transaction, String elanName,
- L2GatewayDevice device, IpAddress internalTunnelIp) {
+ private void putRemoteMcastMac(TypedWriteTransaction<Configuration> transaction, String elanName,
+ L2GatewayDevice device, IpAddress internalTunnelIp) {
Optional<Node> optionalNode = getNode(broker, device.getHwvtepNodeId());
Node dstNode = optionalNode.get();
if (dstNode == null) {
LOG.trace("could not get device node {} ", device.getHwvtepNodeId());
- return null;
+ return;
}
RemoteMcastMacs macs = createRemoteMcastMac(dstNode, elanName, internalTunnelIp);
- HwvtepUtils.putRemoteMcastMac(transaction, dstNode.getNodeId(), macs);
- return transaction;
+ HwvtepUtils.putRemoteMcastMac(TransactionAdapter.toWriteTransaction(transaction), dstNode.getNodeId(), macs);
}
public void installRemoteMcastMac(final BigInteger designatedDpnId, final IpAddress tunnelIp,
LOG.trace("Tunnel Interface is not present {}", tunnelInterfaceName);
return Collections.emptyList();
}
- return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> putRemoteMcastMac(tx, elanInstanceName, device,
tunnelInterface.augmentation(IfTunnel.class).getTunnelSource())));
}
LOG.trace("There are no undesignated DPNs");
return Collections.emptyList();
}
- return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+ return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
for (Pair<IpAddress, String> pair : tunnelIpElanPair) {
if (tunnelIp.equals(pair.getLeft())) {
String elanInstanceName = pair.getRight();
jobCoordinator.enqueueJob(getJobKey(vmMacAddress), () -> {
if (entityOwnershipUtils.isEntityOwner(HwvtepSouthboundConstants.ELAN_ENTITY_TYPE,
HwvtepSouthboundConstants.ELAN_ENTITY_NAME)) {
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- for (final BigInteger dpn : dpns) {
- unInstallDhcpEntries(dpn, vmMacAddress, tx);
- }
- }));
+ return Collections.singletonList(
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ for (final BigInteger dpn : dpns) {
+ unInstallDhcpEntries(dpn, vmMacAddress, tx);
+ }
+ }));
} else {
LOG.trace("Exiting unInstallDhcpEntries since this cluster node is not the owner for dpn");
}
package org.opendaylight.netvirt.dhcpservice;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import java.util.Collections;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
}
}
if (vlanInterface != null) {
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> DhcpServiceUtils.unbindDhcpService(interfaceName, tx)));
}
return Collections.emptyList();
Port port = dhcpManager.getNeutronPort(interfaceName);
Subnet subnet = dhcpManager.getNeutronSubnet(port);
if (null != subnet && subnet.isEnableDhcp()) {
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- LOG.debug("Binding DHCP service for interface {}", interfaceName);
- DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx);
- }));
+ return Collections.singletonList(
+ txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ LOG.debug("Binding DHCP service for interface {}", interfaceName);
+ DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx);
+ }));
}
return Collections.emptyList();
}, DhcpMConstants.RETRY_COUNT);
import javax.inject.Named;
import javax.inject.Singleton;
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;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.FlowEntity;
return prt;
}
- public void installDhcpEntries(@Nullable BigInteger dpnId, @Nullable String vmMacAddress, WriteTransaction tx) {
+ public void installDhcpEntries(@Nullable BigInteger dpnId, @Nullable String vmMacAddress,
+ TypedWriteTransaction<Configuration> tx) {
DhcpServiceUtils.setupDhcpFlowEntry(dpnId, NwConstants.DHCP_TABLE, vmMacAddress, NwConstants.ADD_FLOW,
mdsalUtil, dhcpServiceCounters, tx);
}
- public void unInstallDhcpEntries(@Nullable BigInteger dpId, @Nullable String vmMacAddress, WriteTransaction tx) {
+ public void unInstallDhcpEntries(@Nullable BigInteger dpId, @Nullable String vmMacAddress,
+ TypedWriteTransaction<Configuration> tx) {
DhcpServiceUtils.setupDhcpFlowEntry(dpId, NwConstants.DHCP_TABLE, vmMacAddress, NwConstants.DEL_FLOW,
mdsalUtil, dhcpServiceCounters, tx);
}
*/
package org.opendaylight.netvirt.dhcpservice;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
import java.math.BigInteger;
import java.util.Collections;
import java.util.List;
LOG.trace("Port removed: {}", del);
if (NeutronConstants.IS_ODL_DHCP_PORT.test(del)) {
jobCoordinator.enqueueJob(getJobKey(del),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
java.util.Optional<String> ip4Address = DhcpServiceUtils.getIpV4Address(del);
if (ip4Address.isPresent()) {
dhcpExternalTunnelManager.addOrRemoveDhcpArpFlowforElan(del.getNetworkId().getValue(),
false, ip4Address.get(), del.getMacAddress().getValue());
}
- DhcpServiceUtils.removeSubnetDhcpPortData(del, subnetDhcpPortIdfr -> tx
- .delete(LogicalDatastoreType.CONFIGURATION, subnetDhcpPortIdfr));
+ DhcpServiceUtils.removeSubnetDhcpPortData(del, tx::delete);
processArpResponderForElanDpns(del, arpInput -> {
LOG.trace("Removing ARPResponder Flows for dhcp port {} with ipaddress {} with mac {} "
+ " on dpn {}. ",arpInput.getInterfaceName(), arpInput.getSpa(),
}
// Binding the DHCP service for an existing port because of subnet change.
jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
LOG.debug("Binding DHCP service for interface {}", interfaceName);
DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx);
})), DhcpMConstants.RETRY_COUNT);
LOG.trace("Unable to install the DHCP flow since dpn is not available");
return Collections.emptyList();
}
- return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(
- tx -> dhcpManager.installDhcpEntries(dpnId,
- DhcpServiceUtils.getAndUpdateVmMacAddress(tx, interfaceName, dhcpManager), tx)));
+ String vmMacAddress = txRunner.applyWithNewReadWriteTransactionAndSubmit(OPERATIONAL,
+ tx -> DhcpServiceUtils.getAndUpdateVmMacAddress(tx, interfaceName, dhcpManager)).get();
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> dhcpManager.installDhcpEntries(dpnId, vmMacAddress, tx)));
}, DhcpMConstants.RETRY_COUNT);
}
if (!isVnicTypeDirectOrMacVtap(update)) {
LOG.trace("Port added {}", add);
if (NeutronConstants.IS_ODL_DHCP_PORT.test(add)) {
jobCoordinator.enqueueJob(getJobKey(add),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- DhcpServiceUtils.createSubnetDhcpPortData(add, (subnetDhcpPortIdfr, subnetToDhcpport) -> tx
- .put(LogicalDatastoreType.CONFIGURATION, subnetDhcpPortIdfr, subnetToDhcpport));
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ DhcpServiceUtils.createSubnetDhcpPortData(add, tx::put);
processArpResponderForElanDpns(add, arpInput -> {
LOG.trace(
"Installing ARP RESPONDER Flows for dhcp port {} ipaddress {} with mac {} on dpn {}",
package org.opendaylight.netvirt.dhcpservice;
+import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.net.InetAddress;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
+import java.util.concurrent.ExecutionException;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.Datastore.Operational;
+import org.opendaylight.genius.infra.TransactionAdapter;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.ActionInfo;
public static void setupDhcpFlowEntry(@Nullable BigInteger dpId, short tableId, @Nullable String vmMacAddress,
int addOrRemove,
IMdsalApiManager mdsalUtil, DhcpServiceCounters dhcpServiceCounters,
- WriteTransaction tx) {
+ TypedWriteTransaction<Configuration> tx) {
if (dpId == null || dpId.equals(DhcpMConstants.INVALID_DPID) || vmMacAddress == null) {
return;
}
DhcpMConstants.COOKIE_DHCP_BASE, matches, null);
LOG.trace("Removing DHCP Flow DpId {}, vmMacAddress {}", dpId, vmMacAddress);
dhcpServiceCounters.removeDhcpFlow();
- mdsalUtil.removeFlowToTx(flowEntity, tx);
+ mdsalUtil.removeFlowToTx(flowEntity, TransactionAdapter.toWriteTransaction(tx));
} else {
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId,
getDhcpFlowRef(dpId, tableId, vmMacAddress), DhcpMConstants.DEFAULT_DHCP_FLOW_PRIORITY,
"DHCP", 0, 0, DhcpMConstants.COOKIE_DHCP_BASE, matches, instructions);
LOG.trace("Installing DHCP Flow DpId {}, vmMacAddress {}", dpId, vmMacAddress);
dhcpServiceCounters.installDhcpFlow();
- mdsalUtil.addFlowToTx(flowEntity, tx);
+ mdsalUtil.addFlowToTx(flowEntity, TransactionAdapter.toWriteTransaction(tx));
}
}
public static void setupDhcpDropAction(BigInteger dpId, short tableId, String vmMacAddress, int addOrRemove,
IMdsalApiManager mdsalUtil, DhcpServiceCounters dhcpServiceCounters,
- WriteTransaction tx) {
+ TypedWriteTransaction<Configuration> tx) {
if (dpId == null || dpId.equals(DhcpMConstants.INVALID_DPID) || vmMacAddress == null) {
return;
}
DhcpMConstants.COOKIE_DHCP_BASE, matches, null);
LOG.trace("Removing DHCP Drop Flow DpId {}, vmMacAddress {}", dpId, vmMacAddress);
dhcpServiceCounters.removeDhcpDropFlow();
- mdsalUtil.removeFlowToTx(flowEntity, tx);
+ mdsalUtil.removeFlowToTx(flowEntity, TransactionAdapter.toWriteTransaction(tx));
} else {
FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId,
getDhcpFlowRef(dpId, tableId, vmMacAddress), DhcpMConstants.DEFAULT_DHCP_FLOW_PRIORITY,
"DHCP", 0, 0, DhcpMConstants.COOKIE_DHCP_BASE, matches, instructions);
LOG.trace("Installing DHCP Drop Flow DpId {}, vmMacAddress {}", dpId, vmMacAddress);
dhcpServiceCounters.installDhcpDropFlow();
- mdsalUtil.addFlowToTx(flowEntity, tx);
+ mdsalUtil.addFlowToTx(flowEntity, TransactionAdapter.toWriteTransaction(tx));
}
}
return new StringBuilder().append(DhcpMConstants.DHCP_JOB_KEY_PREFIX).append(interfaceName).toString();
}
- public static void bindDhcpService(String interfaceName, short tableId, WriteTransaction tx) {
+ public static void bindDhcpService(String interfaceName, short tableId, TypedWriteTransaction<Configuration> tx) {
int instructionKey = 0;
List<Instruction> instructions = new ArrayList<>();
instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(tableId, ++instructionKey));
getBoundServices(String.format("%s.%s", "dhcp", interfaceName),
serviceIndex, DhcpMConstants.DEFAULT_FLOW_PRIORITY,
DhcpMConstants.COOKIE_VM_INGRESS_TABLE, instructions);
- tx.put(LogicalDatastoreType.CONFIGURATION,
- buildServiceId(interfaceName, serviceIndex), serviceInfo, WriteTransaction.CREATE_MISSING_PARENTS);
+ tx.put(buildServiceId(interfaceName, serviceIndex), serviceInfo, CREATE_MISSING_PARENTS);
}
- public static void unbindDhcpService(String interfaceName, WriteTransaction tx) {
+ public static void unbindDhcpService(String interfaceName, TypedWriteTransaction<Configuration> tx) {
short serviceIndex = ServiceIndex.getIndex(NwConstants.DHCP_SERVICE_NAME, NwConstants.DHCP_SERVICE_INDEX);
- tx.delete(LogicalDatastoreType.CONFIGURATION,
- buildServiceId(interfaceName, serviceIndex));
+ tx.delete(buildServiceId(interfaceName, serviceIndex));
}
private static InstanceIdentifier<BoundServices> buildServiceId(String interfaceName,
}
@Nullable
- public static String getAndUpdateVmMacAddress(ReadWriteTransaction tx, String interfaceName,
- DhcpManager dhcpManager) throws ReadFailedException {
+ public static String getAndUpdateVmMacAddress(TypedReadWriteTransaction<Operational> tx, String interfaceName,
+ DhcpManager dhcpManager) throws ExecutionException, InterruptedException {
InstanceIdentifier<InterfaceNameMacAddress> instanceIdentifier =
InstanceIdentifier.builder(InterfaceNameMacAddresses.class)
.child(InterfaceNameMacAddress.class, new InterfaceNameMacAddressKey(interfaceName)).build();
- Optional<InterfaceNameMacAddress> existingEntry =
- tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).checkedGet();
+ Optional<InterfaceNameMacAddress> existingEntry = tx.read(instanceIdentifier).get();
if (!existingEntry.isPresent()) {
LOG.trace("Entry for interface {} missing in InterfaceNameVmMacAddress map", interfaceName);
String vmMacAddress = getNeutronMacAddress(interfaceName, dhcpManager);
new InterfaceNameMacAddressBuilder()
.withKey(new InterfaceNameMacAddressKey(interfaceName))
.setInterfaceName(interfaceName).setMacAddress(vmMacAddress).build();
- tx.merge(LogicalDatastoreType.OPERATIONAL, instanceIdentifier, interfaceNameMacAddress,
- WriteTransaction.CREATE_MISSING_PARENTS);
+ tx.merge(instanceIdentifier, interfaceNameMacAddress, CREATE_MISSING_PARENTS);
return vmMacAddress;
}
return existingEntry.get().getMacAddress();
package org.opendaylight.netvirt.dhcpservice;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.base.Optional;
import java.math.BigInteger;
import java.util.List;
//check whether any changes have happened
LOG.trace("DhcpSubnetListener installNeutronPortEntries dpId: {} vmMacAddress : {}", dpId, vmMacAddress);
//Bind the dhcp service when enabled
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx)), LOG,
"Error writing to the datastore");
//install the entries
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> dhcpManager.installDhcpEntries(dpId, vmMacAddress, tx)), LOG,
"Error writing to the datastore");
}
LOG.trace("DhcpSubnetListener uninstallNeutronPortEntries dpId: {} vmMacAddress : {}",
dpId, vmMacAddress);
//Unbind the dhcp service when disabled
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> DhcpServiceUtils.unbindDhcpService(interfaceName, tx)), LOG,
"Error writing to the datastore");
//uninstall the entries
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> dhcpManager.unInstallDhcpEntries(dpId, vmMacAddress, tx)), LOG,
"Error writing to the datastore");
}
*/
package org.opendaylight.netvirt.dhcpservice.jobs;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collections;
import java.util.List;
}
private List<ListenableFuture<Void>> installDhcpEntries() {
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx)));
}
*/
package org.opendaylight.netvirt.dhcpservice.jobs;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collections;
import java.util.List;
}
private List<ListenableFuture<Void>> unInstallDhcpEntries() {
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> DhcpServiceUtils.unbindDhcpService(interfaceName, tx)));
}
}
*/
package org.opendaylight.netvirt.dhcpservice.jobs;
+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 java.util.concurrent.ExecutionException;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
}
@Override
- public List<ListenableFuture<Void>> call() {
+ public List<ListenableFuture<Void>> call() throws ExecutionException, InterruptedException {
String interfaceName = interfaceAdd.getName();
LOG.trace("Received add DCN for interface {}, dpid {}", interfaceName, dpnId);
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
// Support for VM migration use cases.
- futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
tx -> DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx)));
LOG.info("DhcpInterfaceEventListener add isEnableDhcp:{}", subnet.isEnableDhcp());
futures.addAll(installDhcpEntries(interfaceAdd.getName(), dpnId));
return Collections.emptyList();
}
- private List<ListenableFuture<Void>> installDhcpEntries(String interfaceName, BigInteger dpId) {
- return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(
- tx -> dhcpManager.installDhcpEntries(dpId,
- DhcpServiceUtils.getAndUpdateVmMacAddress(tx, interfaceName, dhcpManager), tx)));
+ private List<ListenableFuture<Void>> installDhcpEntries(String interfaceName, BigInteger dpId)
+ throws ExecutionException, InterruptedException {
+ String vmMacAddress = txRunner.applyWithNewReadWriteTransactionAndSubmit(OPERATIONAL,
+ tx -> DhcpServiceUtils.getAndUpdateVmMacAddress(tx, interfaceName, dhcpManager)).get();
+ return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+ tx -> dhcpManager.installDhcpEntries(dpId, vmMacAddress, tx)));
}
}
*/
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 java.util.concurrent.ExecutionException;
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 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.netvirt.dhcpservice.DhcpExternalTunnelManager;
import org.opendaylight.netvirt.dhcpservice.DhcpManager;
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;
}
@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);
}
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()) {
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, BigInteger 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().toJavaUtil().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);