*/
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;
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;
@SuppressWarnings("checkstyle:IllegalCatch")
public void buildTeps() {
- TransportZones transportZonesBuilt = null;
TransportZone transportZone = null;
try {
LOG.debug("no of teps added {}", CHECK);
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();
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();
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);
}
}
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);
}
}
*/
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;
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) {
}
@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 =
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;
}
}
*/
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;
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);
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);
+ }
}
}
}
}
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?
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());
}
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());
}
}
}
- 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");
}
-
}
}
}
//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);
.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);
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),
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;
}
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;
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
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
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);
}
}
}
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?
}
// 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);
}
}
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);
}
}
}
}
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);
}
}
}
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();
}
}
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;
}
}
- 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() ;
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());
.getOvsBridgeReference().getValue();
addPortToBridge(bridgeIid, iface, iface.getName());
}
- return Collections.singletonList(transaction.submit());
}
private void addPortToBridge(InstanceIdentifier<?> bridgeIid, Interface iface, String portName) {
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;
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);
}
@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());
}
}
}
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;
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) {
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);
}
}
}
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;
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;
DirectTunnelUtils directTunnelUtils,
DpnTepStateCache dpnTepStateCache,
OvsBridgeRefEntryCache ovsBridgeRefEntryCache) {
- this.dataBroker = dataBroker;
this.tzone = tzone;
this.monitorProtocol = monitorProtocol;
this.directTunnelUtils = directTunnelUtils;
@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());
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());
}
}
*/
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;
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);
}
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
*/
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;
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);
}
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));
}
}
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;
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)));
}
}
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;
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)));
}
}
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;
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);
} catch (Exception e) {
LOG.warn("Exception trying to create tunnel state for {}", iface.getName(), e);
}
-
- return Collections.singletonList(writeTransaction.submit());
+ return Collections.emptyList();
}
}
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;
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();
}
}
*/
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;
* @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()) {
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 {
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;
}
/**
* @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)
.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);
}
/**
* @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()) {
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;
}
}
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);
}
}
}
* @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)
+ "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)));
}
}
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;
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;
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);
}
}
*/
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;
* @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) {
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.");
}
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;
}
/**
* @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);
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);
}
/**
* @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) {
"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);
}
*
* @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);
}
/**
* 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);
}
}
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;
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);
}
}
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;
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");
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;
}
}
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
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;
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);
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();
}
}
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;
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;
private final ItmInternalTunnelAddWorker itmInternalTunnelAddWorker;
private final ItmExternalTunnelAddWorker externalTunnelAddWorker;
private final DPNTEPsInfoCache dpnTEPsInfoCache;
+ private final ManagedNewTransactionRunner txRunner;
@Inject
public TransportZoneListener(final DataBroker dataBroker,
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);
}
}
@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
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));
}
}
}
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);
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));
}
}
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));
}
}
// 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()) {
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;
private final IInterfaceManager interfaceManager;
private final DpnTepStateCache dpnTepStateCache;
private final OvsBridgeRefEntryCache ovsBridgeRefEntryCache;
+ private final ManagedNewTransactionRunner txRunner;
@Inject
public TunnelMonitorIntervalListener(DataBroker dataBroker, JobCoordinator jobCoordinator,
this.dpnTepStateCache = dpnTepStateCache;
this.interfaceManager = interfaceManager;
this.ovsBridgeRefEntryCache = ovsBridgeRefEntryCache;
+ this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
}
@Override
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);
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;
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;
private final DataBroker broker;
private final JobCoordinator jobCoordinator;
+ private final ManagedNewTransactionRunner txRunner;
private JMXAlarmAgent alarmAgent;
private UnprocessedTunnelsStateCache unprocessedTunnelsStateCache;
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();
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());
}
}
- 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)));
}
}
}
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;
private final EntityOwnershipUtils entityOwnershipUtils;
private final IMdsalApiManager imdsalApiManager;
private final DataTreeEventCallbackRegistrar eventCallbacks;
+ private final ManagedNewTransactionRunner txRunner;
@Inject
public ItmTepInstanceRecoveryHandler(DataBroker dataBroker,
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);
}
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);
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",
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;
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;
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;
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,
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;
this.ovsBridgeRefEntryCache = ovsBridgeRefEntryCache;
this.directTunnelUtils = directTunnelUtils;
this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
+ this.retryingTxRunner = new RetryingManagedNewTransactionRunner(dataBroker);
}
@PostConstruct
//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());
}
result.set(RpcResultBuilder.<RemoveExternalTunnelEndpointOutput>failed()
.withError(RpcError.ErrorType.APPLICATION, msg, error).build());
}
- });
+ }, MoreExecutors.directExecutor());
return result;
}
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;
}
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;
}
//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());
}
result.set(RpcResultBuilder.<AddExternalTunnelEndpointOutput>failed()
.withError(RpcError.ErrorType.APPLICATION, msg, error).build());
}
- });
+ }, MoreExecutors.directExecutor());
return result;
}
.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());
}
result.set(RpcResultBuilder.<DeleteL2GwDeviceOutput>failed()
.withError(RpcError.ErrorType.APPLICATION, msg, error).build());
}
- });
-
+ }, MoreExecutors.directExecutor());
}
} else {
result.set(RpcResultBuilder.<DeleteL2GwDeviceOutput>failed()
.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());
result.set(RpcResultBuilder.<AddL2GwDeviceOutput>failed()
.withError(RpcError.ErrorType.APPLICATION, msg, error).build());
}
- });
+ }, MoreExecutors.directExecutor());
}
} else {
.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());
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) {
.withError(RpcError.ErrorType.APPLICATION, msg, error)
.build());
}
- });
+ }, MoreExecutors.directExecutor());
}
return result;
} catch (Exception e) {
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;
}
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;
+ }
}
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;
@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;
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));
}
@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);
}
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);
}
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;
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;
@Mock ReadOnlyTransaction mockReadTx;
@Mock WriteTransaction mockWriteTx;
@Mock IdManagerService idManagerService;
+ @Mock TypedWriteTransaction<Datastore.Configuration> typedWriteTransaction;
+ @Mock TypedReadWriteTransaction<Datastore.Configuration> typedReadWriteTransaction;
@Before
public void setUp() {
@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
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
+ }
}
}
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;
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;
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;
@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();
.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
// 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);
+ }
+ }
}
*/
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;
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(
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();
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,
.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
.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();
.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
@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);
@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);
//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(),
@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);
.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
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;
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(
@VisibleForTesting
FluentFuture<Void> removeFlowInternal(FlowEntity flowEntity) {
- return addCallBackForDeleteFlowAndReturnm(txRunner
+ return addCallBackForDeleteFlowAndReturn(txRunner
.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
tx -> deleteFlowEntityInternal(flowEntity, tx)));
}
return bucketInstanceId;
}
- private FluentFuture<Void> addCallBackForDeleteFlowAndReturnm(FluentFuture<Void> fluentFuture) {
+ private FluentFuture<Void> addCallBackForDeleteFlowAndReturn(FluentFuture<Void> fluentFuture) {
return callBack(fluentFuture, "Delete Flow");
}