GENIUS-185: Removing usage of databroker tx 62/74962/25
authorEdw7n <n.edwin.anthony@ericsson.com>
Mon, 21 Jan 2019 14:41:03 +0000 (20:11 +0530)
committerHema Gopalakrishnan <hema.gopalkrishnan@ericsson.com>
Tue, 29 Jan 2019 23:25:05 +0000 (23:25 +0000)
- replaces most uses of databroker tx
- few worker classes have been refactored into their respective listeneres
- some classes ommitted in /itm-impl/..../cli/
    would lead to other comprehensive changes which are out of scope

Change-Id: I8d2218636471923b7fb9e61dd2b42b6d80207bcf
Signed-off-by: Edw7n <n.edwin.anthony@ericsson.com>
31 files changed:
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/cli/TepCommandHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/cli/TepDeleteDatastore.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmExternalTunnelAddWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmExternalTunnelDeleteWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmInternalTunnelAddWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmMonitorIntervalWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmMonitorToggleWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmMonitorWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmTepAddWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmTepRemoveWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmTepsNotHostedMoveWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmTepsNotHostedRemoveWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmTunnelStateAddHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmTunnelStateRemoveHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/OvsdbTepAddConfigHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/OvsdbTepAddWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/OvsdbTepRemoveConfigHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/OvsdbTepRemoveWorker.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/impl/ItmUtils.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/InterfaceStateListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/TransportZoneListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/listeners/TunnelMonitorIntervalListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/monitoring/ItmTunnelEventListener.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/recovery/impl/ItmTepInstanceRecoveryHandler.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/rpc/ItmManagerRpcService.java
itm/itm-impl/src/test/java/org/opendaylight/genius/itm/impl/ItmExternalTunnelAddTest.java
itm/itm-impl/src/test/java/org/opendaylight/genius/itm/impl/ItmExternalTunnelDeleteTest.java
itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmManagerRpcServiceTest.java
itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmTepAutoConfigTest.java
itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmTepAutoConfigTestUtil.java
mdsalutil/mdsalutil-impl/src/main/java/org/opendaylight/genius/mdsalutil/internal/MDSALManager.java

index 2d205c7f25c43e908fe2ba76e2a331aea82e3930..376431da451817a5250b04b3833dfdf7222f3a1a 100644 (file)
@@ -7,8 +7,11 @@
  */
 package org.opendaylight.genius.itm.cli;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.Futures;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -30,6 +33,7 @@ import org.apache.felix.service.command.CommandSession;
 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;
 import org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner;
 import org.opendaylight.genius.itm.cache.UnprocessedTunnelsStateCache;
 import org.opendaylight.genius.itm.globals.ITMConstants;
@@ -365,7 +369,6 @@ public class TepCommandHelper {
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     public void buildTeps() {
-        TransportZones transportZonesBuilt = null;
         TransportZone transportZone = null;
         try {
             LOG.debug("no of teps added {}", CHECK);
@@ -416,12 +419,13 @@ public class TepCommandHelper {
                     LOG.debug("tzone object {}", transportZone);
                     transportZoneArrayList.add(transportZone);
                 }
-                transportZonesBuilt = new TransportZonesBuilder().setTransportZone(transportZoneArrayList).build();
+                TransportZones transportZones =
+                    new TransportZonesBuilder().setTransportZone(transportZoneArrayList).build();
                 InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
                 LOG.debug("InstanceIdentifier {}", path);
-                ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, transportZonesBuilt, dataBroker,
-                        ItmUtils.DEFAULT_CALLBACK);
-                LOG.debug("wrote to Config DS {}", transportZonesBuilt);
+                Futures.addCallback(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                    tx -> tx.merge(path, transportZones, true)), ItmUtils.DEFAULT_WRITE_CALLBACK);
+                LOG.debug("wrote to Config DS {}", transportZones);
                 transportZonesHashMap.clear();
                 transportZoneArrayList.clear();
                 subnetList.clear();
@@ -695,8 +699,8 @@ public class TepCommandHelper {
                     allPaths.addAll(vtepPaths);
                     allPaths.addAll(subnetPaths);
                     allPaths.addAll(tzPaths);
-                    ItmUtils.asyncBulkRemove(dataBroker, LogicalDatastoreType.CONFIGURATION, allPaths,
-                            ItmUtils.DEFAULT_CALLBACK);
+                    Futures.addCallback(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+                        tx -> allPaths.forEach(tx::delete)), ItmUtils.DEFAULT_WRITE_CALLBACK);
                 }
                 vtepPaths.clear();
                 subnetPaths.clear();
@@ -896,9 +900,8 @@ public class TepCommandHelper {
         if (!storedTunnelMonitor.isPresent() || storedTunnelMonitor.get().isEnabled() != monitorEnabled) {
             TunnelMonitorParams tunnelMonitor = new TunnelMonitorParamsBuilder().setEnabled(monitorEnabled)
                     .setMonitorProtocol(monitorType).build();
-            ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tunnelMonitor, dataBroker,
-                    ItmUtils.DEFAULT_CALLBACK);
-
+            Futures.addCallback(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                tx -> tx.merge(path, tunnelMonitor, true)), ItmUtils.DEFAULT_WRITE_CALLBACK);
         }
     }
 
@@ -909,8 +912,8 @@ public class TepCommandHelper {
                 dataBroker);
         if (!storedTunnelMonitor.isPresent() || storedTunnelMonitor.get().getInterval() != interval) {
             TunnelMonitorInterval tunnelMonitor = new TunnelMonitorIntervalBuilder().setInterval(interval).build();
-            ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, path, tunnelMonitor, dataBroker,
-                    ItmUtils.DEFAULT_CALLBACK);
+            Futures.addCallback(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                tx -> tx.merge(path, tunnelMonitor, true)), ItmUtils.DEFAULT_WRITE_CALLBACK);
         }
     }
 
index 1ad44ab21cbdd40768867a880415990547ee6ce8..33eb956e566f06560a44ca243bbfa3c3b82f19a0 100644 (file)
@@ -7,12 +7,15 @@
  */
 package org.opendaylight.genius.itm.cli;
 
+import com.google.common.util.concurrent.Futures;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
-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;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.itm.api.IITMProvider;
 import org.opendaylight.genius.itm.impl.ItmUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
@@ -21,12 +24,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.Transp
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 @Command(scope = "tep", name = "deleteDatastore", description = "deleting all tep data from datastore")
 public class TepDeleteDatastore<T extends DataObject>  extends OsgiCommandSupport {
-    private static final Logger LOG = LoggerFactory.getLogger(TepDeleteDatastore.class);
     private IITMProvider itmProvider;
 
     public void setItmProvider(IITMProvider itmProvider) {
@@ -34,8 +34,8 @@ public class TepDeleteDatastore<T extends DataObject>  extends OsgiCommandSuppor
     }
 
     @Override
+    @SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
     protected Object doExecute() {
-        final DataBroker dataBroker =  itmProvider.getDataBroker();
         InstanceIdentifier<TransportZones> itmConfigPath =
                 InstanceIdentifier.builder(TransportZones.class).build();
         InstanceIdentifier<Interfaces> interfacesConfigPath =
@@ -44,20 +44,19 @@ public class TepDeleteDatastore<T extends DataObject>  extends OsgiCommandSuppor
                 InstanceIdentifier.builder(InterfacesState.class).build();
         InstanceIdentifier<Nodes> frmConfigPath =
                 InstanceIdentifier.builder(Nodes.class).build();
-        List<InstanceIdentifier<T>> allConfigPaths =
-                        new ArrayList<>();
+        List<InstanceIdentifier<T>> allConfigPaths = new ArrayList<>();
         allConfigPaths.add((InstanceIdentifier<T>) itmConfigPath);
         allConfigPaths.add((InstanceIdentifier<T>) interfacesConfigPath);
         allConfigPaths.add((InstanceIdentifier<T>) frmConfigPath);
         //allConfigPaths.add((InstanceIdentifier<T>) tunnelsConfigPath);
-        ItmUtils.asyncBulkRemove(dataBroker, LogicalDatastoreType.CONFIGURATION,allConfigPaths,
-                        ItmUtils.DEFAULT_CALLBACK);
-        List<InstanceIdentifier<T>> allOperationalPaths =
-                        new ArrayList<>();
+        final ManagedNewTransactionRunner txrunner = new ManagedNewTransactionRunnerImpl(itmProvider.getDataBroker());
+        Futures.addCallback(txrunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+            tx -> allConfigPaths.forEach(tx::delete)), ItmUtils.DEFAULT_WRITE_CALLBACK);
+        List<InstanceIdentifier<T>> allOperationalPaths = new ArrayList<>();
         // allOperationalPaths.add((InstanceIdentifier<T>) tnStateOpPath);
         allOperationalPaths.add((InstanceIdentifier<T>) ifStateOpPath);
-        ItmUtils.asyncBulkRemove(dataBroker, LogicalDatastoreType.OPERATIONAL, allOperationalPaths,
-                        ItmUtils.DEFAULT_CALLBACK);
+        Futures.addCallback(txrunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.OPERATIONAL,
+            tx -> allOperationalPaths.forEach(tx::delete)), ItmUtils.DEFAULT_WRITE_CALLBACK);
         return null;
     }
 }
index 301290df1c79d145d73c3ea27634fa6fbf051f1f..e0507cf10bfc39808cd8003393061c5d34f63767 100644 (file)
@@ -7,19 +7,18 @@
  */
 package org.opendaylight.genius.itm.confighelpers;
 
+import static org.opendaylight.genius.infra.Datastore.Configuration;
+
 import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigInteger;
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
+import java.util.concurrent.ExecutionException;
 import org.apache.commons.net.util.SubnetUtils;
-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.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache;
 import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.opendaylight.genius.itm.impl.ItmUtils;
