From 0e7badde2c5a85460ef07e9dc8a7bc4de39c2c19 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 8 Feb 2023 13:37:52 +0100 Subject: [PATCH] Convert mdsal-netconf-impl to OSGi DS The blueprint here is just picking up config admin tuneables and wires things together. This patch converts this wiring to OSGi DS. Unfortunately the config admin bits are jumbled together, hence we use factory components to split them up. JIRA: NETCONF-951 Change-Id: Icdabc7b2e62cb77a6bf5659274955463be993f88 Signed-off-by: Robert Varga --- netconf/mdsal-netconf-impl/pom.xml | 48 +++++++--- .../DefaultNetconfMonitoringService.java | 50 ++++++++++ .../mdsal/DefaultNetconfServerDispatcher.java | 43 +++++++++ .../impl/mdsal/NetconfMapperAggregator.java | 4 +- .../netconf/impl/mdsal/OSGiNetconfServer.java | 82 +++++++++++++++++ .../OSGI-INF/blueprint/mdsal-netconf-impl.xml | 91 ------------------- 6 files changed, 215 insertions(+), 103 deletions(-) create mode 100644 netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/DefaultNetconfMonitoringService.java create mode 100644 netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/DefaultNetconfServerDispatcher.java create mode 100644 netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/OSGiNetconfServer.java delete mode 100644 netconf/mdsal-netconf-impl/src/main/resources/OSGI-INF/blueprint/mdsal-netconf-impl.xml diff --git a/netconf/mdsal-netconf-impl/pom.xml b/netconf/mdsal-netconf-impl/pom.xml index 04796b77f5..bed678a633 100644 --- a/netconf/mdsal-netconf-impl/pom.xml +++ b/netconf/mdsal-netconf-impl/pom.xml @@ -22,13 +22,49 @@ - ${project.groupId} + com.google.guava + guava + + + io.netty + netty-common + + + io.netty + netty-transport + + + org.opendaylight.controller + threadpool-config-api + + + org.opendaylight.netconf + netconf-api + + + org.opendaylight.netconf netconf-impl + + org.opendaylight.netconf + netconf-mapping-api + + + org.osgi + org.osgi.framework + + + org.osgi + org.osgi.service.component + org.osgi org.osgi.service.component.annotations + + org.osgi + org.osgi.service.metatype.annotations + @@ -40,16 +76,6 @@ ${project.artifactId} - - io.netty.channel, - io.netty.util, - org.opendaylight.controller.config.threadpool, - org.opendaylight.netconf.api.monitoring, - org.opendaylight.netconf.impl, - org.opendaylight.netconf.impl.osgi, - org.opendaylight.netconf.mapping.api, - * - diff --git a/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/DefaultNetconfMonitoringService.java b/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/DefaultNetconfMonitoringService.java new file mode 100644 index 0000000000..1b918657d7 --- /dev/null +++ b/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/DefaultNetconfMonitoringService.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.netconf.impl.mdsal; + +import static java.util.Objects.requireNonNull; + +import java.util.Map; +import org.opendaylight.controller.config.threadpool.ScheduledThreadPool; +import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.netconf.impl.osgi.NetconfMonitoringServiceImpl; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; + +@Component(factory = DefaultNetconfMonitoringService.FACTORY_NAME, service = NetconfMonitoringService.class) +public final class DefaultNetconfMonitoringService extends NetconfMonitoringServiceImpl { + static final String FACTORY_NAME = "org.opendaylight.netconf.impl.mdsal.DefaultNetconfMonitoringService"; + + private static final String OP_PROVIDER_PROP = ".opProvider"; + private static final String THREAD_POOL_PROP = ".threadPool"; + private static final String UPDATE_INTERVAL_PROP = ".updateInterval"; + + @Activate + public DefaultNetconfMonitoringService(final Map properties) { + super(OSGiNetconfServer.extractProp(properties, OP_PROVIDER_PROP, NetconfOperationServiceFactory.class), + OSGiNetconfServer.extractProp(properties, THREAD_POOL_PROP, ScheduledThreadPool.class), + OSGiNetconfServer.extractProp(properties, UPDATE_INTERVAL_PROP, Long.class)); + } + + @Override + @Deactivate + public void close() { + super.close(); + } + + static Map props(final NetconfOperationServiceFactory opProvider, final ScheduledThreadPool threadPool, + final long updateInterval) { + return Map.of( + "type", "netconf-server-monitoring", + OP_PROVIDER_PROP, requireNonNull(opProvider), + THREAD_POOL_PROP, requireNonNull(threadPool), + UPDATE_INTERVAL_PROP, updateInterval); + } +} diff --git a/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/DefaultNetconfServerDispatcher.java b/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/DefaultNetconfServerDispatcher.java new file mode 100644 index 0000000000..a60317b711 --- /dev/null +++ b/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/DefaultNetconfServerDispatcher.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.netconf.impl.mdsal; + +import static java.util.Objects.requireNonNull; + +import io.netty.channel.EventLoopGroup; +import java.util.Map; +import org.opendaylight.netconf.api.NetconfServerDispatcher; +import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl; +import org.opendaylight.netconf.impl.ServerChannelInitializer; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; + +@Component(factory = DefaultNetconfServerDispatcher.FACTORY_NAME, service = NetconfServerDispatcher.class) +public final class DefaultNetconfServerDispatcher extends NetconfServerDispatcherImpl { + static final String FACTORY_NAME = "org.opendaylight.netconf.impl.mdsal.DefaultNetconfServerDispatcher"; + + private static final String BOSS_PROP = ".bossGroup"; + private static final String WORKER_PROP = ".workerGroup"; + private static final String INITIALIZER_PROP = ".initializer"; + + @Activate + public DefaultNetconfServerDispatcher(final Map properties) { + super(OSGiNetconfServer.extractProp(properties, INITIALIZER_PROP, ServerChannelInitializer.class), + OSGiNetconfServer.extractProp(properties, BOSS_PROP, EventLoopGroup.class), + OSGiNetconfServer.extractProp(properties, WORKER_PROP, EventLoopGroup.class)); + } + + static Map props(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup, + final ServerChannelInitializer initializer) { + return Map.of( + "type", "netconf-server-dispatcher", + BOSS_PROP, requireNonNull(bossGroup), + WORKER_PROP, requireNonNull(workerGroup), + INITIALIZER_PROP, requireNonNull(initializer)); + } +} diff --git a/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/NetconfMapperAggregator.java b/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/NetconfMapperAggregator.java index 44c624fdd9..cf3637a13f 100644 --- a/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/NetconfMapperAggregator.java +++ b/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/NetconfMapperAggregator.java @@ -15,8 +15,10 @@ import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; @Component(service = { NetconfOperationServiceFactory.class, NetconfOperationServiceFactoryListener.class }, - property = "type=mapper-aggregator-registry", immediate = true) + property = NetconfMapperAggregator.OSGI_TYPE, immediate = true) public final class NetconfMapperAggregator extends AggregatedNetconfOperationServiceFactory { + static final String OSGI_TYPE = "type=mapper-aggregator-registry"; + @Activate public NetconfMapperAggregator() { super(); diff --git a/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/OSGiNetconfServer.java b/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/OSGiNetconfServer.java new file mode 100644 index 0000000000..e4bb3ba751 --- /dev/null +++ b/netconf/mdsal-netconf-impl/src/main/java/org/opendaylight/netconf/impl/mdsal/OSGiNetconfServer.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.netconf.impl.mdsal; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +import io.netty.channel.EventLoopGroup; +import io.netty.util.Timer; +import java.util.Map; +import org.opendaylight.controller.config.threadpool.ScheduledThreadPool; +import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory; +import org.opendaylight.netconf.impl.ServerChannelInitializer; +import org.opendaylight.netconf.impl.SessionIdProvider; +import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; +import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; +import org.osgi.framework.FrameworkUtil; +import org.osgi.service.component.ComponentFactory; +import org.osgi.service.component.ComponentInstance; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.Designate; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@Component(service = { }, configurationPid = "org.opendaylight.netconf.impl") +@Designate(ocd = OSGiNetconfServer.Configuration.class) +public final class OSGiNetconfServer { + @ObjectClassDefinition + public @interface Configuration { + @AttributeDefinition(min = "0") + long connection$_$timeout$_$millis() default 20000; + @AttributeDefinition + long monitoring$_$update$_$interval() default 6; + } + + private final AggregatedNetconfOperationServiceFactory mappers = new AggregatedNetconfOperationServiceFactory(); + private final ComponentInstance monitoring; + private final ComponentInstance dispatcher; + + @Activate + public OSGiNetconfServer( + @Reference(target = "(component.factory=" + DefaultNetconfMonitoringService.FACTORY_NAME + ")") + final ComponentFactory monitoringFactory, + @Reference(target = "(component.factory=" + DefaultNetconfServerDispatcher.FACTORY_NAME + ")") + final ComponentFactory dispatcherFactory, + @Reference(target = "(" + NetconfMapperAggregator.OSGI_TYPE + ")") + final NetconfOperationServiceFactory mapperAggregatorRegistry, + @Reference(target = "(type=global-netconf-ssh-scheduled-executor)") + final ScheduledThreadPool sshScheduledExecutor, + @Reference(target = "(type=global-boss-group)") final EventLoopGroup bossGroup, + @Reference(target = "(type=global-boss-group)") final EventLoopGroup workerGroup, + @Reference(target = "(type=global-timer)") final Timer timer, + @Reference final SessionIdProvider sessionIdProvider, + final Configuration configuration) { + mappers.onAddNetconfOperationServiceFactory(mapperAggregatorRegistry); + monitoring = monitoringFactory.newInstance(FrameworkUtil.asDictionary(DefaultNetconfMonitoringService.props( + mapperAggregatorRegistry, sshScheduledExecutor, configuration.monitoring$_$update$_$interval()))); + dispatcher = dispatcherFactory.newInstance(FrameworkUtil.asDictionary(DefaultNetconfServerDispatcher.props( + bossGroup, workerGroup, new ServerChannelInitializer(new NetconfServerSessionNegotiatorFactory(timer, + mappers, sessionIdProvider, configuration.connection$_$timeout$_$millis(), + monitoring.getInstance()))))); + } + + @Deactivate + public void deactivate() { + dispatcher.dispose(); + monitoring.dispose(); + mappers.close(); + } + + static T extractProp(final Map properties, final String key, final Class valueType) { + return valueType.cast(verifyNotNull(properties.get(requireNonNull(key)))); + } +} diff --git a/netconf/mdsal-netconf-impl/src/main/resources/OSGI-INF/blueprint/mdsal-netconf-impl.xml b/netconf/mdsal-netconf-impl/src/main/resources/OSGI-INF/blueprint/mdsal-netconf-impl.xml deleted file mode 100644 index 288991df5f..0000000000 --- a/netconf/mdsal-netconf-impl/src/main/resources/OSGI-INF/blueprint/mdsal-netconf-impl.xml +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 2.36.6