@@ -102,6 +102,8 @@ public class ZeppelinServer extends ResourceConfig {
102102 public static ServiceLocator sharedServiceLocator ;
103103
104104 private static ZeppelinConfiguration conf = ZeppelinConfiguration .create ();
105+ private static final String CONNCETOR_NAME_DEFAULT = "default" ;
106+ private static final String CONNCETOR_NAME_ANGULAR = "angular" ;
105107
106108 @ Inject
107109 public ZeppelinServer () {
@@ -119,9 +121,6 @@ public static void main(String[] args) throws InterruptedException {
119121 ContextHandlerCollection contexts = new ContextHandlerCollection ();
120122 jettyWebServer .setHandler (contexts );
121123
122- // Web UI
123- final WebAppContext webApp = setupWebAppContext (contexts , conf );
124-
125124 sharedServiceLocator = ServiceLocatorFactory .getInstance ().create ("shared-locator" );
126125 ServiceLocatorUtilities .enableImmediateScope (sharedServiceLocator );
127126 ServiceLocatorUtilities .addClasses (sharedServiceLocator ,
@@ -180,25 +179,12 @@ protected void configure() {
180179 }
181180 });
182181
183- webApp .addEventListener (
184- new ServletContextListener () {
185- @ Override
186- public void contextInitialized (ServletContextEvent servletContextEvent ) {
187- servletContextEvent
188- .getServletContext ()
189- .setAttribute (ServletProperties .SERVICE_LOCATOR , sharedServiceLocator );
190- }
191-
192- @ Override
193- public void contextDestroyed (ServletContextEvent servletContextEvent ) {}
194- });
195-
196- // Create `ZeppelinServer` using reflection and setup REST Api
197- setupRestApiContextHandler (webApp , conf );
198-
199- // Notebook server
200- setupNotebookServer (webApp , conf , sharedServiceLocator );
182+ // Multiple Web UI
183+ final WebAppContext defaultWebApp = setupWebAppContext (contexts , conf , conf .getString (ConfVars .ZEPPELIN_WAR ), CONNCETOR_NAME_DEFAULT );
184+ final WebAppContext angularWebApp = setupWebAppContext (contexts , conf , conf .getString (ConfVars .ZEPPELIN_ANGULAR_WAR ), CONNCETOR_NAME_ANGULAR );
201185
186+ initWebApp (defaultWebApp );
187+ initWebApp (angularWebApp );
202188 // Cluster Manager Server
203189 setupClusterManagerServer (sharedServiceLocator );
204190
@@ -304,14 +290,19 @@ private static Server setupJettyServer(ZeppelinConfiguration conf) {
304290 conf .getInt (ConfVars .ZEPPELIN_SERVER_JETTY_THREAD_POOL_MIN ),
305291 conf .getInt (ConfVars .ZEPPELIN_SERVER_JETTY_THREAD_POOL_TIMEOUT ));
306292 final Server server = new Server (threadPool );
307- ServerConnector connector ;
293+ initServerConnector (server , conf .getServerPort (), conf .getServerSslPort (), CONNCETOR_NAME_DEFAULT );
294+ initServerConnector (server , conf .getServerAngularPort (), conf .getServerAngularSslPort (), CONNCETOR_NAME_ANGULAR );
295+ return server ;
296+ }
297+ private static void initServerConnector (Server server , int port , int sslPort , String name ) {
308298
299+ ServerConnector connector ;
309300 HttpConfiguration httpConfig = new HttpConfiguration ();
310301 httpConfig .addCustomizer (new ForwardedRequestCustomizer ());
311302 if (conf .useSsl ()) {
312- LOG .debug ("Enabling SSL for Zeppelin Server on port " + conf . getServerSslPort () );
303+ LOG .debug ("Enabling SSL for Zeppelin Server on port " + sslPort );
313304 httpConfig .setSecureScheme ("https" );
314- httpConfig .setSecurePort (conf . getServerSslPort () );
305+ httpConfig .setSecurePort (sslPort );
315306 httpConfig .setOutputBufferSize (32768 );
316307 httpConfig .setResponseHeaderSize (8192 );
317308 httpConfig .setSendServerVersion (true );
@@ -321,28 +312,21 @@ private static Server setupJettyServer(ZeppelinConfiguration conf) {
321312 httpsConfig .addCustomizer (src );
322313
323314 connector =
324- new ServerConnector (
325- server ,
326- new SslConnectionFactory (getSslContextFactory (conf ), HttpVersion .HTTP_1_1 .asString ()),
327- new HttpConnectionFactory (httpsConfig ));
315+ new ServerConnector (
316+ server ,
317+ new SslConnectionFactory (getSslContextFactory (conf ), HttpVersion .HTTP_1_1 .asString ()),
318+ new HttpConnectionFactory (httpsConfig ));
328319 } else {
329320 connector = new ServerConnector (server , new HttpConnectionFactory (httpConfig ));
321+ connector .setPort (port );
330322 }
331-
332323 configureRequestHeaderSize (conf , connector );
333324 // Set some timeout options to make debugging easier.
334325 int timeout = 1000 * 30 ;
335326 connector .setIdleTimeout (timeout );
336327 connector .setHost (conf .getServerAddress ());
337- if (conf .useSsl ()) {
338- connector .setPort (conf .getServerSslPort ());
339- } else {
340- connector .setPort (conf .getServerPort ());
341- }
342-
328+ connector .setName (name );
343329 server .addConnector (connector );
344-
345- return server ;
346330 }
347331
348332 private static void configureRequestHeaderSize (
@@ -437,18 +421,18 @@ private static void setupRestApiContextHandler(WebAppContext webapp, ZeppelinCon
437421 }
438422
439423 private static WebAppContext setupWebAppContext (
440- ContextHandlerCollection contexts , ZeppelinConfiguration conf ) {
424+ ContextHandlerCollection contexts , ZeppelinConfiguration conf , String warPath , String connectorName ) {
441425 WebAppContext webApp = new WebAppContext ();
442426 webApp .setContextPath (conf .getServerContextPath ());
443- File warPath = new File (conf . getString ( ConfVars . ZEPPELIN_WAR ) );
444- if (warPath .isDirectory ()) {
427+ File warFile = new File (warPath );
428+ if (warFile .isDirectory ()) {
445429 // Development mode, read from FS
446430 // webApp.setDescriptor(warPath+"/WEB-INF/web.xml");
447- webApp .setResourceBase (warPath .getPath ());
431+ webApp .setResourceBase (warFile .getPath ());
448432 webApp .setParentLoaderPriority (true );
449433 } else {
450434 // use packaged WAR
451- webApp .setWar (warPath .getAbsolutePath ());
435+ webApp .setWar (warFile .getAbsolutePath ());
452436 File warTempDirectory = new File (conf .getRelativeDir (ConfVars .ZEPPELIN_WAR_TEMPDIR ));
453437 warTempDirectory .mkdir ();
454438 LOG .info ("ZeppelinServer Webapp path: {}" , warTempDirectory .getPath ());
@@ -463,7 +447,28 @@ private static WebAppContext setupWebAppContext(
463447 webApp .setInitParameter (
464448 "org.eclipse.jetty.servlet.Default.dirAllowed" ,
465449 Boolean .toString (conf .getBoolean (ConfVars .ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED )));
466-
450+ webApp . setVirtualHosts ( new String [] { "@" + connectorName });
467451 return webApp ;
468452 }
453+
454+ private static void initWebApp (WebAppContext webApp ) {
455+ webApp .addEventListener (
456+ new ServletContextListener () {
457+ @ Override
458+ public void contextInitialized (ServletContextEvent servletContextEvent ) {
459+ servletContextEvent
460+ .getServletContext ()
461+ .setAttribute (ServletProperties .SERVICE_LOCATOR , sharedServiceLocator );
462+ }
463+
464+ @ Override
465+ public void contextDestroyed (ServletContextEvent servletContextEvent ) {}
466+ });
467+
468+ // Create `ZeppelinServer` using reflection and setup REST Api
469+ setupRestApiContextHandler (webApp , conf );
470+
471+ // Notebook server
472+ setupNotebookServer (webApp , conf , sharedServiceLocator );
473+ }
469474}
0 commit comments