Search in sources :

Example 26 with Pair

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

the class DefaultV3JobOperations method updateTask.

@Override
public Completable updateTask(String taskId, Function<Task, Optional<Task>> changeFunction, Trigger trigger, String reason, CallMetadata callMetadata) {
    Optional<ReconciliationEngine<JobManagerReconcilerEvent>> engineOpt = reconciliationFramework.findEngineByChildId(taskId).map(Pair::getLeft);
    if (!engineOpt.isPresent()) {
        return Completable.error(JobManagerException.taskNotFound(taskId));
    }
    ReconciliationEngine<JobManagerReconcilerEvent> engine = engineOpt.get();
    TitusChangeAction changeAction = BasicTaskActions.updateTaskInRunningModel(taskId, trigger, jobManagerConfiguration, engine, changeFunction, reason, versionSupplier, titusRuntime, callMetadata);
    return engine.changeReferenceModel(changeAction, taskId).toCompletable();
}
Also used : ReconciliationEngine(com.netflix.titus.common.framework.reconciler.ReconciliationEngine) TitusChangeAction(com.netflix.titus.master.jobmanager.service.common.action.TitusChangeAction) JobManagerReconcilerEvent(com.netflix.titus.master.jobmanager.service.event.JobManagerReconcilerEvent) Pair(com.netflix.titus.common.util.tuple.Pair)

Example 27 with Pair

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

the class CellWithFixedJobsService method findJobs.

@Override
public void findJobs(JobQuery request, StreamObserver<JobQueryResult> responseObserver) {
    Pair<List<Job>, Pagination> page = PaginationUtil.takePageWithCursor(toPage(request.getPage()), getJobsList(), JobManagerCursors.jobCursorOrderComparator(), JobManagerCursors::jobIndexOf, JobManagerCursors::newCursorFrom);
    Set<String> fieldsFilter = new HashSet<>(request.getFieldsList());
    if (!fieldsFilter.isEmpty()) {
        fieldsFilter.add("id");
        page = page.mapLeft(jobs -> jobs.stream().map(job -> ProtobufExt.copy(job, fieldsFilter)).collect(Collectors.toList()));
    }
    JobQueryResult result = JobQueryResult.newBuilder().addAllItems(page.getLeft()).setPagination(toGrpcPagination(page.getRight())).build();
    responseObserver.onNext(result);
    responseObserver.onCompleted();
}
Also used : NOT_FOUND(io.grpc.Status.NOT_FOUND) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) Job(com.netflix.titus.grpc.protogen.Job) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Observable(rx.Observable) HashSet(java.util.HashSet) Empty(com.google.protobuf.Empty) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) GrpcUtil(com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil) StreamObserver(io.grpc.stub.StreamObserver) Pair(com.netflix.titus.common.util.tuple.Pair) Map(java.util.Map) SnapshotEnd(com.netflix.titus.grpc.protogen.JobChangeNotification.SnapshotEnd) PaginationUtil(com.netflix.titus.api.model.PaginationUtil) Set(java.util.Set) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Collectors(java.util.stream.Collectors) ProtobufExt(com.netflix.titus.common.util.ProtobufExt) GrpcJobQueryModelConverters.toPage(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toPage) List(java.util.List) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) Pagination(com.netflix.titus.api.model.Pagination) Collections(java.util.Collections) Subscription(rx.Subscription) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobId(com.netflix.titus.grpc.protogen.JobId) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) Pagination(com.netflix.titus.api.model.Pagination) ArrayList(java.util.ArrayList) List(java.util.List) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) HashSet(java.util.HashSet)

Example 28 with Pair

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

the class CellWithFixedTasksService method findTasks.

@Override
public void findTasks(TaskQuery request, StreamObserver<TaskQueryResult> responseObserver) {
    Pair<List<Task>, Pagination> page = PaginationUtil.takePageWithCursor(toPage(request.getPage()), getTasksList(), JobManagerCursors.taskCursorOrderComparator(), JobManagerCursors::taskIndexOf, JobManagerCursors::newTaskCursorFrom);
    Set<String> fieldsFilter = new HashSet<>(request.getFieldsList());
    if (!fieldsFilter.isEmpty()) {
        fieldsFilter.add("id");
        page = page.mapLeft(tasks -> tasks.stream().map(task -> ProtobufExt.copy(task, fieldsFilter)).collect(Collectors.toList()));
    }
    TaskQueryResult result = TaskQueryResult.newBuilder().addAllItems(page.getLeft()).setPagination(toGrpcPagination(page.getRight())).build();
    responseObserver.onNext(result);
    responseObserver.onCompleted();
}
Also used : NOT_FOUND(io.grpc.Status.NOT_FOUND) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Task(com.netflix.titus.grpc.protogen.Task) TaskId(com.netflix.titus.grpc.protogen.TaskId) Set(java.util.Set) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ProtobufExt(com.netflix.titus.common.util.ProtobufExt) ArrayList(java.util.ArrayList) GrpcJobQueryModelConverters.toPage(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toPage) HashSet(java.util.HashSet) Empty(com.google.protobuf.Empty) List(java.util.List) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) StreamObserver(io.grpc.stub.StreamObserver) Pair(com.netflix.titus.common.util.tuple.Pair) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) Map(java.util.Map) Pagination(com.netflix.titus.api.model.Pagination) Collections(java.util.Collections) PaginationUtil(com.netflix.titus.api.model.PaginationUtil) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) TaskKillRequest(com.netflix.titus.grpc.protogen.TaskKillRequest) GrpcJobQueryModelConverters.toGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toGrpcPagination) Pagination(com.netflix.titus.api.model.Pagination) ArrayList(java.util.ArrayList) List(java.util.List) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) HashSet(java.util.HashSet)

Example 29 with Pair

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

the class ResourceConsumptionEvaluator method computeAllocationsByCapacityGroupAndAppName.

/**
 * @return capacityGroups -> apps -> instanceTypes -> consumption
 */
private Pair<Map<String, Map<String, ResourceConsumption>>, Set<String>> computeAllocationsByCapacityGroupAndAppName() {
    Map<String, Map<String, ResourceConsumption>> consumptionMap = new HashMap<>();
    Set<String> undefinedCapacityGroups = new HashSet<>();
    v3JobOperations.getJobsAndTasks().forEach(jobsAndTasks -> {
        Job job = jobsAndTasks.getLeft();
        List<Task> tasks = jobsAndTasks.getRight();
        List<Task> runningTasks = getRunningWorkers(tasks);
        ResourceDimension taskResources = perTaskResourceDimension(job);
        String appName = Evaluators.getOrDefault(job.getJobDescriptor().getApplicationName(), DEFAULT_APPLICATION);
        ResourceDimension currentConsumption = ResourceDimensions.multiply(taskResources, runningTasks.size());
        ResourceDimension maxConsumption = ResourceDimensions.multiply(taskResources, getMaxJobSize(job));
        Map<String, List<Task>> tasksByInstanceType = tasks.stream().collect(groupingBy(task -> task.getTaskContext().getOrDefault(TaskAttributes.TASK_ATTRIBUTES_AGENT_ITYPE, "unknown")));
        Map<String, ResourceConsumption> consumptionByInstanceType = CollectionsExt.mapValuesWithKeys(tasksByInstanceType, (instanceType, instanceTypeTasks) -> {
            List<Task> runningInstanceTypeTasks = getRunningWorkers(instanceTypeTasks);
            ResourceDimension instanceTypeConsumption = ResourceDimensions.multiply(taskResources, runningInstanceTypeTasks.size());
            return new ResourceConsumption(instanceType, ConsumptionLevel.InstanceType, instanceTypeConsumption, // maxConsumption is not relevant at ConsumptionLevel.InstanceType
            instanceTypeConsumption, getWorkerStateMap(instanceTypeTasks));
        }, HashMap::new);
        ResourceConsumption jobConsumption = new CompositeResourceConsumption(appName, ConsumptionLevel.Application, currentConsumption, maxConsumption, // allowedConsumption is not relevant at ConsumptionLevel.Application
        maxConsumption, getWorkerStateMap(tasks), consumptionByInstanceType, // we consider a job is always within its allowed usage since it can't go over its max
        false);
        String capacityGroup = resolveCapacityGroup(undefinedCapacityGroups, job, appName);
        updateConsumptionMap(appName, capacityGroup, jobConsumption, consumptionMap);
    });
    // Add unused capacity groups
    copyAndRemove(definedCapacityGroups, consumptionMap.keySet()).forEach(capacityGroup -> consumptionMap.put(capacityGroup, Collections.emptyMap()));
    return Pair.of(consumptionMap, undefinedCapacityGroups);
}
Also used : DEFAULT_APPLICATION(com.netflix.titus.master.service.management.ApplicationSlaManagementService.DEFAULT_APPLICATION) ApplicationSlaManagementService(com.netflix.titus.master.service.management.ApplicationSlaManagementService) Task(com.netflix.titus.api.jobmanager.model.job.Task) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) LoggerFactory(org.slf4j.LoggerFactory) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HashMap(java.util.HashMap) ResourceDimensions(com.netflix.titus.master.model.ResourceDimensions) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CollectionsExt.copyAndRemove(com.netflix.titus.common.util.CollectionsExt.copyAndRemove) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ResourceConsumption(com.netflix.titus.master.service.management.ResourceConsumption) Pair(com.netflix.titus.common.util.tuple.Pair) Map(java.util.Map) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) ApplicationSLA(com.netflix.titus.api.model.ApplicationSLA) ConsumptionLevel(com.netflix.titus.master.service.management.ResourceConsumption.ConsumptionLevel) ResourceDimension(com.netflix.titus.api.model.ResourceDimension) SYSTEM_CONSUMER(com.netflix.titus.master.service.management.ResourceConsumption.SYSTEM_CONSUMER) Job(com.netflix.titus.api.jobmanager.model.job.Job) Logger(org.slf4j.Logger) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Collection(java.util.Collection) Set(java.util.Set) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) Tier(com.netflix.titus.api.model.Tier) Collectors(java.util.stream.Collectors) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) List(java.util.List) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) ContainerResources(com.netflix.titus.api.jobmanager.model.job.ContainerResources) TaskAttributes(com.netflix.titus.api.jobmanager.TaskAttributes) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) Evaluators(com.netflix.titus.common.util.Evaluators) Collections(java.util.Collections) ResourceConsumptions(com.netflix.titus.master.service.management.ResourceConsumptions) Task(com.netflix.titus.api.jobmanager.model.job.Task) HashMap(java.util.HashMap) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) ResourceConsumption(com.netflix.titus.master.service.management.ResourceConsumption) CompositeResourceConsumption(com.netflix.titus.master.service.management.CompositeResourceConsumption) ArrayList(java.util.ArrayList) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) HashMap(java.util.HashMap) Map(java.util.Map) ResourceDimension(com.netflix.titus.api.model.ResourceDimension) HashSet(java.util.HashSet)

Example 30 with Pair

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

the class TaskMigrationDescheduler method nextBestMatch.

Optional<Pair<TitusNode, List<Task>>> nextBestMatch() {
    return evacuatedAgentsAllocationTracker.getRemovableAgentsById().values().stream().map(i -> Pair.of(i, computeFitness(i))).filter(p -> p.getRight().getLeft() > 0).max(Comparator.comparingDouble(p -> p.getRight().getLeft())).map(p -> {
        TitusNode agent = p.getLeft();
        List<Task> tasks = p.getRight().getRight();
        tasks.forEach(task -> {
            evacuatedAgentsAllocationTracker.descheduled(task);
            Job<?> job = jobsById.get(task.getJobId());
            if (job != null) {
                evictionQuotaTracker.consumeQuota(task.getJobId(), isJobExemptFromSystemDisruptionWindow(job));
            } else {
                logger.warn("Missing job for ID = {}", task.getJobId());
                evictionQuotaTracker.consumeQuota(task.getJobId(), false);
            }
        });
        return Pair.of(agent, tasks);
    });
}
Also used : DeschedulingFailure(com.netflix.titus.supplementary.relocation.model.DeschedulingFailure) DeschedulingResult(com.netflix.titus.supplementary.relocation.model.DeschedulingResult) Job(com.netflix.titus.api.jobmanager.model.job.Job) Logger(org.slf4j.Logger) Task(com.netflix.titus.api.jobmanager.model.job.Task) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) RelocationPredicates(com.netflix.titus.supplementary.relocation.util.RelocationPredicates) Function(java.util.function.Function) ArrayList(java.util.ArrayList) List(java.util.List) Matcher(java.util.regex.Matcher) Pair(com.netflix.titus.common.util.tuple.Pair) Map(java.util.Map) Optional(java.util.Optional) EvictionConfiguration(com.netflix.titus.runtime.connector.eviction.EvictionConfiguration) Pattern(java.util.regex.Pattern) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) RegExpExt(com.netflix.titus.common.util.RegExpExt) Comparator(java.util.Comparator) Collections(java.util.Collections) Clock(com.netflix.titus.common.util.time.Clock) TitusNode(com.netflix.titus.supplementary.relocation.connector.TitusNode) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) Task(com.netflix.titus.api.jobmanager.model.job.Task) TitusNode(com.netflix.titus.supplementary.relocation.connector.TitusNode)

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