X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fmd%2Fsal%2Fconnector%2Fnetconf%2FNetconfConnectorModule.java;h=2c13166f50c01d2b9b89ee06c2d17c4708ce623f;hp=44b2435da2284358b4a2ed13cbb6e699e23f2115;hb=469a10465ebe09a9199c9316917e13dfd525e11c;hpb=b41630c2fcbb94ecd034e74e7b730771721558c7 diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java index 44b2435da2..2c13166f50 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java @@ -16,6 +16,9 @@ import java.math.BigDecimal; import java.net.InetSocketAddress; import java.util.List; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; import org.opendaylight.controller.config.api.JmxAttributeValidationException; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; @@ -28,8 +31,8 @@ import org.opendaylight.controller.sal.connect.netconf.NetconfDevice; import org.opendaylight.controller.sal.connect.netconf.NetconfStateSchemas; import org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCommunicator; import org.opendaylight.controller.sal.connect.netconf.listener.NetconfSessionPreferences; +import org.opendaylight.controller.sal.connect.netconf.sal.KeepaliveSalFacade; import org.opendaylight.controller.sal.connect.netconf.sal.NetconfDeviceSalFacade; -import org.opendaylight.controller.sal.connect.netconf.schema.mapping.NetconfMessageTransformer; import org.opendaylight.controller.sal.connect.util.RemoteDeviceId; import org.opendaylight.controller.sal.core.api.Broker; import org.opendaylight.protocol.framework.ReconnectStrategy; @@ -74,6 +77,9 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co checkNotNull(getConnectionTimeoutMillis(), connectionTimeoutMillisJmxAttribute); checkCondition(getConnectionTimeoutMillis() > 0, "must be > 0", connectionTimeoutMillisJmxAttribute); + checkNotNull(getConnectionTimeoutMillis(), defaultRequestTimeoutMillisJmxAttribute); + checkCondition(getConnectionTimeoutMillis() > 0, "must be > 0", defaultRequestTimeoutMillisJmxAttribute); + checkNotNull(getBetweenAttemptsTimeoutMillis(), betweenAttemptsTimeoutMillisJmxAttribute); checkCondition(getBetweenAttemptsTimeoutMillis() > 0, "must be > 0", betweenAttemptsTimeoutMillisJmxAttribute); @@ -88,6 +94,23 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co } userCapabilities = getUserCapabilities(); + + if(getKeepaliveExecutor() == null) { + logger.warn("Keepalive executor missing. Using default instance for now, the configuration needs to be updated"); + + // Instantiate the default executor, now we know its necessary + if(DEFAULT_KEEPALIVE_EXECUTOR == null) { + DEFAULT_KEEPALIVE_EXECUTOR = Executors.newScheduledThreadPool(2, new ThreadFactory() { + @Override + public Thread newThread(final Runnable r) { + final Thread thread = new Thread(r); + thread.setName("netconf-southound-keepalives-" + thread.getId()); + thread.setDaemon(true); + return thread; + } + }); + } + } } private boolean isHostAddressPresent(final Host address) { @@ -95,6 +118,9 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co address.getIpAddress() != null && (address.getIpAddress().getIpv4Address() != null || address.getIpAddress().getIpv6Address() != null); } + @Deprecated + private static ScheduledExecutorService DEFAULT_KEEPALIVE_EXECUTOR; + @Override public java.lang.AutoCloseable createInstance() { final RemoteDeviceId id = new RemoteDeviceId(getIdentifier(), getSocketAddress()); @@ -104,18 +130,30 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co final Broker domBroker = getDomRegistryDependency(); final BindingAwareBroker bindingBroker = getBindingRegistryDependency(); - final RemoteDeviceHandler salFacade - = new NetconfDeviceSalFacade(id, domBroker, bindingBroker, bundleContext, globalProcessingExecutor); + RemoteDeviceHandler salFacade + = new NetconfDeviceSalFacade(id, domBroker, bindingBroker, getDefaultRequestTimeoutMillis()); + + final Long keepaliveDelay = getKeepaliveDelay(); + if(shouldSendKeepalive()) { + // Keepalive executor is optional for now and a default instance is supported + final ScheduledExecutorService executor = getKeepaliveExecutor() == null ? + DEFAULT_KEEPALIVE_EXECUTOR : getKeepaliveExecutorDependency().getExecutor(); + salFacade = new KeepaliveSalFacade(id, salFacade, executor, keepaliveDelay); + } final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(schemaRegistry, schemaContextFactory, new NetconfStateSchemas.NetconfStateSchemasResolverImpl()); final NetconfDevice device = - new NetconfDevice(schemaResourcesDTO, id, salFacade, globalProcessingExecutor, new NetconfMessageTransformer(), getReconnectOnChangedSchema()); + new NetconfDevice(schemaResourcesDTO, id, salFacade, globalProcessingExecutor, getReconnectOnChangedSchema()); final NetconfDeviceCommunicator listener = userCapabilities.isPresent() ? new NetconfDeviceCommunicator(id, device, userCapabilities.get()) : new NetconfDeviceCommunicator(id, device); + if(shouldSendKeepalive()) { + ((KeepaliveSalFacade) salFacade).setListener(listener); + } + final NetconfReconnectingClientConfiguration clientConfig = getClientConfig(listener); final NetconfClientDispatcher dispatcher = getClientDispatcherDependency(); @@ -124,6 +162,10 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co return new SalConnectorCloseable(listener, salFacade); } + private boolean shouldSendKeepalive() { + return getKeepaliveDelay() > 0; + } + private Optional getUserCapabilities() { if(getYangModuleCapabilities() == null) { return Optional.absent(); @@ -144,10 +186,6 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co return Optional.of(parsedOverrideCapabilities); } - public void setBundleContext(final BundleContext bundleContext) { - this.bundleContext = bundleContext; - } - public NetconfReconnectingClientConfiguration getClientConfig(final NetconfDeviceCommunicator listener) { final InetSocketAddress socketAddress = getSocketAddress(); final long clientConnectionTimeoutMillis = getConnectionTimeoutMillis(); @@ -160,7 +198,7 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co .withAddress(socketAddress) .withConnectionTimeoutMillis(clientConnectionTimeoutMillis) .withReconnectStrategy(strategy) - .withAuthHandler(new LoginPassword(getUsername(),getPassword())) + .withAuthHandler(new LoginPassword(getUsername(), getPassword())) .withProtocol(getTcpOnly() ? NetconfClientConfiguration.NetconfClientProtocol.TCP : NetconfClientConfiguration.NetconfClientProtocol.SSH)