@@ -53,20 +52,18 @@ import org.slf4j.LoggerFactory;
 public class ItmExternalTunnelAddWorker {
     private static final Logger LOG = LoggerFactory.getLogger(ItmExternalTunnelAddWorker.class);
 
-    private final DataBroker dataBroker;
     private final ItmConfig itmConfig;
     private final DPNTEPsInfoCache dpnTEPsInfoCache;
 
-    public ItmExternalTunnelAddWorker(DataBroker dataBroker, ItmConfig itmConfig, DPNTEPsInfoCache dpnTEPsInfoCache) {
-        this.dataBroker = dataBroker;
+    public ItmExternalTunnelAddWorker(ItmConfig itmConfig, DPNTEPsInfoCache dpnTEPsInfoCache) {
         this.itmConfig = itmConfig;
         this.dpnTEPsInfoCache = dpnTEPsInfoCache;
     }
 
-    public List<ListenableFuture<Void>> buildTunnelsToExternalEndPoint(Collection<DPNTEPsInfo> cfgDpnList,
-            IpAddress extIp, Class<? extends TunnelTypeBase> tunType) {
+    public void buildTunnelsToExternalEndPoint(Collection<DPNTEPsInfo> cfgDpnList, IpAddress extIp,
+                                               Class<? extends TunnelTypeBase> tunType,
+                                               TypedWriteTransaction<Configuration> tx) {
         if (null != cfgDpnList) {
-            WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
             for (DPNTEPsInfo teps : cfgDpnList) {
                 // CHECK -- Assumption -- Only one End Point / Dpn for GRE/Vxlan Tunnels
                 TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0);
@@ -94,57 +91,61 @@ public class ItmExternalTunnelAddWorker {
                 InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
                 LOG.debug(" Trunk Interface Identifier - {} ", trunkIdentifier);
                 LOG.trace(" Writing Trunk Interface to Config DS {}, {} ", trunkIdentifier, iface);
-                transaction.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, iface, true);
+                tx.merge(trunkIdentifier, iface, true);
                 // update external_tunnel_list ds
                 InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class)
                         .child(ExternalTunnel.class, new ExternalTunnelKey(extIp.stringValue(),
                                 teps.getDPNID().toString(), tunType));
                 ExternalTunnel tnl = ItmUtils.buildExternalTunnel(teps.getDPNID().toString(),
                     extIp.stringValue(), tunType, trunkInterfaceName);
-                transaction.merge(LogicalDatastoreType.CONFIGURATION, path, tnl, true);
+                tx.merge(path, tnl, true);
             }
-            return Collections.singletonList(transaction.submit());
         }
-        return Collections.emptyList();
     }
 
-    public List<ListenableFuture<Void>> buildTunnelsFromDpnToExternalEndPoint(List<BigInteger> dpnId, IpAddress extIp,
-            Class<? extends TunnelTypeBase> tunType) {
+    public void buildTunnelsFromDpnToExternalEndPoint(List<BigInteger> dpnId, IpAddress extIp,
+                                                      Class<? extends TunnelTypeBase> tunType,
+                                                      TypedWriteTransaction<Configuration> tx) {
         Collection<DPNTEPsInfo> cfgDpnList = dpnId == null ? dpnTEPsInfoCache.getAllPresent()
                         : ItmUtils.getDpnTepListFromDpnId(dpnTEPsInfoCache, dpnId);
-        return buildTunnelsToExternalEndPoint(cfgDpnList, extIp, tunType);
+        buildTunnelsToExternalEndPoint(cfgDpnList, extIp, tunType, tx);
     }
 
-    public List<ListenableFuture<Void>> buildHwVtepsTunnels(List<DPNTEPsInfo> cfgdDpnList, List<HwVtep> cfgdHwVteps) {
+    public void buildHwVtepsTunnels(List<DPNTEPsInfo> cfgdDpnList, List<HwVtep> cfgdHwVteps,
+                                    TypedReadWriteTransaction<Configuration> tx) {
+
         Integer monitorInterval = ITMConstants.BFD_DEFAULT_MONITOR_INTERVAL;
         Class<? extends TunnelMonitoringTypeBase> monitorProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
 
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
-        WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
         if (null != cfgdDpnList && !cfgdDpnList.isEmpty()) {
             LOG.trace("calling tunnels from OVS {}",cfgdDpnList);
-            tunnelsFromOVS(cfgdDpnList, writeTransaction, monitorInterval, monitorProtocol);
+            tunnelsFromOVS(cfgdDpnList, tx, monitorInterval, monitorProtocol);
         }
         if (null != cfgdHwVteps && !cfgdHwVteps.isEmpty()) {
             LOG.trace("calling tunnels from hwTep {}",cfgdHwVteps);
-            tunnelsFromhWVtep(cfgdHwVteps, writeTransaction, monitorInterval, monitorProtocol);
-        }
-
-        if (cfgdDpnList != null && !cfgdDpnList.isEmpty() || cfgdHwVteps != null && !cfgdHwVteps.isEmpty()) {
-            futures.add(writeTransaction.submit());
+            cfgdHwVteps.forEach(hwVtep -> {
+                try {
+                    tunnelsFromhWVtep(hwVtep, tx, monitorInterval, monitorProtocol);
+                } catch (ExecutionException | InterruptedException e) {
+                    LOG.error("Tunnel Creation failed for {} due to ", hwVtep.getTransportZone(), e);
+                }
+            });
         }
-        return futures;
     }
 
-    private void tunnelsFromOVS(List<DPNTEPsInfo> cfgdDpnList, WriteTransaction transaction, Integer monitorInterval,
-                                Class<? extends TunnelMonitoringTypeBase> monitorProtocol) {
+    private void tunnelsFromOVS(List<DPNTEPsInfo> cfgdDpnList, TypedReadWriteTransaction<Configuration> tx,
+                                Integer monitorInterval, Class<? extends TunnelMonitoringTypeBase> monitorProtocol) {
         for (DPNTEPsInfo dpn : cfgdDpnList) {
-            LOG.trace("processing dpn {}" , dpn);
+            LOG.trace("processing dpn {}", dpn);
             if (dpn.getTunnelEndPoints() != null && !dpn.getTunnelEndPoints().isEmpty()) {
                 for (TunnelEndPoints tep : dpn.getTunnelEndPoints()) {
-                    for (TzMembership zone: tep.getTzMembership()) {
-                        createTunnelsFromOVSinTransportZone(zone.getZoneName(), dpn, tep,
-                                transaction, monitorInterval, monitorProtocol);
+                    for (TzMembership zone : tep.nonnullTzMembership()) {
+                        try {
+                            createTunnelsFromOVSinTransportZone(zone.getZoneName(), dpn, tep, tx, monitorInterval,
+                                monitorProtocol);
+                        } catch (ExecutionException | InterruptedException e) {
+                            LOG.error("Tunnel Creation failed for {} due to ", zone.getZoneName(), e);
+                        }
                     }
                 }
             }
@@ -152,12 +153,10 @@ public class ItmExternalTunnelAddWorker {
     }
 
     private void createTunnelsFromOVSinTransportZone(String zoneName, DPNTEPsInfo dpn, TunnelEndPoints tep,
-            WriteTransaction transaction, Integer monitorInterval,
-            Class<? extends TunnelMonitoringTypeBase> monitorProtocol) {
-        InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
-                .child(TransportZone.class, new TransportZoneKey(zoneName)).build();
-        Optional<TransportZone> transportZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
-                tzonePath, dataBroker);
+        TypedReadWriteTransaction<Configuration> tx, Integer monitorInterval,
+        Class<? extends TunnelMonitoringTypeBase> monitorProtocol) throws ExecutionException, InterruptedException {
+        Optional<TransportZone> transportZoneOptional = tx.read(InstanceIdentifier.builder(TransportZones.class)
+                .child(TransportZone.class, new TransportZoneKey(zoneName)).build()).get();
         if (transportZoneOptional.isPresent()) {
             TransportZone transportZone = transportZoneOptional.get();
             //do we need to check tunnel type?
@@ -176,8 +175,7 @@ public class ItmExternalTunnelAddWorker {
                             if (!wireUp(dpn.getDPNID(), tep.getPortname(), sub.getVlanId(),
                                     tep.getIpAddress(), useOfTunnel, nodeId, hwVtepDS.getIpAddress(),
                                     tep.getSubnetMask(), sub.getGatewayIp(), sub.getPrefix(),
-                                    transportZone.getTunnelType(), false, monitorInterval, monitorProtocol,
-                                    transaction)) {
+                                    transportZone.getTunnelType(), false, monitorInterval, monitorProtocol, tx)) {
                                 LOG.error("Unable to build tunnel {} -- {}",
                                         tep.getIpAddress(), hwVtepDS.getIpAddress());
                             }
@@ -186,7 +184,7 @@ public class ItmExternalTunnelAddWorker {
                             if (!wireUp(hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(),
                                     cssID, tep.getIpAddress(), sub.getPrefix(), sub.getGatewayIp(),
                                     tep.getSubnetMask(), transportZone.getTunnelType(), false, monitorInterval,
-                                    monitorProtocol, transaction)) {
+                                    monitorProtocol, tx)) {
                                 LOG.error("Unable to build tunnel {} -- {}",
                                         hwVtepDS.getIpAddress(), tep.getIpAddress());
                             }
@@ -198,69 +196,65 @@ public class ItmExternalTunnelAddWorker {
         }
     }
 
-    private void tunnelsFromhWVtep(List<HwVtep> cfgdHwVteps, WriteTransaction transaction,
-            Integer monitorInterval, Class<? extends TunnelMonitoringTypeBase> monitorProtocol) {
-        for (HwVtep hwTep : cfgdHwVteps) {
-            InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
-                    .child(TransportZone.class, new TransportZoneKey(hwTep.getTransportZone())).build();
-            Optional<TransportZone> transportZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
-                    tzonePath, dataBroker);
-            Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
-            if (transportZoneOptional.isPresent()) {
-                TransportZone tzone = transportZoneOptional.get();
-                //do we need to check tunnel type?
-                if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
-                    for (Subnets sub : tzone.getSubnets()) {
-                        if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
-                            for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
-                                if (Objects.equals(hwVtepDS.getIpAddress(), hwTep.getHwIp())) {
-                                    continue;//dont mesh with self
-                                }
-                                LOG.trace("wire up {} and {}",hwTep, hwVtepDS);
-                                if (!wireUp(hwTep.getTopoId(), hwTep.getNodeId(), hwTep.getHwIp(),
-                                        hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(), hwTep.getIpPrefix(),
-                                        hwTep.getGatewayIP(), sub.getPrefix(), tunType, false,
-                                        monitorInterval, monitorProtocol, transaction)) {
-                                    LOG.error("Unable to build tunnel {} -- {}",
-                                            hwTep.getHwIp(), hwVtepDS.getIpAddress());
-                                }
-                                //TOR2-TOR1
-                                LOG.trace("wire up {} and {}", hwVtepDS,hwTep);
-                                if (!wireUp(hwTep.getTopoId(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(),
-                                        hwTep.getNodeId(), hwTep.getHwIp(), sub.getPrefix(), sub.getGatewayIp(),
-                                        hwTep.getIpPrefix(), tunType, false, monitorInterval,
-                                        monitorProtocol, transaction)) {
-                                    LOG.error("Unable to build tunnel {} -- {}",
-                                            hwVtepDS.getIpAddress(), hwTep.getHwIp());
-                                }
+    private void tunnelsFromhWVtep(HwVtep hwTep, TypedReadWriteTransaction<Configuration> tx, Integer monitorInterval,
+                                   Class<? extends TunnelMonitoringTypeBase> monitorProtocol) throws ExecutionException,
+                                    InterruptedException {
+        Optional<TransportZone> transportZoneOptional = tx.read(InstanceIdentifier.builder(TransportZones.class)
+            .child(TransportZone.class, new TransportZoneKey(hwTep.getTransportZone())).build()).get();
+        Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
+        if (transportZoneOptional.isPresent()) {
+            TransportZone tzone = transportZoneOptional.get();
+            //do we need to check tunnel type?
+            if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
+                for (Subnets sub : tzone.getSubnets()) {
+                    if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
+                        for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
+                            if (Objects.equals(hwVtepDS.getIpAddress(), hwTep.getHwIp())) {
+                                continue;//dont mesh with self
+                            }
+                            LOG.trace("wire up {} and {}",hwTep, hwVtepDS);
+                            if (!wireUp(hwTep.getTopoId(), hwTep.getNodeId(), hwTep.getHwIp(),
+                                    hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(), hwTep.getIpPrefix(),
+                                    hwTep.getGatewayIP(), sub.getPrefix(), tunType, false,
+                                    monitorInterval, monitorProtocol, tx)) {
+                                LOG.error("Unable to build tunnel {} -- {}",
+                                        hwTep.getHwIp(), hwVtepDS.getIpAddress());
+                            }
+                            //TOR2-TOR1
+                            LOG.trace("wire up {} and {}", hwVtepDS,hwTep);
+                            if (!wireUp(hwTep.getTopoId(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(),
+                                    hwTep.getNodeId(), hwTep.getHwIp(), sub.getPrefix(), sub.getGatewayIp(),
+                                    hwTep.getIpPrefix(), tunType, false, monitorInterval,
+                                    monitorProtocol, tx)) {
+                                LOG.error("Unable to build tunnel {} -- {}",
+                                        hwVtepDS.getIpAddress(), hwTep.getHwIp());
                             }
                         }
-                        if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
-                            for (Vteps vtep : sub.getVteps()) {
-                                if (Objects.equals(vtep.getIpAddress(), hwTep.getHwIp())) {
-                                    continue;
-                                }
-                                //TOR-OVS
-                                String cssID = vtep.getDpnId().toString();
-                                LOG.trace("wire up {} and {}",hwTep, vtep);
-                                if (!wireUp(hwTep.getTopoId(), hwTep.getNodeId(), hwTep.getHwIp(), cssID,
-                                        vtep.getIpAddress(), hwTep.getIpPrefix(), hwTep.getGatewayIP(),
-                                        sub.getPrefix(), tunType,false, monitorInterval, monitorProtocol,
-                                        transaction)) {
-                                    LOG.error("Unable to build tunnel {} -- {}",
-                                            hwTep.getHwIp(), vtep.getIpAddress());
-                                }
-                                //OVS-TOR
-                                LOG.trace("wire up {} and {}", vtep,hwTep);
-                                boolean useOfTunnel = ItmUtils.falseIfNull(vtep.isOptionOfTunnel());
-                                if (!wireUp(vtep.getDpnId(), vtep.getPortname(), sub.getVlanId(), vtep.getIpAddress(),
-                                        useOfTunnel, hwTep.getNodeId(),hwTep.getHwIp(),sub.getPrefix(),
-                                        sub.getGatewayIp(),hwTep.getIpPrefix(), tunType, false,
-                                        monitorInterval, monitorProtocol, transaction)) {
-                                    LOG.debug("wireUp returned false");
-                                }
+                    }
+                    if (sub.getVteps() != null && !sub.getVteps().isEmpty()) {
+                        for (Vteps vtep : sub.getVteps()) {
+                            if (Objects.equals(vtep.getIpAddress(), hwTep.getHwIp())) {
+                                continue;
+                            }
+                            //TOR-OVS
+                            String cssID = vtep.getDpnId().toString();
+                            LOG.trace("wire up {} and {}",hwTep, vtep);
+                            if (!wireUp(hwTep.getTopoId(), hwTep.getNodeId(), hwTep.getHwIp(), cssID,
+                                    vtep.getIpAddress(), hwTep.getIpPrefix(), hwTep.getGatewayIP(),
+                                    sub.getPrefix(), tunType,false, monitorInterval, monitorProtocol,
+                                    tx)) {
+                                LOG.error("Unable to build tunnel {} -- {}",
+                                        hwTep.getHwIp(), vtep.getIpAddress());
+                            }
+                            //OVS-TOR
+                            LOG.trace("wire up {} and {}", vtep,hwTep);
+                            boolean useOfTunnel = ItmUtils.falseIfNull(vtep.isOptionOfTunnel());
+                            if (!wireUp(vtep.getDpnId(), vtep.getPortname(), sub.getVlanId(), vtep.getIpAddress(),
+                                    useOfTunnel, hwTep.getNodeId(),hwTep.getHwIp(),sub.getPrefix(),
+                                    sub.getGatewayIp(),hwTep.getIpPrefix(), tunType, false,
+                                    monitorInterval, monitorProtocol, tx)) {
+                                LOG.debug("wireUp returned false");
                             }
-
                         }
                     }
                 }
@@ -270,9 +264,10 @@ public class ItmExternalTunnelAddWorker {
 
     //for tunnels from TOR device
     private boolean wireUp(String topoId, String srcNodeid, IpAddress srcIp, String dstNodeId, IpAddress dstIp,
-            IpPrefix srcSubnet, IpAddress gwIp, IpPrefix dstSubnet, Class<? extends TunnelTypeBase> tunType,
-            Boolean monitorEnabled, Integer monitorInterval, Class<? extends TunnelMonitoringTypeBase> monitorProtocol,
-            WriteTransaction transaction) {
+                           IpPrefix srcSubnet, IpAddress gwIp, IpPrefix dstSubnet,
+                           Class<? extends TunnelTypeBase> tunType, Boolean monitorEnabled, Integer monitorInterval,
+                           Class<? extends TunnelMonitoringTypeBase> monitorProtocol,
+                           TypedWriteTransaction<Configuration> tx) {
         IpAddress gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
         IpAddress gwyIpAddress = srcSubnet.equals(dstSubnet) ? gatewayIpObj : gwIp;
         String parentIf =  ItmUtils.getHwParentIf(topoId, srcNodeid);
@@ -289,23 +284,24 @@ public class ItmExternalTunnelAddWorker {
                 .child(Interface.class, new InterfaceKey(tunnelIfName)).build();
         LOG.trace(" Writing Trunk Interface to Config DS {}, {} ", ifIID, hwTunnelIf);
         ItmUtils.ITM_CACHE.addInterface(hwTunnelIf);
-        transaction.merge(LogicalDatastoreType.CONFIGURATION, ifIID, hwTunnelIf, true);
+        tx.merge(ifIID, hwTunnelIf, true);
         // also update itm-state ds?
         InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class)
                 .child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey(dstNodeId),
                         getExternalTunnelKey(srcNodeid), tunType));
         ExternalTunnel tnl = ItmUtils.buildExternalTunnel(getExternalTunnelKey(srcNodeid),
                 getExternalTunnelKey(dstNodeId), tunType, tunnelIfName);
-        transaction.merge(LogicalDatastoreType.CONFIGURATION, path, tnl, true);
+        tx.merge(path, tnl, true);
         ItmUtils.ITM_CACHE.addExternalTunnel(tnl);
         return true;
     }
 
     //for tunnels from OVS
     private boolean wireUp(BigInteger dpnId, String portname, Integer vlanId, IpAddress srcIp, Boolean remoteIpFlow,
-            String dstNodeId, IpAddress dstIp, IpPrefix srcSubnet, IpAddress gwIp, IpPrefix dstSubnet,
-            Class<? extends TunnelTypeBase> tunType, Boolean monitorEnabled, Integer monitorInterval,
-            Class<? extends TunnelMonitoringTypeBase> monitorProtocol, WriteTransaction transaction) {
+                           String dstNodeId, IpAddress dstIp, IpPrefix srcSubnet, IpAddress gwIp, IpPrefix dstSubnet,
+                           Class<? extends TunnelTypeBase> tunType, Boolean monitorEnabled, Integer monitorInterval,
+                           Class<? extends TunnelMonitoringTypeBase> monitorProtocol,
+                           TypedWriteTransaction<Configuration> tx) {
         IpAddress gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
         IpAddress gwyIpAddress = srcSubnet.equals(dstSubnet) ? gatewayIpObj : gwIp;
         String parentIf = ItmUtils.getInterfaceName(dpnId, portname, vlanId);
@@ -321,7 +317,7 @@ public class ItmExternalTunnelAddWorker {
         InstanceIdentifier<Interface> ifIID = InstanceIdentifier.builder(Interfaces.class).child(Interface.class,
                 new InterfaceKey(tunnelIfName)).build();
         LOG.trace(" Writing Trunk Interface to Config DS {}, {} ", ifIID, extTunnelIf);
-        transaction.merge(LogicalDatastoreType.CONFIGURATION, ifIID, extTunnelIf, true);
+        tx.merge(ifIID, extTunnelIf, true);
         ItmUtils.ITM_CACHE.addInterface(extTunnelIf);
         InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class)
                 .child(ExternalTunnel.class, new ExternalTunnelKey(getExternalTunnelKey(dstNodeId),
@@ -329,7 +325,7 @@ public class ItmExternalTunnelAddWorker {
         ExternalTunnel tnl = ItmUtils.buildExternalTunnel(dpnId.toString(),
                 getExternalTunnelKey(dstNodeId),
                 tunType, tunnelIfName);
-        transaction.merge(LogicalDatastoreType.CONFIGURATION, path, tnl, true);
+        tx.merge(path, tnl, true);
         ItmUtils.ITM_CACHE.addExternalTunnel(tnl);
         return true;
     }
index 61418df16dcec3005a1466fcd3d79beff909d163..3eb314cb51ac56e105e34f630d088081fa1a138e 100644 (file)
@@ -8,16 +8,14 @@
 package org.opendaylight.genius.itm.confighelpers;
 
 import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
-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 java.util.concurrent.ExecutionException;
+import org.opendaylight.genius.infra.Datastore.Configuration;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.itm.impl.ItmUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
@@ -43,16 +41,14 @@ public final class ItmExternalTunnelDeleteWorker {
 
     private ItmExternalTunnelDeleteWorker() { }
 
-    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker,
-            Collection<DPNTEPsInfo> dpnTepsList, Collection<DPNTEPsInfo> meshedDpnList, IpAddress extIp,
-            Class<? extends TunnelTypeBase> tunType) {
+    public static void deleteTunnels(Collection<DPNTEPsInfo> dpnTepsList, Collection<DPNTEPsInfo> meshedDpnList,
+                                     IpAddress extIp, Class<? extends TunnelTypeBase> tunType,
+                                     TypedWriteTransaction<Configuration> tx) {
         LOG.trace(" Delete Tunnels towards DC Gateway with Ip  {}", extIp);
-
         if (dpnTepsList == null || dpnTepsList.isEmpty()) {
             LOG.debug("no vtep to delete");
-            return Collections.emptyList();
+            return;
         }
-        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
         for (DPNTEPsInfo teps : dpnTepsList) {
             TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0);
             // The membership in the listener will always be 1, to get the actual membership
@@ -64,13 +60,13 @@ public final class ItmExternalTunnelDeleteWorker {
                 String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(interfaceName,
                         firstEndPt.getIpAddress().stringValue(), extIp.stringValue(), tunType.getName());
                 InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
-                transaction.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+                tx.delete(trunkIdentifier);
                 ItmUtils.ITM_CACHE.removeInterface(trunkInterfaceName);
 
-                InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class).child(
-                        ExternalTunnel.class,
+                InstanceIdentifier<ExternalTunnel> path =
+                    InstanceIdentifier.create(ExternalTunnelList.class).child(ExternalTunnel.class,
                         ItmUtils.getExternalTunnelKey(extIp.stringValue(), teps.getDPNID().toString(), tunType));
-                transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
+                tx.delete(path);
                 LOG.debug("Deleting tunnel towards DC gateway, Tunnel interface name {} ", trunkInterfaceName);
                 ItmUtils.ITM_CACHE.removeExternalTunnel(trunkInterfaceName);
                 // Release the Ids for the trunk interface Name
@@ -78,64 +74,54 @@ public final class ItmExternalTunnelDeleteWorker {
                         firstEndPt.getIpAddress().stringValue(), extIp.stringValue(), tunType.getName());
             }
         }
-        return Collections.singletonList(transaction.submit());
     }
 
-    public static List<ListenableFuture<Void>> deleteTunnels(DataBroker dataBroker,
-            Collection<DPNTEPsInfo> dpnTepsList, IpAddress extIp, Class<? extends TunnelTypeBase> tunType) {
+    public static void deleteTunnels(Collection<DPNTEPsInfo> dpnTepsList, IpAddress extIp,
+                                     Class<? extends TunnelTypeBase> tunType, TypedWriteTransaction<Configuration> tx) {
         LOG.trace(" Delete Tunnels towards DC Gateway with Ip  {}", extIp);
 
         if (dpnTepsList == null || dpnTepsList.isEmpty()) {
             LOG.debug("no vtep to delete");
-            return Collections.emptyList();
+            return;
         }
-        WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
         for (DPNTEPsInfo teps : dpnTepsList) {
             TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0);
             String interfaceName = firstEndPt.getInterfaceName();
             String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(interfaceName,
                     firstEndPt.getIpAddress().stringValue(), extIp.stringValue(), tunType.getName());
             InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName);
-            writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+            tx.delete(trunkIdentifier);
             ItmUtils.ITM_CACHE.removeInterface(trunkInterfaceName);
 
-            InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class).child(
-                    ExternalTunnel.class,
+            InstanceIdentifier<ExternalTunnel> path =
+                InstanceIdentifier.create(ExternalTunnelList.class).child(ExternalTunnel.class,
                     ItmUtils.getExternalTunnelKey(extIp.stringValue(), teps.getDPNID().toString(), tunType));
-            writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, path);
+            tx.delete(path);
             LOG.debug("Deleting tunnel towards DC gateway, Tunnel interface name {} ", trunkInterfaceName);
             ItmUtils.ITM_CACHE.removeExternalTunnel(trunkInterfaceName);
             // Release the Ids for the trunk interface Name
             ItmUtils.releaseIdForTrunkInterfaceName(interfaceName,
                     firstEndPt.getIpAddress().stringValue(), extIp.stringValue(), tunType.getName());
         }
-        return Collections.singletonList(writeTransaction.submit());
     }
 
-    public static List<ListenableFuture<Void>> deleteHwVtepsTunnels(DataBroker dataBroker,
-            List<DPNTEPsInfo> delDpnList, List<HwVtep> cfgdHwVteps,
-            TransportZone originalTZone) {
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
-        WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
-
+    public static void deleteHwVtepsTunnels(List<DPNTEPsInfo> delDpnList, List<HwVtep> cfgdHwVteps,
+                                            TransportZone originalTZone, TypedReadWriteTransaction<Configuration> tx)
+                                                throws ExecutionException, InterruptedException {
         if (delDpnList != null || cfgdHwVteps != null) {
-            tunnelsDeletion(delDpnList, cfgdHwVteps, originalTZone, writeTransaction,
-                    dataBroker);
+            tunnelsDeletion(delDpnList, cfgdHwVteps, originalTZone, tx);
         }
-        futures.add(writeTransaction.submit());
-        return futures;
     }
 
     private static void tunnelsDeletion(List<DPNTEPsInfo> cfgdDpnList, List<HwVtep> cfgdhwVteps,
-            TransportZone originalTZone,
-            WriteTransaction writeTransaction, DataBroker dataBroker) {
+                                        TransportZone originalTZone, TypedReadWriteTransaction<Configuration> tx)
+                                            throws ExecutionException, InterruptedException {
         if (cfgdDpnList != null) {
             for (DPNTEPsInfo dpn : cfgdDpnList) {
                 if (dpn.getTunnelEndPoints() != null) {
                     for (TunnelEndPoints srcTep : dpn.getTunnelEndPoints()) {
                         for (TzMembership zone : srcTep.nonnullTzMembership()) {
-                            deleteTunnelsInTransportZone(zone.getZoneName(), dpn, srcTep, cfgdhwVteps, dataBroker,
-                                    writeTransaction);
+                            deleteTunnelsInTransportZone(zone.getZoneName(), dpn, srcTep, cfgdhwVteps, tx);
                         }
                     }
                 }
@@ -147,9 +133,9 @@ public final class ItmExternalTunnelDeleteWorker {
                 LOG.trace("processing hwTep from list {}", hwTep);
                 for (HwVtep hwTepRemote : cfgdhwVteps) {
                     if (!hwTep.getHwIp().equals(hwTepRemote.getHwIp())) {
-                        deleteTrunksTorTor(dataBroker, hwTep.getTopoId(), hwTep.getNodeId(),
-                                hwTep.getHwIp(), hwTepRemote.getTopoId(), hwTepRemote.getNodeId(),
-                                hwTepRemote.getHwIp(), TunnelTypeVxlan.class, writeTransaction);
+                        deleteTrunksTorTor(hwTep.getTopoId(), hwTep.getNodeId(), hwTep.getHwIp(),
+                            hwTepRemote.getTopoId(), hwTepRemote.getNodeId(), hwTepRemote.getHwIp(),
+                            TunnelTypeVxlan.class, tx);
                     }
                 }
                 // do we need to check tunnel type?
@@ -167,9 +153,9 @@ public final class ItmExternalTunnelDeleteWorker {
                                 }
                                 // TOR-TOR
                                 LOG.trace("deleting tor-tor {} and {}", hwTep, hwVtepDS);
-                                deleteTrunksTorTor(dataBroker, hwTep.getTopoId(), hwTep.getNodeId(),
-                                        hwTep.getHwIp(), hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(),
-                                        hwVtepDS.getIpAddress(), originalTZone.getTunnelType(), writeTransaction);
+                                deleteTrunksTorTor(hwTep.getTopoId(), hwTep.getNodeId(), hwTep.getHwIp(),
+                                    hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(), hwVtepDS.getIpAddress(),
+                                    originalTZone.getTunnelType(), tx);
 
                             }
                         }
@@ -179,9 +165,8 @@ public final class ItmExternalTunnelDeleteWorker {
                                 LOG.trace("deleting tor-css-tor {} and {}", hwTep, vtep);
                                 String parentIf = ItmUtils.getInterfaceName(vtep.getDpnId(), vtep.getPortname(),
                                         sub.getVlanId());
-                                deleteTrunksOvsTor(dataBroker, vtep.getDpnId(), parentIf,
-                                        vtep.getIpAddress(), hwTep.getTopoId(), hwTep.getNodeId(), hwTep.getHwIp(),
-                                        originalTZone.getTunnelType(), writeTransaction);
+                                deleteTrunksOvsTor(vtep.getDpnId(), parentIf, vtep.getIpAddress(), hwTep.getTopoId(),
+                                    hwTep.getNodeId(), hwTep.getHwIp(), originalTZone.getTunnelType(), tx);
                             }
                         }
                     }
@@ -191,22 +176,22 @@ public final class ItmExternalTunnelDeleteWorker {
     }
 
     private static void deleteTunnelsInTransportZone(String zoneName, DPNTEPsInfo dpn, TunnelEndPoints srcTep,
-            List<HwVtep> cfgdhwVteps, DataBroker dataBroker, WriteTransaction writeTransaction) {
+        List<HwVtep> cfgdhwVteps, TypedReadWriteTransaction<Configuration> tx)
+            throws InterruptedException, ExecutionException {
         InstanceIdentifier<TransportZone> tzonePath = InstanceIdentifier.builder(TransportZones.class)
                 .child(TransportZone.class, new TransportZoneKey(zoneName)).build();
-        Optional<TransportZone> transportZoneOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, tzonePath,
-                dataBroker);
-        if (transportZoneOptional.isPresent()) {
-            TransportZone tzone = transportZoneOptional.get();
+        Optional<TransportZone> tz = tx.read(tzonePath).get();
+        if (tz.isPresent()) {
+            TransportZone tzone = tz.get();
             // do we need to check tunnel type?
             if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
                 for (Subnets sub : tzone.getSubnets()) {
                     if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
                         for (DeviceVteps hwVtepDS : sub.getDeviceVteps()) {
                             // OVS-TOR-OVS
-                            deleteTrunksOvsTor(dataBroker, dpn.getDPNID(), srcTep.getInterfaceName(),
+                            deleteTrunksOvsTor(dpn.getDPNID(), srcTep.getInterfaceName(),
                                     srcTep.getIpAddress(), hwVtepDS.getTopologyId(), hwVtepDS.getNodeId(),
-                                    hwVtepDS.getIpAddress(), tzone.getTunnelType(), writeTransaction);
+                                    hwVtepDS.getIpAddress(), tzone.getTunnelType(), tx);
 
                         }
                     }
@@ -214,91 +199,92 @@ public final class ItmExternalTunnelDeleteWorker {
             }
             if (cfgdhwVteps != null && !cfgdhwVteps.isEmpty()) {
                 for (HwVtep hwVtep : cfgdhwVteps) {
-                    deleteTrunksOvsTor(dataBroker, dpn.getDPNID(), srcTep.getInterfaceName(),
+                    deleteTrunksOvsTor(dpn.getDPNID(), srcTep.getInterfaceName(),
                             srcTep.getIpAddress(), hwVtep.getTopoId(), hwVtep.getNodeId(), hwVtep.getHwIp(),
-                            TunnelTypeVxlan.class, writeTransaction);
+                            TunnelTypeVxlan.class, tx);
 
                 }
             }
         }
     }
 
-    private static void deleteTrunksOvsTor(DataBroker dataBroker, BigInteger dpnid,
-            String interfaceName, IpAddress cssIpAddress, String topologyId, String nodeId, IpAddress hwIpAddress,
-            Class<? extends TunnelTypeBase> tunType, WriteTransaction transaction) {
+    private static void deleteTrunksOvsTor(BigInteger dpnid, String interfaceName, IpAddress cssIpAddress,
+        String topologyId, String nodeId, IpAddress hwIpAddress, Class<? extends TunnelTypeBase> tunType,
+        TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
         // OVS-TOR
-        if (trunkExists(dpnid.toString(), nodeId, tunType, dataBroker)) {
+        if (trunkExists(dpnid.toString(), nodeId, tunType, tx)) {
             LOG.trace("deleting tunnel from {} to {} ", dpnid.toString(), nodeId);
             String parentIf = interfaceName;
             String fwdTrunkIf = ItmUtils.getTrunkInterfaceName(parentIf,
                     cssIpAddress.stringValue(), hwIpAddress.stringValue(), tunType.getName());
             InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(fwdTrunkIf);
-            transaction.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+            tx.delete(trunkIdentifier);
 
             InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class)
                     .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(nodeId, dpnid.toString(), tunType));
-            transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
+            tx.delete(path);
         } else {
             LOG.trace(" trunk from {} to {} already deleted", dpnid.toString(), nodeId);
         }
         // TOR-OVS
-        if (trunkExists(nodeId, dpnid.toString(), tunType, dataBroker)) {
+        if (trunkExists(nodeId, dpnid.toString(), tunType, tx)) {
             LOG.trace("deleting tunnel from {} to {} ", nodeId, dpnid.toString());
 
             String parentIf = ItmUtils.getHwParentIf(topologyId, nodeId);
             String revTrunkIf = ItmUtils.getTrunkInterfaceName(parentIf,
                     hwIpAddress.stringValue(), cssIpAddress.stringValue(), tunType.getName());
             InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(revTrunkIf);
-            transaction.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+            tx.delete(trunkIdentifier);
 
             InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class)
                     .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(dpnid.toString(), nodeId, tunType));
-            transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
+            tx.delete(path);
         } else {
             LOG.trace(" trunk from {} to {} already deleted", nodeId, dpnid.toString());
         }
     }
 
-    private static void deleteTrunksTorTor(DataBroker dataBroker, String topologyId1,
-            String nodeId1, IpAddress hwIpAddress1, String topologyId2, String nodeId2, IpAddress hwIpAddress2,
-            Class<? extends TunnelTypeBase> tunType, WriteTransaction transaction) {
+    private static void deleteTrunksTorTor(String topologyId1, String nodeId1, IpAddress hwIpAddress1,
+        String topologyId2, String nodeId2, IpAddress hwIpAddress2, Class<? extends TunnelTypeBase> tunType,
+        TypedReadWriteTransaction<Configuration> tx) throws ExecutionException, InterruptedException {
         // TOR1-TOR2
-        if (trunkExists(nodeId1, nodeId2, tunType, dataBroker)) {
+        if (trunkExists(nodeId1, nodeId2, tunType, tx)) {
             LOG.trace("deleting tunnel from {} to {} ", nodeId1, nodeId2);
             String parentIf = ItmUtils.getHwParentIf(topologyId1, nodeId1);
             String fwdTrunkIf = ItmUtils.getTrunkInterfaceName(parentIf,
                     hwIpAddress1.stringValue(), hwIpAddress2.stringValue(), tunType.getName());
             InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(fwdTrunkIf);
-            transaction.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+            tx.delete(trunkIdentifier);
 
             InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class)
                     .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(nodeId2, nodeId1, tunType));
-            transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
+            tx.delete(path);
         } else {
             LOG.trace(" trunk from {} to {} already deleted", nodeId1, nodeId2);
         }
         // TOR2-TOR1
-        if (trunkExists(nodeId2, nodeId1, tunType, dataBroker)) {
+        if (trunkExists(nodeId2, nodeId1, tunType, tx)) {
             LOG.trace("deleting tunnel from {} to {} ", nodeId2, nodeId1);
 
             String parentIf = ItmUtils.getHwParentIf(topologyId2, nodeId2);
             String revTrunkIf = ItmUtils.getTrunkInterfaceName(parentIf,
                     hwIpAddress2.stringValue(), hwIpAddress1.stringValue(), tunType.getName());
             InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(revTrunkIf);
-            transaction.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier);
+            tx.delete(trunkIdentifier);
 
             InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class)
                     .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(nodeId1, nodeId2, tunType));
-            transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
+            tx.delete(path);
         } else {
             LOG.trace(" trunk from {} to {} already deleted", nodeId2, nodeId1);
         }
     }
 
     private static boolean trunkExists(String srcDpnOrNode, String dstDpnOrNode,
-            Class<? extends TunnelTypeBase> tunType, DataBroker dataBroker) {
+        Class<? extends TunnelTypeBase> tunType, TypedReadWriteTransaction<Configuration> tx)
+            throws ExecutionException, InterruptedException {
         InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class)
                 .child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(dstDpnOrNode, srcDpnOrNode, tunType));
-        return ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker).isPresent();
+        return tx.read(path).get().isPresent();
     }
 }
index a8c1769544aa439656687fab09b670ae28226aa6..f1d235097ce69ec8b6a769c05487b7837da7fed3 100644 (file)
@@ -22,7 +22,6 @@ import java.util.Objects;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 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.ReadFailedException;
 import org.opendaylight.genius.infra.Datastore.Configuration;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
@@ -315,10 +314,9 @@ public final class ItmInternalTunnelAddWorker {
         }
     }
 
-    private void createInternalDirectTunnels(TunnelEndPoints srcte, TunnelEndPoints dstte,
-            BigInteger srcDpnId, BigInteger dstDpnId, Class<? extends TunnelTypeBase> tunType,
-            String trunkInterfaceName, String parentInterfaceName) throws ExecutionException, InterruptedException,
-            OperationFailedException {
+    private void createInternalDirectTunnels(TunnelEndPoints srcte, TunnelEndPoints dstte, BigInteger srcDpnId,
+        BigInteger dstDpnId, Class<? extends TunnelTypeBase> tunType, String trunkInterfaceName,
+        String parentInterfaceName) throws ExecutionException, InterruptedException, OperationFailedException {
         IpAddress gatewayIpObj = IpAddressBuilder.getDefaultInstance("0.0.0.0");
         IpAddress gwyIpAddress = Objects.equals(srcte.getSubnetMask(), dstte.getSubnetMask())
                 ? gatewayIpObj : srcte.getGwIpAddress() ;
@@ -365,21 +363,20 @@ public final class ItmInternalTunnelAddWorker {
         ITMBatchingUtils.update(dpnTepsII, dpnTeps, ITMBatchingUtils.EntityType.DEFAULT_CONFIG);
     }
 
-    private List<ListenableFuture<Void>> addTunnelConfiguration(Interface iface) throws ReadFailedException {
+    private void addTunnelConfiguration(Interface iface) throws ReadFailedException {
         // ITM Direct Tunnels This transaction is not being used -- CHECK
-        final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
         ParentRefs parentRefs = iface.augmentation(ParentRefs.class);
         if (parentRefs == null) {
             LOG.warn("ParentRefs for interface: {} Not Found. Creation of Tunnel OF-Port not supported"
                     + " when dpid not provided.", iface.getName());
-            return Collections.emptyList();
+            return;
         }
 
         BigInteger dpId = parentRefs.getDatapathNodeIdentifier();
         if (dpId == null) {
             LOG.warn("dpid for interface: {} Not Found. No DPID provided. Creation of OF-Port not supported.",
                     iface.getName());
-            return Collections.emptyList();
+            return;
         }
 
         LOG.info("adding tunnel configuration for {}", iface.getName());
@@ -396,7 +393,6 @@ public final class ItmInternalTunnelAddWorker {
                             .getOvsBridgeReference().getValue();
             addPortToBridge(bridgeIid, iface, iface.getName());
         }
-        return Collections.singletonList(transaction.submit());
     }
 
     private void addPortToBridge(InstanceIdentifier<?> bridgeIid, Interface iface, String portName) {
index 032964dc3a35b452911558fbb92701401a4350bd..f7f5645074d428a58cb41b55be949ed23bb7ca50 100644 (file)
@@ -8,14 +8,15 @@
 package org.opendaylight.genius.itm.confighelpers;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
 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;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.itm.impl.ItmUtils;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorInterval;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.TunnelMonitorIntervalBuilder;
@@ -30,11 +31,13 @@ public class ItmMonitorIntervalWorker implements Callable<List<ListenableFuture<
     private final DataBroker dataBroker;
     private final String tzone;
     private final Integer interval;
+    private final ManagedNewTransactionRunner txRunner;
 
     public ItmMonitorIntervalWorker(String tzone, Integer interval, DataBroker dataBroker) {
         this.dataBroker = dataBroker;
         this.tzone = tzone;
         this.interval = interval;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
         LOG.debug("ItmMonitorIntervalWorker: monitorInterval = {}",interval);
         LOG.trace("ItmMonitorToggleWorker initialized with  tzone {} and Interval {}",tzone,interval);
     }
@@ -42,30 +45,27 @@ public class ItmMonitorIntervalWorker implements Callable<List<ListenableFuture<
     @Override
     public List<ListenableFuture<Void>> call() {
         LOG.debug("Invoking Tunnel Monitor Worker tzone = {} Interval= {}",tzone,interval);
-        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
-        toggleTunnelMonitoring(transaction);
-        return Collections.singletonList(transaction.submit());
+        return toggleTunnelMonitoring();
     }
 
-    private void toggleTunnelMonitoring(WriteTransaction transaction) {
+    private List<ListenableFuture<Void>> toggleTunnelMonitoring() {
+        List<ListenableFuture<Void>> futures = new ArrayList<>();
         List<String> tunnelList = ItmUtils.getInternalTunnelInterfaces(dataBroker);
         LOG.debug("ItmMonitorIntervalWorker toggleTunnelMonitoring: List of tunnel interfaces: {}" , tunnelList);
         InstanceIdentifier<TunnelMonitorInterval> iid = InstanceIdentifier.builder(TunnelMonitorInterval.class).build();
-        TunnelMonitorInterval intervalBuilder = new TunnelMonitorIntervalBuilder().setInterval(interval).build();
-        ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL,iid, intervalBuilder,
-                dataBroker, ItmUtils.DEFAULT_CALLBACK);
-
-        for (String tunnel : tunnelList) {
-            toggle(tunnel, transaction);
-        }
+        TunnelMonitorInterval monitorInterval = new TunnelMonitorIntervalBuilder().setInterval(interval).build();
+        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.OPERATIONAL,
+            tx -> tx.merge(iid, monitorInterval, true)));
+        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+            tx -> tunnelList.forEach(tunnel -> toggle(tunnel, tx))));
+        return futures;
     }
 
-    private void toggle(String tunnelInterfaceName, WriteTransaction transaction) {
+    private void toggle(String tunnelInterfaceName, TypedWriteTransaction tx) {
         if (tunnelInterfaceName != null) {
             LOG.debug("tunnel {} will have monitor interval {}", tunnelInterfaceName, interval);
-            InstanceIdentifier<IfTunnel> trunkIdentifier = ItmUtils.buildTunnelId(tunnelInterfaceName);
-            IfTunnel tunnel = new IfTunnelBuilder().setMonitorInterval(interval.longValue()).build();
-            transaction.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, tunnel);
+            tx.merge(ItmUtils.buildTunnelId(tunnelInterfaceName),
+                new IfTunnelBuilder().setMonitorInterval(interval.longValue()).build());
         }
     }
 }
index d32a2883f86eb986e60e40a0547cfbf1c04df304..36d77b3e648f29c94bec23ce5b91df99d7600883 100644 (file)
@@ -8,12 +8,14 @@
 package org.opendaylight.genius.itm.confighelpers;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.Callable;
 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;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.itm.impl.ItmUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnelBuilder;
@@ -32,6 +34,7 @@ public class ItmMonitorToggleWorker implements Callable<List<ListenableFuture<Vo
     private final String tzone;
     private final boolean enabled;
     private final Class<? extends TunnelMonitoringTypeBase> monitorProtocol;
+    private final ManagedNewTransactionRunner txRunner;
 
     public ItmMonitorToggleWorker(String tzone, boolean enabled,
             Class<? extends TunnelMonitoringTypeBase> monitorProtocol, DataBroker dataBroker) {
@@ -39,40 +42,39 @@ public class ItmMonitorToggleWorker implements Callable<List<ListenableFuture<Vo
         this.tzone = tzone;
         this.enabled = enabled;
         this.monitorProtocol = monitorProtocol;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
         LOG.trace("ItmMonitorToggleWorker initialized with  tzone {} and toggleBoolean {}",tzone,enabled);
         LOG.debug("TunnelMonitorToggleWorker with monitor protocol = {} ",monitorProtocol);
     }
 
     @Override public List<ListenableFuture<Void>> call() {
         LOG.debug("ItmMonitorToggleWorker invoked with tzone = {} enabled {}",tzone,enabled);
-        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
-        toggleTunnelMonitoring(transaction);
-        return Collections.singletonList(transaction.submit());
+        return toggleTunnelMonitoring();
     }
 
-    private void toggleTunnelMonitoring(WriteTransaction transaction) {
+    private List<ListenableFuture<Void>> toggleTunnelMonitoring() {
         List<String> tunnelList = ItmUtils.getInternalTunnelInterfaces(dataBroker);
         LOG.debug("toggleTunnelMonitoring: TunnelList size {}", tunnelList.size());
         InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.builder(TunnelMonitorParams.class).build();
-        TunnelMonitorParams protocolBuilder = new TunnelMonitorParamsBuilder()
+        TunnelMonitorParams monitorParams = new TunnelMonitorParamsBuilder()
                 .setEnabled(enabled).setMonitorProtocol(monitorProtocol).build();
         LOG.debug("toggleTunnelMonitoring: Updating Operational DS");
-        ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL,iid, protocolBuilder,
-                dataBroker, ItmUtils.DEFAULT_CALLBACK);
-
-        for (String tunnel : tunnelList) {
-            toggle(tunnel, transaction);
-        }
+        List<ListenableFuture<Void>> futures = new ArrayList<>();
+        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.OPERATIONAL,
+            tx -> tx.merge(iid, monitorParams, true)));
+        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+            tx -> tunnelList.forEach(tunnel -> toggle(tunnel, tx))));
+        return futures;
     }
 
-    private void toggle(String tunnelInterfaceName, WriteTransaction transaction) {
+    private void toggle(String tunnelInterfaceName, TypedWriteTransaction<Datastore.Configuration> tx) {
         if (tunnelInterfaceName != null) {
             InstanceIdentifier<IfTunnel> trunkIdentifier = ItmUtils.buildTunnelId(tunnelInterfaceName);
-            LOG.debug("TunnelMonitorToggleWorker: tunnelInterfaceName: {}, monitorProtocol = {},  "
+            LOG.debug("TunnelMonitorToggleWorker: tunnelInterfaceName: {}, monitorProtocol = {}, "
                     + "monitorEnable = {} ",tunnelInterfaceName, monitorProtocol, enabled);
-            IfTunnel tunnel = new IfTunnelBuilder().setMonitorEnabled(enabled)
-                    .setMonitorProtocol(monitorProtocol).build();
-            transaction.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, tunnel);
+            IfTunnel tunnel =
+                    new IfTunnelBuilder().setMonitorEnabled(enabled).setMonitorProtocol(monitorProtocol).build();
+            tx.merge(trunkIdentifier, tunnel);
         }
     }
 }
index 2d5143434cb2e5dd858d773add49af135770f386..f40f16f2fe84f7ff0e2152f5d4548cc2cce7c49d 100644 (file)
@@ -12,16 +12,15 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
-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.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;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.itm.cache.DpnTepStateCache;
 import org.opendaylight.genius.itm.cache.OvsBridgeRefEntryCache;
 import org.opendaylight.genius.itm.itmdirecttunnels.renderer.ovs.utilities.DirectTunnelUtils;
@@ -44,7 +43,6 @@ public class ItmMonitorWorker implements Callable<List<ListenableFuture<Void>>>
 
     private static final Logger LOG = LoggerFactory.getLogger(ItmMonitorWorker.class);
 
-    private final DataBroker dataBroker;
     private final String tzone;
     private final Class<? extends TunnelMonitoringTypeBase> monitorProtocol;
     private final DirectTunnelUtils directTunnelUtils;
@@ -59,7 +57,6 @@ public class ItmMonitorWorker implements Callable<List<ListenableFuture<Void>>>
                                 DirectTunnelUtils directTunnelUtils,
                                 DpnTepStateCache dpnTepStateCache,
                                 OvsBridgeRefEntryCache ovsBridgeRefEntryCache) {
-        this.dataBroker = dataBroker;
         this.tzone = tzone;
         this.monitorProtocol = monitorProtocol;
         this.directTunnelUtils = directTunnelUtils;
@@ -80,44 +77,50 @@ public class ItmMonitorWorker implements Callable<List<ListenableFuture<Void>>>
 
     @Override public List<ListenableFuture<Void>> call() {
         LOG.debug("ItmMonitorWorker invoked with tzone = {} enabled {}", tzone, enabled);
-        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(transaction -> {
-            toggleTunnelMonitoring(transaction);
-        }));
+        List<ListenableFuture<Void>> futures = new ArrayList<>();
+        return toggleTunnelMonitoring(futures);
     }
 
-    private void toggleTunnelMonitoring(WriteTransaction transaction) throws ReadFailedException,
-        InterruptedException, ExecutionException {
-        updateOperationalDS(transaction);
-        Collection<DpnsTeps> dpnsTeps = dpnTepStateCache.getAllPresent();
-        LOG.debug("toggleTunnelMonitoring: DpnsTepsList size {}", dpnsTeps.size());
-        if (dpnsTeps.isEmpty()) {
+    private List<ListenableFuture<Void>> toggleTunnelMonitoring(List<ListenableFuture<Void>> futures) {
+        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.OPERATIONAL,
+            tx -> updateOperationalDS(tx)));
+        Collection<DpnsTeps> dpnsTepsCollection = dpnTepStateCache.getAllPresent();
+        LOG.debug("toggleTunnelMonitoring: DpnsTepsList size {}", dpnsTepsCollection.size());
+        if (dpnsTepsCollection.isEmpty()) {
             LOG.info("There are no teps configured");
         }
         else {
-            for (DpnsTeps dpnTeps : dpnsTeps) {
-                toggleForDirectEnabled(dpnTeps, transaction);
-            }
+            futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+                tx -> {
+                    for (DpnsTeps dpnTeps : dpnsTepsCollection) {
+                        toggleForDirectEnabled(dpnTeps, tx);
+                    }
+                }
+            ));
         }
+        return futures;
     }
 
-    private void updateOperationalDS(WriteTransaction transaction) {
+    private void updateOperationalDS(TypedWriteTransaction<Datastore.Operational> tx) {
         LOG.debug("toggleTunnelMonitoring: Updating Operational DS");
         if (enabled != null) {
             InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.builder(TunnelMonitorParams.class).build();
             TunnelMonitorParams monitorBuilder = new TunnelMonitorParamsBuilder()
                 .setEnabled(enabled).setMonitorProtocol(monitorProtocol).build();
             LOG.debug("toggleTunnelMonitoring: TunnelMonitorParams {}", monitorBuilder);
-            transaction.merge(LogicalDatastoreType.OPERATIONAL, iid, monitorBuilder);
+            tx.merge(iid, monitorBuilder);
         } else if (interval != null) {
             InstanceIdentifier<TunnelMonitorInterval> iid = InstanceIdentifier.builder(TunnelMonitorInterval.class)
                                                                 .build();
             TunnelMonitorInterval intervalBuilder = new TunnelMonitorIntervalBuilder().setInterval(interval).build();
             LOG.debug("updateTunnelMonitorInterval: TunnelMonitorInterval {}", intervalBuilder);
-            transaction.merge(LogicalDatastoreType.OPERATIONAL, iid, intervalBuilder);
+            tx.merge(iid, intervalBuilder);
         }
     }
 
-    private void toggleForDirectEnabled(DpnsTeps dpnTeps, WriteTransaction transaction) throws ReadFailedException {
+
+    private void toggleForDirectEnabled(DpnsTeps dpnTeps, TypedWriteTransaction<Datastore.Configuration> tx)
+            throws ReadFailedException, InterruptedException, ExecutionException {
         List<RemoteDpns> remoteDpnTepNewList = new ArrayList<>();
         RemoteDpns remoteDpnNew = null;
         Optional<OvsBridgeRefEntry> ovsBridgeRefEntry = ovsBridgeRefEntryCache.get(dpnTeps.getSourceDpnId());
@@ -136,16 +139,16 @@ public class ItmMonitorWorker implements Callable<List<ListenableFuture<Void>>>
             LOG.debug("toggleMonitoring: RemoteDpnNew {}", remoteDpnNew);
             directTunnelUtils.updateBfdConfiguration(dpnTeps.getSourceDpnId(), remoteDpnNew, ovsBridgeRefEntry);
         }
-        updateMonitoringDS(dpnTeps.getSourceDpnId(), remoteDpnTepNewList, transaction);
+        updateMonitoringDS(dpnTeps.getSourceDpnId(), remoteDpnTepNewList, tx);
     }
 
     public void updateMonitoringDS(BigInteger sourceDpnId,List<RemoteDpns> remoteDpnTepNewList,
-                                   WriteTransaction transaction) {
+                                   TypedWriteTransaction<Datastore.Configuration> tx) {
         InstanceIdentifier<DpnsTeps> iid = DirectTunnelUtils.createDpnTepsInstanceIdentifier(sourceDpnId);
         DpnsTepsBuilder builder = new DpnsTepsBuilder().withKey(new DpnsTepsKey(sourceDpnId))
             .setRemoteDpns(remoteDpnTepNewList);
         LOG.debug("DirectTunnelUtils - Builder remoteDPNs: {}", builder.getRemoteDpns());
-        transaction.merge(LogicalDatastoreType.CONFIGURATION, iid, builder.build());
+        tx.merge(iid, builder.build());
     }
 
 }
index bb892b303fa818fe53e56a44b8f3e9cc4be00efd..65d9ba14ebf0e27d4c3f11bfef874cb305d7c11b 100644 (file)
@@ -7,18 +7,23 @@
  */
 package org.opendaylight.genius.itm.confighelpers;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
+import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.Callable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache;
+import org.opendaylight.genius.infra.Datastore;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.itm.impl.ItmUtils;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.config.rev160406.ItmConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.dc.gateway.ip.list.DcGatewayIp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,22 +36,20 @@ public class ItmTepAddWorker implements Callable<List<ListenableFuture<Void>>> {
     private final List<DPNTEPsInfo> cfgdDpnList ;
     private final IMdsalApiManager mdsalManager;
     private final List<HwVtep> cfgdHwVteps;
-    private final ItmConfig itmConfig;
     private final ItmInternalTunnelAddWorker itmInternalTunnelAddWorker;
     private final ItmExternalTunnelAddWorker externalTunnelAddWorker;
-    private final DPNTEPsInfoCache dpnTEPsInfoCache;
+    private final ManagedNewTransactionRunner txRunner;
 
     public ItmTepAddWorker(List<DPNTEPsInfo> cfgdDpnList, List<HwVtep> hwVtepList, DataBroker broker,
-            IMdsalApiManager mdsalManager, ItmConfig itmConfig, ItmInternalTunnelAddWorker itmInternalTunnelAddWorker,
-            ItmExternalTunnelAddWorker externalTunnelAddWorker, DPNTEPsInfoCache dpnTEPsInfoCache) {
+                           IMdsalApiManager mdsalManager, ItmInternalTunnelAddWorker itmInternalTunnelAddWorker,
+                           ItmExternalTunnelAddWorker externalTunnelAddWorker) {
         this.cfgdDpnList = cfgdDpnList ;
         this.dataBroker = broker ;
         this.mdsalManager = mdsalManager;
         this.cfgdHwVteps = hwVtepList;
-        this.itmConfig = itmConfig;
         this.itmInternalTunnelAddWorker = itmInternalTunnelAddWorker;
         this.externalTunnelAddWorker = externalTunnelAddWorker;
-        this.dpnTEPsInfoCache = dpnTEPsInfoCache;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
         LOG.trace("ItmTepAddWorker initialized with  DpnList {}",cfgdDpnList);
         LOG.trace("ItmTepAddWorker initialized with  hwvteplist {}",hwVtepList);
     }
@@ -57,20 +60,25 @@ public class ItmTepAddWorker implements Callable<List<ListenableFuture<Void>>> {
         this.meshedDpnList = ItmUtils.getDpnTEPsInfos(dataBroker);
         LOG.debug("Invoking Internal Tunnel build method with Configured DpnList {} ; Meshed DpnList {} ",
                 cfgdDpnList, meshedDpnList);
-        futures.addAll(itmInternalTunnelAddWorker.buildAllTunnels(mdsalManager, cfgdDpnList,
-                meshedDpnList)) ;
+        futures.addAll(itmInternalTunnelAddWorker.buildAllTunnels(mdsalManager, cfgdDpnList, meshedDpnList));
+
         // IF EXTERNAL TUNNELS NEEDS TO BE BUILT, DO IT HERE. IT COULD BE TO DC GATEWAY OR TOR SWITCH
-        List<DcGatewayIp> dcGatewayIpList = ItmUtils.getDcGatewayIpList(dataBroker);
-        if (dcGatewayIpList != null && !dcGatewayIpList.isEmpty()) {
-            for (DcGatewayIp dcGatewayIp : dcGatewayIpList) {
-                futures.addAll(externalTunnelAddWorker.buildTunnelsToExternalEndPoint(cfgdDpnList,
-                        dcGatewayIp.getIpAddress(), dcGatewayIp.getTunnnelType()));
+        futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+            tx -> {
+                Optional<DcGatewayIpList> optional = tx.read(InstanceIdentifier.builder(DcGatewayIpList.class)
+                        .build()).get();
+                if (optional.isPresent()) {
+                    optional.get().getDcGatewayIp().forEach(dcGatewayIp ->
+                        externalTunnelAddWorker.buildTunnelsToExternalEndPoint(cfgdDpnList, dcGatewayIp.getIpAddress(),
+                        dcGatewayIp.getTunnnelType(), tx));
+                }
             }
-        }
+        ));
         //futures.addAll(ItmExternalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker,meshedDpnList, extIp) ;
         LOG.debug("invoking build hwVtepTunnels with hwVteplist {}", cfgdHwVteps);
-        futures.addAll(externalTunnelAddWorker.buildHwVtepsTunnels(cfgdDpnList,cfgdHwVteps));
-        return futures ;
+        futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(Datastore.CONFIGURATION,
+            tx -> externalTunnelAddWorker.buildHwVtepsTunnels(cfgdDpnList, cfgdHwVteps, tx)));
+        return futures;
     }
 
     @Override
index b4bd36f45b1c906255ce737cae3edaa17e38f887..028a5e86bd3c44fa22833ecc9c8960dc0c9612c7 100644 (file)
@@ -7,19 +7,25 @@
  */
 package org.opendaylight.genius.itm.confighelpers;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
+import com.google.common.base.Optional;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.Callable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.genius.infra.Datastore;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache;
-import org.opendaylight.genius.itm.impl.ItmUtils;
 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.dc.gateway.ip.list.DcGatewayIp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -27,25 +33,27 @@ public class ItmTepRemoveWorker implements Callable<List<ListenableFuture<Void>>
 
     private static final Logger LOG = LoggerFactory.getLogger(ItmTepRemoveWorker.class);
 
-    private final DataBroker dataBroker;
     private final List<DPNTEPsInfo> delDpnList ;
-    private Collection<DPNTEPsInfo> meshedDpnList ;
     private final IMdsalApiManager mdsalManager;
     private final List<HwVtep> cfgdHwVteps;
     private final TransportZone originalTZone;
     private final ItmInternalTunnelDeleteWorker itmInternalTunnelDeleteWorker;
     private final DPNTEPsInfoCache dpnTEPsInfoCache;
+    private final ManagedNewTransactionRunner txRunner;
+
+    private Collection<DPNTEPsInfo> meshedDpnList ;
 
     public ItmTepRemoveWorker(List<DPNTEPsInfo> delDpnList, List<HwVtep> delHwList, TransportZone originalTZone,
-            DataBroker broker, IMdsalApiManager mdsalManager,
-            ItmInternalTunnelDeleteWorker itmInternalTunnelDeleteWorker, DPNTEPsInfoCache dpnTEPsInfoCache) {
+                              IMdsalApiManager mdsalManager,
+                              ItmInternalTunnelDeleteWorker itmInternalTunnelDeleteWorker,
+                              DPNTEPsInfoCache dpnTEPsInfoCache, ManagedNewTransactionRunner txRunner) {
         this.delDpnList = delDpnList;
-        this.dataBroker = broker;
         this.mdsalManager = mdsalManager;
         this.cfgdHwVteps = delHwList;
         this.originalTZone = originalTZone;
         this.itmInternalTunnelDeleteWorker = itmInternalTunnelDeleteWorker;
         this.dpnTEPsInfoCache = dpnTEPsInfoCache;
+        this.txRunner = txRunner;
         LOG.trace("ItmTepRemoveWorker initialized with  DpnList {}", delDpnList);
         LOG.trace("ItmTepRemoveWorker initialized with  cfgdHwTeps {}", delHwList);
     }
@@ -54,37 +62,45 @@ public class ItmTepRemoveWorker implements Callable<List<ListenableFuture<Void>>
     public List<ListenableFuture<Void>> call() {
         List<ListenableFuture<Void>> futures = new ArrayList<>() ;
         this.meshedDpnList = dpnTEPsInfoCache.getAllPresent();
-        futures.addAll(itmInternalTunnelDeleteWorker.deleteTunnels(mdsalManager, delDpnList,
-                meshedDpnList));
+        futures.addAll(itmInternalTunnelDeleteWorker.deleteTunnels(mdsalManager, delDpnList, meshedDpnList));
         LOG.debug("Invoking Internal Tunnel delete method with DpnList to be deleted {} ; Meshed DpnList {} ",
                 delDpnList, meshedDpnList);
         // IF EXTERNAL TUNNELS NEEDS TO BE DELETED, DO IT HERE, IT COULD BE TO DC GATEWAY OR TOR SWITCH
-        List<DcGatewayIp> dcGatewayIpList = ItmUtils.getDcGatewayIpList(dataBroker);
-        if (dcGatewayIpList != null && !dcGatewayIpList.isEmpty()) {
-            List<DPNTEPsInfo>  dpnDeleteList = new ArrayList<>();
-            for (DPNTEPsInfo dpnTEPInfo : delDpnList) {
-                List<TunnelEndPoints> tunnelEndPointsList = dpnTEPInfo.nonnullTunnelEndPoints();
-                if (tunnelEndPointsList.size() == 1) {
-                    dpnDeleteList.add(dpnTEPInfo);
-                } else {
-                    LOG.error("DPNTEPInfo not available in data store for dpnId {}. Unable to delete external tunnel "
-                            + "for dpn ", dpnTEPInfo.getDPNID());
+        futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+            tx -> {
+                Optional<DcGatewayIpList> optional = tx.read(InstanceIdentifier.builder(DcGatewayIpList.class)
+                        .build()).get();
+                if (optional.isPresent()) {
+                    List<DcGatewayIp> dcGatewayIpList = optional.get().getDcGatewayIp();
+                    if (dcGatewayIpList != null && !dcGatewayIpList.isEmpty()) {
+                        processExternalTunnelTepDelete(dcGatewayIpList, tx);
+                    }
                 }
             }
-            for (DcGatewayIp dcGatewayIp : dcGatewayIpList) {
-                futures.addAll(ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker,
-                        dpnDeleteList , meshedDpnList, dcGatewayIp.getIpAddress(), dcGatewayIp.getTunnnelType()));
-            }
-        }
-
-        futures.addAll(ItmExternalTunnelDeleteWorker.deleteHwVtepsTunnels(dataBroker, delDpnList,
-                cfgdHwVteps, this.originalTZone));
-        return futures ;
+        ));
+        futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+            tx -> ItmExternalTunnelDeleteWorker.deleteHwVtepsTunnels(delDpnList, cfgdHwVteps, this.originalTZone, tx)));
+        return futures;
     }
 
     @Override
     public String toString() {
-        return "ItmTepRemoveWorker  { "
-                + "Delete Dpn List : " + delDpnList + " }" ;
+        return "ItmTepRemoveWorker  { Delete Dpn List : " + delDpnList + " }" ;
+    }
+
+    private void processExternalTunnelTepDelete(Collection<DcGatewayIp> dcGatewayIpList,
+                                                TypedReadWriteTransaction<Datastore.Configuration> tx) {
+        List<DPNTEPsInfo>  dpnDeleteList = new ArrayList<>();
+        for (DPNTEPsInfo dpnTEPInfo : delDpnList) {
+            List<TunnelEndPoints> tunnelEndPointsList = dpnTEPInfo.nonnullTunnelEndPoints();
+            if (tunnelEndPointsList.size() == 1) {
+                dpnDeleteList.add(dpnTEPInfo);
+            } else {
+                LOG.error("DPNTEPInfo not available in data store for dpnId {}. Unable to delete external tunnel "
+                        + "for dpn ", dpnTEPInfo.getDPNID());
+            }
+        }
+        dcGatewayIpList.forEach(dcGatewayIp -> ItmExternalTunnelDeleteWorker.deleteTunnels(dpnDeleteList,
+            meshedDpnList, dcGatewayIp.getIpAddress(), dcGatewayIp.getTunnnelType(), tx));
     }
 }
index 42c36cd08e9c01184b1ee49149036458262fb2ad..e99359abcb342193fc1de9e9b14539b768c85818 100644 (file)
@@ -13,12 +13,10 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.genius.infra.Datastore;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.opendaylight.genius.itm.impl.ItmUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,30 +24,26 @@ import org.slf4j.LoggerFactory;
 public class ItmTepsNotHostedMoveWorker implements Callable<List<ListenableFuture<Void>>> {
 
     private static final Logger LOG = LoggerFactory.getLogger(ItmTepsNotHostedMoveWorker.class);
+
     private final  List<Vteps> vtepsList;
     private final  String tzName;
-    private final  DataBroker dataBroker;
+    private final ManagedNewTransactionRunner txRunner;
 
-    public ItmTepsNotHostedMoveWorker(List<Vteps> vtepsList, String tzName, DataBroker broker) {
+    public ItmTepsNotHostedMoveWorker(List<Vteps> vtepsList, String tzName, ManagedNewTransactionRunner txRunner) {
         this.vtepsList = vtepsList;
         this.tzName = tzName;
-        this.dataBroker = broker ;
+        this.txRunner = txRunner;
     }
 
     @Override
     public List<ListenableFuture<Void>> call() throws Exception {
-        WriteTransaction wrTx = dataBroker.newWriteOnlyTransaction();
-        List<Subnets> subnetList = new ArrayList<>();
-        IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
-        BigInteger dpnId = BigInteger.valueOf(0);
-
         LOG.trace("Move TEP from TepsNotHosted list to NBI configured TZ task is picked from "
                 + "DataStoreJobCoordinator for execution.");
 
         // Move TEP from TepsNotHosted list to NBI configured TZ.
-        OvsdbTepAddConfigHelper.addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepsList, null /*tepIpAddress*/,
-                tzName, dpnId, ITMConstants.DUMMY_PORT, false, wrTx);
-
-        return Collections.singletonList(wrTx.submit());
+        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore
+            .CONFIGURATION, tx -> OvsdbTepAddConfigHelper.addVtepInITMConfigDS(new ArrayList<>(),
+            ItmUtils.getDummySubnet(), vtepsList, null /*tepIpAddress*/, tzName, BigInteger.ZERO,
+            ITMConstants.DUMMY_PORT, false, tx)));
     }
 }
index 36abb9f30fdb5e10f164c3c6721631a823b42f9d..f97268a5cd47a732c09579d47016b27091e8cd85 100644 (file)
@@ -13,7 +13,8 @@ import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.genius.infra.Datastore;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,23 +27,24 @@ public class ItmTepsNotHostedRemoveWorker implements Callable<List<ListenableFut
     private final String tzName;
     private final BigInteger dpnId;
     private final DataBroker dataBroker;
+    private final ManagedNewTransactionRunner txRunner;
 
-    public ItmTepsNotHostedRemoveWorker(String tzName, IpAddress tepIpAddress, BigInteger dpnId, DataBroker broker) {
+    public ItmTepsNotHostedRemoveWorker(String tzName, IpAddress tepIpAddress, BigInteger dpnId, DataBroker broker,
+                                        ManagedNewTransactionRunner txRunner) {
         this.tepIpAddress = tepIpAddress;
         this.tzName = tzName;
         this.dpnId = dpnId;
-        this.dataBroker = broker ;
+        this.dataBroker = broker;
+        this.txRunner = txRunner;
     }
 
     @Override
     public List<ListenableFuture<Void>> call() throws Exception {
-        WriteTransaction wrTx = dataBroker.newWriteOnlyTransaction();
-
         LOG.trace("Remove TEP from TepsNotHosted list task is picked from DataStoreJobCoordinator for execution.");
 
         // Remove TEP from TepsNotHosted list.
-        OvsdbTepRemoveConfigHelper.removeUnknownTzTepFromTepsNotHosted(tzName, tepIpAddress, dpnId, dataBroker, wrTx);
-
-        return Collections.singletonList(wrTx.submit());
+        return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(Datastore.OPERATIONAL,
+            tx -> OvsdbTepRemoveConfigHelper
+                    .removeUnknownTzTepFromTepsNotHosted(tzName, tepIpAddress, dpnId, dataBroker, tx)));
     }
 }
index bf9421d6a24cec66c9c4bf1d207e2b5ff1b09b12..898812c41af026d509cc90aada070451fcce3010 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collections;
 import java.util.List;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.itm.impl.ITMBatchingUtils;
 import org.opendaylight.genius.itm.impl.ItmUtils;
@@ -32,7 +31,6 @@ public final class ItmTunnelStateAddHelper {
     public static List<ListenableFuture<Void>> addTunnel(Interface iface, IInterfaceManager ifaceManager,
                                                          DataBroker broker) throws Exception {
         LOG.debug("Invoking ItmTunnelStateAddHelper for Interface {} ", iface);
-        final WriteTransaction writeTransaction = broker.newWriteOnlyTransaction();
         StateTunnelListKey tlKey = ItmUtils.getTunnelStateKey(iface);
         LOG.trace("TunnelStateKey: {} for interface: {}", tlKey, iface.getName());
         InstanceIdentifier<StateTunnelList> stListId = ItmUtils.buildStateTunnelListId(tlKey);
@@ -66,8 +64,7 @@ public final class ItmTunnelStateAddHelper {
         } catch (Exception e) {
             LOG.warn("Exception trying to create tunnel state for {}", iface.getName(), e);
         }
-
-        return Collections.singletonList(writeTransaction.submit());
+        return Collections.emptyList();
     }
 
 }
index 987a7a398a0c935a4956c470e25ad80cb7bf7c25..09d1d540cca3148067f982da44d0b722ab719fea 100644 (file)
@@ -10,8 +10,6 @@ package org.opendaylight.genius.itm.confighelpers;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collections;
 import java.util.List;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.genius.itm.impl.ITMBatchingUtils;
 import org.opendaylight.genius.itm.impl.ItmUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
@@ -26,15 +24,12 @@ public final class ItmTunnelStateRemoveHelper {
 
     private ItmTunnelStateRemoveHelper() { }
 
-    public static List<ListenableFuture<Void>> removeTunnel(Interface iface, DataBroker broker) throws Exception {
-        LOG.debug("Invoking ItmTunnelStateRemoveHelper for Interface {} ", iface);
-        WriteTransaction writeTransaction = broker.newWriteOnlyTransaction();
-
+    public static List<ListenableFuture<Void>> removeTunnel(Interface iface) throws Exception {
+        LOG.debug("Invoking removeTunnel for Interface {}", iface);
         StateTunnelListKey tlKey = ItmUtils.getTunnelStateKey(iface);
         InstanceIdentifier<StateTunnelList> stListId = ItmUtils.buildStateTunnelListId(tlKey);
         LOG.trace("Deleting tunnel_state for Id: {}", stListId);
         ITMBatchingUtils.delete(stListId, ITMBatchingUtils.EntityType.DEFAULT_OPERATIONAL);
-
-        return Collections.singletonList(writeTransaction.submit());
+        return Collections.emptyList();
     }
 }
index a3aaa917bd16bdaeafd67d547cfd060c0201e05b..ebdb7c1674d6f55627a9540316680a9dfd6de00b 100644 (file)
@@ -7,13 +7,16 @@
  */
 package org.opendaylight.genius.itm.confighelpers;
 
+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.Objects;
 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;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.opendaylight.genius.itm.impl.ItmUtils;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
@@ -58,11 +61,12 @@ public final class OvsdbTepAddConfigHelper {
      * @param tzName transport zone name in string
      * @param ofTunnel boolean flag for TEP to enable/disable of-tunnel feature on it
      * @param dataBroker data broker handle to perform operations on config/operational datastore
-     * @param wrTx WriteTransaction object
+     * @param txRunner ManagedTransactionRunner object
      */
 
-    public static void addTepReceivedFromOvsdb(String tepIp, String strDpnId, String tzName,
-                                               boolean ofTunnel, DataBroker dataBroker, WriteTransaction wrTx) {
+    public static List<ListenableFuture<Void>> addTepReceivedFromOvsdb(String tepIp, String strDpnId, String tzName,
+        boolean ofTunnel, DataBroker dataBroker, ManagedNewTransactionRunner txRunner) {
+        List<ListenableFuture<Void>> futures = new ArrayList<>();
         BigInteger dpnId = BigInteger.valueOf(0);
 
         if (strDpnId != null && !strDpnId.isEmpty()) {
@@ -81,9 +85,8 @@ public final class OvsdbTepAddConfigHelper {
             if (tzone == null) {
                 // Case: default-TZ is not yet created, then add TEP into "teps-in-not-hosted-transport-zone"
                 LOG.trace("Adding TEP with default TZ into teps-in-not-hosted-transport-zone.");
-                addUnknownTzTepIntoTepsNotHosted(tzName, tepIpAddress, dpnId, ofTunnel,
-                        dataBroker, wrTx);
-                return;
+                return addUnknownTzTepIntoTepsNotHostedAndReturnFutures(tzName, tepIpAddress, dpnId, ofTunnel,
+                    dataBroker, txRunner);
             }
             LOG.trace("Add TEP into default-transport-zone.");
         } else {
@@ -92,74 +95,20 @@ public final class OvsdbTepAddConfigHelper {
             if (tzone == null) {
                 // Case: TZ is not configured from Northbound, then add TEP into "teps-in-not-hosted-transport-zone"
                 LOG.trace("Adding TEP with unknown TZ into teps-in-not-hosted-transport-zone.");
-                addUnknownTzTepIntoTepsNotHosted(tzName, tepIpAddress, dpnId, ofTunnel,
-                    dataBroker, wrTx);
-                return;
+                return addUnknownTzTepIntoTepsNotHostedAndReturnFutures(tzName, tepIpAddress, dpnId, ofTunnel,
+                    dataBroker, txRunner);
             } else {
                 LOG.trace("Add TEP into transport-zone already configured by Northbound.");
             }
         }
 
         // Get subnet list of corresponding TZ created from Northbound.
-        List<Subnets> subnetList = tzone.getSubnets();
-        String portName = ITMConstants.DUMMY_PORT;
-
-        IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
-
-        if (subnetList == null || subnetList.isEmpty()) {
-            if (subnetList == null) {
-                subnetList = new ArrayList<>();
-            }
-            List<Vteps> vtepList = new ArrayList<>();
-            LOG.trace("Add TEP in transport-zone when no subnet-list.");
-            addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName, dpnId,
-                portName, ofTunnel, wrTx);
-        } else {
-            List<Vteps> vtepList = null;
-
-            // subnet list already exists case; check for dummy-subnet
-            for (Subnets subnet : subnetList) {
-                if (subnet.key().getPrefix().equals(subnetMaskObj)) {
-                    LOG.trace("Subnet exists in the subnet list of transport-zone {}.", tzName);
-                    // get vtep list of existing subnet
-                    vtepList = subnet.getVteps();
-                    break;
-                }
-            }
-
-            if (vtepList == null || vtepList.isEmpty()) {
-                //  case: vtep list does not exist or it has no elements
-                if (vtepList == null) {
-                    vtepList = new ArrayList<>();
-                }
-                LOG.trace("Add TEP in transport-zone when no vtep-list for specific subnet.");
-                addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName,
-                    dpnId, portName, ofTunnel, wrTx);
-            } else {
-                //  case: vtep list has elements
-                boolean vtepFound = false;
-                Vteps oldVtep = null;
-
-                for (Vteps vtep : vtepList) {
-                    if (Objects.equals(vtep.getDpnId(), dpnId)) {
-                        vtepFound = true;
-                        oldVtep = vtep;
-                        // get portName of existing vtep
-                        portName = vtep.getPortname();
-                        break;
-                    }
-                }
-                if (!vtepFound) {
-                    addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName,
-                        dpnId, portName, ofTunnel, wrTx);
-                } else {
-                    // vtep is found, update it with tep-ip
-                    vtepList.remove(oldVtep);
-                    addVtepInITMConfigDS(subnetList, subnetMaskObj, vtepList, tepIpAddress, tzName,
-                        dpnId, portName, ofTunnel, wrTx);
-                }
-            }
-        }
+        final List<Subnets> subnetList = tzone.getSubnets();
+        final BigInteger id = dpnId;
+        final String name = tzName;
+        futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+            tx -> addConfig(subnetList, name, id, tepIpAddress, ofTunnel, tx)));
+        return futures;
     }
 
     /**
@@ -174,11 +123,11 @@ public final class OvsdbTepAddConfigHelper {
      * @param dpid bridge datapath ID in BigInteger
      * @param portName port name as a part of VtepsKey
      * @param ofTunnel boolean flag for TEP to enable/disable of-tunnel feature on it
-     * @param wrTx WriteTransaction object
+     * @param tx TypedWriteTransaction object
      */
     public static void addVtepInITMConfigDS(List<Subnets> subnetList, IpPrefix subnetMaskObj,
         List<Vteps> updatedVtepList, IpAddress tepIpAddress, String tzName, BigInteger dpid,
-        String portName, boolean ofTunnel, WriteTransaction wrTx) {
+        String portName, boolean ofTunnel, TypedWriteTransaction<Datastore.Configuration> tx) {
         //Create TZ node path
         InstanceIdentifier<TransportZone> tranzportZonePath =
             InstanceIdentifier.builder(TransportZones.class)
@@ -227,7 +176,7 @@ public final class OvsdbTepAddConfigHelper {
                 .setZoneName(tzName).build();
 
         // Update TZ in Config DS to add vtep in TZ
-        wrTx.merge(LogicalDatastoreType.CONFIGURATION, tranzportZonePath, updatedTzone, true);
+        tx.merge(tranzportZonePath, updatedTzone, true);
     }
 
     /**
@@ -239,18 +188,17 @@ public final class OvsdbTepAddConfigHelper {
      * @param dpid bridge datapath ID in BigInteger
      * @param ofTunnel boolean flag for TEP to enable/disable of-tunnel feature on it
      * @param dataBroker data broker handle to perform operations on operational datastore
-     * @param wrTx WriteTransaction object
+     * @param tx TypedWriteTransaction object
      */
     protected static void addUnknownTzTepIntoTepsNotHosted(String tzName, IpAddress tepIpAddress,
-        BigInteger dpid, boolean ofTunnel, DataBroker dataBroker, WriteTransaction wrTx) {
-        List<UnknownVteps> vtepList = null;
-
+        BigInteger dpid, boolean ofTunnel, DataBroker dataBroker, TypedWriteTransaction<Datastore.Operational> tx) {
+        List<UnknownVteps> vtepList;
         TepsInNotHostedTransportZone tepsInNotHostedTransportZone =
             ItmUtils.getUnknownTransportZoneFromITMOperDS(tzName, dataBroker);
         if (tepsInNotHostedTransportZone == null) {
             LOG.trace("Unhosted TransportZone ({}) does not exist in OperDS.", tzName);
             vtepList = new ArrayList<>();
-            addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, wrTx);
+            addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, tx);
         } else {
             vtepList = tepsInNotHostedTransportZone.getUnknownVteps();
             if (vtepList == null || vtepList.isEmpty()) {
@@ -259,7 +207,7 @@ public final class OvsdbTepAddConfigHelper {
                     vtepList = new ArrayList<>();
                 }
                 LOG.trace("Add TEP into unhosted TZ ({}) when no vtep-list in the TZ.", tzName);
-                addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, wrTx);
+                addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, tx);
             } else {
                 //  case: vtep list has elements
                 boolean vtepFound = false;
@@ -273,13 +221,11 @@ public final class OvsdbTepAddConfigHelper {
                     }
                 }
                 if (!vtepFound) {
-                    addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid,
-                        ofTunnel, wrTx);
+                    addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, tx);
                 } else {
                     // vtep is found, update it with tep-ip
                     vtepList.remove(oldVtep);
-                    addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid,
-                        ofTunnel, wrTx);
+                    addVtepIntoTepsNotHosted(vtepList, tepIpAddress, tzName, dpid, ofTunnel, tx);
                 }
             }
         }
