public SchedulerApiServer(SchedulerConfig schedulerConfig, Collection<Object> resources) { this.port = schedulerConfig.getApiServerPort(); this.server = JettyHttpContainerFactory.createServer( UriBuilder.fromUri("http://0.0.0.0/").port(this.port).build(), new ResourceConfig(MultiPartFeature.class).registerInstances(new HashSet<>(resources)), false /* don't start yet. wait for start() call below. */); this.startTimeout = schedulerConfig.getApiServerInitTimeout(); ServletContextHandler context = new ServletContextHandler(); // Metrics + Prometheus Metrics.configureMetricsEndpoints(context, "/v1/metrics", "/v1/metrics/prometheus"); // Resources ResourceConfig resourceConfig = new ResourceConfig(MultiPartFeature.class) .registerInstances(new HashSet<>(resources)); ServletHolder resourceHolder = new ServletHolder(new ServletContainer(resourceConfig)); context.addServlet(resourceHolder, "/*"); final InstrumentedHandler handler = new InstrumentedHandler(Metrics.getRegistry()); handler.setHandler(context); server.setHandler(handler); }
/** * Creates the Jetty server instance for the Flux API endpoint. * @param port where the service is available. * @return Jetty Server instance */ @Named("APIJettyServer") @Provides @Singleton Server getAPIJettyServer(@Named("Api.service.port") int port, @Named("APIResourceConfig")ResourceConfig resourceConfig, @Named("Api.service.acceptors") int acceptorThreads, @Named("Api.service.selectors") int selectorThreads, @Named("Api.service.workers") int maxWorkerThreads, ObjectMapper objectMapper, MetricRegistry metricRegistry) throws URISyntaxException, UnknownHostException { JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(objectMapper); resourceConfig.register(provider); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMaxThreads(maxWorkerThreads); Server server = new Server(threadPool); ServerConnector http = new ServerConnector(server, acceptorThreads, selectorThreads); http.setPort(port); server.addConnector(http); ServletContextHandler context = new ServletContextHandler(server, "/*"); ServletHolder servlet = new ServletHolder(new ServletContainer(resourceConfig)); context.addServlet(servlet, "/*"); final InstrumentedHandler handler = new InstrumentedHandler(metricRegistry); handler.setHandler(context); server.setHandler(handler); server.setStopAtShutdown(true); return server; }
private Handler getPoseidonHandler() { ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.setContextPath("/"); servletContextHandler.addServlet(new ServletHolder(getPoseidonServlet()), "/*"); addFilters(servletContextHandler); InstrumentedHandler instrumentedHandler = new InstrumentedHandler(Metrics.getRegistry()); instrumentedHandler.setHandler(servletContextHandler); return instrumentedHandler; }
@Override protected List<Handler> additionalHandlers(){ metricRegistry= new MetricRegistry(); return Arrays.asList(new InstrumentedHandler(metricRegistry,"monitoring example")); }