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();
}
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();
}
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();
}
}
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"));
}
}
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);
}
}
Aggregations