Search in sources :

Example 1 with SamzaMonitorService

use of org.apache.samza.monitor.SamzaMonitorService in project samza by apache.

the class SamzaRestService method main.

/**
   * Command line interface to run the server.
   *
   * @param args arguments supported by {@link org.apache.samza.util.CommandLine}.
   *             In particular, --config-path and --config-factory are used to read the Samza REST config file.
   * @throws Exception if the server could not be successfully started.
   */
public static void main(String[] args) throws Exception {
    try {
        SamzaRestConfig config = parseConfig(args);
        ReadableMetricsRegistry metricsRegistry = new MetricsRegistryMap();
        log.info("Creating new SamzaRestService with config: {}", config);
        MetricsConfig metricsConfig = new MetricsConfig(config);
        Map<String, MetricsReporter> metricsReporters = MetricsReporterLoader.getMetricsReporters(metricsConfig, Util.getLocalHost().getHostName());
        SamzaRestService restService = new SamzaRestService(new Server(config.getPort()), metricsRegistry, metricsReporters, new ServletContextHandler(ServletContextHandler.SESSIONS));
        // Add applications
        SamzaRestApplication samzaRestApplication = new SamzaRestApplication(config);
        ServletContainer container = new ServletContainer(samzaRestApplication);
        restService.addServlet(container, "/*");
        // Schedule monitors to run
        ScheduledExecutorService schedulingService = Executors.newScheduledThreadPool(1);
        ScheduledExecutorSchedulingProvider schedulingProvider = new ScheduledExecutorSchedulingProvider(schedulingService);
        SamzaMonitorService monitorService = new SamzaMonitorService(config, metricsRegistry, schedulingProvider);
        monitorService.start();
        restService.runBlocking();
        monitorService.stop();
    } catch (Throwable t) {
        log.error("Exception in main.", t);
    }
}
Also used : ReadableMetricsRegistry(org.apache.samza.metrics.ReadableMetricsRegistry) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Server(org.eclipse.jetty.server.Server) MetricsConfig(org.apache.samza.config.MetricsConfig) ScheduledExecutorSchedulingProvider(org.apache.samza.monitor.ScheduledExecutorSchedulingProvider) MetricsReporter(org.apache.samza.metrics.MetricsReporter) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) SamzaMonitorService(org.apache.samza.monitor.SamzaMonitorService)

Aggregations

ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 MetricsConfig (org.apache.samza.config.MetricsConfig)1 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)1 MetricsReporter (org.apache.samza.metrics.MetricsReporter)1 ReadableMetricsRegistry (org.apache.samza.metrics.ReadableMetricsRegistry)1 SamzaMonitorService (org.apache.samza.monitor.SamzaMonitorService)1 ScheduledExecutorSchedulingProvider (org.apache.samza.monitor.ScheduledExecutorSchedulingProvider)1 Server (org.eclipse.jetty.server.Server)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)1