@@ -295,11 +241,11 @@ public final class OvsdbTepAddConfigHelper {
      * @param tzName transport zone name in string
      * @param dpid bridge datapath ID in BigInteger
      * @param ofTunnel boolean flag for TEP to enable/disable of-tunnel feature on it
-     * @param wrTx WriteTransaction object
+     * @param tx TypedWriteTransaction object
      */
     protected static void addVtepIntoTepsNotHosted(List<UnknownVteps> updatedVtepList,
         IpAddress tepIpAddress, String tzName, BigInteger dpid, boolean ofTunnel,
-        WriteTransaction wrTx) {
+        TypedWriteTransaction<Datastore.Operational> tx) {
         //Create TZ node path
         InstanceIdentifier<TepsInNotHostedTransportZone> tepsInNotHostedTransportZoneIid =
             InstanceIdentifier.builder(NotHostedTransportZones.class)
@@ -324,6 +270,70 @@ public final class OvsdbTepAddConfigHelper {
                 + "inside ITM Oper DS.", dpid, tepIpAddress, ofTunnel, tzName);
 
         // Update TZ in Oper DS.
-        wrTx.merge(LogicalDatastoreType.OPERATIONAL, tepsInNotHostedTransportZoneIid, updatedTzone, true);
+        tx.merge(tepsInNotHostedTransportZoneIid, updatedTzone, true);
+    }
+
+    private static void addConfig(List<Subnets> subnets, String tzName, BigInteger dpnId, IpAddress ipAdd,
+                                  boolean ofTunnel, TypedWriteTransaction<Datastore.Configuration> tx) {
+        String portName = ITMConstants.DUMMY_PORT;
+        IpPrefix subnetMask = ItmUtils.getDummySubnet(); // get subnetMaskObject
+
+        if (subnets == null || subnets.isEmpty()) {
+            if (subnets == null) {
+                subnets = new ArrayList<>();
+            }
+            List<Vteps> vtepList = new ArrayList<>();
+            LOG.trace("Add TEP in transport-zone when no subnet-list.");
+            addVtepInITMConfigDS(subnets, subnetMask, vtepList, ipAdd, tzName, dpnId, portName, ofTunnel, tx);
+        } else {
+            List<Vteps> vtepList = null;
+
+            // subnet list already exists case; check for dummy-subnet
+            for (Subnets subnet : subnets) {
+                if (subnet.key().getPrefix().equals(subnetMask)) {
+                    LOG.trace("Subnet exists in the subnet list of transport-zone {}.", tzName);
+                    // get vtep list of existing subnet
+                    vtepList = subnet.getVteps();
+                    break;
+                }
+            }
+
+            if (vtepList == null || vtepList.isEmpty()) {
+                //  case: vtep list does not exist or it has no elements
+                if (vtepList == null) {
+                    vtepList = new ArrayList<>();
+                }
+                LOG.trace("Add TEP in transport-zone when no vtep-list for specific subnet.");
+                addVtepInITMConfigDS(subnets, subnetMask, vtepList, ipAdd, tzName, dpnId, portName, ofTunnel, tx);
+            } else {
+                //  case: vtep list has elements
+                boolean vtepFound = false;
+                Vteps oldVtep = null;
+
+                for (Vteps vtep : vtepList) {
+                    if (Objects.equals(vtep.getDpnId(),dpnId)) {
+                        vtepFound = true;
+                        oldVtep = vtep;
+                        // get portName of existing vtep
+                        portName = vtep.getPortname();
+                        break;
+                    }
+                }
+                if (!vtepFound) {
+                    addVtepInITMConfigDS(subnets, subnetMask, vtepList, ipAdd, tzName, dpnId, portName, ofTunnel, tx);
+                } else {
+                    // vtep is found, update it with tep-ip
+                    vtepList.remove(oldVtep);
+                    addVtepInITMConfigDS(subnets, subnetMask, vtepList, ipAdd, tzName, dpnId, portName, ofTunnel, tx);
+                }
+            }
+        }
+    }
+
+    private static List<ListenableFuture<Void>> addUnknownTzTepIntoTepsNotHostedAndReturnFutures(String tzName,
+        IpAddress tepIpAddress, BigInteger id, boolean ofTunnel, DataBroker dataBroker,
+        ManagedNewTransactionRunner txRunner) {
+        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.OPERATIONAL,
+            tx -> addUnknownTzTepIntoTepsNotHosted(tzName, tepIpAddress, id, ofTunnel, dataBroker, tx)));
     }
 }
index 7dd65e7d899121d62cc46582bf70b7fe5f1b9c40..5d72a38db0b746587260fde5a37ea0b29546800f 100644 (file)
@@ -8,11 +8,11 @@
 package org.opendaylight.genius.itm.confighelpers;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -25,6 +25,7 @@ public class OvsdbTepAddWorker implements Callable<List<ListenableFuture<Void>>>
     private final String tzName;
     private final boolean ofTunnel;
     private final DataBroker dataBroker;
+    private final ManagedNewTransactionRunner txRunner;
 
     public OvsdbTepAddWorker(String tepIp, String strDpnId, String tzName,  boolean ofTunnel, DataBroker broker) {
         this.tepIp = tepIp;
@@ -32,18 +33,13 @@ public class OvsdbTepAddWorker implements Callable<List<ListenableFuture<Void>>>
         this.tzName = tzName;
         this.ofTunnel = ofTunnel;
         this.dataBroker = broker;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
     }
 
     @Override
     public List<ListenableFuture<Void>> call() throws Exception {
-        WriteTransaction wrTx = dataBroker.newWriteOnlyTransaction();
-
         LOG.trace("Add TEP task is picked from DataStoreJobCoordinator for execution.");
-
         // add TEP received from southbound OVSDB into ITM config DS.
-        OvsdbTepAddConfigHelper.addTepReceivedFromOvsdb(tepIp, strDpid, tzName, ofTunnel,
-            dataBroker, wrTx);
-
-        return Collections.singletonList(wrTx.submit());
+        return OvsdbTepAddConfigHelper.addTepReceivedFromOvsdb(tepIp, strDpid, tzName, ofTunnel, dataBroker, txRunner);
     }
 }
index 043eba2c39551c585816e0f054ea9c94696b19bb..13f647f8c11458c53638bead562b48c9840a578a 100644 (file)
@@ -7,12 +7,15 @@
  */
 package org.opendaylight.genius.itm.confighelpers;
 
+import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 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;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.opendaylight.genius.itm.impl.ItmUtils;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
@@ -52,22 +55,22 @@ public final class OvsdbTepRemoveConfigHelper {
      * @param strDpnId bridge datapath ID in string
      * @param tzName transport zone name in string
      * @param dataBroker data broker handle to perform operations on config/operational datastore
-     * @param wrTx WriteTransaction object
+     * @param txRunner ManagedNewTransactionRunner object
      */
 
-    public static void removeTepReceivedFromOvsdb(String tepIp, String strDpnId, String tzName,
-                                                  DataBroker dataBroker, WriteTransaction wrTx) {
-        BigInteger dpnId = BigInteger.valueOf(0);
-
+    public static List<ListenableFuture<Void>> removeTepReceivedFromOvsdb(String tepIp, String strDpnId, String tzName,
+                                                                          DataBroker dataBroker,
+                                                                          ManagedNewTransactionRunner txRunner) {
+        List<ListenableFuture<Void>> futures = new ArrayList<>();
+        BigInteger dpnId = BigInteger.ZERO;
         LOG.trace("Remove TEP: TEP-IP: {}, TZ name: {}, DPID: {}", tepIp, tzName, strDpnId);
 
         if (strDpnId != null && !strDpnId.isEmpty()) {
             dpnId = MDSALUtil.getDpnId(strDpnId);
         }
-
         // Get tep IP
         IpAddress tepIpAddress = IpAddressBuilder.getDefaultInstance(tepIp);
-        TransportZone transportZone = null;
+        TransportZone transportZone;
 
         // Case: TZ name is not given from OVS's other_config parameters.
         if (tzName == null) {
@@ -76,18 +79,21 @@ public final class OvsdbTepRemoveConfigHelper {
             transportZone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
             if (transportZone == null) {
                 LOG.error("Error: default-transport-zone is not yet created.");
-                return;
+                return futures;
             }
             LOG.trace("Remove TEP from default-transport-zone.");
         } else {
             // Case: Add TEP into corresponding TZ created from Northbound.
             transportZone = ItmUtils.getTransportZoneFromConfigDS(tzName, dataBroker);
+            String name = tzName;
+            BigInteger id = dpnId;
             if (transportZone == null) {
                 // Case: TZ is not configured from Northbound, then add TEP into
                 // "teps-in-not-hosted-transport-zone"
                 LOG.trace("Removing TEP from teps-in-not-hosted-transport-zone list.");
-                removeUnknownTzTepFromTepsNotHosted(tzName, tepIpAddress, dpnId, dataBroker, wrTx);
-                return;
+                futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.OPERATIONAL,
+                    tx -> removeUnknownTzTepFromTepsNotHosted(name, tepIpAddress, id, dataBroker, tx)));
+                return futures;
             } else {
                 LOG.trace("Remove TEP from transport-zone already configured by Northbound.");
             }
@@ -135,13 +141,17 @@ public final class OvsdbTepRemoveConfigHelper {
                     LOG.trace("Remove TEP from vtep list in subnet list of transport-zone.");
                     dpnId = oldVtep.getDpnId();
                     String portName = oldVtep.getPortname();
-                    removeVtepFromTZConfig(subnetMaskObj, tzName, dpnId, portName, wrTx);
+                    String name = tzName;
+                    BigInteger id = dpnId;
+                    futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+                        tx -> removeVtepFromTZConfig(subnetMaskObj, name, id, portName, tx)));
                 } else {
                     LOG.trace(
                         "TEP is not found in the vtep list in subnet list of transport-zone. Nothing to do.");
                 }
             }
         }
+        return futures;
     }
 
     /**
@@ -152,10 +162,10 @@ public final class OvsdbTepRemoveConfigHelper {
      * @param dpnId bridge datapath ID in BigInteger
      * @param tzName transport zone name in string
      * @param portName port name as a part of VtepsKey
-     * @param wrTx WriteTransaction object
+     * @param tx TypedWriteTransaction object
      */
     private static void removeVtepFromTZConfig(IpPrefix subnetMaskObj, String tzName, BigInteger dpnId,
-        String portName, WriteTransaction wrTx) {
+        String portName, TypedWriteTransaction<Datastore.Configuration> tx) {
         SubnetsKey subnetsKey = new SubnetsKey(subnetMaskObj);
         VtepsKey vtepkey = new VtepsKey(dpnId, portName);
 
@@ -166,7 +176,7 @@ public final class OvsdbTepRemoveConfigHelper {
         LOG.trace("Removing TEP from (TZ: {} Subnet: {} DPN-ID: {}) inside ITM Config DS.",
                 tzName, subnetMaskObj, dpnId);
         // remove vtep
-        wrTx.delete(LogicalDatastoreType.CONFIGURATION, vtepPath);
+        tx.delete(vtepPath);
     }
 
     /**
@@ -177,13 +187,12 @@ public final class OvsdbTepRemoveConfigHelper {
      * @param tepIpAddress TEP IP address in IpAddress object
      * @param dpnId bridge datapath ID in BigInteger
      * @param dataBroker data broker handle to perform operations on operational datastore
-     * @param wrTx WriteTransaction object
+     * @param tx TypedWriteTransaction object
      */
     public static void removeUnknownTzTepFromTepsNotHosted(String tzName, IpAddress tepIpAddress,
                                                            BigInteger dpnId, DataBroker dataBroker,
-                                                           WriteTransaction wrTx) {
-        List<UnknownVteps> vtepList = null;
-
+                                                           TypedWriteTransaction<Datastore.Operational> tx) {
+        List<UnknownVteps> vtepList;
         TepsInNotHostedTransportZone tepsInNotHostedTransportZone =
             ItmUtils.getUnknownTransportZoneFromITMOperDS(tzName, dataBroker);
         if (tepsInNotHostedTransportZone == null) {
@@ -212,9 +221,9 @@ public final class OvsdbTepRemoveConfigHelper {
                         "Remove TEP with IP ({}) from unhosted TZ ({}) inside not-hosted-transport-zones list.",
                         tepIpAddress, tzName);
                     if (vtepList.size() == 1) {
-                        removeTzFromTepsNotHosted(tzName, wrTx);
+                        removeTzFromTepsNotHosted(tzName, tx);
                     } else {
-                        removeVtepFromTepsNotHosted(tzName, dpnId, wrTx);
+                        removeVtepFromTepsNotHosted(tzName, dpnId, tx);
                     }
                     vtepList.remove(foundVtep);
                 }
@@ -228,20 +237,15 @@ public final class OvsdbTepRemoveConfigHelper {
      *
      * @param tzName transport zone name in string
      * @param dpnId bridge datapath ID in BigInteger
-     * @param wrTx WriteTransaction object
+     * @param tx TypedWriteTransaction object
      */
     private static void removeVtepFromTepsNotHosted(String tzName, BigInteger dpnId,
-                                                      WriteTransaction wrTx) {
-
-        UnknownVtepsKey unknownVtepkey = new UnknownVtepsKey(dpnId);
+                                                    TypedWriteTransaction<Datastore.Operational> tx) {
         InstanceIdentifier<UnknownVteps> vtepPath = InstanceIdentifier.builder(NotHostedTransportZones.class)
             .child(TepsInNotHostedTransportZone.class, new TepsInNotHostedTransportZoneKey(tzName))
-            .child(UnknownVteps.class, unknownVtepkey).build();
-
-        LOG.trace("Removing TEP from unhosted (TZ: {}, DPID: {}) inside ITM Oper DS.",
-                tzName, dpnId);
-        // remove vtep
-        wrTx.delete(LogicalDatastoreType.OPERATIONAL, vtepPath);
+            .child(UnknownVteps.class, new UnknownVtepsKey(dpnId)).build();
+        LOG.trace("Removing TEP from unhosted (TZ: {}, DPID: {}) inside ITM Oper DS.", tzName, dpnId);
+        tx.delete(vtepPath);
     }
 
     /**
@@ -249,16 +253,13 @@ public final class OvsdbTepRemoveConfigHelper {
      * from ITM operational Datastore by delete operation with write transaction.
      *
      * @param tzName transport zone name in string
-     * @param wrTx WriteTransaction object
+     * @param tx TypedWriteTransaction object
      */
-    private static void removeTzFromTepsNotHosted(String tzName, WriteTransaction wrTx) {
+    private static void removeTzFromTepsNotHosted(String tzName, TypedWriteTransaction<Datastore.Operational> tx) {
         InstanceIdentifier<TepsInNotHostedTransportZone> tepsInNotHostedTransportZoneIid =
-                InstanceIdentifier.builder(NotHostedTransportZones.class)
-                .child(TepsInNotHostedTransportZone.class,
+            InstanceIdentifier.builder(NotHostedTransportZones.class).child(TepsInNotHostedTransportZone.class,
                     new TepsInNotHostedTransportZoneKey(tzName)).build();
-
         LOG.trace("Removing TZ ({})from not-hosted-transport-zones list inside ITM Oper DS.", tzName);
-        // remove TZ from TepsNotHosted list
-        wrTx.delete(LogicalDatastoreType.OPERATIONAL, tepsInNotHostedTransportZoneIid);
+        tx.delete(tepsInNotHostedTransportZoneIid);
     }
 }
index 883182a7e3a45a213f84db139ce6d3bb36abc7bd..d886e084938c42f49ec4df20b07c81a7c721285a 100644 (file)
@@ -8,11 +8,11 @@
 package org.opendaylight.genius.itm.confighelpers;
 
 import com.google.common.util.concurrent.ListenableFuture;
-import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.Callable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -24,23 +24,22 @@ public class OvsdbTepRemoveWorker implements Callable<List<ListenableFuture<Void
     private final String strDpid;
     private final String tzName;
     private final DataBroker dataBroker;
+    private final ManagedNewTransactionRunner txRunner;
 
     public OvsdbTepRemoveWorker(String tepIp, String strDpid, String tzName, DataBroker broker) {
         this.tepIp = tepIp;
         this.strDpid = strDpid;
         this.tzName = tzName;
-        this.dataBroker = broker ;
+        this.dataBroker = broker;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
     }
 
     @Override
     public List<ListenableFuture<Void>> call() throws Exception {
-        WriteTransaction wrTx = dataBroker.newWriteOnlyTransaction();
 
         LOG.trace("Remove TEP task is picked from DataStoreJobCoordinator for execution.");
 
         // remove TEP received from southbound OVSDB from ITM config DS.
-        OvsdbTepRemoveConfigHelper.removeTepReceivedFromOvsdb(tepIp, strDpid, tzName, dataBroker, wrTx);
-
-        return Collections.singletonList(wrTx.submit());
+        return OvsdbTepRemoveConfigHelper.removeTepReceivedFromOvsdb(tepIp, strDpid, tzName, dataBroker, txRunner);
     }
 }
index a64e9a2fe45b2ed58e996440156c151db34527c6..fbdecde2bbe376603df3a0e7b9a9af00c0770ec8 100644 (file)
@@ -128,10 +128,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tun
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.state.tunnel.list.DstInfoBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.state.tunnel.list.SrcInfoBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.NotHostedTransportZones;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.TransportZones;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.dc.gateway.ip.list.DcGatewayIp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZoneKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
@@ -174,7 +172,7 @@ public final class ItmUtils {
     private ItmUtils() {
     }
 
-    public static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
+    public static final FutureCallback<Void> DEFAULT_WRITE_CALLBACK = new FutureCallback<Void>() {
         @Override
         public void onSuccess(Void result) {
             LOG.debug("Success in Datastore write operation");
@@ -1130,20 +1128,6 @@ public final class ItmUtils {
         return result;
     }
 
-    public static List<DcGatewayIp> getDcGatewayIpList(DataBroker broker) {
-        InstanceIdentifier<DcGatewayIpList> dcGatewayIpListid =
-                InstanceIdentifier.builder(DcGatewayIpList.class).build();
-        Optional<DcGatewayIpList> dcGatewayIpListConfig =
-                ItmUtils.read(LogicalDatastoreType.CONFIGURATION, dcGatewayIpListid, broker);
-        if (dcGatewayIpListConfig.isPresent()) {
-            DcGatewayIpList containerList = dcGatewayIpListConfig.get();
-            if (containerList != null) {
-                return containerList.getDcGatewayIp();
-            }
-        }
-        return null;
-    }
-
     public static boolean falseIfNull(Boolean value) {
         return value == null ? false : value;
     }
@@ -1413,8 +1397,7 @@ public final class ItmUtils {
     }
 
     public static InstanceIdentifier<StateTunnelList> buildStateTunnelListId(StateTunnelListKey tlKey) {
-        return InstanceIdentifier.builder(TunnelsState.class)
-                .child(StateTunnelList.class, tlKey).build();
+        return InstanceIdentifier.builder(TunnelsState.class).child(StateTunnelList.class, tlKey).build();
     }
 
     @Nonnull
index 3204bb5ed62ded93710666ff89d502654242bbe3..da384c2eca19c694af30318d86148ea14dd7bca1 100644 (file)
@@ -17,8 +17,8 @@ import javax.annotation.Nonnull;
 import javax.inject.Inject;
 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.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.itm.cache.TunnelStateCache;
 import org.opendaylight.genius.itm.cache.UnprocessedTunnelsStateCache;
@@ -87,7 +87,7 @@ public class InterfaceStateListener extends AbstractSyncDataTreeChangeListener<I
         if (ItmUtils.isItmIfType(iface.getType())) {
             LOG.debug("Tunnel interface deleted: {}", iface.getName());
             jobCoordinator.enqueueJob(ITMConstants.ITM_PREFIX + iface.getName(),
-                () -> ItmTunnelStateRemoveHelper.removeTunnel(iface, dataBroker));
+                () -> ItmTunnelStateRemoveHelper.removeTunnel(iface));
             if (tunnelAggregationHelper.isTunnelAggregationEnabled()) {
                 tunnelAggregationHelper.updateLogicalTunnelState(iface, ItmTunnelAggregationHelper.DEL_TUNNEL,
                                                                  dataBroker);
@@ -119,40 +119,41 @@ public class InterfaceStateListener extends AbstractSyncDataTreeChangeListener<I
 
     private List<ListenableFuture<Void>> updateTunnel(Interface updated) throws Exception {
         LOG.debug("Invoking ItmTunnelStateUpdateHelper for Interface {} ", updated);
-        final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
-
         StateTunnelListKey tlKey = ItmUtils.getTunnelStateKey(updated);
         LOG.trace("TunnelStateKey: {} for interface: {}", tlKey, updated.getName());
-        InstanceIdentifier<StateTunnelList> stListId = ItmUtils.buildStateTunnelListId(tlKey);
-        Optional<StateTunnelList> tunnelsState = tunnelStateCache.get(stListId);
         StateTunnelListBuilder stlBuilder;
         TunnelOperStatus tunnelOperStatus;
-        boolean tunnelState = OperStatus.Up.equals(updated.getOperStatus());
-        switch (updated.getOperStatus()) {
-            case Up:
-                tunnelOperStatus = TunnelOperStatus.Up;
-                break;
-            case Down:
-                tunnelOperStatus = TunnelOperStatus.Down;
-                break;
-            case Unknown:
-                tunnelOperStatus = TunnelOperStatus.Unknown;
-                break;
-            default:
-                tunnelOperStatus = TunnelOperStatus.Ignore;
-        }
-        if (tunnelsState.isPresent()) {
-            stlBuilder = new StateTunnelListBuilder(tunnelsState.get());
-            stlBuilder.setTunnelState(tunnelState);
-            stlBuilder.setOperState(tunnelOperStatus);
-            StateTunnelList stList = stlBuilder.build();
-            LOG.trace("Batching the updation of tunnel_state: {} for Id: {}", stList, stListId);
-            ITMBatchingUtils.update(stListId, stList, ITMBatchingUtils.EntityType.DEFAULT_OPERATIONAL);
-        } else {
-            LOG.debug("Tunnel is not yet added but an update has come in for {},so cache it",updated.getName());
-            unprocessedTunnelsStateCache.add(updated.getName(),tunnelOperStatus);
+        try {
+            InstanceIdentifier<StateTunnelList> stListId = ItmUtils.buildStateTunnelListId(tlKey);
+            Optional<StateTunnelList> tunnelsState = tunnelStateCache.get(stListId);
+            boolean tunnelState = OperStatus.Up.equals(updated.getOperStatus());
+            switch (updated.getOperStatus()) {
+                case Up:
+                    tunnelOperStatus = TunnelOperStatus.Up;
+                    break;
+                case Down:
+                    tunnelOperStatus = TunnelOperStatus.Down;
+                    break;
+                case Unknown:
+                    tunnelOperStatus = TunnelOperStatus.Unknown;
+                    break;
+                default:
+                    tunnelOperStatus = TunnelOperStatus.Ignore;
+            }
+            if (tunnelsState.isPresent()) {
+                stlBuilder = new StateTunnelListBuilder(tunnelsState.get());
+                stlBuilder.setTunnelState(tunnelState);
+                stlBuilder.setOperState(tunnelOperStatus);
+                StateTunnelList stList = stlBuilder.build();
+                LOG.trace("Batching the updation of tunnel_state: {} for Id: {}", stList, stListId);
+                ITMBatchingUtils.update(stListId, stList, ITMBatchingUtils.EntityType.DEFAULT_OPERATIONAL);
+            } else {
+                LOG.debug("Tunnel is not yet added but an update has come in for {},so cache it", updated.getName());
+                unprocessedTunnelsStateCache.add(updated.getName(), tunnelOperStatus);
+            }
+        } catch (ReadFailedException e) {
+            LOG.debug("TunnelState cache returned with error while processing {}", updated.getName());
         }
-
-        return Collections.singletonList(writeTransaction.submit());
+        return Collections.emptyList();
     }
 }
index 879c2af53f5f192264c9ef301ce44780673f332e..89f7e881a517ff99ddbf78bf021b1e23e2c93b36 100644 (file)
@@ -9,7 +9,7 @@
 package org.opendaylight.genius.itm.listeners;
 
 import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -22,9 +22,10 @@ import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 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.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache;
 import org.opendaylight.genius.itm.cache.DpnTepStateCache;
@@ -92,6 +93,7 @@ public class TransportZoneListener extends AbstractSyncDataTreeChangeListener<Tr
     private final ItmInternalTunnelAddWorker itmInternalTunnelAddWorker;
     private final ItmExternalTunnelAddWorker externalTunnelAddWorker;
     private final DPNTEPsInfoCache dpnTEPsInfoCache;
+    private final ManagedNewTransactionRunner txRunner;
 
     @Inject
     public TransportZoneListener(final DataBroker dataBroker,
@@ -109,16 +111,17 @@ public class TransportZoneListener extends AbstractSyncDataTreeChangeListener<Tr
               InstanceIdentifier.create(TransportZones.class).child(TransportZone.class));
         this.dataBroker = dataBroker;
         this.jobCoordinator = jobCoordinator;
-        initializeTZNode(dataBroker);
         this.mdsalManager = mdsalManager;
         this.itmConfig = itmConfig;
         this.dpnTEPsInfoCache = dpnTEPsInfoCache;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
+        initializeTZNode();
         this.itmInternalTunnelDeleteWorker = new ItmInternalTunnelDeleteWorker(dataBroker, jobCoordinator,
                 tunnelMonitoringConfig, interfaceManager, dpnTepStateCache, ovsBridgeEntryCache,
                 ovsBridgeRefEntryCache, tunnelStateCache, directTunnelUtils);
         this.itmInternalTunnelAddWorker = new ItmInternalTunnelAddWorker(dataBroker, jobCoordinator,
                 tunnelMonitoringConfig, itmConfig, directTunnelUtils, interfaceManager, ovsBridgeRefEntryCache);
-        this.externalTunnelAddWorker = new ItmExternalTunnelAddWorker(dataBroker, itmConfig, dpnTEPsInfoCache);
+        this.externalTunnelAddWorker = new ItmExternalTunnelAddWorker(itmConfig, dpnTEPsInfoCache);
         serviceRecoveryRegistry.addRecoverableListener(ItmServiceRecoveryHandler.getServiceRegistryKey(), this);
     }
 
@@ -133,22 +136,17 @@ public class TransportZoneListener extends AbstractSyncDataTreeChangeListener<Tr
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
-    private void initializeTZNode(DataBroker db) {
-        ReadWriteTransaction transaction = db.newReadWriteTransaction();
+    private void initializeTZNode() {
         InstanceIdentifier<TransportZones> path = InstanceIdentifier.create(TransportZones.class);
-        CheckedFuture<Optional<TransportZones>, ReadFailedException> tzones = transaction
-                .read(LogicalDatastoreType.CONFIGURATION, path);
-        try {
-            if (!tzones.get().isPresent()) {
-                TransportZonesBuilder tzb = new TransportZonesBuilder();
-                transaction.put(LogicalDatastoreType.CONFIGURATION, path, tzb.build());
-                transaction.submit();
-            } else {
-                transaction.cancel();
+        txRunner.callWithNewReadWriteTransactionAndSubmit(Datastore.CONFIGURATION,
+            tx -> {
+                FluentFuture<Optional<TransportZones>> tzones = tx.read(path);
+                if (!tzones.get().isPresent()) {
+                    TransportZonesBuilder tzb = new TransportZonesBuilder();
+                    tx.put(path, tzb.build());
+                }
             }
-        } catch (Exception e) {
-            LOG.error("Error initializing TransportZones {}", e);
-        }
+        ).isDone();
     }
 
     @Override
@@ -186,8 +184,8 @@ public class TransportZoneListener extends AbstractSyncDataTreeChangeListener<Tr
             if (!opDpnList.isEmpty() || !hwVtepList.isEmpty()) {
                 LOG.trace("Delete: Invoking ItmManager with hwVtep List {} ", hwVtepList);
                 jobCoordinator.enqueueJob(transportZone.getZoneName(),
-                        new ItmTepRemoveWorker(opDpnList, hwVtepList, transportZone, dataBroker, mdsalManager,
-                                itmInternalTunnelDeleteWorker, dpnTEPsInfoCache));
+                    new ItmTepRemoveWorker(opDpnList, hwVtepList, transportZone, mdsalManager,
+                        itmInternalTunnelDeleteWorker, dpnTEPsInfoCache, txRunner));
             }
         }
     }
@@ -218,14 +216,14 @@ public class TransportZoneListener extends AbstractSyncDataTreeChangeListener<Tr
         if (!newDpnTepsList.isEmpty()) {
             LOG.trace("Adding TEPs ");
             jobCoordinator.enqueueJob(updatedTransportZone.getZoneName(),
-                    new ItmTepAddWorker(newDpnTepsList, Collections.emptyList(), dataBroker, mdsalManager, itmConfig,
-                            itmInternalTunnelAddWorker, externalTunnelAddWorker, dpnTEPsInfoCache));
+                    new ItmTepAddWorker(newDpnTepsList, Collections.emptyList(), dataBroker, mdsalManager,
+                            itmInternalTunnelAddWorker, externalTunnelAddWorker));
         }
         if (!oldDpnTepsList.isEmpty()) {
             LOG.trace("Removing TEPs ");
             jobCoordinator.enqueueJob(updatedTransportZone.getZoneName(),
-                    new ItmTepRemoveWorker(oldDpnTepsList, Collections.emptyList(), originalTransportZone, dataBroker,
-                            mdsalManager, itmInternalTunnelDeleteWorker, dpnTEPsInfoCache));
+                new ItmTepRemoveWorker(oldDpnTepsList, Collections.emptyList(), originalTransportZone, mdsalManager,
+                    itmInternalTunnelDeleteWorker, dpnTEPsInfoCache, txRunner));
         }
         List<HwVtep> oldHwList = createhWVteps(originalTransportZone);
         List<HwVtep> newHwList = createhWVteps(updatedTransportZone);
@@ -245,14 +243,13 @@ public class TransportZoneListener extends AbstractSyncDataTreeChangeListener<Tr
         if (!newHwList.isEmpty()) {
             LOG.trace("Adding HW TEPs ");
             jobCoordinator.enqueueJob(updatedTransportZone.getZoneName(), new ItmTepAddWorker(Collections.emptyList(),
-                    newHwList, dataBroker, mdsalManager, itmConfig, itmInternalTunnelAddWorker, externalTunnelAddWorker,
-                    dpnTEPsInfoCache));
+                    newHwList, dataBroker, mdsalManager, itmInternalTunnelAddWorker, externalTunnelAddWorker));
         }
         if (!oldHwList.isEmpty()) {
             LOG.trace("Removing HW TEPs ");
-            jobCoordinator.enqueueJob(updatedTransportZone.getZoneName(), new ItmTepRemoveWorker(
-                    Collections.emptyList(), oldHwList, originalTransportZone, dataBroker, mdsalManager,
-                    itmInternalTunnelDeleteWorker, dpnTEPsInfoCache));
+            jobCoordinator.enqueueJob(updatedTransportZone.getZoneName(),
+                new ItmTepRemoveWorker(Collections.emptyList(), oldHwList, originalTransportZone, mdsalManager,
+                    itmInternalTunnelDeleteWorker, dpnTEPsInfoCache, txRunner));
         }
     }
 
