From cd7e3f44b04374429cb1dbb4d28d0ae9238d4cc1 Mon Sep 17 00:00:00 2001 From: Deepthi L S Date: Tue, 6 Oct 2020 12:26:45 +0530 Subject: [PATCH] Table 220 flows not removed Signed-off-by: Deepthi L S Change-Id: I2e65191d7b730e8e3876b340c78ae92929a5578d --- .../InterfaceInventoryStateListener.java | 44 +++++++++++++++++-- .../listeners/MigrationInProgressCache.java | 34 ++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/MigrationInProgressCache.java diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceInventoryStateListener.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceInventoryStateListener.java index a840b87c0..b53bf95db 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceInventoryStateListener.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/InterfaceInventoryStateListener.java @@ -10,6 +10,8 @@ package org.opendaylight.genius.interfacemanager.listeners; import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION; import static org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import java.util.ArrayList; @@ -96,6 +98,7 @@ public class InterfaceInventoryStateListener private final InterfaceMetaUtils interfaceMetaUtils; private final PortNameCache portNameCache; private final InterfacemgrProvider interfacemgrProvider; + private final MigrationInProgressCache migrationInProgressCache; @Inject public InterfaceInventoryStateListener(@Reference final DataBroker dataBroker, @@ -114,7 +117,7 @@ public class InterfaceInventoryStateListener super(dataBroker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class) .child(Node.class).child(NodeConnector.class) .augmentation(FlowCapableNodeConnector.class), - Executors.newSingleThreadExecutor("InterfaceInventoryStateListener", LOG)); + Executors.newFixedThreadPool(1, "InterfaceInventoryStateListener", LOG)); this.dataBroker = dataBroker; this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker); this.idManager = idManagerService; @@ -127,6 +130,7 @@ public class InterfaceInventoryStateListener this.interfaceMetaUtils = interfaceMetaUtils; this.portNameCache = portNameCache; this.interfacemgrProvider = interfacemgrProvider; + this.migrationInProgressCache = new MigrationInProgressCache(); serviceRecoveryRegistry.addRecoverableListener(interfaceServiceRecoveryHandler.buildServiceRegistryKey(), this); } @@ -243,6 +247,12 @@ public class InterfaceInventoryStateListener EVENT_LOGGER.debug("IFM-InterfaceInventoryState Entity Owner,ADD {},{}", portName, nodeConnectorId.getValue()); if (InterfaceManagerCommonUtils.isNovaPort(portName) || InterfaceManagerCommonUtils.isK8SPort(portName)) { + Optional nodeConnectorIdFromCache = migrationInProgressCache.get(interfaceName); + if (nodeConnectorIdFromCache.isPresent() && nodeConnectorIdFromCache.get().equals(nodeConnectorId)) { + LOG.error("NodeConnectorId is changed. Dropping Port update event for {} from NodeConnectorId {}", + fcNodeConnectorNew.getName(), nodeConnectorId); + return; + } NodeConnectorId nodeConnectorIdOld = null; org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang .ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = interfaceManagerCommonUtils @@ -266,6 +276,7 @@ public class InterfaceInventoryStateListener LOG.warn("Port number update detected for {}", fcNodeConnectorNew.getName()); } //VM Migration or Port Number Update: Delete existing interface entry for older DPN + migrationInProgressCache.put(interfaceName, nodeConnectorIdOld); LOG.trace("Removing entry for port id {} from map",nodeConnectorIdOld.getValue()); portNameCache.remove(nodeConnectorIdOld.getValue()); EVENT_LOGGER.debug("IFM-VMMigration,{}", portName); @@ -283,7 +294,7 @@ public class InterfaceInventoryStateListener } InterfaceStateAddWorker ifStateAddWorker = new InterfaceStateAddWorker(idManager, nodeConnectorId, - fcNodeConnectorNew, portName); + fcNodeConnectorNew, portName, interfaceName, IfmConstants.JOB_MAX_RETRIES); coordinator.enqueueJob(portName, ifStateAddWorker, IfmConstants.JOB_MAX_RETRIES); } @@ -293,13 +304,18 @@ public class InterfaceInventoryStateListener private final FlowCapableNodeConnector fcNodeConnectorNew; private final String interfaceName; private final IdManagerService idManager; + private final String migrationCacheKey; + private int maxRetries; InterfaceStateAddWorker(IdManagerService idManager, NodeConnectorId nodeConnectorId, - FlowCapableNodeConnector fcNodeConnectorNew, String portName) { + FlowCapableNodeConnector fcNodeConnectorNew, String portName, String migrationCacheKey, + int maxRetries) { this.nodeConnectorId = nodeConnectorId; this.fcNodeConnectorNew = fcNodeConnectorNew; this.interfaceName = portName; this.idManager = idManager; + this.migrationCacheKey = migrationCacheKey; + this.maxRetries = maxRetries; } @Override @@ -310,9 +326,29 @@ public class InterfaceInventoryStateListener getInterfaceChildEntries(interfaceName); for (InterfaceChildEntry interfaceChildEntry : interfaceChildEntries.values()) { InterfaceStateAddWorker interfaceStateAddWorker = new InterfaceStateAddWorker(idManager, - nodeConnectorId, fcNodeConnectorNew, interfaceChildEntry.getChildInterface()); + nodeConnectorId, fcNodeConnectorNew, interfaceChildEntry.getChildInterface(), null, 0); coordinator.enqueueJob(interfaceName, interfaceStateAddWorker); } + + if (migrationCacheKey != null && futures != null && !futures.isEmpty()) { + ListenableFuture> completedFuture = Futures.allAsList(futures); + Futures.addCallback(completedFuture, new FutureCallback>() { + @Override + public void onFailure(Throwable error) { + maxRetries--; + if (maxRetries == 0) { + migrationInProgressCache.remove(migrationCacheKey); + LOG.error("OvsInterfaceStateAddHelper addState failed for interface {}", + migrationCacheKey); + } + } + + @Override + public void onSuccess(List result) { + migrationInProgressCache.remove(migrationCacheKey); + } + }, MoreExecutors.directExecutor()); + } return futures; } diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/MigrationInProgressCache.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/MigrationInProgressCache.java new file mode 100644 index 000000000..f39e14d15 --- /dev/null +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/listeners/MigrationInProgressCache.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.genius.interfacemanager.listeners; + +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import javax.inject.Singleton; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; + +@Singleton +public class MigrationInProgressCache { + @NonNull + private final ConcurrentMap migrationInProgressCache = new ConcurrentHashMap<>(); + + protected void put(@NonNull String interfaceName, NodeConnectorId nodeConnectorId) { + migrationInProgressCache.put(interfaceName, nodeConnectorId); + } + + protected void remove(@NonNull String interfaceName) { + migrationInProgressCache.remove(interfaceName); + } + + public Optional get(@NonNull String interfaceName) { + return Optional.ofNullable(migrationInProgressCache.get(interfaceName)); + } +} \ No newline at end of file -- 2.36.6