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