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.",
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;
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;
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;
}
}
+ 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)) {
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();
--- /dev/null
+/*
+ * 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();
+ }
+}