Search in sources :

Example 1 with ConnectorServer

use of org.eclipse.jetty.jmx.ConnectorServer in project jetty.project by eclipse.

the class JmxIT method startJetty.

public static void startJetty() throws Exception {
    File target = MavenTestingUtils.getTargetDir();
    File jettyBase = new File(target, "test-base");
    File webapps = new File(jettyBase, "webapps");
    File war = new File(webapps, "jmx-webapp.war");
    //create server instance
    __server = new Server(0);
    //set up the webapp
    WebAppContext context = new WebAppContext();
    context.setWar(war.getCanonicalPath());
    context.setContextPath("/jmx-webapp");
    Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(__server);
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
    context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$");
    __server.setHandler(context);
    //set up jmx remote
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    __server.addBean(mbContainer);
    JMXServiceURL serviceUrl = new JMXServiceURL("rmi", "localhost", 1099, "/jndi/rmi://localhost:1099/jmxrmi");
    ConnectorServer jmxConnServer = new ConnectorServer(serviceUrl, "org.eclipse.jetty.jmx:name=rmiconnectorserver");
    __server.addBean(jmxConnServer);
    //start server
    __server.start();
    //remember chosen port
    __port = ((NetworkConnector) __server.getConnectors()[0]).getLocalPort();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer) Configuration(org.eclipse.jetty.webapp.Configuration) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer) File(java.io.File)

Example 2 with ConnectorServer

use of org.eclipse.jetty.jmx.ConnectorServer in project jetty.project by eclipse.

the class ServerWithJMX method main.

public static void main(String[] args) throws Exception {
    // === jetty-jmx.xml ===
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    Server server = new Server(8080);
    server.addBean(mbContainer);
    ConnectorServer jmx = new ConnectorServer(new JMXServiceURL("rmi", null, 1999, "/jndi/rmi://localhost:1999/jmxrmi"), "org.eclipse.jetty.jmx:name=rmiconnectorserver");
    server.addBean(jmx);
    server.start();
    server.dumpStdErr();
    server.join();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer) Server(org.eclipse.jetty.server.Server) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer)

Example 3 with ConnectorServer

use of org.eclipse.jetty.jmx.ConnectorServer 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)

Example 4 with ConnectorServer

use of org.eclipse.jetty.jmx.ConnectorServer in project vespa by vespa-engine.

the class JettyHttpServer method setupJmx.

private static void setupJmx(Server server, ServerConfig serverConfig) {
    if (serverConfig.jmx().enabled()) {
        System.setProperty("java.rmi.server.hostname", "localhost");
        server.addBean(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
        server.addBean(new ConnectorServer(createJmxLoopbackOnlyServiceUrl(serverConfig.jmx().listenPort()), "org.eclipse.jetty.jmx:name=rmiconnectorserver"));
    }
}
Also used : MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer)

Example 5 with ConnectorServer

use of org.eclipse.jetty.jmx.ConnectorServer in project Openfire by igniterealtime.

the class JMXManager method start.

private void start() {
    setContainer(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
    int jmxPort = JMXManager.getPort();
    String jmxUrl = "/jndi/rmi://localhost:" + jmxPort + "/jmxrmi";
    Map<String, Object> env = new HashMap<>();
    if (JMXManager.isSecure()) {
        env.put("jmx.remote.authenticator", new JMXAuthenticator() {

            @Override
            public Subject authenticate(Object credentials) {
                if (!(credentials instanceof String[])) {
                    if (credentials == null) {
                        throw new SecurityException("Credentials required");
                    }
                    throw new SecurityException("Credentials should be String[]");
                }
                final String[] aCredentials = (String[]) credentials;
                if (aCredentials.length < 2) {
                    throw new SecurityException("Credentials should have at least two elements");
                }
                String username = aCredentials[0];
                String password = aCredentials[1];
                try {
                    AuthFactory.authenticate(username, password);
                } catch (Exception ex) {
                    Log.error("Authentication failed for " + username);
                    throw new SecurityException();
                }
                if (AdminManager.getInstance().isUserAdmin(username, true)) {
                    return new Subject(true, Collections.singleton(new JMXPrincipal(username)), Collections.EMPTY_SET, Collections.EMPTY_SET);
                } else {
                    Log.error("Authorization failed for " + username);
                    throw new SecurityException();
                }
            }
        });
    }
    try {
        jmxServer = new ConnectorServer(new JMXServiceURL("rmi", null, jmxPort, jmxUrl), env, "org.eclipse.jetty.jmx:name=rmiconnectorserver");
        jmxServer.start();
    } catch (Exception e) {
        Log.error("Failed to start JMX connector", e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXAuthenticator(javax.management.remote.JMXAuthenticator) JMXPrincipal(javax.management.remote.JMXPrincipal) Subject(javax.security.auth.Subject) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) ConnectorServer(org.eclipse.jetty.jmx.ConnectorServer)

Aggregations

ConnectorServer (org.eclipse.jetty.jmx.ConnectorServer)5 MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)5 JMXServiceURL (javax.management.remote.JMXServiceURL)4 Server (org.eclipse.jetty.server.Server)2 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)2 TimedHandler (io.micrometer.core.instrument.binder.jetty.TimedHandler)1 File (java.io.File)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Singleton (javax.inject.Singleton)1 JMXAuthenticator (javax.management.remote.JMXAuthenticator)1 JMXPrincipal (javax.management.remote.JMXPrincipal)1 Subject (javax.security.auth.Subject)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