final MetricRegistry metricsRegistry = new MetricRegistry();
final RiemannSupport riemannSupport = new RiemannSupport(metricsRegistry,
config.getRiemannHostPort(), config.getName(), "helios-master");
riemannFacade = riemannSupport.getFacade();
log.info("Starting metrics");
final Metrics metrics;
if (config.isInhibitMetrics()) {
metrics = new NoopMetrics();
} else {
metrics = new MetricsImpl(metricsRegistry);
metrics.start();
environment.lifecycle().manage(riemannSupport);
environment.lifecycle().manage(new ManagedStatsdReporter(config.getStatsdHostPort(),
"helios-master", metricsRegistry));
}
// Set up the master model
this.zooKeeperClient = setupZookeeperClient(config);
final ZooKeeperModelReporter modelReporter = new ZooKeeperModelReporter(
riemannFacade, metrics.getZooKeeperMetrics());
final ZooKeeperClientProvider zkClientProvider = new ZooKeeperClientProvider(
zooKeeperClient, modelReporter);
final MasterModel model = new ZooKeeperMasterModel(zkClientProvider);
final ZooKeeperHealthChecker zooKeeperHealthChecker = new ZooKeeperHealthChecker(
zooKeeperClient, Paths.statusMasters(), riemannFacade, TimeUnit.MINUTES, 2);
environment.lifecycle().manage(zooKeeperHealthChecker);
environment.healthChecks().register("zookeeper", zooKeeperHealthChecker);
environment.lifecycle().manage(new RiemannHeartBeat(TimeUnit.MINUTES, 2, riemannFacade));
// Set up service registrar
this.registrar = createServiceRegistrar(config.getServiceRegistrarPlugin(),
config.getServiceRegistryAddress(),
config.getDomain());
// Set up reaping of expired jobs
this.expiredJobReaper = ExpiredJobReaper.newBuilder()
.setMasterModel(model)
.build();
// Set up http server
environment.servlets()
.addFilter("VersionResponseFilter", VersionResponseFilter.class)
.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
environment.jersey().register(
new ReportingResourceMethodDispatchAdapter(metrics.getMasterMetrics()));
environment.jersey().register(new JobsResource(model, metrics.getMasterMetrics()));
environment.jersey().register(new HistoryResource(model, metrics.getMasterMetrics()));
environment.jersey().register(new HostsResource(model));
environment.jersey().register(new MastersResource(model));
environment.jersey().register(new VersionResource());
environment.jersey().register(new UserProvider());