@@ -267,8 +264,8 @@ public class TransportZoneListener extends AbstractSyncDataTreeChangeListener<Tr
             LOG.trace("Add: Invoking ItmManager with DPN List {} ", opDpnList);
             LOG.trace("Add: Invoking ItmManager with hwVtep List {} ", hwVtepList);
             jobCoordinator.enqueueJob(transportZone.getZoneName(),
-                    new ItmTepAddWorker(opDpnList, hwVtepList, dataBroker, mdsalManager, itmConfig,
-                            itmInternalTunnelAddWorker, externalTunnelAddWorker, dpnTEPsInfoCache));
+                new ItmTepAddWorker(opDpnList, hwVtepList, dataBroker, mdsalManager, itmInternalTunnelAddWorker,
+                        externalTunnelAddWorker));
         }
     }
 
@@ -322,17 +319,14 @@ public class TransportZoneListener extends AbstractSyncDataTreeChangeListener<Tr
 
                 // Enqueue 'remove TEP from TepsNotHosted list' operation
                 // into DataStoreJobCoordinator
-                ItmTepsNotHostedRemoveWorker
-                    removeWorker = new ItmTepsNotHostedRemoveWorker(newZoneName, ipAddress, dpnID, dataBroker);
-                jobCoordinator.enqueueJob(newZoneName, removeWorker);
+                jobCoordinator.enqueueJob(newZoneName,
+                    new ItmTepsNotHostedRemoveWorker(newZoneName, ipAddress, dpnID, dataBroker, txRunner));
             }
         }
 
         // Enqueue 'add TEP received from southbound OVSDB into ITM config DS' operation
         // into DataStoreJobCoordinator
