Handle EOS Timeout for the Hwvtep Node addition. 54/88454/3
authorChandra Shekar S <chandra.shekar.s@ericsson.com>
Tue, 17 Mar 2020 09:40:18 +0000 (15:10 +0530)
committerChandra Shekar S <chandra.shekar.s@ericsson.com>
Mon, 23 Mar 2020 07:21:12 +0000 (12:51 +0530)
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 <chandra.shekar.s@ericsson.com>
Change-Id: Ib805f1689f5f696c0df876f833a855da1e537e45

hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepOperGlobalListener.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundConstants.java
utils/mdsal-utils/pom.xml
utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/Scheduler.java [new file with mode: 0644]

index 440899b842d815bca96a2042b3584173b33a51b1..864dcaf209bc07000b6051cf5a5570751eeb4723 100644 (file)
@@ -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.",
index b3b44e9fe7aefa241f097a578f64864ae11f02a6..b0f0da79589ceadf278bc2b183e21e4408fbee48 100644 (file)
@@ -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<InstanceIdentifier<Node>, ConnectionInfo> NODE_CONNECTION_INFO = new ConcurrentHashMap<>();
+    private static final Map<InstanceIdentifier<Node>, ScheduledFuture> TIMEOUT_FTS = new ConcurrentHashMap<>();
 
     private ListenerRegistration<HwvtepOperGlobalListener> registration;
     private final HwvtepConnectionManager hcm;
@@ -81,6 +84,20 @@ public class HwvtepOperGlobalListener implements ClusteredDataTreeChangeListener
         }
     }
 
+    public static void runAfterTimeoutIfNodeNotCreated(InstanceIdentifier<Node> 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<Node> iid, Callable<Void> 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();
index c5ea525e00a5ee3683bf4725470669c902050e6a..328945cf29bdce0c2940c8f4c03c0c1da4a9bc38 100644 (file)
@@ -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);
 
 }
index e7e7787cbf0066f1744f4406f2ded9ec789cbbea..fef9e5947b0aef47d2104f9eb2b6bd4482f1e326 100644 (file)
@@ -58,7 +58,12 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
-
+      <dependency>
+          <groupId>javax.inject</groupId>
+          <artifactId>javax.inject</artifactId>
+          <version>1</version>
+          <scope>compile</scope>
+      </dependency>
   </dependencies>
 
   <build>
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 (file)
index 0000000..629942d
--- /dev/null
@@ -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();
+    }
+}