Search in sources :

Example 1 with TimedHandler

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();
    }
}
Also used : SchedulerService(org.apache.zeppelin.notebook.scheduler.SchedulerService) NoSchedulerService(org.apache.zeppelin.notebook.scheduler.NoSchedulerService) QuartzSchedulerService(org.apache.zeppelin.notebook.scheduler.QuartzSchedulerService) QuartzSchedulerService(org.apache.zeppelin.notebook.scheduler.QuartzSchedulerService) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) NoSchedulerService(org.apache.zeppelin.notebook.scheduler.NoSchedulerService) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) RemoteInterpreterProcessListener(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) NoSearchService(org.apache.zeppelin.search.NoSearchService) LuceneSearch(org.apache.zeppelin.search.LuceneSearch) NoSearchService(org.apache.zeppelin.search.NoSearchService) SearchService(org.apache.zeppelin.search.SearchService) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) JMXServiceURL(javax.management.remote.JMXServiceURL) Notebook(org.apache.zeppelin.notebook.Notebook) TimedHandler(io.micrometer.core.instrument.binder.jetty.TimedHandler) Immediate(org.glassfish.hk2.api.Immediate) IOException(java.io.IOException) InterpreterSettingManager(org.apache.zeppelin.interpreter.InterpreterSettingManager) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) NotebookRepoSync(org.apache.zeppelin.notebook.repo.NotebookRepoSync) NotebookServer(org.apache.zeppelin.socket.NotebookServer) Singleton(javax.inject.Singleton) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer) Credentials(org.apache.zeppelin.user.Credentials) NoteEventListener(org.apache.zeppelin.notebook.NoteEventListener)

Aggregations

TimedHandler (io.micrometer.core.instrument.binder.jetty.TimedHandler)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Singleton (javax.inject.Singleton)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)1 InterpreterSettingManager (org.apache.zeppelin.interpreter.InterpreterSettingManager)1 RemoteInterpreterProcessListener (org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener)1 NoteEventListener (org.apache.zeppelin.notebook.NoteEventListener)1 Notebook (org.apache.zeppelin.notebook.Notebook)1 NotebookRepoSync (org.apache.zeppelin.notebook.repo.NotebookRepoSync)1 NoSchedulerService (org.apache.zeppelin.notebook.scheduler.NoSchedulerService)1 QuartzSchedulerService (org.apache.zeppelin.notebook.scheduler.QuartzSchedulerService)1 SchedulerService (org.apache.zeppelin.notebook.scheduler.SchedulerService)1 LuceneSearch (org.apache.zeppelin.search.LuceneSearch)1 NoSearchService (org.apache.zeppelin.search.NoSearchService)1 SearchService (org.apache.zeppelin.search.SearchService)1 NotebookServer (org.apache.zeppelin.socket.NotebookServer)1 Credentials (org.apache.zeppelin.user.Credentials)1 ConnectorServer (org.eclipse.jetty.jmx.ConnectorServer)1