Search in sources :

Example 1 with KafkaCruiseControlServlet

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.");
}
Also used : Server(org.eclipse.jetty.server.Server) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) JmxReporter(com.codahale.metrics.JmxReporter) FileInputStream(java.io.FileInputStream) KafkaCruiseControlServlet(com.linkedin.kafka.cruisecontrol.servlet.KafkaCruiseControlServlet) AsyncKafkaCruiseControl(com.linkedin.kafka.cruisecontrol.async.AsyncKafkaCruiseControl) KafkaCruiseControlConfig(com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

JmxReporter (com.codahale.metrics.JmxReporter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 AsyncKafkaCruiseControl (com.linkedin.kafka.cruisecontrol.async.AsyncKafkaCruiseControl)1 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)1 KafkaCruiseControlServlet (com.linkedin.kafka.cruisecontrol.servlet.KafkaCruiseControlServlet)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 Server (org.eclipse.jetty.server.Server)1 DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1