use of com.linkedin.kafka.cruisecontrol.servlet.KafkaCruiseControlServlet in project cruise-control by linkedin.
the class KafkaCruiseControlMain method main.
public static void main(String[] args) throws Exception {
// Check the command line arguments.
if (args.length == 0) {
printErrorMessageAndDie();
}
// Load all the properties.
Properties props = new Properties();
try (InputStream propStream = new FileInputStream(args[0])) {
props.load(propStream);
}
int port = 9090;
if (args.length > 1) {
try {
port = Integer.parseInt(args[1]);
} catch (Exception e) {
printErrorMessageAndDie();
}
}
MetricRegistry dropwizardMetricsRegistry = new MetricRegistry();
JmxReporter jmxReporter = JmxReporter.forRegistry(dropwizardMetricsRegistry).inDomain(METRIC_DOMAIN).build();
jmxReporter.start();
AsyncKafkaCruiseControl kafkaCruiseControl = new AsyncKafkaCruiseControl(new KafkaCruiseControlConfig(props), dropwizardMetricsRegistry);
Server server = new Server(port);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
// Placeholder for any static content
DefaultServlet defaultServlet = new DefaultServlet();
ServletHolder holderWebapp = new ServletHolder("default", defaultServlet);
holderWebapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
holderWebapp.setInitParameter("resourceBase", "./cruise-control-ui/dist/");
context.addServlet(holderWebapp, "/*");
// Kafka Cruise Control servlet data
KafkaCruiseControlServlet kafkaCruiseControlServlet = new KafkaCruiseControlServlet(kafkaCruiseControl, 10000L, 60000L, dropwizardMetricsRegistry);
ServletHolder servletHolder = new ServletHolder(kafkaCruiseControlServlet);
context.addServlet(servletHolder, "/kafkacruisecontrol/*");
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
kafkaCruiseControl.shutdown();
jmxReporter.close();
}
});
kafkaCruiseControl.startUp();
server.start();
System.out.println("Application directory: " + System.getProperty("user.dir"));
System.out.println("Kafka Cruise Control started.");
}
Aggregations