From: Robert Varga Date: Wed, 8 Feb 2023 19:04:52 +0000 (+0100) Subject: Refactor restconf-nb blueprint X-Git-Tag: v5.0.2~14 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=commitdiff_plain;h=refs%2Fchanges%2F26%2F104326%2F2 Refactor restconf-nb blueprint Blueprint here is really a large code fragment. Move it to a new class, RestconfNorthbound, so that we purely inject dependencies/configuration. JIRA: NETCONF-958 Change-Id: Ic7214393a599c136aa3876c111145182cc68db0b Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb/pom.xml b/restconf/restconf-nb/pom.xml index dcacf4fc14..ad0cc62362 100644 --- a/restconf/restconf-nb/pom.xml +++ b/restconf/restconf-nb/pom.xml @@ -194,6 +194,10 @@ org.opendaylight.controller threadpool-config-api + + org.opendaylight.controller + threadpool-config-impl + net.java.dev.stax-utils @@ -282,11 +286,6 @@ testutils test - - org.opendaylight.controller - threadpool-config-impl - test - org.mockito mockito-core diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/JaxRsNorthbound.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/JaxRsNorthbound.java new file mode 100644 index 0000000000..8537fc965e --- /dev/null +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/JaxRsNorthbound.java @@ -0,0 +1,62 @@ +/* + * 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.restconf.nb.rfc8040; + +import com.google.common.annotations.Beta; +import javax.servlet.ServletException; +import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration; +import org.opendaylight.aaa.web.WebContextSecurer; +import org.opendaylight.aaa.web.WebServer; +import org.opendaylight.aaa.web.servlet.ServletSupport; +import org.opendaylight.controller.config.threadpool.util.NamingThreadPoolFactory; +import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper; +import org.opendaylight.mdsal.dom.api.DOMActionService; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.mdsal.dom.api.DOMMountPointService; +import org.opendaylight.mdsal.dom.api.DOMNotificationService; +import org.opendaylight.mdsal.dom.api.DOMRpcService; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; +import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider; +import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataStreamServiceImpl; +import org.opendaylight.restconf.nb.rfc8040.streams.Configuration; +import org.opendaylight.restconf.nb.rfc8040.streams.WebSocketInitializer; +import org.opendaylight.restconf.nb.rfc8040.web.WebInitializer; + +/** + * Main entrypoint into RFC8040 northbound. Take care of wiring up all applications activating them through JAX-RS. + */ +@Beta +public final class JaxRsNorthbound implements AutoCloseable { + private final WebInitializer webInitializer; + + public JaxRsNorthbound(final WebServer webServer, final WebContextSecurer webContextSecurer, + final ServletSupport servletSupport, final CustomFilterAdapterConfiguration filterAdapterConfiguration, + final DOMActionService actionService, final DOMDataBroker dataBroker, + final DOMMountPointService mountPointService, final DOMNotificationService notificationService, + final DOMRpcService rpcService, final DOMSchemaService schemaService, + final DatabindProvider databindProvider, + final String pingNamePrefix, final int pingMaxThreadCount, final int maximumFragmentLength, + final int heartbeatInterval, final int idleTimeout, final boolean useSSE) throws ServletException { + final var configuration = new Configuration(maximumFragmentLength, idleTimeout, heartbeatInterval, useSSE); + final var scheduledThreadPool = new ScheduledThreadPoolWrapper(pingMaxThreadCount, + new NamingThreadPoolFactory(pingNamePrefix)); + + webInitializer = new WebInitializer(webServer, webContextSecurer, servletSupport, + new RestconfApplication(databindProvider, mountPointService, dataBroker, rpcService, actionService, + notificationService, schemaService, configuration), + new DataStreamApplication(databindProvider, mountPointService, + new RestconfDataStreamServiceImpl(scheduledThreadPool, configuration)), + filterAdapterConfiguration, + new WebSocketInitializer(scheduledThreadPool, configuration)); + } + + @Override + public void close() { + webInitializer.close(); + } +} diff --git a/restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml b/restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml index 6f5eaecf8a..2bf394bb26 100644 --- a/restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml +++ b/restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml @@ -32,58 +32,23 @@ - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + +