Port dhcpservice to datastore-constrained txes 40/73440/3
authorStephen Kitt <skitt@redhat.com>
Tue, 26 Jun 2018 09:50:56 +0000 (11:50 +0200)
committerStephen Kitt <skitt@redhat.com>
Tue, 26 Jun 2018 13:09:49 +0000 (15:09 +0200)
This uses TransactionAdapter for calls to Genius, which will need to
be fixed once Genius migrates.

JIRA: NETVIRT-1338
Change-Id: Ifa20efa982f21a3e354d2a7cb528060b03e4f39f
Signed-off-by: Stephen Kitt <skitt@redhat.com>
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpExternalTunnelManager.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpInterfaceConfigListener.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpManager.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpNeutronPortListener.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpServiceUtils.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpSubnetListener.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/jobs/DhcpAllocationPoolAddJob.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/jobs/DhcpAllocationPoolRemoveJob.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/jobs/DhcpInterfaceAddJob.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/jobs/DhcpInterfaceRemoveJob.java

index 359b29efd158bc6cf707bf44ef0e6760d8a3ea5f..039c0db38f729fbb8632e3579d44ee7ab2cc753e 100644 (file)
@@ -7,6 +7,8 @@
  */
 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;
@@ -32,11 +34,13 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
 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;
@@ -225,13 +229,14 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
         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");
             }
@@ -242,7 +247,8 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
         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);
         }
@@ -328,7 +334,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
         }
         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);
             }
@@ -407,7 +413,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
         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) {
@@ -422,7 +428,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
     }
 
     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;
@@ -440,7 +446,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
     }
 
     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;
@@ -510,7 +516,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
         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);
     }
@@ -631,12 +637,12 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
     }
 
 
-    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);
     }
@@ -662,7 +668,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
                     }
                 }
             }
-            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();
@@ -828,17 +834,16 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
         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,
@@ -870,7 +875,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
                     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())));
             }
@@ -915,7 +920,7 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
                 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();
@@ -961,11 +966,12 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
         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");
             }
index 0c18dbc3089be76838702038381786124aec2dfd..e6ac823e212bfaa0ee2b3f19d5ad9cc48e77ab7b 100644 (file)
@@ -8,6 +8,8 @@
 
 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;
@@ -75,7 +77,7 @@ public class DhcpInterfaceConfigListener
                 }
             }
             if (vlanInterface != null) {
-                return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                     tx -> DhcpServiceUtils.unbindDhcpService(interfaceName, tx)));
             }
             return Collections.emptyList();
@@ -98,10 +100,11 @@ public class DhcpInterfaceConfigListener
             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);
index 687db4e75cfea72ac0d19b6f39fe8aca8d97eeda..0aa139371ebee88345182dcd0d226b6da642230d 100644 (file)
@@ -18,8 +18,9 @@ import javax.inject.Inject;
 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;
@@ -184,12 +185,14 @@ public class DhcpManager {
         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);
     }
index 394becb549d7fab2571f33b822841f4db4176b06..80f77a3edc1367486246fd52e5a292d8a7f4c27c 100644 (file)
@@ -7,6 +7,9 @@
  */
 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;
@@ -102,14 +105,13 @@ public class DhcpNeutronPortListener
         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(),
@@ -143,7 +145,7 @@ public class DhcpNeutronPortListener
             }
             // 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);
@@ -153,9 +155,10 @@ public class DhcpNeutronPortListener
                     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)) {
@@ -190,9 +193,8 @@ public class DhcpNeutronPortListener
         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 {}",
index 0dd255d95309b0324f3ff641e1b9b05cd27ebdac..2d6b677db32e12697810720842a467c7969440c6 100644 (file)
@@ -8,6 +8,8 @@
 
 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;
@@ -18,6 +20,7 @@ import java.util.Collections;
 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;
@@ -27,11 +30,14 @@ import javax.annotation.Nonnull;
 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;
@@ -116,7 +122,7 @@ public final class DhcpServiceUtils {
     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;
         }
@@ -134,14 +140,14 @@ public final class DhcpServiceUtils {
                     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));
         }
     }
 
