Search in sources :

Example 1 with AsyncKafkaCruiseControl

use of com.linkedin.kafka.cruisecontrol.async.AsyncKafkaCruiseControl in project cruise-control by linkedin.

the class KafkaCruiseControlServletDataFromTest method test.

@Test
public void test() throws Exception {
    AsyncKafkaCruiseControl mockKCC = EasyMock.createMock(AsyncKafkaCruiseControl.class);
    HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
    HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
    HttpSession session = EasyMock.createMock(HttpSession.class);
    EasyMock.expect(request.getSession()).andReturn(session).anyTimes();
    EasyMock.expect(request.getMethod()).andReturn("GET").anyTimes();
    EasyMock.expect(request.getRequestURI()).andReturn("/test").anyTimes();
    EasyMock.expect(request.getParameterMap()).andReturn(Collections.emptyMap()).anyTimes();
    EasyMock.expect(session.getLastAccessedTime()).andReturn(Long.MAX_VALUE);
    KafkaCruiseControlState kccState = getState(_numReadyGoals, _totalGoals, _numValidWindows);
    OperationFuture<KafkaCruiseControlState> kccStateFuture = new OperationFuture<>("test");
    kccStateFuture.complete(kccState);
    EasyMock.expect(mockKCC.state()).andReturn(kccStateFuture).anyTimes();
    EasyMock.replay(mockKCC, request, response, session);
    KafkaCruiseControlServlet servlet = new KafkaCruiseControlServlet(mockKCC, 10, 100, new MetricRegistry());
    KafkaCruiseControlServlet.GoalsAndRequirements goalsAndRequirements = servlet.getGoalsAndRequirements(request, response, Collections.emptyList(), _dataFrom, false);
    assertEquals(new HashSet<>(goalsAndRequirements.goals()), new HashSet<>(_expectedGoalsToUse));
    if (_expectedRequirements != null) {
        assertEquals(_expectedRequirements.minRequiredNumWindows(), goalsAndRequirements.requirements().minRequiredNumWindows());
        assertEquals(_expectedRequirements.minMonitoredPartitionsPercentage(), goalsAndRequirements.requirements().minMonitoredPartitionsPercentage(), 0.0);
        assertEquals(_expectedRequirements.includeAllTopics(), goalsAndRequirements.requirements().includeAllTopics());
    } else {
        assertNull("The requirement should be null", goalsAndRequirements.requirements());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AsyncKafkaCruiseControl(com.linkedin.kafka.cruisecontrol.async.AsyncKafkaCruiseControl) KafkaCruiseControlState(com.linkedin.kafka.cruisecontrol.KafkaCruiseControlState) HttpSession(javax.servlet.http.HttpSession) MetricRegistry(com.codahale.metrics.MetricRegistry) HttpServletResponse(javax.servlet.http.HttpServletResponse) OperationFuture(com.linkedin.kafka.cruisecontrol.async.OperationFuture) Test(org.junit.Test)

Example 2 with AsyncKafkaCruiseControl

use of com.linkedin.kafka.cruisecontrol.async.AsyncKafkaCruiseControl 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

MetricRegistry (com.codahale.metrics.MetricRegistry)2 AsyncKafkaCruiseControl (com.linkedin.kafka.cruisecontrol.async.AsyncKafkaCruiseControl)2 JmxReporter (com.codahale.metrics.JmxReporter)1 KafkaCruiseControlState (com.linkedin.kafka.cruisecontrol.KafkaCruiseControlState)1 OperationFuture (com.linkedin.kafka.cruisecontrol.async.OperationFuture)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 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)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 Test (org.junit.Test)1