use of com.netflix.titus.master.TitusMasterModule in project titus-control-plane by Netflix.
the class EmbeddedTitusMaster method boot.
public EmbeddedTitusMaster boot() {
Stopwatch timer = Stopwatch.createStarted();
logger.info("Starting Titus Master");
Module embeddedKubeModule;
if (embeddedKubeCluster == null) {
embeddedKubeModule = new AbstractModule() {
@Override
protected void configure() {
}
};
} else {
embeddedKubeModule = new EmbeddedKubeModule(embeddedKubeCluster);
}
injector = InjectorBuilder.fromModules(Modules.override(new TitusRuntimeModule(false)).with(new AbstractModule() {
@Override
protected void configure() {
bind(Archaius2ConfigurationLogger.class).asEagerSingleton();
bind(Registry.class).toInstance(new DefaultRegistry());
}
}), embeddedKubeModule, Modules.override(new TitusMasterModule(enableREST, TitusMasterModule.Mode.EMBEDDED_KUBE)).with(new AbstractModule() {
@Override
protected void configure() {
bind(InstanceCloudConnector.class).toInstance(new NoOpInstanceCloudConnector());
bind(MasterDescription.class).toInstance(masterDescription);
bind(MasterMonitor.class).to(LocalMasterMonitor.class);
bind(AppScalePolicyStore.class).to(InMemoryPolicyStore.class);
bind(LoadBalancerStore.class).to(InMemoryLoadBalancerStore.class);
bind(LoadBalancerConnector.class).to(NoOpLoadBalancerConnector.class);
bind(LoadBalancerJobValidator.class).to(NoOpLoadBalancerJobValidator.class);
}
@Provides
@Singleton
public JobStore getJobStore(TitusRuntime titusRuntime) {
if (!cassandraJobStore) {
return jobStore;
}
try {
JobStore jobStore = EmbeddedCassandraStoreFactory.newBuilder().withTitusRuntime(titusRuntime).build().getJobStore();
return jobStore;
} catch (Throwable e) {
e.printStackTrace();
return null;
}
}
}), newJettyModule(), new ArchaiusModule() {
@Override
protected void configureArchaius() {
bindApplicationConfigurationOverride().toInstance(config);
}
}).createInjector();
if (grpcPort <= 0) {
grpcPort = getGrpcPort();
config.setProperty("titus.master.grpcServer.port", "" + grpcPort);
}
injector.getInstance(ContainerEventBus.class).submitInOrder(new ContainerEventBus.ContainerStartedEvent());
injector.getInstance(LeaderActivator.class).becomeLeader();
injector.getInstance(AuditLogService.class).auditLogEvents().subscribe(auditLogs::add);
if (enableREST) {
// Since jetty API server is run on a separate thread, it may not be ready yet
// We do not have better way, but call it until it replies.
getClient().findAllApplicationSLA().retryWhen(attempts -> {
return attempts.zipWith(Observable.range(1, 5), (n, i) -> i).flatMap(i -> {
return Observable.timer(i, TimeUnit.SECONDS);
});
}).timeout(30, TimeUnit.SECONDS).toBlocking().firstOrDefault(null);
}
logger.info("Embedded TitusMaster started in {}ms", timer.elapsed(TimeUnit.MILLISECONDS));
return this;
}
Aggregations