From: Robert Varga Date: Wed, 8 Feb 2023 23:18:52 +0000 (+0100) Subject: Convert JaxRsNorthbound into a Component X-Git-Tag: v5.0.2~10 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F38%2F104338%2F2;p=netconf.git Convert JaxRsNorthbound into a Component We have all we need to ditch blueprint, rehost Config Admin binding and turn JaxRsNorthbound into a proper Component. JIRA: NETCONF-959 Change-Id: Id2af0cc4925b34de01198cfcfd98bc63351399d3 Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb/pom.xml b/restconf/restconf-nb/pom.xml index ad0cc62362..34496f6df4 100644 --- a/restconf/restconf-nb/pom.xml +++ b/restconf/restconf-nb/pom.xml @@ -58,6 +58,10 @@ org.osgi org.osgi.service.component.annotations + + org.osgi + org.osgi.service.metatype.annotations + org.opendaylight.netconf 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 index 66e1132baa..afd17c770e 100644 --- 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 @@ -35,25 +35,66 @@ import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataStre import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration; import org.opendaylight.restconf.nb.rfc8040.streams.WebSocketInitializer; import org.opendaylight.yangtools.concepts.Registration; +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; /** * Main entrypoint into RFC8040 northbound. Take care of wiring up all applications activating them through JAX-RS. */ @Beta +@Component(service = { }, configurationPid = "org.opendaylight.restconf.nb.rfc8040") +@Designate(ocd = JaxRsNorthbound.Configuration.class) public final class JaxRsNorthbound implements AutoCloseable { + @ObjectClassDefinition + public @interface Configuration { + @AttributeDefinition(min = "0", max = "" + StreamsConfiguration.MAXIMUM_FRAGMENT_LENGTH_LIMIT) + int maximum$_$fragment$_$length() default 0; + @AttributeDefinition(min = "0") + int heartbeat$_$interval() default 10000; + @AttributeDefinition(min = "1") + int idle$_$timeout() default 30000; + @AttributeDefinition(min = "1") + String ping$_$executor$_$name$_$prefix() default "ping-executor"; + // FIXME: this is a misnomer: it specifies the core pool size, i.e. minimum thread count, the maximum is set to + // Integer.MAX_VALUE, which is not what we want + @AttributeDefinition(min = "0") + int max$_$thread$_$count() default 1; + @AttributeDefinition + boolean use$_$sse() default true; + } + private final Registration discoveryReg; private final Registration restconfReg; + @Activate + public JaxRsNorthbound(@Reference final WebServer webServer, @Reference final WebContextSecurer webContextSecurer, + @Reference final ServletSupport servletSupport, + @Reference final CustomFilterAdapterConfiguration filterAdapterConfiguration, + @Reference final DOMActionService actionService, @Reference final DOMDataBroker dataBroker, + @Reference final DOMMountPointService mountPointService, + @Reference final DOMNotificationService notificationService, @Reference final DOMRpcService rpcService, + @Reference final DOMSchemaService schemaService, @Reference final DatabindProvider databindProvider, + final Configuration configuration) throws ServletException { + this(webServer, webContextSecurer, servletSupport, filterAdapterConfiguration, actionService, dataBroker, + mountPointService, notificationService, rpcService, schemaService, databindProvider, + configuration.ping$_$executor$_$name$_$prefix(), configuration.max$_$thread$_$count(), + new StreamsConfiguration(configuration.maximum$_$fragment$_$length(), configuration.heartbeat$_$interval(), + configuration.idle$_$timeout(), configuration.use$_$sse())); + } + 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 streamsConfiguration = new StreamsConfiguration(maximumFragmentLength, idleTimeout, heartbeatInterval, - useSSE); + final String pingNamePrefix, final int pingMaxThreadCount, + final StreamsConfiguration streamsConfiguration) throws ServletException { final var scheduledThreadPool = new ScheduledThreadPoolWrapper(pingMaxThreadCount, new NamingThreadPoolFactory(pingNamePrefix)); @@ -108,6 +149,7 @@ public final class JaxRsNorthbound implements AutoCloseable { discoveryReg = webServer.registerWebContext(discoveryBuilder.build()); } + @Deactivate @Override public void close() { discoveryReg.close(); diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/StreamsConfiguration.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/StreamsConfiguration.java index b8b700228f..6a10286bfa 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/StreamsConfiguration.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/StreamsConfiguration.java @@ -19,8 +19,12 @@ import static com.google.common.base.Preconditions.checkArgument; * @param useSSE when is {@code true} use SSE else use WS */ public record StreamsConfiguration(int maximumFragmentLength, int idleTimeout, int heartbeatInterval, boolean useSSE) { + // FIXME: can this be 64KiB exactly? if so, maximumFragmentLength should become a Uint16 and validation should be + // pushed out to users + public static final int MAXIMUM_FRAGMENT_LENGTH_LIMIT = 65534; + public StreamsConfiguration { - checkArgument(maximumFragmentLength >= 0 && maximumFragmentLength < 65535, + checkArgument(maximumFragmentLength >= 0 && maximumFragmentLength <= MAXIMUM_FRAGMENT_LENGTH_LIMIT, "Maximum fragment length must be disabled (0) or specified by positive value less than 64KiB"); checkArgument(idleTimeout > 0, "Idle timeout must be specified by positive value."); checkArgument(heartbeatInterval >= 0, 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 deleted file mode 100644 index 2bf394bb26..0000000000 --- a/restconf/restconf-nb/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -