Search in sources :

Example 16 with Pair

use of com.netflix.titus.common.util.tuple.Pair in project titus-control-plane by Netflix.

the class ReservationUsageCalculator method buildCapacityGroupUsage.

public ReservationUsage buildCapacityGroupUsage(String capacityGroupName) {
    ApplicationSLA capacityGroup = capacityManagementService.getApplicationSLA(capacityGroupName);
    if (capacityGroup == null) {
        return ReservationUsage.none();
    }
    List<Pair<Job, List<Task>>> jobsAndTasks = jobOperations.getJobsAndTasks();
    ResourceAccumulator accumulator = new ResourceAccumulator();
    for (Pair<Job, List<Task>> jobAndTasks : jobsAndTasks) {
        Job job = jobAndTasks.getLeft();
        if (capacityGroupName.equals(job.getJobDescriptor().getCapacityGroup())) {
            processJob(accumulator, jobAndTasks);
        }
    }
    return accumulator.toReservationUsage();
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) Pair(com.netflix.titus.common.util.tuple.Pair)

Example 17 with Pair

use of com.netflix.titus.common.util.tuple.Pair in project titus-control-plane by Netflix.

the class DefaultHealthService method getServerStatus.

public Details getServerStatus() {
    RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
    Duration uptime = Durations.fromMillis(rb.getUptime());
    if (!leaderActivator.isLeader()) {
        return Details.newBuilder().setStatus(NOT_SERVING).setLeader(false).setActive(false).setUptime(uptime).build();
    }
    boolean active = leaderActivator.isActivated();
    List<ServiceActivation> serviceActivations = activationLifecycle.getServiceActionTimesMs().stream().sorted(Comparator.comparing(Pair::getRight)).map(pair -> ServiceActivation.newBuilder().setName(pair.getLeft()).setActivationTime(Durations.fromMillis(pair.getRight())).build()).collect(Collectors.toList());
    Details.Builder details = Details.newBuilder().setStatus(SERVING).setCell(cellInfoResolver.getCellName()).setLeader(true).setActive(active).setUptime(uptime).setElectionTimestamp(Timestamps.fromMillis(leaderActivator.getElectionTimestamp())).setActivationTimestamp(Timestamps.fromMillis(leaderActivator.getActivationEndTimestamp())).addAllServiceActivationTimes(serviceActivations);
    if (active) {
        details.setActivationTime(Durations.fromMillis(leaderActivator.getActivationTime()));
    }
    return details.build();
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean) LeaderActivator(com.netflix.titus.api.supervisor.service.LeaderActivator) NOT_SERVING(com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.NOT_SERVING) ServiceActivation(com.netflix.titus.grpc.protogen.ServiceActivation) SERVING(com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.SERVING) Timestamps(com.google.protobuf.util.Timestamps) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) Durations(com.google.protobuf.util.Durations) Inject(javax.inject.Inject) List(java.util.List) Duration(com.google.protobuf.Duration) Pair(com.netflix.titus.common.util.tuple.Pair) ActivationLifecycle(com.netflix.titus.common.util.guice.ActivationLifecycle) CellInfoResolver(com.netflix.titus.master.config.CellInfoResolver) Details(com.netflix.titus.grpc.protogen.HealthCheckResponse.Details) ManagementFactory(java.lang.management.ManagementFactory) Comparator(java.util.Comparator) Details(com.netflix.titus.grpc.protogen.HealthCheckResponse.Details) Duration(com.google.protobuf.Duration) RuntimeMXBean(java.lang.management.RuntimeMXBean) ServiceActivation(com.netflix.titus.grpc.protogen.ServiceActivation)

Example 18 with Pair

use of com.netflix.titus.common.util.tuple.Pair in project titus-control-plane by Netflix.

the class ResourceConsumptionServiceMetrics method update.

public void update(DefaultResourceConsumptionService.ConsumptionEvaluationResult evaluationResult) {
    CompositeResourceConsumption systemConsumption = evaluationResult.getSystemConsumption();
    Set<Pair<String, String>> touchedApps = new HashSet<>();
    Set<String> touchedGroups = new HashSet<>();
    systemConsumption.getContributors().values().forEach(tierConsumption -> updateTier((CompositeResourceConsumption) tierConsumption, touchedApps, touchedGroups));
    // Remove no longer referenced items
    copyAndRemove(metricsByCapacityGroupAndApp.keySet(), touchedApps).forEach(removed -> metricsByCapacityGroupAndApp.remove(removed).reset());
    copyAndRemove(capacityGroupLimits.keySet(), touchedGroups).forEach(removed -> capacityGroupLimits.remove(removed).reset());
    updateTimestamp = registry.clock().wallTime();
}
Also used : CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) Pair(com.netflix.titus.common.util.tuple.Pair) HashSet(java.util.HashSet)

