From: Jakub Morvay Date: Mon, 6 Aug 2018 14:50:23 +0000 (+0000) Subject: Merge "NECONF-524 : Setting the netconf keepalive logic to be more proactive." X-Git-Tag: release/fluorine~3 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=1e174be6002940e17aee31d15f8914273d30f25c;hp=5798be3510627fb77585d7d49e91f0602d78417f;p=netconf.git Merge "NECONF-524 : Setting the netconf keepalive logic to be more proactive." --- diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java index 5244692290..68366c115c 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java @@ -215,14 +215,19 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector { LOG.info("{}: Concurrent rpc limit is smaller than 1, no limit will be enforced.", remoteDeviceId); } - return new NetconfConnectorDTO( - userCapabilities.isPresent() ? new NetconfDeviceCommunicator(remoteDeviceId, device, - new UserPreferences(userCapabilities.get(), - Objects.isNull(node.getYangModuleCapabilities()) - ? false : node.getYangModuleCapabilities().isOverride(), - Objects.isNull(node.getNonModuleCapabilities()) - ? false : node.getNonModuleCapabilities().isOverride()), rpcMessageLimit) - : new NetconfDeviceCommunicator(remoteDeviceId, device, rpcMessageLimit), salFacade); + NetconfDeviceCommunicator netconfDeviceCommunicator = + userCapabilities.isPresent() ? new NetconfDeviceCommunicator(remoteDeviceId, device, + new UserPreferences(userCapabilities.get(), + Objects.isNull(node.getYangModuleCapabilities()) + ? false : node.getYangModuleCapabilities().isOverride(), + Objects.isNull(node.getNonModuleCapabilities()) + ? false : node.getNonModuleCapabilities().isOverride()), rpcMessageLimit) + : new NetconfDeviceCommunicator(remoteDeviceId, device, rpcMessageLimit); + + if (salFacade instanceof KeepaliveSalFacade) { + ((KeepaliveSalFacade)salFacade).setListener(netconfDeviceCommunicator); + } + return new NetconfConnectorDTO(netconfDeviceCommunicator, salFacade); } private static Optional getUserCapabilities(final NetconfNode node) { diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java index c9ec7bf87f..342d3e9cda 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java @@ -373,9 +373,15 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { LOG.info("Concurrent rpc limit is smaller than 1, no limit will be enforced for device {}", remoteDeviceId); } - return new NetconfConnectorDTO(userCapabilities.isPresent() - ? new NetconfDeviceCommunicator(remoteDeviceId, device, userCapabilities.get(), rpcMessageLimit) - : new NetconfDeviceCommunicator(remoteDeviceId, device, rpcMessageLimit), salFacade); + NetconfDeviceCommunicator netconfDeviceCommunicator = + userCapabilities.isPresent() ? new NetconfDeviceCommunicator(remoteDeviceId, device, + userCapabilities.get(), rpcMessageLimit) + : new NetconfDeviceCommunicator(remoteDeviceId, device, rpcMessageLimit); + + if (salFacade instanceof KeepaliveSalFacade) { + ((KeepaliveSalFacade)salFacade).setListener(netconfDeviceCommunicator); + } + return new NetconfConnectorDTO(netconfDeviceCommunicator, salFacade); } protected NetconfDevice.SchemaResourcesDTO setupSchemaCacheDTO(final NodeId nodeId, final NetconfNode node) { diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfDeviceCommunicator.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfDeviceCommunicator.java index 7968fcda97..b962ae2075 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfDeviceCommunicator.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfDeviceCommunicator.java @@ -167,7 +167,7 @@ public class NetconfDeviceCommunicator public void disconnect() { // If session is already in closing, no need to close it again - if (currentSession != null && isSessionClosing.compareAndSet(false, true)) { + if (currentSession != null && isSessionClosing.compareAndSet(false, true) && currentSession.isUp()) { currentSession.close(); } } diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java index 82cf4b2337..73b1296ef8 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java @@ -21,6 +21,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opendaylight.controller.md.sal.dom.api.DOMNotification; @@ -66,6 +67,7 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler currentKeepalive; private volatile DOMRpcService currentDeviceRpc; + private final AtomicBoolean lastKeepAliveSucceeded = new AtomicBoolean(false); public KeepaliveSalFacade(final RemoteDeviceId id, final RemoteDeviceHandler salFacade, final ScheduledExecutorService executor, final long keepaliveDelaySeconds, @@ -104,7 +106,7 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler { - private final ScheduledFuture previousKeepalive; - - Keepalive(final ScheduledFuture previousKeepalive) { - this.previousKeepalive = previousKeepalive; - } - @Override public void run() { LOG.trace("{}: Invoking keepalive RPC", id); try { - if (previousKeepalive != null && !previousKeepalive.isDone()) { + boolean lastJobSucceeded = lastKeepAliveSucceeded.getAndSet(false); + if (!lastJobSucceeded) { onFailure(new IllegalStateException("Previous keepalive timed out")); } else { Futures.addCallback(currentDeviceRpc.invokeRpc(PATH, KEEPALIVE_PAYLOAD), this, @@ -212,11 +211,10 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler