Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notifications to CommunityRestConf #1703

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private LightyController initController(final ControllerConfiguration config) th

private CommunityRestConf initRestconf(final RestConfConfiguration config, final LightyServices services) {
final RestConfConfiguration conf = RestConfConfigUtils.getRestConfConfiguration(config, services);
return CommunityRestConfBuilder.from(conf).build();
return CommunityRestConfBuilder.from(conf).withScheduledThreadPool(services.getScheduledThreadPool()).build();
}

private GnmiSouthboundModule initGnmiModule(final LightyServices services,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private CommunityRestConf initRestconf(final RestConfConfiguration rcConfig, fin

return CommunityRestConfBuilder.from(restConfConfiguration)
.withLightyServer(jettyServerBuilder)
.withScheduledThreadPool(services.getScheduledThreadPool())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public synchronized void start(String[] args) throws InterruptedException, Execu

restconf = CommunityRestConfBuilder
.from(RestConfConfigUtils.getRestConfConfiguration(restConfConfiguration, controller.getServices()))
.withScheduledThreadPool(controller.getServices().getScheduledThreadPool())
.build();
Preconditions.checkState(startLightyModule(restconf, modulesConfig.getModuleTimeoutSeconds()),
"Unable to start restconf module");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ private void startLighty(final ControllerConfiguration controllerConfiguration,
.from(RestConfConfigUtils.getRestConfConfiguration(restconfConfiguration,
this.lightyController.getServices()))
.withLightyServer(jettyServerBuilder)
.withScheduledThreadPool(this.lightyController.getServices().getScheduledThreadPool())
.build();
final boolean restconfStartOk = this.restconf.start()
.get(modulesConfig.getModuleTimeoutSeconds(), TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void start() {
}

@SuppressWarnings("IllegalCatch")
@SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
@SuppressFBWarnings({"SLF4J_SIGN_ONLY_FORMAT", "REC_CATCH_EXCEPTION"})
public void start(String[] args, boolean registerShutdownHook) {
final Stopwatch stopwatch = Stopwatch.createStarted();
LOG.info(".__ .__ .__ __ .__ _________________ _______");
Expand Down Expand Up @@ -158,6 +158,7 @@ private void startLighty(final ControllerConfiguration controllerConfiguration,
.from(RestConfConfigUtils.getRestConfConfiguration(restconfConfiguration,
this.lightyController.getServices()))
.withLightyServer(jettyServerBuilder)
.withScheduledThreadPool(lightyController.getServices().getScheduledThreadPool())
.build();

//3. start openApi and RestConf server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ private void startLighty(final ControllerConfiguration controllerConfiguration,
throws ConfigurationException, ExecutionException, InterruptedException, TimeoutException,
ModuleStartupException {

//FIXME remove this after paths NETCONF-1218 is resolved.
restconfConfiguration.setRestconfServletContextPath("/rests");
restconfConfiguration.setHttpPort(8181);

//1. initialize and start Lighty controller (MD-SAL, Controller, YangTools, Akka)
LightyControllerBuilder lightyControllerBuilder = new LightyControllerBuilder();
this.lightyController = lightyControllerBuilder.from(controllerConfiguration).build();
Expand All @@ -149,6 +153,7 @@ private void startLighty(final ControllerConfiguration controllerConfiguration,
.from(RestConfConfigUtils.getRestConfConfiguration(restconfConfiguration,
this.lightyController.getServices()))
.withLightyServer(jettyServerBuilder)
.withScheduledThreadPool(lightyController.getServices().getScheduledThreadPool())
.build();

//3. start openApi and RestConf server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RestconfAppTest {
public static void init() {
restconfApp = new Main();
restconfApp.start();
restClient = new RestClient("http://localhost:8888/");
restClient = new RestClient("http://localhost:8181/");
}

/**
Expand All @@ -46,7 +46,7 @@ public static void init() {
@Test
public void simpleApplicationTest() throws IOException, InterruptedException {
HttpResponse<String> operations;
restClient.POST("restconf/data/network-topology:network-topology/topology=topology-netconf",
restClient.POST("rests/data/network-topology:network-topology/topology=topology-netconf",
"""
{
"netconf-topology:node": [
Expand All @@ -56,11 +56,11 @@ public void simpleApplicationTest() throws IOException, InterruptedException {
]
}""");

operations = restClient.GET("restconf/operations");
operations = restClient.GET("rests/operations");
Assert.assertEquals(operations.statusCode(), 200);
operations = restClient.GET("restconf/data/network-topology:network-topology?content=config");
operations = restClient.GET("rests/data/network-topology:network-topology?content=config");
Assert.assertEquals(operations.statusCode(), 200);
operations = restClient.GET("restconf/data/network-topology:network-topology?content=nonconfig");
operations = restClient.GET("rests/data/network-topology:network-topology?content=nonconfig");
Assert.assertEquals(operations.statusCode(), 200);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static CommunityRestConf startRestconf(RestConfConfiguration restConfConf
final CommunityRestConf communityRestConf = CommunityRestConfBuilder
.from(RestConfConfigUtils.getRestConfConfiguration(restConfConfiguration,
services))
.withScheduledThreadPool(services.getScheduledThreadPool())
.build();

LOG.info("Starting CommunityRestConf");
Expand Down
4 changes: 4 additions & 0 deletions lighty-modules/lighty-restconf-nb-community/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-sse</artifactId>
</dependency>

<!--Tests-->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/
package io.lighty.modules.northbound.restconf.community.impl;

import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.DATA_SUBSCRIPTION;
import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.NOTIFICATION_STREAM;

import com.google.common.base.Stopwatch;
import com.google.common.base.Throwables;
import io.lighty.core.controller.api.AbstractLightyModule;
Expand All @@ -15,23 +18,30 @@
import io.lighty.server.LightyServerBuilder;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import javax.servlet.ServletContext;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
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.DataStreamApplication;
import org.opendaylight.restconf.nb.rfc8040.RestconfApplication;
import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
import org.opendaylight.restconf.nb.rfc8040.databind.mdsal.DOMDatabindProvider;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataStreamServiceImpl;
import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
import org.opendaylight.restconf.nb.rfc8040.streams.WebSocketInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -51,13 +61,14 @@ public class CommunityRestConf extends AbstractLightyModule {
private Server jettyServer;
private LightyServerBuilder lightyServerBuilder;
private SchemaContextHandler schemaCtxHandler;
private final ScheduledThreadPool scheduledThreadPool;

public CommunityRestConf(final DOMDataBroker domDataBroker, final DOMRpcService domRpcService,
final DOMActionService domActionService, final DOMNotificationService domNotificationService,
final DOMMountPointService domMountPointService,
final DOMSchemaService domSchemaService, final InetAddress inetAddress,
final int httpPort, final String restconfServletContextPath,
final LightyServerBuilder serverBuilder) {
final LightyServerBuilder serverBuilder, final ScheduledThreadPool threadPool) {
this.domDataBroker = domDataBroker;
this.domRpcService = domRpcService;
this.domActionService = domActionService;
Expand All @@ -68,16 +79,17 @@ public CommunityRestConf(final DOMDataBroker domDataBroker, final DOMRpcService
this.httpPort = httpPort;
this.inetAddress = inetAddress;
this.restconfServletContextPath = restconfServletContextPath;
this.scheduledThreadPool = threadPool;
}

public CommunityRestConf(final DOMDataBroker domDataBroker,
final DOMRpcService domRpcService, final DOMActionService domActionService,
final DOMNotificationService domNotificationService, final DOMMountPointService domMountPointService,
final DOMSchemaService domSchemaService, final InetAddress inetAddress, final int httpPort,
final String restconfServletContextPath) {
final String restconfServletContextPath, final ScheduledThreadPool threadPool) {
this(domDataBroker, domRpcService, domActionService, domNotificationService,
domMountPointService, domSchemaService, inetAddress, httpPort,
restconfServletContextPath, null);
restconfServletContextPath, null, threadPool);
}

@Override
Expand All @@ -93,10 +105,16 @@ protected boolean initProcedure() {
final RestconfApplication restconfApplication = new RestconfApplication(databindProvider,
this.domMountPointService, this.domDataBroker, this.domRpcService, this.domActionService,
this.domNotificationService, this.domSchemaService, streamsConfiguration);
final DataStreamApplication dataStreamApplication = new DataStreamApplication(databindProvider,
this.domMountPointService, new RestconfDataStreamServiceImpl(scheduledThreadPool, streamsConfiguration));
final ServletContainer servletContainer8040 = new ServletContainer(ResourceConfig
.forApplication(restconfApplication));
final ServletHolder jaxrs = new ServletHolder(servletContainer8040);

final ServletContainer dataStreamServletContainer = new ServletContainer(
ResourceConfig.forApplication(dataStreamApplication));
final ServletHolder dataStreamHolder = new ServletHolder(dataStreamServletContainer);

LOG.info("RestConf init complete, starting Jetty");
LOG.info("http address:port {}:{}, url prefix: {}", this.inetAddress.toString(), this.httpPort,
this.restconfServletContextPath);
Expand All @@ -107,6 +125,19 @@ protected boolean initProcedure() {
final ServletContextHandler mainHandler =
new ServletContextHandler(contexts, this.restconfServletContextPath, true, false);
mainHandler.addServlet(jaxrs, "/*");
mainHandler.addServlet(dataStreamHolder, "/notif/*");

final ServletContextHandler dataHandler = new ServletContextHandler(
contexts, "/" + DATA_SUBSCRIPTION, true, false);
final ServletContextHandler notifHandler = new ServletContextHandler(
contexts, "/" + NOTIFICATION_STREAM, true, false);
final WebSocketInitializer webSocketInitializer = new WebSocketInitializer(
scheduledThreadPool, streamsConfiguration);
final ServletContext context = notifHandler.getServletContext();
final WebSocketServletFactory factory = new WebSocketServerFactory(context);
webSocketInitializer.configure(factory);
dataHandler.addServlet(new ServletHolder(webSocketInitializer), "/*");
notifHandler.addServlet(new ServletHolder(webSocketInitializer), "/*");

final ServletContextHandler rrdHandler =
new ServletContextHandler(contexts, "/.well-known", true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import io.lighty.modules.northbound.restconf.community.impl.config.RestConfConfiguration;
import io.lighty.server.LightyServerBuilder;
import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;

/**
* Builder for {@link CommunityRestConf}.
Expand All @@ -17,6 +18,7 @@ public final class CommunityRestConfBuilder {

private RestConfConfiguration restconfConfiguration = null;
private LightyServerBuilder lightyServerBuilder = null;
private ScheduledThreadPool threadPool = null;


private CommunityRestConfBuilder(final RestConfConfiguration configuration) {
Expand Down Expand Up @@ -44,6 +46,17 @@ public CommunityRestConfBuilder withLightyServer(final LightyServerBuilder serve
return this;
}

/**
* Add ScheduledThreadPool.
*
* @param pool input scheduledThreadPool.
* @return instance of {@link CommunityRestConfBuilder}.
*/
public CommunityRestConfBuilder withScheduledThreadPool(final ScheduledThreadPool pool) {
this.threadPool = pool;
return this;
}

/**
* Build new {@link CommunityRestConf} instance from {@link CommunityRestConfBuilder}.
* @return instance of CommunityRestConf.
Expand All @@ -55,6 +68,6 @@ public CommunityRestConf build() {
this.restconfConfiguration.getDomMountPointService(),
this.restconfConfiguration.getDomSchemaService(),
this.restconfConfiguration.getInetAddress(), this.restconfConfiguration.getHttpPort(),
this.restconfConfiguration.getRestconfServletContextPath(), this.lightyServerBuilder);
this.restconfConfiguration.getRestconfServletContextPath(), this.lightyServerBuilder, this.threadPool);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final class RestConfConfigUtils {
org.opendaylight.yang.gen.v1.subscribe.to.notification.rev161028
.$YangModuleInfoImpl.getInstance(),
org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121
.$YangModuleInfoImpl.getInstance()
);
.$YangModuleInfoImpl.getInstance(),
org.opendaylight.yang.gen.v1.urn.opendaylight.device.notification.rev221106
.$YangModuleInfoImpl.getInstance());
public static final int MAXIMUM_FRAGMENT_LENGTH = 0;
public static final int IDLE_TIMEOUT = 30000;
public static final int HEARTBEAT_INTERVAL = 10000;
Expand Down
Loading