From 065c99f7eec9377001dff286dd5a4e76c1781882 Mon Sep 17 00:00:00 2001 From: Chandra Shekar S Date: Tue, 17 Mar 2020 15:10:18 +0530 Subject: [PATCH] Handle EOS Timeout for the Hwvtep Node addition. If the Hwvtep Node is not added after the connection because of any error/exceptions ( ex: EOS) , add a job to disconnect hwvtep to the schedular so that the next iteration it could successed. Signed-off-by: Chandra Shekar S Change-Id: Ib805f1689f5f696c0df876f833a855da1e537e45 --- .../HwvtepConnectionManager.java | 4 +++ .../HwvtepOperGlobalListener.java | 21 ++++++++++++ .../HwvtepSouthboundConstants.java | 1 + utils/mdsal-utils/pom.xml | 7 +++- .../ovsdb/utils/mdsal/utils/Scheduler.java | 32 +++++++++++++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/Scheduler.java diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java index 440899b84..864dcaf20 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java @@ -128,6 +128,10 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo externalClient.getConnectionInfo().getLocalPort()); hwClient = connectedButCallBacksNotRegistered(externalClient); registerEntityForOwnership(hwClient); + HwvtepOperGlobalListener.runAfterTimeoutIfNodeNotCreated(hwClient.getInstanceIdentifier(), () -> { + externalClient.disconnect(); + disconnected(externalClient); + }); } } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.warn("Unable to fetch Database list from device {}. Disconnecting from the device.", diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepOperGlobalListener.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepOperGlobalListener.java index b3b44e9fe..b0f0da795 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepOperGlobalListener.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepOperGlobalListener.java @@ -14,6 +14,7 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener; @@ -23,6 +24,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.Mod import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.ovsdb.utils.mdsal.utils.Scheduler; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ConnectionInfo; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; @@ -38,6 +40,7 @@ public class HwvtepOperGlobalListener implements ClusteredDataTreeChangeListener private static final Logger LOG = LoggerFactory.getLogger(HwvtepOperGlobalListener.class); private static final Map, ConnectionInfo> NODE_CONNECTION_INFO = new ConcurrentHashMap<>(); + private static final Map, ScheduledFuture> TIMEOUT_FTS = new ConcurrentHashMap<>(); private ListenerRegistration registration; private final HwvtepConnectionManager hcm; @@ -81,6 +84,20 @@ public class HwvtepOperGlobalListener implements ClusteredDataTreeChangeListener } } + public static void runAfterTimeoutIfNodeNotCreated(InstanceIdentifier iid, Runnable job) { + ScheduledFuture ft = TIMEOUT_FTS.get(iid); + if (ft != null) { + ft.cancel(false); + } + ft = Scheduler.getScheduledExecutorService().schedule(() -> { + TIMEOUT_FTS.remove(iid); + if (!NODE_CONNECTION_INFO.containsKey(iid)) { + job.run(); + } + }, HwvtepSouthboundConstants.EOS_TIMEOUT, TimeUnit.SECONDS); + TIMEOUT_FTS.put(iid, ft); + } + public void runAfterNodeDeleted(InstanceIdentifier iid, Callable job) throws Exception { synchronized (HwvtepOperGlobalListener.class) { if (NODE_DELET_WAITING_JOBS.containsKey(iid)) { @@ -123,6 +140,10 @@ public class HwvtepOperGlobalListener implements ClusteredDataTreeChangeListener return; } CONNECTED_NODES.put(key, node); + ScheduledFuture ft = TIMEOUT_FTS.remove(key); + if (ft != null) { + ft.cancel(false); + } HwvtepGlobalAugmentation globalAugmentation = node.augmentation(HwvtepGlobalAugmentation.class); if (globalAugmentation != null) { ConnectionInfo connectionInfo = globalAugmentation.getConnectionInfo(); diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundConstants.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundConstants.java index c5ea525e0..328945cf2 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundConstants.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundConstants.java @@ -52,5 +52,6 @@ public interface HwvtepSouthboundConstants { "hwvtep.intransit.job.check.period.millis", 30000); long CONFIG_NODE_UPDATE_MAX_DELAY_MS = Integer.getInteger( "config.node.update.max.delay.ms", 10000); + int EOS_TIMEOUT = Integer.getInteger("hwvtep.eos.timeout.delay.secs", 240); } diff --git a/utils/mdsal-utils/pom.xml b/utils/mdsal-utils/pom.xml index e7e7787cb..fef9e5947 100644 --- a/utils/mdsal-utils/pom.xml +++ b/utils/mdsal-utils/pom.xml @@ -58,7 +58,12 @@ and is available at http://www.eclipse.org/legal/epl-v10.html test-jar test - + + javax.inject + javax.inject + 1 + compile + diff --git a/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/Scheduler.java b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/Scheduler.java new file mode 100644 index 000000000..629942d7e --- /dev/null +++ b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/Scheduler.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 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.ovsdb.utils.mdsal.utils; + +import com.google.common.util.concurrent.ThreadFactoryBuilder; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import javax.inject.Singleton; + +@Singleton +public class Scheduler implements AutoCloseable { + private static final ThreadFactory NAMED_THREAD_FACTORY = new ThreadFactoryBuilder() + .setNameFormat("ovsdb-sched-%d").build(); + private static final ScheduledExecutorService SCHEDULED_EXECUTOR_SERVICE + = Executors.newSingleThreadScheduledExecutor(NAMED_THREAD_FACTORY); + + public static ScheduledExecutorService getScheduledExecutorService() { + return SCHEDULED_EXECUTOR_SERVICE; + } + + @Override + public void close() { + SCHEDULED_EXECUTOR_SERVICE.shutdown(); + } +} -- 2.36.6