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);
}
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);
}
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);
}
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;
}));
}
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);
}
Aggregations