Search in sources :

Example 16 with CallMetadata

use of com.netflix.titus.api.model.callmetadata.CallMetadata in project titus-control-plane by Netflix.

the class DefaultJobManagementServiceGrpc method findTasks.

@Override
public void findTasks(TaskQuery request, StreamObserver<TaskQueryResult> responseObserver) {
    if (!checkPageIsValid(request.getPage(), responseObserver)) {
        return;
    }
    CallMetadata callMetadata = resolveCallMetadata();
    logPageNumberUsage(systemLog, callMetadata, getClass().getSimpleName(), "findTasks", request.getPage());
    Subscription subscription = jobServiceGateway.findTasks(request, callMetadata).subscribe(responseObserver::onNext, e -> safeOnError(logger, e, responseObserver), responseObserver::onCompleted);
    attachCancellingCallback(responseObserver, subscription);
}
Also used : CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) Subscription(rx.Subscription)

Example 17 with CallMetadata

use of com.netflix.titus.api.model.callmetadata.CallMetadata in project titus-control-plane by Netflix.

the class DefaultLoadBalancerServiceGrpc method getAllLoadBalancers.

@Override
public void getAllLoadBalancers(com.netflix.titus.grpc.protogen.GetAllLoadBalancersRequest request, StreamObserver<GetAllLoadBalancersResult> responseObserver) {
    logger.debug("Received get all load balancer request {}", request);
    CallMetadata callMetadata = resolveCallMetadata();
    logPageNumberUsage(systemLog, callMetadata, getClass().getSimpleName(), "getAllLoadBalancers", request.getPage());
    Subscription subscription = loadBalancerService.getAllLoadBalancers(request, callMetadata).subscribe(responseObserver::onNext, e -> safeOnError(logger, e, responseObserver), responseObserver::onCompleted);
    attachCancellingCallback(responseObserver, subscription);
}
Also used : CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) Subscription(rx.Subscription)

Example 18 with CallMetadata

use of com.netflix.titus.api.model.callmetadata.CallMetadata in project titus-control-plane by Netflix.

the class RemoveUnschedulableJobsCommand method execute.

@Override
public void execute(CommandContext context) throws Exception {
    long stuckInAcceptedThresholdMs = TimeUnitExt.toMillis(context.getCLI().getOptionValue('e')).orElseThrow(() -> new IllegalArgumentException("Wrong expiry threshold"));
    int limit = Integer.parseInt(context.getCLI().getOptionValue('l'));
    Pair<Map<String, Job>, Map<String, Map<String, Task>>> all = loadActiveJobsAndTasks(context);
    Map<String, Job> jobs = all.getLeft();
    Map<String, UnschedulableJob> unschedulable = UnschedulableFinder.findUnschedulableJobs(context, all.getLeft(), all.getRight(), stuckInAcceptedThresholdMs);
    logger.info("Found {} unschedulable jobs", unschedulable.size());
    logger.info("Removing the oldest {}...", limit);
    List<Job> orderedJobs = unschedulable.keySet().stream().map(jobs::get).sorted(Comparator.comparingLong(j -> j.getStatus().getTimestamp())).collect(Collectors.toList());
    RemoteJobManagementClient jobClient = context.getJobManagementClient();
    int len = Math.min(orderedJobs.size(), limit);
    for (int i = 0; i < len; i++) {
        Job jobToRemove = orderedJobs.get(i);
        logger.info("Removing job {}...", jobToRemove);
        CallMetadata callMetadata = CallMetadata.newBuilder().withCallReason(unschedulable.get(jobToRemove.getId()).getReason()).withCallers(Collections.singletonList(Caller.newBuilder().withId(Evaluators.getOrDefault(System.getenv("USER"), "titusCLI")).withCallerType(CallerType.User).build())).build();
        jobClient.killJob(jobToRemove.getId(), callMetadata).block(Duration.ofSeconds(60));
    }
    logger.info("Removed {} unschedulable jobs out of {} (left {})", len, unschedulable.size(), unschedulable.size() - len);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) Job(com.netflix.titus.api.jobmanager.model.job.Job) Map(java.util.Map) RemoteJobManagementClient(com.netflix.titus.runtime.connector.jobmanager.RemoteJobManagementClient)

Example 19 with CallMetadata

use of com.netflix.titus.api.model.callmetadata.CallMetadata in project titus-control-plane by Netflix.

the class DefaultAppAutoScalingCallbackService method setScalableTargetResourceInfo.