-        ItmTepsNotHostedMoveWorker
-            moveWorker = new ItmTepsNotHostedMoveWorker(vtepsList, newZoneName, dataBroker);
-        jobCoordinator.enqueueJob(newZoneName, moveWorker);
+        jobCoordinator.enqueueJob(newZoneName, new ItmTepsNotHostedMoveWorker(vtepsList, newZoneName, txRunner));
 
         if (mapNotHostedDPNToTunnelEndpt.size() > 0) {
             for (Entry<BigInteger, List<TunnelEndPoints>> entry: mapNotHostedDPNToTunnelEndpt.entrySet()) {
index ffb20e0ff96338e2c1bc065f11a00168b4d3d7e8..524aa45b3deb2f088219ee6fa156917e806b3a22 100644 (file)
@@ -13,6 +13,8 @@ import javax.inject.Inject;
 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.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.itm.cache.DpnTepStateCache;
 import org.opendaylight.genius.itm.cache.OvsBridgeRefEntryCache;
@@ -40,6 +42,7 @@ public class TunnelMonitorIntervalListener extends AbstractSyncDataTreeChangeLis
     private final IInterfaceManager interfaceManager;
     private final DpnTepStateCache dpnTepStateCache;
     private final OvsBridgeRefEntryCache ovsBridgeRefEntryCache;
+    private final ManagedNewTransactionRunner txRunner;
 
     @Inject
     public TunnelMonitorIntervalListener(DataBroker dataBroker, JobCoordinator jobCoordinator,
@@ -54,6 +57,7 @@ public class TunnelMonitorIntervalListener extends AbstractSyncDataTreeChangeLis
         this.dpnTepStateCache = dpnTepStateCache;
         this.interfaceManager = interfaceManager;
         this.ovsBridgeRefEntryCache = ovsBridgeRefEntryCache;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
     }
 
     @Override
@@ -69,10 +73,9 @@ public class TunnelMonitorIntervalListener extends AbstractSyncDataTreeChangeLis
                 LOG.debug("Remove:Calling TunnelMonitorIntervalWorker with tzone = {} and {}", tzone.getZoneName(),
                           dataObjectModification.getInterval());
                 if (interfaceManager.isItmDirectTunnelsEnabled()) {
-                    ItmMonitorWorker monitorWorker = new ItmMonitorWorker(tzone.getZoneName(),
-                        dataObjectModification.getInterval(),null, broker, directTunnelUtils,
-                        dpnTepStateCache, ovsBridgeRefEntryCache);
-                    jobCoordinator.enqueueJob(tzone.getZoneName(), monitorWorker);
+                    jobCoordinator.enqueueJob(tzone.getZoneName(), new ItmMonitorWorker(tzone.getZoneName(),
+                        dataObjectModification.getInterval(), null, broker, directTunnelUtils, dpnTepStateCache,
+                        ovsBridgeRefEntryCache));
                 } else {
                     ItmMonitorIntervalWorker toggleWorker = new ItmMonitorIntervalWorker(tzone.getZoneName(),
                         dataObjectModification.getInterval(), broker);
index b789c3c7bebf0b23844b485b17b3c2617b342129..a77d6060b8b1686608bee50645f6393211a14311 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.genius.itm.monitoring;
 
 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.Objects;
 import java.util.concurrent.Callable;
@@ -19,8 +19,10 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import javax.management.JMException;
 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;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.itm.cache.UnprocessedTunnelsStateCache;
 import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.opendaylight.genius.itm.impl.ItmUtils;
@@ -43,6 +45,7 @@ public class ItmTunnelEventListener extends AbstractSyncDataTreeChangeListener<S
 
     private final DataBroker broker;
     private final JobCoordinator jobCoordinator;
+    private final ManagedNewTransactionRunner txRunner;
     private JMXAlarmAgent alarmAgent;
     private UnprocessedTunnelsStateCache unprocessedTunnelsStateCache;
 
@@ -53,6 +56,7 @@ public class ItmTunnelEventListener extends AbstractSyncDataTreeChangeListener<S
               InstanceIdentifier.create(TunnelsState.class).child(StateTunnelList.class));
         this.broker = dataBroker;
         this.jobCoordinator = jobCoordinator;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
         this.unprocessedTunnelsStateCache = unprocessedTunnelsStateCache;
         try {
             alarmAgent = new JMXAlarmAgent();
@@ -110,7 +114,8 @@ public class ItmTunnelEventListener extends AbstractSyncDataTreeChangeListener<S
         if (operStatus != null) {
             if (operStatus != stateTunnelList.getOperState()) {
                 jobCoordinator.enqueueJob(stateTunnelList.getTunnelInterfaceName(),
-                        new ItmTunnelStatusOutOfOrderEventWorker(instanceIdentifier, stateTunnelList, operStatus));
+                        new ItmTunnelStatusOutOfOrderEventWorker(instanceIdentifier, stateTunnelList, operStatus,
+                                txRunner));
             } else {
                 LOG.debug("BFD status in unprocessed cache is the same as in DTCN for {} "
                     + "hence no operations ",stateTunnelList.getTunnelInterfaceName());
@@ -337,30 +342,29 @@ public class ItmTunnelEventListener extends AbstractSyncDataTreeChangeListener<S
         }
     }
 
-    private class ItmTunnelStatusOutOfOrderEventWorker implements Callable<List<ListenableFuture<Void>>> {
+    private static class ItmTunnelStatusOutOfOrderEventWorker implements Callable<List<ListenableFuture<Void>>> {
         private InstanceIdentifier<StateTunnelList> identifier;
         private StateTunnelList add;
         private TunnelOperStatus operStatus;
+        private ManagedNewTransactionRunner txRunner;
 
         ItmTunnelStatusOutOfOrderEventWorker(InstanceIdentifier<StateTunnelList> identifier, StateTunnelList add,
-                                             TunnelOperStatus operStatus) {
+                                             TunnelOperStatus operStatus,
+                                             ManagedNewTransactionRunner tx) {
             this.identifier = identifier;
             this.add = add;
             this.operStatus = operStatus;
+            this.txRunner = tx;
         }
 
         @Override
         public List<ListenableFuture<Void>> call() throws Exception {
             // Process any unprocessed interface bfd updates
-            final List<ListenableFuture<Void>> futures = new ArrayList<>();
             LOG.debug(" Tunnel events are processed out order for {} hence updating it from cache",
                     add.getTunnelInterfaceName());
-            WriteTransaction transaction = broker.newWriteOnlyTransaction();
-            StateTunnelListBuilder stlBuilder = new StateTunnelListBuilder(add);
-            stlBuilder.setOperState(operStatus);
-            transaction.merge(LogicalDatastoreType.OPERATIONAL, identifier, stlBuilder.build(), false);
-            futures.add(transaction.submit());
-            return futures;
+            return Collections.singletonList(txRunner
+                .callWithNewWriteOnlyTransactionAndSubmit(Datastore.OPERATIONAL, tx -> tx.merge(identifier,
+                    new StateTunnelListBuilder(add).setOperState(operStatus).build(), false)));
         }
     }
 }
index 78c6d95442195d09213f7cf3910fc649adeb50f4..87996508a500f1221c91145eb8968f5833c064a6 100644 (file)
@@ -17,6 +17,8 @@ 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.listeners.DataTreeEventCallbackRegistrar;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache;
 import org.opendaylight.genius.itm.cache.DpnTepStateCache;
@@ -68,6 +70,7 @@ public class ItmTepInstanceRecoveryHandler implements ServiceRecoveryInterface {
     private final EntityOwnershipUtils entityOwnershipUtils;
     private final IMdsalApiManager imdsalApiManager;
     private final DataTreeEventCallbackRegistrar eventCallbacks;
+    private final ManagedNewTransactionRunner txRunner;
 
     @Inject
     public ItmTepInstanceRecoveryHandler(DataBroker dataBroker,
@@ -90,14 +93,13 @@ public class ItmTepInstanceRecoveryHandler implements ServiceRecoveryInterface {
         this.dpntePsInfoCache = dpntePsInfoCache;
         this.entityOwnershipUtils = entityOwnershipUtils;
         this.eventCallbacks = eventCallbacks;
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
         this.itmInternalTunnelAddWorker = new ItmInternalTunnelAddWorker(dataBroker, jobCoordinator,
                 tunnelMonitoringConfig, itmConfig, directTunnelUtils, interfaceManager, ovsBridgeRefEntryCache);
-        this.itmExternalTunnelAddWorker = new ItmExternalTunnelAddWorker(dataBroker, itmConfig,
-                dpntePsInfoCache);
+        this.itmExternalTunnelAddWorker = new ItmExternalTunnelAddWorker(itmConfig, dpntePsInfoCache);
         this.itmInternalTunnelDeleteWorker = new ItmInternalTunnelDeleteWorker(dataBroker, jobCoordinator,
                 tunnelMonitoringConfig, interfaceManager, dpnTepStateCache, ovsBridgeEntryCache,
-                ovsBridgeRefEntryCache, tunnelStateCache,
-                directTunnelUtils);
+                ovsBridgeRefEntryCache, tunnelStateCache, directTunnelUtils);
         serviceRecoveryRegistry.registerServiceRecoveryRegistry(getServiceRegistryKey(), this);
     }
 
@@ -143,7 +145,7 @@ public class ItmTepInstanceRecoveryHandler implements ServiceRecoveryInterface {
             if (oldTz != null) {
                 LOG.trace("Deleting transportzone {}", tzName);
                 ItmTepRemoveWorker tepRemoveWorker = new ItmTepRemoveWorker(tepsToRecover, null, oldTz,
-                        dataBroker, imdsalApiManager, itmInternalTunnelDeleteWorker, dpntePsInfoCache);
+                    imdsalApiManager, itmInternalTunnelDeleteWorker, dpntePsInfoCache, txRunner);
                 jobCoordinator.enqueueJob(tzName, tepRemoveWorker);
                 AtomicInteger eventCallbackCount = new AtomicInteger(0);
                 AtomicInteger eventRegistrationCount = new AtomicInteger(0);
@@ -180,9 +182,8 @@ public class ItmTepInstanceRecoveryHandler implements ServiceRecoveryInterface {
         eventCallbackCount.incrementAndGet();
         if (eventCallbackCount.intValue() == registeredEventSize || registeredEventSize == 0) {
             LOG.info("Re-creating TEP {}", tzName);
-            ItmTepAddWorker tepAddWorker = new ItmTepAddWorker(tepts, null, dataBroker,
-                    imdsalApiManager, itmConfig, itmInternalTunnelAddWorker, itmExternalTunnelAddWorker,
-                    dpntePsInfoCache);
+            ItmTepAddWorker tepAddWorker = new ItmTepAddWorker(tepts, null, dataBroker, imdsalApiManager,
+                    itmInternalTunnelAddWorker, itmExternalTunnelAddWorker);
             jobCoordinator.enqueueJob(tzName, tepAddWorker);
         } else {
             LOG.trace("{} call back events registered for {} tunnel interfaces",
index e2aca26ed3ef72bc23924fdaa454c9aff2fb6071..2a9aebd33dc0897e2234c60f36487e9cd343f153 100644 (file)
@@ -14,6 +14,7 @@ import static org.opendaylight.yangtools.yang.common.RpcResultBuilder.failed;
 
 import com.google.common.base.Objects;
 import com.google.common.base.Optional;
+import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -26,6 +27,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
 import javax.annotation.PostConstruct;
@@ -33,12 +35,14 @@ import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 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.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
+import org.opendaylight.genius.infra.Datastore;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
 import org.opendaylight.genius.interfacemanager.interfaces.InterfaceManagerService;
 import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache;
@@ -182,6 +186,7 @@ public class ItmManagerRpcService implements ItmRpcService {
     private final OvsBridgeRefEntryCache ovsBridgeRefEntryCache;
     private final DirectTunnelUtils directTunnelUtils;
     private final ManagedNewTransactionRunner txRunner;
+    private final RetryingManagedNewTransactionRunner retryingTxRunner;
 
     @Inject
     public ItmManagerRpcService(final DataBroker dataBroker, final IMdsalApiManager mdsalManager,
@@ -194,7 +199,7 @@ public class ItmManagerRpcService implements ItmRpcService {
         this.dataBroker = dataBroker;
         this.mdsalManager = mdsalManager;
         this.dpnTEPsInfoCache = dpnTEPsInfoCache;
-        this.externalTunnelAddWorker = new ItmExternalTunnelAddWorker(dataBroker, itmConfig, dpnTEPsInfoCache);
+        this.externalTunnelAddWorker = new ItmExternalTunnelAddWorker(itmConfig, dpnTEPsInfoCache);
         this.singleTransactionDataBroker = new SingleTransactionDataBroker(dataBroker);
         this.interfaceManager = interfaceManager;
         this.interfaceManagerService = interfaceManagerService;
@@ -203,6 +208,7 @@ public class ItmManagerRpcService implements ItmRpcService {
         this.ovsBridgeRefEntryCache = ovsBridgeRefEntryCache;
         this.directTunnelUtils = directTunnelUtils;
         this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
+        this.retryingTxRunner = new RetryingManagedNewTransactionRunner(dataBroker);
     }
 
     @PostConstruct
@@ -383,15 +389,16 @@ public class ItmManagerRpcService implements ItmRpcService {
         //Ignore the Futures for now
         final SettableFuture<RpcResult<RemoveExternalTunnelEndpointOutput>> result = SettableFuture.create();
         Collection<DPNTEPsInfo> meshedDpnList = dpnTEPsInfoCache.getAllPresent();
-        ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker, meshedDpnList,
-                input.getDestinationIp(), input.getTunnelType());
-        InstanceIdentifier<DcGatewayIp> extPath = InstanceIdentifier.builder(DcGatewayIpList.class)
-                .child(DcGatewayIp.class, new DcGatewayIpKey(input.getDestinationIp())).build();
-        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
-        transaction.delete(LogicalDatastoreType.CONFIGURATION, extPath);
-        ListenableFuture<Void> futureCheck = transaction.submit();
-        Futures.addCallback(futureCheck, new FutureCallback<Void>() {
-
+        FluentFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+            tx -> {
+                ItmExternalTunnelDeleteWorker.deleteTunnels(meshedDpnList, input.getDestinationIp(),
+                    input.getTunnelType(), tx);
+                InstanceIdentifier<DcGatewayIp> extPath = InstanceIdentifier.builder(DcGatewayIpList.class)
+                    .child(DcGatewayIp.class, new DcGatewayIpKey(input.getDestinationIp())).build();
+                tx.delete(extPath);
+            }
+        );
+        future.addCallback(new FutureCallback<Void>() {
             @Override public void onSuccess(Void voidInstance) {
                 result.set(RpcResultBuilder.<RemoveExternalTunnelEndpointOutput>success().build());
             }
@@ -404,7 +411,7 @@ public class ItmManagerRpcService implements ItmRpcService {
                 result.set(RpcResultBuilder.<RemoveExternalTunnelEndpointOutput>failed()
                         .withError(RpcError.ErrorType.APPLICATION, msg, error).build());
             }
-        });
+        }, MoreExecutors.directExecutor());
         return result;
     }
 
@@ -413,10 +420,25 @@ public class ItmManagerRpcService implements ItmRpcService {
             RemoveExternalTunnelFromDpnsInput input) {
         //Ignore the Futures for now
         final SettableFuture<RpcResult<RemoveExternalTunnelFromDpnsOutput>> result = SettableFuture.create();
-        List<DPNTEPsInfo> cfgDpnList = ItmUtils.getDpnTepListFromDpnId(dpnTEPsInfoCache, input.getDpnId()) ;
-        ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker, cfgDpnList,
-                input.getDestinationIp(), input.getTunnelType());
-        result.set(RpcResultBuilder.<RemoveExternalTunnelFromDpnsOutput>success().build());
+        List<DPNTEPsInfo> cfgDpnList = ItmUtils.getDpnTepListFromDpnId(dpnTEPsInfoCache, input.getDpnId());
+        FluentFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+            tx -> ItmExternalTunnelDeleteWorker.deleteTunnels(cfgDpnList, input.getDestinationIp(),
+                input.getTunnelType(), tx));
+
+        future.addCallback(new FutureCallback<Void>() {
+            @Override
+            public void onSuccess(Void voidInstance) {
+                result.set(RpcResultBuilder.<RemoveExternalTunnelFromDpnsOutput>success().build());
+            }
+
+            @Override
+            public void onFailure(Throwable error) {
+                String msg = "Unable to remove external tunnel from DPN";
+                LOG.error("remove ext tunnel failed. {}.", msg, error);
+                result.set(RpcResultBuilder.<RemoveExternalTunnelFromDpnsOutput>failed()
+                        .withError(RpcError.ErrorType.APPLICATION, msg, error).build());
+            }
+        }, MoreExecutors.directExecutor());
         return result;
     }
 
@@ -425,25 +447,26 @@ public class ItmManagerRpcService implements ItmRpcService {
             BuildExternalTunnelFromDpnsInput input) {
         //Ignore the Futures for now
         final SettableFuture<RpcResult<BuildExternalTunnelFromDpnsOutput>> result = SettableFuture.create();
-        List<ListenableFuture<Void>> extTunnelResultList = externalTunnelAddWorker
-            .buildTunnelsFromDpnToExternalEndPoint(input.getDpnId(), input.getDestinationIp(),input.getTunnelType());
-        for (ListenableFuture<Void> extTunnelResult : extTunnelResultList) {
-            Futures.addCallback(extTunnelResult, new FutureCallback<Void>() {
-
-                @Override
-                public void onSuccess(Void voidInstance) {
-                    result.set(RpcResultBuilder.<BuildExternalTunnelFromDpnsOutput>success().build());
-                }
+        FluentFuture<Void> extTunnelResultList =
+            txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                tx -> externalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(input.getDpnId(),
+                    input.getDestinationIp(),input.getTunnelType(), tx));
 
-                @Override
-                public void onFailure(Throwable error) {
-                    String msg = "Unable to create ext tunnel";
-                    LOG.error("create ext tunnel failed. {}.", msg, error);
-                    result.set(RpcResultBuilder.<BuildExternalTunnelFromDpnsOutput>failed()
-                            .withError(RpcError.ErrorType.APPLICATION, msg, error).build());
-                }
-            });
-        }
+        extTunnelResultList.addCallback(new FutureCallback<Void>() {
+
+            @Override
+            public void onSuccess(Void voidInstance) {
+                result.set(RpcResultBuilder.<BuildExternalTunnelFromDpnsOutput>success().build());
+            }
+
+            @Override
+            public void onFailure(Throwable error) {
+                String msg = "Unable to create ext tunnel";
+                LOG.error("create ext tunnel failed. {}.", msg, error);
+                result.set(RpcResultBuilder.<BuildExternalTunnelFromDpnsOutput>failed()
+                        .withError(RpcError.ErrorType.APPLICATION, msg, error).build());
+            }
+        }, MoreExecutors.directExecutor());
         return result;
     }
 
@@ -455,18 +478,20 @@ public class ItmManagerRpcService implements ItmRpcService {
         //Ignore the Futures for now
         final SettableFuture<RpcResult<AddExternalTunnelEndpointOutput>> result = SettableFuture.create();
         Collection<DPNTEPsInfo> meshedDpnList = dpnTEPsInfoCache.getAllPresent();
-        externalTunnelAddWorker.buildTunnelsToExternalEndPoint(meshedDpnList,
-                input.getDestinationIp(), input.getTunnelType());
         InstanceIdentifier<DcGatewayIp> extPath = InstanceIdentifier.builder(DcGatewayIpList.class)
                 .child(DcGatewayIp.class, new DcGatewayIpKey(input.getDestinationIp())).build();
         DcGatewayIp dcGatewayIp =
                 new DcGatewayIpBuilder().setIpAddress(input.getDestinationIp())
                         .setTunnnelType(input.getTunnelType()).build();
-        WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
-        writeTransaction.put(LogicalDatastoreType.CONFIGURATION, extPath,dcGatewayIp, true);
-        ListenableFuture<Void> futureCheck = writeTransaction.submit();
-        Futures.addCallback(futureCheck, new FutureCallback<Void>() {
 
+        FluentFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+            tx -> {
+                externalTunnelAddWorker.buildTunnelsToExternalEndPoint(meshedDpnList, input.getDestinationIp(),
+                        input.getTunnelType(), tx);
+                tx.put(extPath, dcGatewayIp, true);
+            }
+        );
+        future.addCallback(new FutureCallback<Void>() {
             @Override public void onSuccess(Void voidInstance) {
                 result.set(RpcResultBuilder.<AddExternalTunnelEndpointOutput>success().build());
             }
@@ -481,7 +506,7 @@ public class ItmManagerRpcService implements ItmRpcService {
                 result.set(RpcResultBuilder.<AddExternalTunnelEndpointOutput>failed()
                         .withError(RpcError.ErrorType.APPLICATION, msg, error).build());
             }
-        });
+        }, MoreExecutors.directExecutor());
         return result;
     }
 
@@ -699,14 +724,9 @@ public class ItmManagerRpcService implements ItmRpcService {
                             .child(TransportZone.class, new TransportZoneKey(transportZone))
                             .child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey)
                             .build();
-                    WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
-                    //TO DO: add retry if it fails
-
-                    transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
-
-                    ListenableFuture<Void> futureCheck = transaction.submit();
-                    Futures.addCallback(futureCheck, new FutureCallback<Void>() {
-
+                    FluentFuture<Void> future =
+                        retryingTxRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> tx.delete(path));
+                    future.addCallback(new FutureCallback<Void>() {
                         @Override public void onSuccess(Void voidInstance) {
                             result.set(RpcResultBuilder.<DeleteL2GwDeviceOutput>success().build());
                         }
@@ -717,8 +737,7 @@ public class ItmManagerRpcService implements ItmRpcService {
                             result.set(RpcResultBuilder.<DeleteL2GwDeviceOutput>failed()
                                     .withError(RpcError.ErrorType.APPLICATION, msg, error).build());
                         }
-                    });
-
+                    }, MoreExecutors.directExecutor());
                 }
             } else {
                 result.set(RpcResultBuilder.<DeleteL2GwDeviceOutput>failed()
@@ -779,12 +798,11 @@ public class ItmManagerRpcService implements ItmRpcService {
                             .build();
                     DeviceVteps deviceVtep = new DeviceVtepsBuilder().withKey(deviceVtepKey).setIpAddress(hwIp)
                             .setNodeId(nodeId).setTopologyId(input.getTopologyId()).build();
-                    WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
                     //TO DO: add retry if it fails
-                    transaction.put(LogicalDatastoreType.CONFIGURATION, path, deviceVtep, true);
+                    FluentFuture<Void> future = retryingTxRunner
+                        .callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> tx.put(path, deviceVtep, true));
 
-                    ListenableFuture<Void> futureCheck = transaction.submit();
-                    Futures.addCallback(futureCheck, new FutureCallback<Void>() {
+                    future.addCallback(new FutureCallback<Void>() {
 
                         @Override public void onSuccess(Void voidInstance) {
                             result.set(RpcResultBuilder.<AddL2GwDeviceOutput>success().build());
@@ -796,7 +814,7 @@ public class ItmManagerRpcService implements ItmRpcService {
                             result.set(RpcResultBuilder.<AddL2GwDeviceOutput>failed()
                                     .withError(RpcError.ErrorType.APPLICATION, msg, error).build());
                         }
-                    });
+                    }, MoreExecutors.directExecutor());
 
                 }
             } else {
@@ -859,27 +877,26 @@ public class ItmManagerRpcService implements ItmRpcService {
                                 .child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey).build();
                 DeviceVteps deviceVtep = new DeviceVtepsBuilder().withKey(deviceVtepKey).setIpAddress(hwIp)
                         .setNodeId(nodeId.get(0)).setTopologyId(input.getTopologyId()).build();
-                WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
-                //TO DO: add retry if it fails
-                LOG.trace("writing hWvtep{}",deviceVtep);
-                writeTransaction.put(LogicalDatastoreType.CONFIGURATION, path, deviceVtep, true);
-
-                if (nodeId.size() == 2) {
-                    LOG.trace("second node-id {}",nodeId.get(1));
-                    DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, nodeId.get(1));
-                    InstanceIdentifier<DeviceVteps> path2 = InstanceIdentifier.builder(TransportZones.class)
-                            .child(TransportZone.class, new TransportZoneKey(transportZone))
-                            .child(Subnets.class, subnetsKey).child(DeviceVteps.class, deviceVtepKey2).build();
-                    DeviceVteps deviceVtep2 = new DeviceVtepsBuilder().withKey(deviceVtepKey2).setIpAddress(hwIp)
-                            .setNodeId(nodeId.get(1))
-                            .setTopologyId(input.getTopologyId()).build();
-                    //TO DO: add retry if it fails
-                    LOG.trace("writing {}",deviceVtep2);
-                    writeTransaction.put(LogicalDatastoreType.CONFIGURATION, path2, deviceVtep2, true);
-                }
-                ListenableFuture<Void> futureCheck = writeTransaction.submit();
-                Futures.addCallback(futureCheck, new FutureCallback<Void>() {
-
+                LOG.trace("writing hWvtep{}", deviceVtep);
+                FluentFuture<Void> future =
+                    retryingTxRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                        tx -> {
+                            tx.put(path, deviceVtep, true);
+                            if (nodeId.size() == 2) {
+                                LOG.trace("second node-id {}", nodeId.get(1));
+                                DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, nodeId.get(1));
+                                InstanceIdentifier<DeviceVteps> path2 = InstanceIdentifier.builder(TransportZones.class)
+                                        .child(TransportZone.class, new TransportZoneKey(transportZone))
+                                        .child(Subnets.class, subnetsKey)
+                                        .child(DeviceVteps.class, deviceVtepKey2).build();
+                                DeviceVteps deviceVtep2 = new DeviceVtepsBuilder().withKey(deviceVtepKey2)
+                                        .setIpAddress(hwIp).setNodeId(nodeId.get(1))
+                                        .setTopologyId(input.getTopologyId()).build();
+                                LOG.trace("writing {}", deviceVtep2);
+                                tx.put(path2, deviceVtep2, true);
+                            }
+                        });
+                future.addCallback(new FutureCallback<Void>() {
                     @Override
                     public void onSuccess(Void voidInstance) {
                         result.set(RpcResultBuilder.<AddL2GwMlagDeviceOutput>success().build());
@@ -930,27 +947,28 @@ public class ItmManagerRpcService implements ItmRpcService {
                     return result;
                 }
                 SubnetsKey subnetsKey = tzones.getTransportZone().get(0).getSubnets().get(0).key();
-                DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, nodeId.get(0));
-                InstanceIdentifier<DeviceVteps> path =
-                        InstanceIdentifier.builder(TransportZones.class)
-                                .child(TransportZone.class, new TransportZoneKey(transportZone))
-                                .child(Subnets.class, subnetsKey).child(DeviceVteps.class,
-                                deviceVtepKey).build();
-                WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
-                //TO DO: add retry if it fails
-                transaction.delete(LogicalDatastoreType.CONFIGURATION, path);
-
-                DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, nodeId.get(1));
-                InstanceIdentifier<DeviceVteps> path2 =
-                        InstanceIdentifier.builder(TransportZones.class)
-                                .child(TransportZone.class, new TransportZoneKey(transportZone))
-                                .child(Subnets.class, subnetsKey).child(DeviceVteps.class,
-                                deviceVtepKey2).build();
-                //TO DO: add retry if it fails
-                transaction.delete(LogicalDatastoreType.CONFIGURATION, path2);
 
-                ListenableFuture<Void> futureCheck = transaction.submit();
-                Futures.addCallback(futureCheck, new FutureCallback<Void>() {
+                FluentFuture<Void> future =
+                    retryingTxRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                        tx -> {
+                            DeviceVtepsKey deviceVtepKey = new DeviceVtepsKey(hwIp, nodeId.get(0));
+                            InstanceIdentifier<DeviceVteps> path =
+                                    InstanceIdentifier.builder(TransportZones.class)
+                                            .child(TransportZone.class, new TransportZoneKey(transportZone))
+                                            .child(Subnets.class, subnetsKey).child(DeviceVteps.class,
+                                            deviceVtepKey).build();
+                            tx.delete(path);
+                            DeviceVtepsKey deviceVtepKey2 = new DeviceVtepsKey(hwIp, nodeId.get(1));
+                            InstanceIdentifier<DeviceVteps> path2 =
+                                    InstanceIdentifier.builder(TransportZones.class)
+                                            .child(TransportZone.class, new TransportZoneKey(transportZone))
+                                            .child(Subnets.class, subnetsKey).child(DeviceVteps.class,
+                                            deviceVtepKey2).build();
+                            tx.delete(path2);
+                        }
+                    );
+
+                future.addCallback(new FutureCallback<Void>() {
 
                     @Override
                     public void onSuccess(Void voidInstance) {
@@ -965,7 +983,7 @@ public class ItmManagerRpcService implements ItmRpcService {
                                 .withError(RpcError.ErrorType.APPLICATION, msg, error)
                                 .build());
                     }
-                });
+                }, MoreExecutors.directExecutor());
             }
             return result;
         } catch (Exception e) {
@@ -1000,12 +1018,15 @@ public class ItmManagerRpcService implements ItmRpcService {
     public ListenableFuture<RpcResult<IsDcgwPresentOutput>> isDcgwPresent(IsDcgwPresentInput input) {
         RpcResultBuilder<IsDcgwPresentOutput> resultBld = RpcResultBuilder.success();
 
-        List<DcGatewayIp> dcGatewayIpList = ItmUtils.getDcGatewayIpList(dataBroker);
+        List<DcGatewayIp> dcGatewayIpList = new ArrayList<>();
+        txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+            tx -> dcGatewayIpList.addAll(getDcGatewayIpList(tx))).isDone();
+
         String dcgwIpStr = input.getDcgwIp();
         IpAddress dcgwIpAddr = IpAddressBuilder.getDefaultInstance(dcgwIpStr);
         long retVal;
 
-        if (dcGatewayIpList != null && !dcGatewayIpList.isEmpty()
+        if (!dcGatewayIpList.isEmpty()
                 && dcGatewayIpList.stream().anyMatch(gwIp -> Objects.equal(gwIp.getIpAddress(), dcgwIpAddr))) {
             //Match found
             retVal = 1;
@@ -1182,4 +1203,33 @@ public class ItmManagerRpcService implements ItmRpcService {
         }
         return result;
     }
+
+    public static List<DcGatewayIp> getDcGatewayIpList(TypedReadWriteTransaction<Datastore.Configuration> tx)
+            throws ExecutionException, InterruptedException {
+        List<DcGatewayIp> dcGatewayIpList = new ArrayList<>();
+        FluentFuture<Optional<DcGatewayIpList>> future =
+                tx.read(InstanceIdentifier.builder(DcGatewayIpList.class).build());
+        future.addCallback(new FutureCallback<Optional<DcGatewayIpList>>() {
+            @Override
+            public void onSuccess(@Nonnull  Optional<DcGatewayIpList> optional) {
+                try {
+                    Optional<DcGatewayIpList> opt = future.get();
+                    if (opt.isPresent()) {
+                        DcGatewayIpList list = opt.get();
+                        if (list != null) {
+                            dcGatewayIpList.addAll(list.getDcGatewayIp());
+                        }
+                    }
+                } catch (ExecutionException | InterruptedException e) {
+                    LOG.error("DcGateway IpList read failed", e);
+                }
+            }
+
+            @Override
+            public void onFailure(Throwable error) {
+                LOG.error("DcGateway IpList read failed", error);
+            }
+        }, MoreExecutors.directExecutor());
+        return dcGatewayIpList;
+    }
 }
index d9ca45207a0ca17bd0ce47ed73be99a9f80882c2..789369b5407c0614dcf70be9532288ace3cf9144 100644 (file)
@@ -29,6 +29,9 @@ 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.genius.infra.Datastore;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.itm.cache.DPNTEPsInfoCache;
 import org.opendaylight.genius.itm.cache.UnprocessedNodeConnectorEndPointCache;
 import org.opendaylight.genius.itm.confighelpers.HwVtep;
@@ -166,6 +169,8 @@ public class ItmExternalTunnelAddTest {
     @Mock JobCoordinator jobCoordinator;
     @Mock ReadOnlyTransaction mockReadTx;
     @Mock WriteTransaction mockWriteTx;
+    @Mock TypedWriteTransaction<Datastore.Configuration> typedWriteTransaction;
+    @Mock TypedReadWriteTransaction<Datastore.Configuration> typedReadWriteTransaction;
     @Mock IdManagerService idManagerService;
     @Mock ItmConfig itmConfig;
     @Mock EntityOwnershipUtils entityOwnershipUtils;
@@ -189,9 +194,9 @@ public class ItmExternalTunnelAddTest {
         doReturn(Futures.immediateCheckedFuture(tunnelMonitorIntervalOptional))
                 .when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION, tunnelMonitorIntervalIdentifier);
 
-        externalTunnelAddWorker = new ItmExternalTunnelAddWorker(dataBroker, itmConfig,
-            new DPNTEPsInfoCache(dataBroker, new GuavaCacheProvider(new CacheManagersRegistryImpl()),
-                directTunnelUtils, jobCoordinator, unprocessedNodeConnectorEndPointCache));
+        externalTunnelAddWorker = new ItmExternalTunnelAddWorker(itmConfig,
+            new DPNTEPsInfoCache(dataBroker, new GuavaCacheProvider(new CacheManagersRegistryImpl()), directTunnelUtils,
+            jobCoordinator, unprocessedNodeConnectorEndPointCache));
 
     }
 
@@ -299,22 +304,20 @@ public class ItmExternalTunnelAddTest {
 
     @Test
     public void testBuildTunnelsToExternalEndPoint() {
-
-        externalTunnelAddWorker.buildTunnelsToExternalEndPoint(cfgdDpnListVxlan, ipAddress2, tunnelType1);
-
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,interfaceIdentifier,iface,true);
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier,externalTunnel,true);
+        externalTunnelAddWorker
+            .buildTunnelsToExternalEndPoint(cfgdDpnListVxlan, ipAddress2, tunnelType1, typedWriteTransaction);
+        verify(typedWriteTransaction).merge(interfaceIdentifier, iface, true);
+        verify(typedWriteTransaction).merge(externalTunnelIdentifier, externalTunnel, true);
 
     }
 
     @Ignore
     @Test
     public void testBuildTunnelsFromDpnToExternalEndPoint() {
-
-        externalTunnelAddWorker.buildTunnelsFromDpnToExternalEndPoint(bigIntegerList, ipAddress2, tunnelType1);
-
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,interfaceIdentifier,iface,true);
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier,externalTunnel,true);
+        externalTunnelAddWorker
+            .buildTunnelsFromDpnToExternalEndPoint(bigIntegerList, ipAddress2, tunnelType1, typedWriteTransaction);
+        verify(typedWriteTransaction).merge(interfaceIdentifier, iface, true);
+        verify(typedWriteTransaction).merge(externalTunnelIdentifier, externalTunnel, true);
 
     }
 
@@ -398,32 +401,24 @@ public class ItmExternalTunnelAddTest {
                         new ExternalTunnelKey(getExternalTunnelKey(source),
                                 getExternalTunnelKey(destination), tunnelType1));
 
