use of com.netflix.titus.common.runtime.TitusRuntime 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.common.runtime.TitusRuntime in project titus-control-plane by Netflix.
the class DefaultNodeConditionControllerTest method badNodeConditionsIgnoredForJobsNotOptingIn.
@Test
public void badNodeConditionsIgnoredForJobsNotOptingIn() {
Map<String, TitusNode> nodeMap = buildNodes();
List<Job<BatchJobExt>> jobs = getJobs(false);
Map<String, List<Task>> stringListMap = buildTasksForJobAndNodeAssignment(new ArrayList<>(nodeMap.values()), jobs);
TitusRuntime titusRuntime = mock(TitusRuntime.class);
when(titusRuntime.getRegistry()).thenReturn(new DefaultRegistry());
RelocationConfiguration configuration = mock(RelocationConfiguration.class);
when(configuration.getBadNodeConditionPattern()).thenReturn(".*Failure");
when(configuration.isTaskTerminationOnBadNodeConditionEnabled()).thenReturn(true);
NodeDataResolver nodeDataResolver = mock(NodeDataResolver.class);
when(nodeDataResolver.resolve()).thenReturn(nodeMap);
JobDataReplicator jobDataReplicator = mock(JobDataReplicator.class);
when(jobDataReplicator.getStalenessMs()).thenReturn(0L);
// Job attribute "terminateContainerOnBadAgent" = False
ReadOnlyJobOperations readOnlyJobOperations = mock(ReadOnlyJobOperations.class);
when(readOnlyJobOperations.getJobs()).thenReturn(new ArrayList<>(jobs));
stringListMap.forEach((key, value) -> when(readOnlyJobOperations.getTasks(key)).thenReturn(value));
JobManagementClient jobManagementClient = mock(JobManagementClient.class);
Set<String> terminatedTaskIds = new HashSet<>();
when(jobManagementClient.killTask(anyString(), anyBoolean(), any())).thenAnswer(invocation -> {
String taskIdToBeTerminated = invocation.getArgument(0);
terminatedTaskIds.add(taskIdToBeTerminated);
return Mono.empty();
});
DefaultNodeConditionController nodeConditionController = new DefaultNodeConditionController(configuration, nodeDataResolver, jobDataReplicator, readOnlyJobOperations, jobManagementClient, titusRuntime);
ExecutionContext executionContext = ExecutionContext.newBuilder().withIteration(ExecutionId.initial()).build();
StepVerifier.create(nodeConditionController.handleNodesWithBadCondition(executionContext)).verifyComplete();
// no tasks should be terminated for jobs
assertThat(terminatedTaskIds).isEmpty();
}
use of com.netflix.titus.common.runtime.TitusRuntime in project titus-control-plane by Netflix.
the class BaseGcController method enterActiveMode.
@Activator
public void enterActiveMode() {
ScheduleDescriptor gcScheduleDescriptor = ScheduleDescriptor.newBuilder().withName(name).withDescription(description).withInitialDelay(Duration.ofMillis(controllerConfiguration.getControllerInitialDelayMs())).withInterval(Duration.ofMillis(controllerConfiguration.getControllerIntervalMs())).withTimeout(Duration.ofMillis(controllerConfiguration.getControllerTimeoutMs())).build();
executorService = ExecutorsExt.namedSingleThreadExecutor(name);
schedulerRef = scheduler.schedule(gcScheduleDescriptor, e -> doGc(), executorService);
tokenBucket = Limiters.createInstrumentedFixedIntervalTokenBucket(name + "TokenBucket", tokenBucketConfiguration, currentTokenBucket -> logger.info("Token bucket: {} configuration updated with: {}", name, currentTokenBucket), titusRuntime);
}
use of com.netflix.titus.common.runtime.TitusRuntime in project titus-control-plane by Netflix.
the class LoadBalancerTests method getMockLoadBalancerService.
public static LoadBalancerService getMockLoadBalancerService() {
final TitusRuntime runtime = TitusRuntimes.internal();
final LoadBalancerConfiguration loadBalancerConfig = mockConfiguration(5_000);
final LoadBalancerConnector connector = mock(LoadBalancerConnector.class);
final V3JobOperations v3JobOperations = mock(V3JobOperations.class);
when(v3JobOperations.observeJobs()).thenReturn(PublishSubject.create());
final LoadBalancerJobOperations loadBalancerJobOperations = new LoadBalancerJobOperations(v3JobOperations);
final LoadBalancerReconciler reconciler = mock(LoadBalancerReconciler.class);
when(reconciler.events()).thenReturn(PublishSubject.create());
final LoadBalancerStore loadBalancerStore = new InMemoryLoadBalancerStore();
final LoadBalancerJobValidator validator = new NoOpLoadBalancerJobValidator();
final TestScheduler testScheduler = Schedulers.test();
return new DefaultLoadBalancerService(runtime, loadBalancerConfig, connector, loadBalancerStore, loadBalancerJobOperations, reconciler, validator, testScheduler);
}
use of com.netflix.titus.common.runtime.TitusRuntime in project titus-control-plane by Netflix.
the class JobScenarioBuilder method triggerComputePlatformEvent.
private JobScenarioBuilder triggerComputePlatformEvent(Task task, TaskState taskState, String reason, int errorCode) {
String reasonMessage;
if (taskState == TaskState.Finished) {
reasonMessage = errorCode == 0 ? "Completed successfully" : "Container terminated with an error " + errorCode;
} else {
reasonMessage = "Task changed state to " + taskState;
}
AtomicBoolean done = new AtomicBoolean();
final Map<String, String> newTaskContext = new HashMap<>();
if (taskState == TaskState.Launched) {
newTaskContext.putAll(computeProvider.getScheduledTaskContext(task.getId()));
}
TaskStatus taskStatus = JobModel.newTaskStatus().withState(taskState).withReasonCode(reason).withReasonMessage(reasonMessage).withTimestamp(testScheduler.now()).build();
Function<Task, Optional<Task>> changeFunction = currentTask -> JobManagerUtil.newMesosTaskStateUpdater(taskStatus, titusRuntime).apply(currentTask).map(updated -> updated.toBuilder().withTaskContext(CollectionsExt.merge(updated.getTaskContext(), newTaskContext)).build());
jobOperations.updateTask(task.getId(), changeFunction, Trigger.ComputeProvider, String.format("ComputeProvider callback taskStatus=%s, reason=%s (%s)", taskState, reason, reasonMessage), callMetadata).subscribe(() -> done.set(true));
autoAdvanceUntil(done::get);
assertThat(done.get()).isTrue();
return this;
}
Aggregations