@Override
public Observable<ScalableTargetResourceInfo> setScalableTargetResourceInfo(String jobId, ScalableTargetResourceInfo scalableTargetResourceInfo, CallMetadata callMetadata) {
    logger.info("(BEFORE setting job instances) for jobId {} :: {}", jobId, scalableTargetResourceInfo);
    JobCapacityWithOptionalAttributes jobCapacityWithOptionalAttributes = JobCapacityWithOptionalAttributes.newBuilder().setDesired(UInt32Value.newBuilder().setValue(scalableTargetResourceInfo.getDesiredCapacity()).build()).build();
    JobCapacityUpdateWithOptionalAttributes jobCapacityRequest = JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId).setJobCapacityWithOptionalAttributes(jobCapacityWithOptionalAttributes).build();
    return jobServiceGateway.updateJobCapacityWithOptionalAttributes(jobCapacityRequest, callMetadata).andThen(getScalableTargetResourceInfo(jobId, callMetadata).map(scalableTargetResourceInfoReturned -> {
        scalableTargetResourceInfoReturned.setScalingStatus(ScalingStatus.Pending.name());
        logger.info("(set job instances) Returning value Instances for jobId {} :: {}", jobId, scalableTargetResourceInfo);
        return scalableTargetResourceInfoReturned;
    }));
}
Also used : JobCapacityUpdateWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityUpdateWithOptionalAttributes) Logger(org.slf4j.Logger) ServiceJobSpec(com.netflix.titus.grpc.protogen.ServiceJobSpec) UInt32Value(com.google.protobuf.UInt32Value) JobStatus(com.netflix.titus.grpc.protogen.JobStatus) LoggerFactory(org.slf4j.LoggerFactory) Job(com.netflix.titus.grpc.protogen.Job) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) Page(com.netflix.titus.grpc.protogen.Page) Observable(rx.Observable) Inject(javax.inject.Inject) List(java.util.List) Pair(com.netflix.titus.common.util.tuple.Pair) Optional(java.util.Optional) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) JobServiceGateway(com.netflix.titus.runtime.jobmanager.gateway.JobServiceGateway) JobCapacityWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityWithOptionalAttributes) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobCapacityUpdateWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityUpdateWithOptionalAttributes) JobCapacityWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityWithOptionalAttributes)

Example 20 with CallMetadata

use of com.netflix.titus.api.model.callmetadata.CallMetadata in project titus-control-plane by Netflix.

the class AppAutoScalingCallbackSpringResourceTest method testResponseEntity.

@Test
public void testResponseEntity() {
    AppAutoScalingCallbackService appAutoScalingCallbackService = mock(AppAutoScalingCallbackService.class);
    String jobId = "job-1";
    ScalableTargetResourceInfo scalableTargetResourceInfo = ScalableTargetResourceInfo.newBuilder().actualCapacity(4).desiredCapacity(6).scalingStatus(DefaultAppAutoScalingCallbackService.ScalingStatus.Pending.name()).build();
    CallMetadata callMetadata = CallMetadata.newBuilder().withCallerId("unit-testing").build();
    CallMetadataAuthentication callMetadataAuthentication = mock(CallMetadataAuthentication.class);
    when(callMetadataAuthentication.getCallMetadata()).thenReturn(callMetadata);
    when(appAutoScalingCallbackService.setScalableTargetResourceInfo(jobId, scalableTargetResourceInfo, callMetadata)).thenReturn(Observable.just(scalableTargetResourceInfo));
    AppAutoScalingCallbackSpringResource springResource = new AppAutoScalingCallbackSpringResource(appAutoScalingCallbackService);
    ResponseEntity<ScalableTargetResourceInfo> resp = springResource.setScalableTargetResourceInfo(jobId, scalableTargetResourceInfo, callMetadataAuthentication);
    assertThat(resp).isNotNull();
    assertThat(resp.getStatusCodeValue()).isEqualTo(200);
    assertThat(resp.getBody()).isEqualTo(scalableTargetResourceInfo);
    scalableTargetResourceInfo.setDesiredCapacity(-1);
    ResponseEntity<ScalableTargetResourceInfo> resp2 = springResource.setScalableTargetResourceInfo(jobId, scalableTargetResourceInfo, callMetadataAuthentication);
    assertThat(resp2).isNotNull();
    assertThat(resp2.getStatusCodeValue()).isEqualTo(400);
}
Also used : CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) CallMetadataAuthentication(com.netflix.titus.runtime.endpoint.metadata.spring.CallMetadataAuthentication) Test(org.junit.Test)

Aggregations

CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)35 List (java.util.List)16 ArrayList (java.util.ArrayList)14 Task (com.netflix.titus.api.jobmanager.model.job.Task)13 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)12 Completable (rx.Completable)12 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)11 Collections (java.util.Collections)11 Collectors (java.util.stream.Collectors)11 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)10 Test (org.junit.Test)10 TaskStatus (com.netflix.titus.api.jobmanager.model.job.TaskStatus)9 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)9 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)9 Pair (com.netflix.titus.common.util.tuple.Pair)9 Set (java.util.Set)9 TimeUnit (java.util.concurrent.TimeUnit)9 TaskAttributes (com.netflix.titus.api.jobmanager.TaskAttributes)7 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)7 JobManagerEvent (com.netflix.titus.api.jobmanager.model.job.event.JobManagerEvent)7