use of io.micrometer.core.instrument.binder.jetty.TimedHandler in project zeppelin by apache.
the class ZeppelinServer method main.
public static void main(String[] args) throws InterruptedException, IOException {
ZeppelinServer.conf = ZeppelinConfiguration.create();
jettyWebServer = setupJettyServer(conf);
initMetrics(conf);
TimedHandler timedHandler = new TimedHandler(Metrics.globalRegistry, Tags.empty());
jettyWebServer.setHandler(timedHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
timedHandler.setHandler(contexts);
sharedServiceLocator = ServiceLocatorFactory.getInstance().create("shared-locator");
ServiceLocatorUtilities.enableImmediateScope(sharedServiceLocator);
ServiceLocatorUtilities.addClasses(sharedServiceLocator, NotebookRepoSync.class, ImmediateErrorHandlerImpl.class);
ImmediateErrorHandlerImpl handler = sharedServiceLocator.getService(ImmediateErrorHandlerImpl.class);
ServiceLocatorUtilities.bind(sharedServiceLocator, new AbstractBinder() {
@Override
protected void configure() {
Credentials credentials = new Credentials(conf);
bindAsContract(InterpreterFactory.class).in(Singleton.class);
bindAsContract(NotebookRepoSync.class).to(NotebookRepo.class).in(Immediate.class);
bindAsContract(Helium.class).in(Singleton.class);
bind(conf).to(ZeppelinConfiguration.class);
bindAsContract(InterpreterSettingManager.class).in(Singleton.class);
bindAsContract(InterpreterService.class).in(Singleton.class);
bind(credentials).to(Credentials.class);
bindAsContract(GsonProvider.class).in(Singleton.class);
bindAsContract(WebApplicationExceptionMapper.class).in(Singleton.class);
bindAsContract(AdminService.class).in(Singleton.class);
bindAsContract(AuthorizationService.class).in(Singleton.class);
bindAsContract(ConnectionManager.class).in(Singleton.class);
bindAsContract(NoteManager.class).in(Singleton.class);
// TODO(jl): Will make it more beautiful
if (!StringUtils.isBlank(conf.getShiroPath())) {
bind(ShiroAuthenticationService.class).to(AuthenticationService.class).in(Singleton.class);
} else {
// TODO(jl): Will be added more type
bind(NoAuthenticationService.class).to(AuthenticationService.class).in(Singleton.class);
}
bindAsContract(HeliumBundleFactory.class).in(Singleton.class);
bindAsContract(HeliumApplicationFactory.class).in(Singleton.class);
bindAsContract(ConfigurationService.class).in(Singleton.class);
bindAsContract(NotebookService.class).in(Singleton.class);
bindAsContract(JobManagerService.class).in(Singleton.class);
bindAsContract(Notebook.class).in(Singleton.class);
bindAsContract(NotebookServer.class).to(AngularObjectRegistryListener.class).to(RemoteInterpreterProcessListener.class).to(ApplicationEventListener.class).to(NoteEventListener.class).to(WebSocketServlet.class).in(Singleton.class);
if (conf.isZeppelinNotebookCronEnable()) {
bind(QuartzSchedulerService.class).to(SchedulerService.class).in(Singleton.class);
} else {
bind(NoSchedulerService.class).to(SchedulerService.class).in(Singleton.class);
}
if (conf.getBoolean(ConfVars.ZEPPELIN_SEARCH_ENABLE)) {
bind(LuceneSearch.class).to(SearchService.class).in(Singleton.class);
} else {
bind(NoSearchService.class).to(SearchService.class).in(Singleton.class);
}
}
});
// Multiple Web UI
final WebAppContext defaultWebApp = setupWebAppContext(contexts, conf, conf.getString(ConfVars.ZEPPELIN_WAR), conf.getServerContextPath());
final WebAppContext nextWebApp = setupWebAppContext(contexts, conf, conf.getString(ConfVars.ZEPPELIN_ANGULAR_WAR), WEB_APP_CONTEXT_NEXT);
initWebApp(defaultWebApp);
initWebApp(nextWebApp);
// Cluster Manager Server
setupClusterManagerServer(sharedServiceLocator);
// JMX Enable
if (conf.isJMXEnabled()) {
int port = conf.getJMXPort();
// Setup JMX
MBeanContainer mbeanContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
jettyWebServer.addBean(mbeanContainer);
JMXServiceURL jmxURL = new JMXServiceURL(String.format("service:jmx:rmi://0.0.0.0:%d/jndi/rmi://0.0.0.0:%d/jmxrmi", port, port));
ConnectorServer jmxServer = new ConnectorServer(jmxURL, "org.eclipse.jetty.jmx:name=rmiconnectorserver");
jettyWebServer.addBean(jmxServer);
LOG.info("JMX Enabled with port: {}", port);
}
LOG.info("Starting zeppelin server");
try {
// Instantiates ZeppelinServer
jettyWebServer.start();
List<ErrorData> errorData = handler.waitForAtLeastOneConstructionError(5 * 1000);
if (errorData.size() > 0 && errorData.get(0).getThrowable() != null) {
throw new Exception(errorData.get(0).getThrowable());
}
if (conf.getJettyName() != null) {
org.eclipse.jetty.http.HttpGenerator.setJettyVersion(conf.getJettyName());
}
} catch (Exception e) {
LOG.error("Error while running jettyServer", e);
System.exit(-1);
}
LOG.info("Done, zeppelin server started");
runNoteOnStart(conf);
Runtime.getRuntime().addShutdownHook(shutdown(conf));
// Try to get Notebook from ServiceLocator, because Notebook instantiation is lazy, it is
// created when user open zeppelin in browser if we don't get it explicitly here.
// Lazy loading will cause paragraph recovery and cron job initialization is delayed.
Notebook notebook = ServiceLocatorUtilities.getService(sharedServiceLocator, Notebook.class.getName());
ServiceLocatorUtilities.getService(sharedServiceLocator, SearchService.class.getName());
ServiceLocatorUtilities.getService(sharedServiceLocator, SchedulerService.class.getName());
// Try to recover here, don't do it in constructor of Notebook, because it would cause deadlock.
notebook.recoveryIfNecessary();
// for graceful shutdown, input any key in console window
if (System.getenv("ZEPPELIN_IDENT_STRING") == null) {
try {
System.in.read();
} catch (IOException e) {
LOG.error("Exception in ZeppelinServer while main ", e);
}
System.exit(0);
}
jettyWebServer.join();
if (!conf.isRecoveryEnabled()) {
sharedServiceLocator.getService(InterpreterSettingManager.class).close();
}
}
Aggregations