-        Optional<TransportZone> optionalTransportZone = Optional.of(transportZone);
-
-        doReturn(Futures.immediateCheckedFuture(optionalTransportZone)).when(mockReadTx).read(LogicalDatastoreType
-                .CONFIGURATION,transportZoneIdentifier);
-
-        externalTunnelAddWorker.buildHwVtepsTunnels(cfgdDpnListVxlan, null);
-        externalTunnelAddWorker.buildHwVtepsTunnels(null, cfgdHwVtepsList);
-
-        verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,ifIID1,extTunnelIf1,true);
-        verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier1,
-                externalTunnel1, true);
-        verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,ifIID2,hwTunnelIf2,true);
-        verify(mockWriteTx, times(2)).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier2,
-                externalTunnel2, true);
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID3,extTunnelIf3,true);
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier3,
-                externalTunnel3, true);
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID4,hwTunnelIf4,true);
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier4,
-                externalTunnel4, true);
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID5,hwTunnelIf5,true);
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier5,
-                externalTunnel5, true);
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,ifIID6,hwTunnelIf6,true);
-        verify(mockWriteTx).merge(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier6,
-                externalTunnel6, true);
+        doReturn(Futures.immediateCheckedFuture(Optional.of(transportZone))).when(typedReadWriteTransaction)
+            .read(transportZoneIdentifier);
+
+        externalTunnelAddWorker.buildHwVtepsTunnels(cfgdDpnListVxlan, null, typedReadWriteTransaction);
+        externalTunnelAddWorker.buildHwVtepsTunnels(null, cfgdHwVtepsList, typedReadWriteTransaction);
+
+        verify(typedReadWriteTransaction, times(2)).merge(ifIID1, extTunnelIf1, true);
+        verify(typedReadWriteTransaction, times(2)).merge(externalTunnelIdentifier1, externalTunnel1, true);
+        verify(typedReadWriteTransaction, times(2)).merge(ifIID2, hwTunnelIf2, true);
+        verify(typedReadWriteTransaction, times(2)).merge(externalTunnelIdentifier2, externalTunnel2, true);
+        verify(typedReadWriteTransaction).merge(ifIID3,extTunnelIf3,true);
+        verify(typedReadWriteTransaction).merge(externalTunnelIdentifier3, externalTunnel3, true);
+        verify(typedReadWriteTransaction).merge(ifIID4, hwTunnelIf4, true);
+        verify(typedReadWriteTransaction).merge(externalTunnelIdentifier4, externalTunnel4, true);
+        verify(typedReadWriteTransaction).merge(ifIID5, hwTunnelIf5, true);
+        verify(typedReadWriteTransaction).merge(externalTunnelIdentifier5, externalTunnel5, true);
+        verify(typedReadWriteTransaction).merge(ifIID6, hwTunnelIf6, true);
+        verify(typedReadWriteTransaction).merge(externalTunnelIdentifier6, externalTunnel6, true);
 
     }
 
index 170f5547655a8dab021595244680f43a11c890a1..9e20064da3d4b8155eb83afea9b7cffb80dc8e97 100644 (file)
@@ -19,7 +19,9 @@ import com.google.common.util.concurrent.Futures;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import junit.framework.TestCase;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -29,7 +31,9 @@ import org.mockito.runners.MockitoJUnitRunner;
 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.genius.infra.Datastore;
+import org.opendaylight.genius.infra.TypedReadWriteTransaction;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.itm.confighelpers.HwVtep;
 import org.opendaylight.genius.itm.confighelpers.ItmExternalTunnelDeleteWorker;
 import org.opendaylight.genius.itm.globals.ITMConstants;
@@ -142,6 +146,8 @@ public class ItmExternalTunnelDeleteTest {
     @Mock ReadOnlyTransaction mockReadTx;
     @Mock WriteTransaction mockWriteTx;
     @Mock IdManagerService idManagerService;
+    @Mock TypedWriteTransaction<Datastore.Configuration> typedWriteTransaction;
+    @Mock TypedReadWriteTransaction<Datastore.Configuration> typedReadWriteTransaction;
 
     @Before
     public void setUp() {
@@ -259,10 +265,9 @@ public class ItmExternalTunnelDeleteTest {
 
     @Test
     public void testDeleteTunnels() {
-        ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker, dpnTepsList,ipAddress1,tunnelType1);
-
-        verify(mockWriteTx).delete(LogicalDatastoreType.CONFIGURATION,trunkIdentifier);
-        verify(mockWriteTx).delete(LogicalDatastoreType.CONFIGURATION,path);
+        ItmExternalTunnelDeleteWorker.deleteTunnels(dpnTepsList, ipAddress1, tunnelType1, typedWriteTransaction);
+        verify(typedWriteTransaction).delete(trunkIdentifier);
+        verify(typedWriteTransaction).delete(path);
     }
 
     @Test
@@ -292,30 +297,32 @@ public class ItmExternalTunnelDeleteTest {
         Optional<TransportZone> optionalTransportZone = Optional.of(transportZone);
         Optional<ExternalTunnel> exTunnels = Optional.of(externalTunnel);
 
-        doReturn(Futures.immediateCheckedFuture(optionalTransportZone)).when(mockReadTx).read(LogicalDatastoreType
-                .CONFIGURATION,transportZoneIdentifier);
-        doReturn(Futures.immediateCheckedFuture(exTunnels)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
-                externalTunnelIdentifier1);
-        doReturn(Futures.immediateCheckedFuture(exTunnels)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
-                externalTunnelIdentifier2);
-        doReturn(Futures.immediateCheckedFuture(exTunnels)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
-                externalTunnelIdentifier3);
-        doReturn(Futures.immediateCheckedFuture(exTunnels)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
-                externalTunnelIdentifier4);
-        doReturn(Futures.immediateCheckedFuture(exTunnels)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
-                externalTunnelIdentifier5);
-        doReturn(Futures.immediateCheckedFuture(exTunnels)).when(mockReadTx).read(LogicalDatastoreType.CONFIGURATION,
-                externalTunnelIdentifier6);
-
-        ItmExternalTunnelDeleteWorker.deleteHwVtepsTunnels(dataBroker, dpnTepsList, cfgdHwVtepsList,
-                transportZone);
-
-        verify(mockWriteTx).delete(LogicalDatastoreType.CONFIGURATION,trunkIdentifier);
-        verify(mockWriteTx, times(2)).delete(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier1);
-        verify(mockWriteTx, times(2)).delete(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier2);
-        verify(mockWriteTx, times(2)).delete(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier3);
-        verify(mockWriteTx, times(2)).delete(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier4);
-        verify(mockWriteTx).delete(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier5);
-        verify(mockWriteTx).delete(LogicalDatastoreType.CONFIGURATION,externalTunnelIdentifier6);
+        doReturn(Futures.immediateCheckedFuture(optionalTransportZone))
+                .when(typedReadWriteTransaction).read(transportZoneIdentifier);
+        doReturn(Futures.immediateCheckedFuture(exTunnels))
+                .when(typedReadWriteTransaction).read(externalTunnelIdentifier1);
+        doReturn(Futures.immediateCheckedFuture(exTunnels))
+                .when(typedReadWriteTransaction).read(externalTunnelIdentifier2);
+        doReturn(Futures.immediateCheckedFuture(exTunnels)).when(typedReadWriteTransaction)
+                .read(externalTunnelIdentifier3);
+        doReturn(Futures.immediateCheckedFuture(exTunnels)).when(typedReadWriteTransaction)
+                .read(externalTunnelIdentifier4);
+        doReturn(Futures.immediateCheckedFuture(exTunnels)).when(typedReadWriteTransaction)
+                .read(externalTunnelIdentifier5);
+        doReturn(Futures.immediateCheckedFuture(exTunnels)).when(typedReadWriteTransaction)
+                .read(externalTunnelIdentifier6);
+        try {
+            ItmExternalTunnelDeleteWorker
+                    .deleteHwVtepsTunnels(dpnTepsList, cfgdHwVtepsList, transportZone, typedReadWriteTransaction);
+            verify(typedReadWriteTransaction).delete(trunkIdentifier);
+            verify(typedReadWriteTransaction, times(2)).delete(externalTunnelIdentifier1);
+            verify(typedReadWriteTransaction, times(2)).delete(externalTunnelIdentifier2);
+            verify(typedReadWriteTransaction, times(2)).delete(externalTunnelIdentifier3);
+            verify(typedReadWriteTransaction, times(2)).delete(externalTunnelIdentifier4);
+            verify(typedReadWriteTransaction).delete(externalTunnelIdentifier5);
+            verify(typedReadWriteTransaction).delete(externalTunnelIdentifier6);
+        } catch (ExecutionException | InterruptedException e) {
+            TestCase.fail();// Fail in case of an exception
+        }
     }
 }
index 5469bad5b4f4c1d9b4af482f6209874a8f97d08f..23f65d78db49f97546318bbff7405e390e22f8e7 100644 (file)
@@ -17,6 +17,7 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import javax.inject.Inject;
 import org.junit.Before;
@@ -28,6 +29,9 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorEventsWaiter;
 import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorTestModule;
 import org.opendaylight.genius.datastoreutils.testutils.TestableDataTreeChangeListenerModule;
+import org.opendaylight.genius.infra.Datastore;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.itm.impl.ItmUtils;
 import org.opendaylight.genius.itm.rpc.ItmManagerRpcService;
 import org.opendaylight.genius.itm.tests.xtend.ExpectedDeviceVtepsObjects;
@@ -99,6 +103,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.R
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.RemoveExternalTunnelFromDpnsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.RemoveExternalTunnelFromDpnsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.RemoveExternalTunnelFromDpnsOutput;
+import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
@@ -172,9 +177,11 @@ public class ItmManagerRpcServiceTest {
     @Inject DataBroker dataBroker;
     private @Inject JobCoordinatorEventsWaiter coordinatorEventsWaiter;
     @Inject ItmManagerRpcService itmManagerRpcService ;
+    ManagedNewTransactionRunner txRunner;
 
     @Before
     public void setUp() throws Exception {
+        this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
         deviceVteps = new DeviceVtepsBuilder().setIpAddress(ItmTestConstants.IP_ADDRESS_3).withKey(new DeviceVtepsKey(
             ItmTestConstants.IP_ADDRESS_3,ItmTestConstants.SOURCE_DEVICE))
             .setNodeId(ItmTestConstants.SOURCE_DEVICE).setTopologyId(ItmTestConstants.DESTINATION_DEVICE).build();
@@ -273,25 +280,19 @@ public class ItmManagerRpcServiceTest {
                 .setInterfaceName(ItmTestConstants.PARENT_INTERFACE_NAME).build();
 
         // commit external tunnel into config DS
-
-        ItmUtils.syncWrite(LogicalDatastoreType.CONFIGURATION, externalTunnelIdentifier,
-            externalTunnel, dataBroker);
-        ItmUtils.syncWrite(LogicalDatastoreType.CONFIGURATION, externalTunnelIdentifier2,
-            externalTunnel2, dataBroker);
+        syncWrite(externalTunnelIdentifier, externalTunnel);
+        syncWrite(externalTunnelIdentifier2, externalTunnel2);
 
         // commit internal tunnel into config DS
-        ItmUtils.syncWrite(LogicalDatastoreType.CONFIGURATION, internalTunnelIdentifier,
-            internalTunnel, dataBroker);
+        syncWrite(internalTunnelIdentifier, internalTunnel);
 
         // commit dpnEndpoints into config DS
-        ItmUtils.syncWrite(LogicalDatastoreType.CONFIGURATION, dpnEndpointsIdentifier,
-            dpnEndpoints, dataBroker);
+        syncWrite(dpnEndpointsIdentifier, dpnEndpoints);
 
         // wait for completion of ITM config DS default-TZ creation task of DJC
         coordinatorEventsWaiter.awaitEventsConsumption();
         // commit TZ into config DS
-        ItmUtils.syncWrite(LogicalDatastoreType.CONFIGURATION, transportZonesIdentifier,
-            transportZones, dataBroker);
+        syncWrite(transportZonesIdentifier, transportZones);
     }
 
     @Test
@@ -466,4 +467,13 @@ public class ItmManagerRpcServiceTest {
         // check for interfaceName
         assertThat(ItmTestConstants.PARENT_INTERFACE_NAME).isEqualTo(rpcRes.get().getResult().getInterfaceName());
     }
+
+    private <T extends DataObject> void syncWrite(InstanceIdentifier<T> path, T data) {
+        try {
+            txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+                tx -> tx.put(path, data, true)).get();
+        } catch (InterruptedException | ExecutionException e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
 }
index 719898ec78e08db2c44e7c5b618e8fae82f29297..7ba4ccc0683d1cacf46b516cc124583bc5116682 100644 (file)
@@ -7,10 +7,12 @@
  */
 package org.opendaylight.genius.itm.tests;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.mdsal.binding.testutils.AssertDataObjects.assertEqualBeans;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
 import javax.inject.Inject;
 import org.junit.Assert;
 import org.junit.Before;
@@ -102,9 +104,8 @@ public class ItmTepAutoConfigTest {
         ItmConfig itmConfigObj = new ItmConfigBuilder().setDefTzEnabled(false).build();
 
         // write into config DS
-        CheckedFuture<Void, TransactionCommitFailedException> futures =
-            ItmTepAutoConfigTestUtil.writeItmConfig(iid, itmConfigObj, dataBroker);
-        futures.get();
+        txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> tx.put(iid, itmConfigObj, true));
+        Thread.sleep(1000);
 
         // read from config DS
         boolean defTzEnabled = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(
@@ -119,10 +120,8 @@ public class ItmTepAutoConfigTest {
         ItmConfig itmConfigObj = new ItmConfigBuilder().setDefTzEnabled(true).build();
 
         // write into config DS
-        CheckedFuture<Void, TransactionCommitFailedException> futures =
-            ItmTepAutoConfigTestUtil.writeItmConfig(iid, itmConfigObj, dataBroker);
-        futures.get();
-
+        txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> tx.put(iid, itmConfigObj, true));
+        Thread.sleep(1000);
         // read from config DS
         boolean defTzEnabled = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(
             dataBroker, LogicalDatastoreType.CONFIGURATION, iid).get().isDefTzEnabled();
@@ -248,10 +247,10 @@ public class ItmTepAutoConfigTest {
         IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
 
         // add TEP into default-TZ
-        CheckedFuture<Void, TransactionCommitFailedException> futures =
+        ListenableFuture<Void> futures =
             ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.DEF_TZ_TEP_IP,
             ItmTestConstants.DEF_BR_DPID,
-            ITMConstants.DEFAULT_TRANSPORT_ZONE, false, dataBroker);
+            ITMConstants.DEFAULT_TRANSPORT_ZONE, false, dataBroker, txRunner);
         futures.get();
 
         InstanceIdentifier<Vteps> vtepPath = ItmTepAutoConfigTestUtil.getTepIid(subnetMaskObj,
@@ -264,8 +263,8 @@ public class ItmTepAutoConfigTest {
             .read(LogicalDatastoreType.CONFIGURATION, tzonePath).checkedGet().get());
 
         // remove tep from default-TZ
-        futures = ItmTepAutoConfigTestUtil.deleteTep(ItmTestConstants.DEF_TZ_TEP_IP,
-            ItmTestConstants.DEF_BR_DPID, ITMConstants.DEFAULT_TRANSPORT_ZONE, dataBroker);
+        futures = ItmTepAutoConfigTestUtil.deleteTep(ItmTestConstants.DEF_TZ_TEP_IP, ItmTestConstants.DEF_BR_DPID,
+            ITMConstants.DEFAULT_TRANSPORT_ZONE, dataBroker, txRunner);
         futures.get();
 
         // check TEP is deleted from default-TZ
@@ -292,9 +291,8 @@ public class ItmTepAutoConfigTest {
                 .read(LogicalDatastoreType.CONFIGURATION, tzonePath).checkedGet().get().getZoneName());
 
         // add tep
-        CheckedFuture<Void, TransactionCommitFailedException> futures =
-            ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NB_TZ_TEP_IP,
-                ItmTestConstants.DEF_BR_DPID, ItmTestConstants.TZ_NAME, false, dataBroker);
+        ListenableFuture<Void> futures = ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NB_TZ_TEP_IP,
+            ItmTestConstants.DEF_BR_DPID, ItmTestConstants.TZ_NAME, false, dataBroker, txRunner);
         futures.get();
 
         IpPrefix subnetMaskObj = ItmUtils.getDummySubnet();
@@ -309,8 +307,8 @@ public class ItmTepAutoConfigTest {
             .read(LogicalDatastoreType.CONFIGURATION, tzonePath).checkedGet().get());
 
         // remove tep
-        futures = ItmTepAutoConfigTestUtil.deleteTep(ItmTestConstants.NB_TZ_TEP_IP,
-                ItmTestConstants.DEF_BR_DPID, ItmTestConstants.TZ_NAME, dataBroker);
+        futures = ItmTepAutoConfigTestUtil.deleteTep(ItmTestConstants.NB_TZ_TEP_IP, ItmTestConstants.DEF_BR_DPID,
+            ItmTestConstants.TZ_NAME, dataBroker, txRunner);
         futures.get();
 
         // check TEP is deleted
@@ -638,9 +636,8 @@ public class ItmTepAutoConfigTest {
     @Test
     public void tepAddIntoTepsNotHostedListTest() throws Exception {
         // add into not hosted list
-        CheckedFuture<Void, TransactionCommitFailedException> future =
-            ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
-                ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME, false, dataBroker);
+        ListenableFuture<Void> future = ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
+            ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME, false, dataBroker, txRunner);
         future.get();
         InstanceIdentifier<TepsInNotHostedTransportZone> notHostedPath =
             ItmTepAutoConfigTestUtil.getTepNotHostedInTZIid(ItmTestConstants.NOT_HOSTED_TZ_NAME);
@@ -654,9 +651,8 @@ public class ItmTepAutoConfigTest {
     @Test
     public void tepDeleteFromTepsNotHostedListTest() throws Exception {
         // add into not hosted list
-        CheckedFuture<Void, TransactionCommitFailedException> future =
-            ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
-                ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME, false, dataBroker);
+        ListenableFuture<Void> future = ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
+            ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME, false, dataBroker, txRunner);
         future.get();
         InstanceIdentifier<TepsInNotHostedTransportZone> notHostedPath =
             ItmTepAutoConfigTestUtil.getTepNotHostedInTZIid(ItmTestConstants.NOT_HOSTED_TZ_NAME);
@@ -668,7 +664,7 @@ public class ItmTepAutoConfigTest {
 
         //delete from not hosted list
         future = ItmTepAutoConfigTestUtil.deleteTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
-            ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME, dataBroker);
+            ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME, dataBroker, txRunner);
         future.get();
 
         Assert.assertEquals(Optional.absent(),
@@ -679,10 +675,8 @@ public class ItmTepAutoConfigTest {
     @Test
     public void tepMoveFromTepsNotHostedListToTzTest() throws Exception {
         // add into not hosted list
-        CheckedFuture<Void, TransactionCommitFailedException> future =
-            ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
-                ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME, false,
-                dataBroker);
+        ListenableFuture<Void> future = ItmTepAutoConfigTestUtil.addTep(ItmTestConstants.NOT_HOSTED_TZ_TEP_IP,
+            ItmTestConstants.NOT_HOSTED_TZ_TEPDPN_ID, ItmTestConstants.NOT_HOSTED_TZ_NAME, false, dataBroker, txRunner);
         future.get();
         InstanceIdentifier<TepsInNotHostedTransportZone> notHostedPath =
             ItmTepAutoConfigTestUtil.getTepNotHostedInTZIid(ItmTestConstants.NOT_HOSTED_TZ_NAME);
@@ -698,8 +692,8 @@ public class ItmTepAutoConfigTest {
             .withKey(new TransportZoneKey(ItmTestConstants.NOT_HOSTED_TZ_NAME)).build();
         Assert.assertNotNull(transportZoneNorth);
 
-        ItmUtils.syncWrite(LogicalDatastoreType.CONFIGURATION, ItmTepAutoConfigTestUtil
-            .getTzIid(ItmTestConstants.NOT_HOSTED_TZ_NAME), transportZoneNorth, dataBroker);
+        txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> tx.put(ItmTepAutoConfigTestUtil
+                .getTzIid(ItmTestConstants.NOT_HOSTED_TZ_NAME), transportZoneNorth, true)).get();
 
         // wait for TransportZoneListener to perform config DS update
         // for TEP movement through transaction
index 35bc64ee80dc0c5f9d749a4117165a5f98d6ed6e..7b8a6510f555a1f399edc795bd437911ce358d36 100644 (file)
@@ -8,11 +8,13 @@
 package org.opendaylight.genius.itm.tests;
 
 import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.math.BigInteger;
 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.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.itm.confighelpers.OvsdbTepAddConfigHelper;
 import org.opendaylight.genius.itm.confighelpers.OvsdbTepRemoveConfigHelper;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
@@ -34,23 +36,15 @@ public final class ItmTepAutoConfigTestUtil {
     private ItmTepAutoConfigTestUtil() { }
 
     /* transaction methods */
-    public static CheckedFuture<Void, TransactionCommitFailedException> addTep(String tepIp,
-        String strDpnId, String tzName, boolean ofTunnel, DataBroker dataBroker) {
-        WriteTransaction wrTx = dataBroker.newWriteOnlyTransaction();
-
-        // add TEP received from southbound OVSDB into ITM config DS.
-        OvsdbTepAddConfigHelper.addTepReceivedFromOvsdb(tepIp, strDpnId, tzName, ofTunnel,
-            dataBroker, wrTx);
-        return wrTx.submit();
+    public static ListenableFuture<Void> addTep(String tepIp, String strDpnId, String tzName, boolean ofTunnel,
+                                                DataBroker dataBroker, ManagedNewTransactionRunner tx) {
+        return
+            OvsdbTepAddConfigHelper.addTepReceivedFromOvsdb(tepIp, strDpnId, tzName, ofTunnel, dataBroker, tx).get(0);
     }
 
-    public static CheckedFuture<Void, TransactionCommitFailedException> deleteTep(String tepIp,
-        String strDpnId, String tzName, DataBroker dataBroker) {
-        WriteTransaction wrTx = dataBroker.newWriteOnlyTransaction();
-
-        // remove TEP received from southbound OVSDB from ITM config DS.
-        OvsdbTepRemoveConfigHelper.removeTepReceivedFromOvsdb(tepIp, strDpnId, tzName, dataBroker, wrTx);
-        return wrTx.submit();
+    public static ListenableFuture<Void> deleteTep(String tepIp, String strDpnId, String tzName,
+                                                   DataBroker dataBroker, ManagedNewTransactionRunner tx) {
+        return OvsdbTepRemoveConfigHelper.removeTepReceivedFromOvsdb(tepIp, strDpnId, tzName, dataBroker, tx).get(0);
     }
 
     public static CheckedFuture<Void, TransactionCommitFailedException> writeItmConfig(
index a4a739166a7dfee63aca2612b611c8eab7de9827..9872b9cb2a416d8350b3864c29a642052be46ad1 100644 (file)
@@ -178,7 +178,7 @@ public class MDSALManager extends AbstractLifecycle implements IMdsalApiManager
 
     @VisibleForTesting
     FluentFuture<Void> removeFlowInternal(FlowEntity flowEntity) {
-        return addCallBackForDeleteFlowAndReturnm(txRunner
+        return addCallBackForDeleteFlowAndReturn(txRunner
                 .callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
                     tx -> deleteFlowEntityInternal(flowEntity, tx)));
     }
@@ -680,7 +680,7 @@ public class MDSALManager extends AbstractLifecycle implements IMdsalApiManager
         return bucketInstanceId;
     }
 
-    private FluentFuture<Void> addCallBackForDeleteFlowAndReturnm(FluentFuture<Void> fluentFuture) {
+    private FluentFuture<Void> addCallBackForDeleteFlowAndReturn(FluentFuture<Void> fluentFuture) {
         return callBack(fluentFuture, "Delete Flow");
     }