Skip to content

Commit 2f5be89

Browse files
Tobianasihrasko
authored andcommitted
Initialize notifications in CommunityRestConf
Initialize /notif endpoint and everything related to it inside CommunityRestConf. Signed-off-by: tobias.pobocik <tobias.pobocik@pantheon.tech>
1 parent 53a2c8c commit 2f5be89

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

lighty-examples/lighty-community-restconf-actions-app/src/main/java/io/lighty/examples/controllers/actions/Main.java

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ private void startLighty(final ControllerConfiguration controllerConfiguration,
158158
.from(RestConfConfigUtils.getRestConfConfiguration(restconfConfiguration,
159159
this.lightyController.getServices()))
160160
.withLightyServer(jettyServerBuilder)
161+
.withScheduledThreadPool(lightyController.getServices().getScheduledThreadPool())
161162
.build();
162163

163164
//3. start openApi and RestConf server

lighty-modules/lighty-restconf-nb-community/src/main/java/io/lighty/modules/northbound/restconf/community/impl/CommunityRestConf.java

+34-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
*/
88
package io.lighty.modules.northbound.restconf.community.impl;
99

10+
import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.DATA_SUBSCRIPTION;
11+
import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.NOTIFICATION_STREAM;
12+
import static org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants.NOTIF;
13+
1014
import com.google.common.base.Stopwatch;
1115
import com.google.common.base.Throwables;
1216
import io.lighty.core.controller.api.AbstractLightyModule;
@@ -15,23 +19,30 @@
1519
import io.lighty.server.LightyServerBuilder;
1620
import java.net.InetAddress;
1721
import java.net.InetSocketAddress;
22+
import javax.servlet.ServletContext;
1823
import org.eclipse.jetty.server.Server;
1924
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
2025
import org.eclipse.jetty.servlet.ServletContextHandler;
2126
import org.eclipse.jetty.servlet.ServletHolder;
27+
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
28+
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
2229
import org.glassfish.jersey.server.ResourceConfig;
2330
import org.glassfish.jersey.servlet.ServletContainer;
31+
import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
2432
import org.opendaylight.mdsal.dom.api.DOMActionService;
2533
import org.opendaylight.mdsal.dom.api.DOMDataBroker;
2634
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
2735
import org.opendaylight.mdsal.dom.api.DOMNotificationService;
2836
import org.opendaylight.mdsal.dom.api.DOMRpcService;
2937
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
38+
import org.opendaylight.restconf.nb.rfc8040.DataStreamApplication;
3039
import org.opendaylight.restconf.nb.rfc8040.RestconfApplication;
3140
import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
3241
import org.opendaylight.restconf.nb.rfc8040.databind.mdsal.DOMDatabindProvider;
3342
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
43+
import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataStreamServiceImpl;
3444
import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
45+
import org.opendaylight.restconf.nb.rfc8040.streams.WebSocketInitializer;
3546
import org.slf4j.Logger;
3647
import org.slf4j.LoggerFactory;
3748

@@ -51,13 +62,14 @@ public class CommunityRestConf extends AbstractLightyModule {
5162
private Server jettyServer;
5263
private LightyServerBuilder lightyServerBuilder;
5364
private SchemaContextHandler schemaCtxHandler;
65+
private final ScheduledThreadPool scheduledThreadPool;
5466

5567
public CommunityRestConf(final DOMDataBroker domDataBroker, final DOMRpcService domRpcService,
5668
final DOMActionService domActionService, final DOMNotificationService domNotificationService,
5769
final DOMMountPointService domMountPointService,
5870
final DOMSchemaService domSchemaService, final InetAddress inetAddress,
5971
final int httpPort, final String restconfServletContextPath,
60-
final LightyServerBuilder serverBuilder) {
72+
final LightyServerBuilder serverBuilder, final ScheduledThreadPool threadPool) {
6173
this.domDataBroker = domDataBroker;
6274
this.domRpcService = domRpcService;
6375
this.domActionService = domActionService;
@@ -68,16 +80,17 @@ public CommunityRestConf(final DOMDataBroker domDataBroker, final DOMRpcService
6880
this.httpPort = httpPort;
6981
this.inetAddress = inetAddress;
7082
this.restconfServletContextPath = restconfServletContextPath;
83+
this.scheduledThreadPool = threadPool;
7184
}
7285

7386
public CommunityRestConf(final DOMDataBroker domDataBroker,
7487
final DOMRpcService domRpcService, final DOMActionService domActionService,
7588
final DOMNotificationService domNotificationService, final DOMMountPointService domMountPointService,
7689
final DOMSchemaService domSchemaService, final InetAddress inetAddress, final int httpPort,
77-
final String restconfServletContextPath) {
90+
final String restconfServletContextPath, final ScheduledThreadPool threadPool) {
7891
this(domDataBroker, domRpcService, domActionService, domNotificationService,
7992
domMountPointService, domSchemaService, inetAddress, httpPort,
80-
restconfServletContextPath, null);
93+
restconfServletContextPath, null, threadPool);
8194
}
8295

8396
@Override
@@ -93,10 +106,15 @@ protected boolean initProcedure() {
93106
final RestconfApplication restconfApplication = new RestconfApplication(databindProvider,
94107
this.domMountPointService, this.domDataBroker, this.domRpcService, this.domActionService,
95108
this.domNotificationService, this.domSchemaService, streamsConfiguration);
109+
final DataStreamApplication dataStreamApplication = new DataStreamApplication(databindProvider, this.domMountPointService,
110+
new RestconfDataStreamServiceImpl(scheduledThreadPool, streamsConfiguration));
96111
final ServletContainer servletContainer8040 = new ServletContainer(ResourceConfig
97112
.forApplication(restconfApplication));
98113
final ServletHolder jaxrs = new ServletHolder(servletContainer8040);
99114

115+
final ServletContainer dataStreamServletContainer = new ServletContainer(ResourceConfig.forApplication(dataStreamApplication));
116+
final ServletHolder dataStreamHolder = new ServletHolder(dataStreamServletContainer);
117+
100118
LOG.info("RestConf init complete, starting Jetty");
101119
LOG.info("http address:port {}:{}, url prefix: {}", this.inetAddress.toString(), this.httpPort,
102120
this.restconfServletContextPath);
@@ -108,6 +126,19 @@ protected boolean initProcedure() {
108126
new ServletContextHandler(contexts, this.restconfServletContextPath, true, false);
109127
mainHandler.addServlet(jaxrs, "/*");
110128

129+
final ServletContextHandler notifHandler =
130+
new ServletContextHandler(contexts, "/" + NOTIF, true, false);
131+
notifHandler.addServlet(dataStreamHolder, "/*");
132+
133+
final ServletContextHandler wsHandler = new ServletContextHandler(contexts, "/" + DATA_SUBSCRIPTION, true, false);
134+
final ServletContextHandler wsHandler1 = new ServletContextHandler(contexts, "/" + NOTIFICATION_STREAM, true, false);
135+
final WebSocketInitializer webSocketInitializer = new WebSocketInitializer(scheduledThreadPool, streamsConfiguration);
136+
ServletContext context = wsHandler1.getServletContext();
137+
WebSocketServletFactory factory = new WebSocketServerFactory(context);
138+
webSocketInitializer.configure(factory);
139+
wsHandler.addServlet(new ServletHolder(webSocketInitializer), "/*");
140+
wsHandler1.addServlet(new ServletHolder(webSocketInitializer), "/*");
141+
111142
final ServletContextHandler rrdHandler =
112143
new ServletContextHandler(contexts, "/.well-known", true, false);
113144
final RootFoundApplication rootDiscoveryApp = new RootFoundApplication(restconfServletContextPath);

lighty-modules/lighty-restconf-nb-community/src/main/java/io/lighty/modules/northbound/restconf/community/impl/CommunityRestConfBuilder.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import io.lighty.modules.northbound.restconf.community.impl.config.RestConfConfiguration;
1111
import io.lighty.server.LightyServerBuilder;
12+
import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
1213

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

1819
private RestConfConfiguration restconfConfiguration = null;
1920
private LightyServerBuilder lightyServerBuilder = null;
21+
private ScheduledThreadPool threadPool = null;
2022

2123

2224
private CommunityRestConfBuilder(final RestConfConfiguration configuration) {
@@ -44,6 +46,19 @@ public CommunityRestConfBuilder withLightyServer(final LightyServerBuilder serve
4446
return this;
4547
}
4648

49+
50+
/**
51+
* Inject lighty server builder.
52+
*
53+
* @param pool input server builder.
54+
* @return instance of {@link CommunityRestConfBuilder}.
55+
*/
56+
public CommunityRestConfBuilder withScheduledThreadPool(final ScheduledThreadPool pool) {
57+
this.threadPool = pool;
58+
return this;
59+
}
60+
61+
4762
/**
4863
* Build new {@link CommunityRestConf} instance from {@link CommunityRestConfBuilder}.
4964
* @return instance of CommunityRestConf.
@@ -55,6 +70,6 @@ public CommunityRestConf build() {
5570
this.restconfConfiguration.getDomMountPointService(),
5671
this.restconfConfiguration.getDomSchemaService(),
5772
this.restconfConfiguration.getInetAddress(), this.restconfConfiguration.getHttpPort(),
58-
this.restconfConfiguration.getRestconfServletContextPath(), this.lightyServerBuilder);
73+
this.restconfConfiguration.getRestconfServletContextPath(), this.lightyServerBuilder, this.threadPool);
5974
}
6075
}

0 commit comments

Comments
 (0)