Refactor restconf-nb blueprint 26/104326/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Feb 2023 19:04:52 +0000 (20:04 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Feb 2023 19:28:34 +0000 (20:28 +0100)
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 <robert.varga@pantheon.tech>
restconf/restconf-nb/pom.xml
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/JaxRsNorthbound.java [new file with mode: 0644]
restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml

index dcacf4fc1446e33f532f63f3a18ff3983cf347cd..ad0cc62362765ba329f075a271597416520aea3f 100644 (file)
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>threadpool-config-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>threadpool-config-impl</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>net.java.dev.stax-utils</groupId>
       <artifactId>testutils</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>threadpool-config-impl</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
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 (file)
index 0000000..8537fc9
--- /dev/null
@@ -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();
+    }
+}
index 6f5eaecf8a1c268a98b4264d5a0e044056f44b54..2bf394bb2616c4d86565b973e121d899d44d22a7 100644 (file)
   <reference id="dOMRpcService" interface="org.opendaylight.mdsal.dom.api.DOMRpcService"/>
   <reference id="dOMSchemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
 
-  <bean id="scheduledThreadPool"
-        class="org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper">
-    <argument value="${max-thread-count}"/>
-    <argument>
-      <bean class="org.opendaylight.controller.config.threadpool.util.NamingThreadPoolFactory">
-        <argument value="${ping-executor-name-prefix}"/>
-      </bean>
-    </argument>
-  </bean>
-
-  <bean id="configuration"
-        class="org.opendaylight.restconf.nb.rfc8040.streams.Configuration">
-    <argument value="${maximum-fragment-length}"/>
-    <argument value="${idle-timeout}"/>
-    <argument value="${heartbeat-interval}"/>
-    <argument value="${use-sse}" />
-  </bean>
-
-  <bean id="webInitializer" class="org.opendaylight.restconf.nb.rfc8040.web.WebInitializer" destroy-method="close">
+  <bean id="restconfNorthbound" class="org.opendaylight.restconf.nb.rfc8040.JaxRsNorthbound" destroy-method="close">
     <argument ref="webServer"/>
     <argument ref="webContextSecurer"/>
     <argument ref="servletSupport"/>
-    <argument>
-      <bean class="org.opendaylight.restconf.nb.rfc8040.RestconfApplication">
-        <argument ref="databindProvider"/>
-        <argument ref="dOMMountPointService"/>
-        <argument ref="dOMDataBroker"/>
-        <argument ref="dOMRpcService"/>
-        <argument ref="dOMActionService"/>
-        <argument ref="dOMNotificationService"/>
-        <argument ref="dOMSchemaService"/>
-        <argument ref="configuration"/>
-      </bean>
-    </argument>
-    <argument>
-      <bean class="org.opendaylight.restconf.nb.rfc8040.DataStreamApplication">
-        <argument ref="databindProvider"/>
-        <argument ref="dOMMountPointService"/>
-        <argument>
-          <bean class="org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataStreamServiceImpl">
-            <argument ref="scheduledThreadPool"/>
-            <argument ref="configuration"/>
-          </bean>
-        </argument>
-      </bean>
-    </argument>
     <argument ref="customFilterAdapterConfiguration"/>
-    <argument>
-      <bean class="org.opendaylight.restconf.nb.rfc8040.streams.WebSocketInitializer">
-        <argument ref="scheduledThreadPool"/>
-        <argument ref="configuration"/>
-      </bean>
-    </argument>
+    <argument ref="dOMActionService"/>
+    <argument ref="dOMDataBroker"/>
+    <argument ref="dOMMountPointService"/>
+    <argument ref="dOMNotificationService"/>
+    <argument ref="dOMRpcService"/>
+    <argument ref="dOMSchemaService"/>
+    <argument ref="databindProvider"/>
+    <argument value="${ping-executor-name-prefix}"/>
+    <argument value="${max-thread-count}"/>
+    <argument value="${maximum-fragment-length}"/>
+    <argument value="${heartbeat-interval}"/>
+    <argument value="${idle-timeout}"/>
+    <argument value="${use-sse}"/>
   </bean>
 </blueprint>