MdsalApiManager cleanup - dhcpservice 72/76172/3
authorStephen Kitt <skitt@redhat.com>
Mon, 17 Sep 2018 13:14:13 +0000 (15:14 +0200)
committerSam Hague <shague@redhat.com>
Wed, 19 Sep 2018 00:30:47 +0000 (00:30 +0000)
This removes all calls to deprecated methods in MdsalManager, so that
they can be removed in the near future.

Change-Id: I2e3f6d05a238973e9125624ac764b547a7d91f09
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/DhcpManager.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/DhcpServiceUtils.java
dhcpservice/impl/src/main/java/org/opendaylight/netvirt/dhcpservice/NodeListener.java

index 07d590a0a9d242cfc60d2fb75b1cde0fb9b453d3..05c5e774791a83afd1c462785d869d262ffee873 100644 (file)
@@ -36,6 +36,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 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.Datastore.Configuration;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
@@ -572,23 +573,26 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
                     String strVni = DhcpServiceUtils.getSegmentationId(nwUuid, broker);
                     BigInteger vni = strVni != null ? new BigInteger(strVni) : BigInteger.ZERO;
                     if (!vni.equals(BigInteger.ZERO)) {
-                        if (addFlow) {
-                            LOG.trace("Installing the SR-IOV DHCP Arp flow for DPN {} Port Ip {}, Lport {}.",
-                                    dpnId, dhcpIpAddress, lportTag);
-                            installDhcpArpRequestFlows(dpnId, vni, dhcpIpAddress, lportTag,
-                                    optElan.get().getElanTag());
-                            installDhcpArpResponderFlows(dpnId, tunnelInterfaceName, lportTag, elanInstanceName,
-                                    dhcpIpAddress, dhcpMacAddress);
-                        } else {
-                            LOG.trace("Uninstalling the SR-IOV DHCP Arp flows for DPN {} Port Ip {}, Lport {}.",
-                                    dpnId, dhcpIpAddress, lportTag);
-                            uninstallDhcpArpRequestFlows(dpnId, vni, dhcpIpAddress, lportTag);
-                            uninstallDhcpArpResponderFlows(dpnId, tunnelInterfaceName, lportTag, dhcpIpAddress);
-                        }
+                        return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(
+                            Datastore.CONFIGURATION, tx -> {
+                                if (addFlow) {
+                                    LOG.trace("Installing the SR-IOV DHCP Arp flow for DPN {} Port Ip {}, Lport {}.",
+                                        dpnId, dhcpIpAddress, lportTag);
+                                    installDhcpArpRequestFlows(tx, dpnId, vni, dhcpIpAddress, lportTag,
+                                        optElan.get().getElanTag());
+                                    installDhcpArpResponderFlows(dpnId, tunnelInterfaceName, lportTag, elanInstanceName,
+                                        dhcpIpAddress, dhcpMacAddress);
+                                } else {
+                                    LOG.trace("Uninstalling the SR-IOV DHCP Arp flows for DPN {} Port Ip {}, Lport {}.",
+                                        dpnId, dhcpIpAddress, lportTag);
+                                    uninstallDhcpArpRequestFlows(tx, dpnId, vni, dhcpIpAddress, lportTag);
+                                    uninstallDhcpArpResponderFlows(dpnId, tunnelInterfaceName, lportTag, dhcpIpAddress);
+                                }
+                            }));
                     }
                 }
             }
-            return null;
+            return Collections.emptyList();
         });
     }
 
@@ -605,10 +609,11 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
         return optSubnetDhcp;
     }
 
-    private void installDhcpArpRequestFlows(BigInteger dpnId, BigInteger vni, String dhcpIpAddress,
-                                            int lportTag, Long elanTag) {
+    private void installDhcpArpRequestFlows(TypedReadWriteTransaction<Configuration> tx, BigInteger dpnId,
+                                            BigInteger vni, String dhcpIpAddress, int lportTag, Long elanTag)
+            throws ExecutionException, InterruptedException {
         DhcpServiceUtils.setupDhcpArpRequest(dpnId, NwConstants.EXTERNAL_TUNNEL_TABLE, vni, dhcpIpAddress,
-                lportTag, elanTag, true, mdsalUtil);
+                lportTag, elanTag, true, mdsalUtil, tx);
     }
 
     private void installDhcpArpResponderFlows(BigInteger dpnId, String interfaceName, int lportTag,
@@ -632,10 +637,11 @@ public class DhcpExternalTunnelManager implements IDhcpExternalTunnelManager {
         elanService.removeArpResponderFlow(arpInput);
     }
 
-    private void uninstallDhcpArpRequestFlows(BigInteger dpnId, BigInteger vni, String dhcpIpAddress,
-                                              int lportTag) {
+    private void uninstallDhcpArpRequestFlows(TypedReadWriteTransaction<Configuration> tx, BigInteger dpnId,
+                                              BigInteger vni, String dhcpIpAddress, int lportTag)
+            throws ExecutionException, InterruptedException {
         DhcpServiceUtils.setupDhcpArpRequest(dpnId, NwConstants.EXTERNAL_TUNNEL_TABLE, vni, dhcpIpAddress,
-                lportTag, null, false, mdsalUtil);
+                lportTag, null, false, mdsalUtil, tx);
     }
 
 
index 62961362ab1470292b0f0a33345524a1b60930e4..eaaad90fd89afdd22cb17caabca9cb4e14116fbc 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+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;
@@ -198,14 +199,14 @@ public class DhcpManager {
                 mdsalUtil, dhcpServiceCounters, tx);
     }
 
-    public void setupDefaultDhcpFlows(BigInteger dpId) {
-        setupTableMissForDhcpTable(dpId);
+    public void setupDefaultDhcpFlows(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
+        setupTableMissForDhcpTable(tx, dpId);
         if (config.isDhcpDynamicAllocationPoolEnabled()) {
-            setupDhcpAllocationPoolFlow(dpId);
+            setupDhcpAllocationPoolFlow(tx, dpId);
         }
     }
 
-    private void setupTableMissForDhcpTable(BigInteger dpId) {
+    private void setupTableMissForDhcpTable(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
         List<MatchInfo> matches = new ArrayList<>();
         List<InstructionInfo> instructions = new ArrayList<>();
         List<ActionInfo> actionsInfos = new ArrayList<>();
@@ -215,11 +216,11 @@ public class DhcpManager {
                 0, "DHCP Table Miss Flow", 0, 0,
                 DhcpMConstants.COOKIE_DHCP_BASE, matches, instructions);
         dhcpServiceCounters.installDhcpTableMissFlow();
-        mdsalUtil.installFlow(flowEntity);
-        setupTableMissForHandlingExternalTunnel(dpId);
+        mdsalUtil.addFlow(tx, flowEntity);
+        setupTableMissForHandlingExternalTunnel(tx, dpId);
     }
 
-    private void setupDhcpAllocationPoolFlow(BigInteger dpId) {
+    private void setupDhcpAllocationPoolFlow(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
         List<MatchInfo> matches = DhcpServiceUtils.getDhcpMatch();
         List<InstructionInfo> instructions = new ArrayList<>();
         List<ActionInfo> actionsInfos = new ArrayList<>();
@@ -230,10 +231,10 @@ public class DhcpManager {
                 "Dhcp Allocation Pool Flow", 0, 0, DhcpMConstants.COOKIE_DHCP_BASE, matches, instructions);
         LOG.trace("Installing DHCP Allocation Pool Flow DpId {}", dpId);
         dhcpServiceCounters.installDhcpFlow();
-        mdsalUtil.installFlow(flowEntity);
+        mdsalUtil.addFlow(tx, flowEntity);
     }
 
-    private void setupTableMissForHandlingExternalTunnel(BigInteger dpId) {
+    private void setupTableMissForHandlingExternalTunnel(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
         List<MatchInfo> matches = new ArrayList<>();
         List<InstructionInfo> instructions = new ArrayList<>();
         instructions.add(new InstructionGotoTable(NwConstants.EXTERNAL_TUNNEL_TABLE));
@@ -243,6 +244,6 @@ public class DhcpManager {
                 0, "DHCP Table Miss Flow For External Tunnel", 0, 0,
                 DhcpMConstants.COOKIE_DHCP_BASE, matches, instructions);
         dhcpServiceCounters.installDhcpTableMissFlowForExternalTable();
-        mdsalUtil.installFlow(flowEntity);
+        mdsalUtil.addFlow(tx, flowEntity);
     }
 }
index fcb394ced41362d880bc7041376615b1b08a4afb..153518709b3bad1e207723689fc7f5476f78dd91 100644 (file)
@@ -192,21 +192,23 @@ public final class DhcpServiceUtils {
     }
 
     public static void setupDhcpArpRequest(BigInteger dpId, short tableId, BigInteger vni, String dhcpIpAddress,
-                                           int lportTag, Long elanTag, boolean add, IMdsalApiManager mdsalUtil) {
+                                           int lportTag, Long elanTag, boolean add, IMdsalApiManager mdsalUtil,
+                                           TypedReadWriteTransaction<Configuration> tx)
+            throws ExecutionException, InterruptedException {
         List<MatchInfo> matches = getDhcpArpMatch(vni, dhcpIpAddress);
         if (add) {
             Flow flow = MDSALUtil.buildFlowNew(tableId, getDhcpArpFlowRef(dpId, tableId, lportTag, dhcpIpAddress),
                     DhcpMConstants.DEFAULT_DHCP_ARP_FLOW_PRIORITY, "DHCPArp", 0, 0,
                     generateDhcpArpCookie(lportTag, dhcpIpAddress), matches, null);
             LOG.trace("Removing DHCP ARP Flow DpId {}, DHCP Port IpAddress {}", dpId, dhcpIpAddress);
-            mdsalUtil.removeFlow(dpId, flow);
+            mdsalUtil.removeFlow(tx, dpId, flow);
         } else {
             Flow flow = MDSALUtil.buildFlowNew(tableId, getDhcpArpFlowRef(dpId, tableId, lportTag, dhcpIpAddress),
                     DhcpMConstants.DEFAULT_DHCP_ARP_FLOW_PRIORITY, "DHCPArp", 0, 0,
                     generateDhcpArpCookie(lportTag, dhcpIpAddress), matches,
                     getDhcpArpInstructions(elanTag, lportTag));
             LOG.trace("Adding DHCP ARP Flow DpId {}, DHCPPort IpAddress {}", dpId, dhcpIpAddress);
-            mdsalUtil.installFlow(dpId, flow);
+            mdsalUtil.addFlow(tx, dpId, flow);
         }
     }
 
index fa04d1b9ce810b6c1d890618953198a6af4e8d4a..7b1c07321eb12a2f2965c22663f6daf03b2831de 100644 (file)
@@ -16,7 +16,11 @@ import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.genius.infra.Datastore;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
+import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
 import org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -33,6 +37,7 @@ public class NodeListener extends AsyncDataTreeChangeListenerBase<Node, NodeList
     private final DataBroker broker;
     private final DhcpManager dhcpManager;
     private final DhcpExternalTunnelManager dhcpExternalTunnelManager;
+    private final ManagedNewTransactionRunner txRunner;
 
     @Inject
     public NodeListener(final DataBroker db, final DhcpManager dhcpMgr,
@@ -41,6 +46,7 @@ public class NodeListener extends AsyncDataTreeChangeListenerBase<Node, NodeList
         this.broker = db;
         this.dhcpManager = dhcpMgr;
         this.dhcpExternalTunnelManager = dhcpExternalTunnelManager;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(db);
     }
 
     @Override
@@ -71,7 +77,8 @@ public class NodeListener extends AsyncDataTreeChangeListenerBase<Node, NodeList
             return;
         }
         BigInteger dpId = new BigInteger(node[1]);
-        dhcpManager.setupDefaultDhcpFlows(dpId);
+        ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+            tx -> dhcpManager.setupDefaultDhcpFlows(tx, dpId)), LOG, "Error handling node addition for {}", add);
         dhcpExternalTunnelManager.installDhcpDropActionOnDpn(dpId);
         List<BigInteger> listOfDpns = DhcpServiceUtils.getListOfDpns(broker);
         dhcpExternalTunnelManager.handleDesignatedDpnDown(DhcpMConstants.INVALID_DPID, listOfDpns);