Example 19 with Pair

use of com.netflix.titus.common.util.tuple.Pair in project titus-control-plane by Netflix.

the class TaskTerminationExecutorTest method testTerminateTaskWithNoQuota.

@Test
public void testTerminateTaskWithNoQuota() {
    Pair<Job, List<Task>> jobAndTask = createAndStartJobWithTasks(1);
    Job<?> job = jobAndTask.getLeft();
    Task task = jobAndTask.getRight().get(0);
    when(quotasManager.tryConsumeQuota(job, task)).thenReturn(ConsumptionResult.rejected("no quota"));
    StepVerifier.withVirtualTime(() -> newTerminationExecutor().terminateTask(task.getId(), EVICTION_REASON, "callerContext")).consumeErrorWith(e -> expectEvictionError(e, ErrorCode.NoQuota)).verify();
    expectTaskTerminationEvent(task, false);
    verify(quotasManager, times(1)).tryConsumeQuota(job, task);
}
Also used : Archaius2Ext(com.netflix.titus.common.util.archaius2.Archaius2Ext) StepVerifier(reactor.test.StepVerifier) ConsumptionResult(com.netflix.titus.master.eviction.service.quota.ConsumptionResult) Task(com.netflix.titus.api.jobmanager.model.job.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EvictionQuota(com.netflix.titus.api.eviction.model.EvictionQuota) EvictionEvent(com.netflix.titus.api.eviction.model.event.EvictionEvent) EvictionException(com.netflix.titus.api.eviction.service.EvictionException) TaskTerminationEvent(com.netflix.titus.api.eviction.model.event.TaskTerminationEvent) Pair(com.netflix.titus.common.util.tuple.Pair) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) Schedulers(reactor.core.scheduler.Schedulers) Job(com.netflix.titus.api.jobmanager.model.job.Job) TitusQuotasManager(com.netflix.titus.master.eviction.service.quota.TitusQuotasManager) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) JobGenerator(com.netflix.titus.testkit.model.job.JobGenerator) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) Reference(com.netflix.titus.api.model.reference.Reference) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) ErrorCode(com.netflix.titus.api.eviction.service.EvictionException.ErrorCode) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) Mockito.when(org.mockito.Mockito.when) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Flux(reactor.core.publisher.Flux) List(java.util.List) JobComponentStub(com.netflix.titus.testkit.model.job.JobComponentStub) Optional(java.util.Optional) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Task(com.netflix.titus.api.jobmanager.model.job.Task) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) Test(org.junit.Test)

Example 20 with Pair

use of com.netflix.titus.common.util.tuple.Pair in project titus-control-plane by Netflix.

the class RetryActionInterceptorTest method expectAboveExecutionLimits.

private EntityHolder expectAboveExecutionLimits(ModelAction updateAction, EntityHolder model) {
    Optional<Pair<EntityHolder, EntityHolder>> pair = updateAction.apply(model);
    assertThat(pair).isPresent();
    EntityHolder modelWithTag = pair.get().getRight();
    assertThat(retryInterceptor.executionLimits(modelWithTag)).isFalse();
    return modelWithTag;
}
Also used : EntityHolder(com.netflix.titus.common.framework.reconciler.EntityHolder) Pair(com.netflix.titus.common.util.tuple.Pair)

Aggregations

Pair (com.netflix.titus.common.util.tuple.Pair)41 Task (com.netflix.titus.api.jobmanager.model.job.Task)22 List (java.util.List)21 ArrayList (java.util.ArrayList)18 Job (com.netflix.titus.api.jobmanager.model.job.Job)14 Map (java.util.Map)10 Collectors (java.util.stream.Collectors)10 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)8 Optional (java.util.Optional)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)7 HashMap (java.util.HashMap)7 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)6 Collections (java.util.Collections)6 Observable (rx.Observable)6 TaskRelocationPlan (com.netflix.titus.api.relocation.model.TaskRelocationPlan)5 Function (java.util.function.Function)5 PreparedStatement (com.datastax.driver.core.PreparedStatement)4 Session (com.datastax.driver.core.Session)4