use of com.netflix.titus.api.supervisor.service.MasterDescription in project titus-control-plane by Netflix.
the class LeaderResource method getLeader.
@GET
public LeaderRepresentation getLeader() {
MasterDescription masterDescription = masterMonitor.getLatestLeader();
LeaderRepresentation.Builder builder = LeaderRepresentation.newBuilder().withHostname(masterDescription.getHostname()).withHostIP(masterDescription.getHostIP()).withApiPort(masterDescription.getApiPort()).withApiStatusUri(masterDescription.getApiStatusUri()).withCreateTime(masterDescription.getCreateTime());
return builder.build();
}
use of com.netflix.titus.api.supervisor.service.MasterDescription 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;
}
use of com.netflix.titus.api.supervisor.service.MasterDescription in project titus-control-plane by Netflix.
the class ZookeeperMasterMonitorTest method testMonitorWorksForMultipleLeaderUpdates.
@Test(timeout = 30_000)
public void testMonitorWorksForMultipleLeaderUpdates() throws Exception {
// Note we intentionally didn't set the initial value of master description because we'd like to make sure
// that the monitor will work property even if it fails occasionally (in this case, it will fail to deserialize
// the master description in the very beginning
ExtTestSubscriber<MasterDescription> leaderSubscriber = new ExtTestSubscriber<>();
masterMonitor.getLeaderObservable().filter(Objects::nonNull).subscribe(leaderSubscriber);
for (int i = 0; i < 5; i++) {
curator.setData().forPath(zkPaths.getLeaderAnnouncementPath(), ObjectMappers.defaultMapper().writeValueAsBytes(newMasterDescription(i)));
// Try a few times, as we can get update for the same entity more than once.
for (int j = 0; j < 3; j++) {
MasterDescription newLeader = leaderSubscriber.takeNext(5, TimeUnit.SECONDS);
if (newLeader != null && newLeader.getApiPort() == i) {
return;
}
}
fail("Did not received TitusMaster update for iteration " + i);
}
}
use of com.netflix.titus.api.supervisor.service.MasterDescription in project titus-control-plane by Netflix.
the class ZkLeaderVerificator method setupZKLeaderVerification.
@PostConstruct
void setupZKLeaderVerification() {
final String myHostname = System.getenv("EC2_PUBLIC_HOSTNAME");
final String myLocalIP = System.getenv("EC2_LOCAL_IPV4");
if (myHostname == null || myHostname.isEmpty()) {
logger.warn("Did not find public hostname variable, OK if not running cloud");
return;
}
if (myLocalIP == null || myLocalIP.isEmpty()) {
logger.warn("Did not find local IP variable, OK if not running cloud");
return;
}
logger.info("Setting up ZK leader verification with myHostname=" + myHostname + ", localIP=" + myLocalIP);
long delay = 20;
final AtomicReference<MasterDescription> ref = new AtomicReference<>();
masterMonitor.getLeaderObservable().doOnNext(ref::set).subscribe();
final AtomicInteger falseCount = new AtomicInteger(0);
final int MAX_FALSE_COUNTS = 10;
new ScheduledThreadPoolExecutor(1).scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
boolean foundFault = false;
try {
if (leaderActivator.isLeader()) {
logger.info("I'm leader, masterDescription=" + ref.get());
if (ref.get() != null && !myHostname.equals(ref.get().getHostname()) && !myLocalIP.equals(ref.get().getHostname())) {
foundFault = true;
logger.warn("ZK says leader is " + ref.get().getHostname() + ", not us (" + myHostname + ")");
if (falseCount.incrementAndGet() > MAX_FALSE_COUNTS) {
logger.error("Too many attempts failed to verify ZK leader status, exiting!");
SystemExt.forcedProcessExit(5);
}
}
}
} catch (Exception e) {
logger.warn("Error verifying leader status: " + e.getMessage(), e);
}
if (!foundFault) {
falseCount.set(0);
}
}
}, delay, delay, TimeUnit.SECONDS);
}
Aggregations