@@ -162,7 +168,7 @@ public final class DhcpServiceUtils {
 
     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;
         }
@@ -180,14 +186,14 @@ public final class DhcpServiceUtils {
                     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));
         }
     }
 
@@ -334,7 +340,7 @@ public final class DhcpServiceUtils {
         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));
@@ -344,14 +350,12 @@ public final class DhcpServiceUtils {
                 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,
@@ -484,13 +488,12 @@ public final class DhcpServiceUtils {
     }
 
     @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);
@@ -502,8 +505,7 @@ public final class DhcpServiceUtils {
                     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();
index 00b3d0ab26cf0577d6dc9b67e25613fb25c0b22c..d66194438dc3193c08200bca6eb1289f0d247d3a 100644 (file)
@@ -8,6 +8,8 @@
 
 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;
@@ -131,11 +133,11 @@ public class DhcpSubnetListener extends AsyncClusteredDataTreeChangeListenerBase
             //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");
         }
@@ -153,12 +155,12 @@ public class DhcpSubnetListener extends AsyncClusteredDataTreeChangeListenerBase
             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");
         }
index 8bd43ee57d3f7e5f4022359cc2926d1bbc9481f0..06ca214c3b1116fb1aa8d381f2fa7b588083c3c2 100644 (file)
@@ -7,6 +7,8 @@
  */
 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;
@@ -31,7 +33,7 @@ public class DhcpAllocationPoolAddJob implements Callable<List<ListenableFuture<
     }
 
     private List<ListenableFuture<Void>> installDhcpEntries() {
-        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
             tx -> DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx)));
     }
 
index 0ec9e150bd0bb36e9dba5d303c434f8e730f4db5..3aff1a0c108691b530086d4acabaea581fd85972 100644 (file)
@@ -7,6 +7,8 @@
  */
 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;
@@ -30,7 +32,7 @@ public class DhcpAllocationPoolRemoveJob implements Callable<List<ListenableFutu
     }
 
     private List<ListenableFuture<Void>> unInstallDhcpEntries() {
-        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
             tx -> DhcpServiceUtils.unbindDhcpService(interfaceName, tx)));
     }
 }
index 9e983f37f756dc92013a88380b1fb6596dba04cd..9e92823f96eae5898c8793ba8903587e6ee9fe05 100644 (file)
@@ -7,12 +7,16 @@
  */
 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;
@@ -65,7 +69,7 @@ public class DhcpInterfaceAddJob implements Callable<List<ListenableFuture<Void>
     }
 
     @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 =
@@ -90,7 +94,7 @@ public class DhcpInterfaceAddJob implements Callable<List<ListenableFuture<Void>
             }
             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));
@@ -114,9 +118,11 @@ public class DhcpInterfaceAddJob implements Callable<List<ListenableFuture<Void>
         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)));
     }
 }
index e1048eaf3a152e8fec62562263e66183ae2c6da5..7d94e248f5a985f1f02152e5341f37c8faace4ee 100644 (file)
@@ -7,20 +7,22 @@
  */
 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;
@@ -43,18 +45,6 @@ public class DhcpInterfaceRemoveJob implements Callable<List<ListenableFuture<Vo
 
     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;
@@ -81,7 +71,7 @@ public class DhcpInterfaceRemoveJob implements Callable<List<ListenableFuture<Vo
     }
 
     @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);
@@ -98,7 +88,7 @@ public class DhcpInterfaceRemoveJob implements Callable<List<ListenableFuture<Vo
         }
         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()) {
@@ -116,22 +106,26 @@ public class DhcpInterfaceRemoveJob implements Callable<List<ListenableFuture<Vo
         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);