X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=itm%2Fitm-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fgenius%2Fitm%2Fconfighelpers%2FItmInternalTunnelDeleteWorker.java;h=79d8eefa9974bf9f5fcdb61d61d9b41635b788b0;hb=fe2f58ba565f247e800b9980f66349837b9d6f83;hp=dd56dc8cfdae72d2a8035ef82939d673534c27e7;hpb=1dcfbae79006880df221f1d14aabcb570350f395;p=genius.git diff --git a/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmInternalTunnelDeleteWorker.java b/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmInternalTunnelDeleteWorker.java index dd56dc8cf..79d8eefa9 100644 --- a/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmInternalTunnelDeleteWorker.java +++ b/itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/ItmInternalTunnelDeleteWorker.java @@ -7,10 +7,11 @@ */ package org.opendaylight.genius.itm.confighelpers; +import static java.util.Collections.singletonList; + 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; @@ -19,9 +20,11 @@ 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.datastoreutils.DataStoreJobCoordinator; +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.infrautils.jobcoordinator.JobCoordinator; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase; import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeLldp; @@ -41,25 +44,32 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ItmInternalTunnelDeleteWorker { + private static final Logger LOG = LoggerFactory.getLogger(ItmInternalTunnelDeleteWorker.class) ; + private final DataBroker dataBroker; + private final ManagedNewTransactionRunner txRunner; + private final JobCoordinator jobCoordinator; + + public ItmInternalTunnelDeleteWorker(DataBroker dataBroker, JobCoordinator jobCoordinator) { + this.dataBroker = dataBroker; + this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker); + this.jobCoordinator = jobCoordinator; + } + @SuppressWarnings("checkstyle:IllegalCatch") - public static List> deleteTunnels(DataBroker dataBroker, - IMdsalApiManager mdsalManager, - List dpnTepsList, - List meshedDpnList) { + public List> deleteTunnels(IMdsalApiManager mdsalManager, List dpnTepsList, + List meshedDpnList) { LOG.trace("TEPs to be deleted {} " , dpnTepsList); - List> futures = new ArrayList<>(); - WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); - try { + return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(writeTransaction -> { if (dpnTepsList == null || dpnTepsList.size() == 0) { LOG.debug("no vtep to delete"); - return futures ; + return; } if (meshedDpnList == null || meshedDpnList.size() == 0) { LOG.debug("No Meshed Vteps"); - return futures ; + return; } for (DPNTEPsInfo srcDpn : dpnTepsList) { LOG.trace("Processing srcDpn {}", srcDpn); @@ -67,7 +77,7 @@ public class ItmInternalTunnelDeleteWorker { List meshedEndPtCache = ItmUtils.getTEPsForDpn(srcDpn.getDPNID(), meshedDpnList); if (meshedEndPtCache == null) { LOG.debug("No Tunnel End Point configured for this DPN {}", srcDpn.getDPNID()); - continue ; + continue; } LOG.debug("Entries in meshEndPointCache {} for DPN Id{} ", meshedEndPtCache.size(), srcDpn.getDPNID()); for (TunnelEndPoints srcTep : srcDpn.getTunnelEndPoints()) { @@ -92,8 +102,8 @@ public class ItmInternalTunnelDeleteWorker { // remove all trunk interfaces LOG.trace("Invoking removeTrunkInterface between source TEP {} , " + "Destination TEP {} ", srcTep, dstTep); - removeTrunkInterface(dataBroker, srcTep, dstTep, srcDpn - .getDPNID(), dstDpn.getDPNID(), writeTransaction); + removeTrunkInterface(srcTep, dstTep, srcDpn.getDPNID(), dstDpn.getDPNID(), + writeTransaction); } } } @@ -172,16 +182,11 @@ public class ItmInternalTunnelDeleteWorker { } } } - futures.add(writeTransaction.submit()); - } catch (Exception e1) { - LOG.error("exception while deleting tep", e1); - } - return futures ; + })); } - private static void removeTrunkInterface(DataBroker dataBroker, - TunnelEndPoints srcTep, TunnelEndPoints dstTep, BigInteger srcDpnId, - BigInteger dstDpnId, WriteTransaction transaction) { + private void removeTrunkInterface(TunnelEndPoints srcTep, TunnelEndPoints dstTep, + BigInteger srcDpnId, BigInteger dstDpnId, WriteTransaction transaction) { String trunkfwdIfName = ItmUtils.getTrunkInterfaceName(srcTep.getInterfaceName(), new String(srcTep.getIpAddress().getValue()), new String(dstTep.getIpAddress().getValue()), @@ -191,18 +196,18 @@ public class ItmInternalTunnelDeleteWorker { LOG.debug(" Removing Trunk Interface Name - {} , Id - {} from Config DS ", trunkfwdIfName, trunkIdentifier) ; transaction.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier); - ItmUtils.itmCache.removeInterface(trunkfwdIfName); + ItmUtils.ITM_CACHE.removeInterface(trunkfwdIfName); // also update itm-state ds -- Delete the forward tunnel-interface from the tunnel list InstanceIdentifier path = InstanceIdentifier.create(TunnelList.class) .child(InternalTunnel.class, new InternalTunnelKey(dstDpnId, srcDpnId, srcTep.getTunnelType())); transaction.delete(LogicalDatastoreType.CONFIGURATION,path) ; - ItmUtils.itmCache.removeInternalTunnel(trunkfwdIfName); + ItmUtils.ITM_CACHE.removeInternalTunnel(trunkfwdIfName); // Release the Ids for the forward trunk interface Name ItmUtils.releaseIdForTrunkInterfaceName(srcTep.getInterfaceName(), new String(srcTep.getIpAddress().getValue()), new String(dstTep.getIpAddress().getValue()), srcTep.getTunnelType().getName()); - removeLogicalGroupTunnel(srcDpnId, dstDpnId, dataBroker); + removeLogicalGroupTunnel(srcDpnId, dstDpnId); String trunkRevIfName = ItmUtils.getTrunkInterfaceName(dstTep.getInterfaceName(), new String(dstTep.getIpAddress().getValue()), @@ -213,7 +218,7 @@ public class ItmInternalTunnelDeleteWorker { LOG.debug(" Removing Trunk Interface Name - {} , Id - {} from Config DS ", trunkRevIfName, trunkIdentifier) ; transaction.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier); - ItmUtils.itmCache.removeInternalTunnel(trunkRevIfName); + ItmUtils.ITM_CACHE.removeInternalTunnel(trunkRevIfName); // also update itm-state ds -- Delete the reverse tunnel-interface from the tunnel list path = InstanceIdentifier.create(TunnelList.class) .child(InternalTunnel.class, new InternalTunnelKey(srcDpnId, dstDpnId, dstTep.getTunnelType())); @@ -224,7 +229,7 @@ public class ItmInternalTunnelDeleteWorker { new String(dstTep.getIpAddress().getValue()), new String(srcTep.getIpAddress().getValue()), dstTep.getTunnelType().getName()); - removeLogicalGroupTunnel(dstDpnId, srcDpnId, dataBroker); + removeLogicalGroupTunnel(dstDpnId, srcDpnId); } private static boolean checkIfTrunkExists(BigInteger srcDpnId, BigInteger dstDpnId, @@ -234,17 +239,15 @@ public class ItmInternalTunnelDeleteWorker { return ItmUtils.read(LogicalDatastoreType.CONFIGURATION,path, dataBroker).isPresent(); } - private static void removeLogicalGroupTunnel(BigInteger srcDpnId, BigInteger dstDpnId, - DataBroker dataBroker) { + private void removeLogicalGroupTunnel(BigInteger srcDpnId, BigInteger dstDpnId) { boolean tunnelAggregationEnabled = ItmTunnelAggregationHelper.isTunnelAggregationEnabled(); if (!tunnelAggregationEnabled) { return; } String logicTunnelName = ItmUtils.getLogicalTunnelGroupName(srcDpnId, dstDpnId); - DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance(); ItmTunnelAggregationDeleteWorker addWorker = new ItmTunnelAggregationDeleteWorker(logicTunnelName, srcDpnId, dstDpnId, dataBroker); - coordinator.enqueueJob(logicTunnelName, addWorker); + jobCoordinator.enqueueJob(logicTunnelName, addWorker); } private static class ItmTunnelAggregationDeleteWorker implements Callable>> { @@ -252,18 +255,18 @@ public class ItmInternalTunnelDeleteWorker { private final String logicTunnelName; private final BigInteger srcDpnId; private final BigInteger dstDpnId; - private final DataBroker dataBroker; + private final ManagedNewTransactionRunner txRunner; ItmTunnelAggregationDeleteWorker(String groupName, BigInteger srcDpnId, BigInteger dstDpnId, DataBroker db) { this.logicTunnelName = groupName; this.srcDpnId = srcDpnId; this.dstDpnId = dstDpnId; - this.dataBroker = db; + this.txRunner = new ManagedNewTransactionRunnerImpl(db); } @Override public List> call() throws Exception { - Collection tunnels = ItmUtils.itmCache.getAllInternalTunnel(); + Collection tunnels = ItmUtils.ITM_CACHE.getAllInternalTunnel(); if (tunnels == null) { return Collections.emptyList(); } @@ -282,18 +285,18 @@ public class ItmInternalTunnelDeleteWorker { } } if (emptyTunnelGroup && foundLogicGroupIface) { - WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); - LOG.debug("MULTIPLE_VxLAN_TUNNELS: remove the logical tunnel group {} because a last tunnel" - + " interface on srcDpnId {} dstDpnId {} is removed", logicTunnelName, srcDpnId, dstDpnId); - InstanceIdentifier trunkIdentifier = ItmUtils.buildId(logicTunnelName); - tx.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier); - ItmUtils.itmCache.removeInterface(logicTunnelName); - InstanceIdentifier path = InstanceIdentifier.create(TunnelList.class) - .child(InternalTunnel.class, - new InternalTunnelKey(dstDpnId, srcDpnId, TunnelTypeLogicalGroup.class)); - tx.delete(LogicalDatastoreType.CONFIGURATION, path); - ItmUtils.itmCache.removeInternalTunnel(logicTunnelName); - return Collections.singletonList(tx.submit()); + return singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> { + LOG.debug("MULTIPLE_VxLAN_TUNNELS: remove the logical tunnel group {} because a last tunnel" + + " interface on srcDpnId {} dstDpnId {} is removed", logicTunnelName, srcDpnId, dstDpnId); + InstanceIdentifier trunkIdentifier = ItmUtils.buildId(logicTunnelName); + tx.delete(LogicalDatastoreType.CONFIGURATION, trunkIdentifier); + ItmUtils.ITM_CACHE.removeInterface(logicTunnelName); + InstanceIdentifier path = InstanceIdentifier.create(TunnelList.class) + .child(InternalTunnel.class, + new InternalTunnelKey(dstDpnId, srcDpnId, TunnelTypeLogicalGroup.class)); + tx.delete(LogicalDatastoreType.CONFIGURATION, path); + ItmUtils.ITM_CACHE.removeInternalTunnel(logicTunnelName); + })); } else if (!emptyTunnelGroup) { LOG.debug("MULTIPLE_VxLAN_TUNNELS: not last tunnel in logical tunnel group {}", logicTunnelName); }