Search in sources :

Example 1 with CallMetadata

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

the class AggregatingJobServiceGateway method killJob.

@Override
public Completable killJob(String jobId, CallMetadata callMetadata) {
    JobId id = JobId.newBuilder().setId(jobId).build();
    Observable<Empty> result = jobManagementServiceHelper.findJobInAllCells(jobId, callMetadata).flatMap(response -> singleCellCall(response.getCell(), (client, streamObserver) -> client.killJob(id, streamObserver), callMetadata));
    return result.toCompletable();
}
Also used : JobAttributesUpdate(com.netflix.titus.grpc.protogen.JobAttributesUpdate) JOB_ATTRIBUTES_FEDERATED_JOB_ID(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_FEDERATED_JOB_ID) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) TaskId(com.netflix.titus.grpc.protogen.TaskId) JOB_ATTRIBUTES_STACK(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_STACK) LoggerFactory(org.slf4j.LoggerFactory) StringExt(com.netflix.titus.common.util.StringExt) PageAggregationUtil.takeCombinedPage(com.netflix.titus.federation.service.PageAggregationUtil.takeCombinedPage) ReactorExt(com.netflix.titus.common.util.rx.ReactorExt) CHECKPOINT_FED_CLIENT(com.netflix.titus.runtime.connector.jobmanager.JobEventPropagationUtil.CHECKPOINT_FED_CLIENT) TaskUpdate(com.netflix.titus.grpc.protogen.JobChangeNotification.TaskUpdate) Empty(com.google.protobuf.Empty) JobDisruptionBudgetUpdate(com.netflix.titus.grpc.protogen.JobDisruptionBudgetUpdate) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) GrpcUtil(com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil) StreamObserver(io.grpc.stub.StreamObserver) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) JobCapacityUpdate(com.netflix.titus.grpc.protogen.JobCapacityUpdate) Map(java.util.Map) PageAggregationUtil.combinePagination(com.netflix.titus.federation.service.PageAggregationUtil.combinePagination) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobCapacityUpdateWithOptionalAttributes(com.netflix.titus.grpc.protogen.JobCapacityUpdateWithOptionalAttributes) TaskKillRequest(com.netflix.titus.grpc.protogen.TaskKillRequest) CellRouter(com.netflix.titus.federation.service.router.CellRouter) JobEventPropagationUtil(com.netflix.titus.runtime.connector.jobmanager.JobEventPropagationUtil) JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) JobProcessesUpdate(com.netflix.titus.grpc.protogen.JobProcessesUpdate) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Cell(com.netflix.titus.api.federation.model.Cell) Task(com.netflix.titus.grpc.protogen.Task) Set(java.util.Set) GrpcUtil.createRequestObservable(com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil.createRequestObservable) EmitterWithMultipleSubscriptions(com.netflix.titus.common.util.rx.EmitterWithMultipleSubscriptions) Collectors(java.util.stream.Collectors) ProtobufExt(com.netflix.titus.common.util.ProtobufExt) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CellConnectorUtil.callToCell(com.netflix.titus.federation.service.CellConnectorUtil.callToCell) JobUpdate(com.netflix.titus.grpc.protogen.JobChangeNotification.JobUpdate) Optional(java.util.Optional) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobId(com.netflix.titus.grpc.protogen.JobId) Completable(rx.Completable) TaskMoveRequest(com.netflix.titus.grpc.protogen.TaskMoveRequest) TASK_ATTRIBUTES_STACK(com.netflix.titus.api.jobmanager.TaskAttributes.TASK_ATTRIBUTES_STACK) JobAttributesDeleteRequest(com.netflix.titus.grpc.protogen.JobAttributesDeleteRequest) Job(com.netflix.titus.grpc.protogen.Job) Singleton(javax.inject.Singleton) Observable(rx.Observable) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CallbackCountDownLatch(com.netflix.titus.common.util.concurrency.CallbackCountDownLatch) TitusFederationConfiguration(com.netflix.titus.federation.startup.TitusFederationConfiguration) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) Pair(com.netflix.titus.common.util.tuple.Pair) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) BiConsumer(java.util.function.BiConsumer) JobServiceGateway(com.netflix.titus.runtime.jobmanager.gateway.JobServiceGateway) TaskAttributesUpdate(com.netflix.titus.grpc.protogen.TaskAttributesUpdate) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) Logger(org.slf4j.Logger) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Mono(reactor.core.publisher.Mono) Pagination(com.netflix.titus.grpc.protogen.Pagination) GrpcUtil.createWrappedStub(com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil.createWrappedStub) Emitter(rx.Emitter) JobStatusUpdate(com.netflix.titus.grpc.protogen.JobStatusUpdate) JOB_ATTRIBUTE_ROUTING_CELL(com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTE_ROUTING_CELL) JobManagerCursors(com.netflix.titus.runtime.jobmanager.JobManagerCursors) GrpcJobQueryModelConverters.emptyGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.emptyGrpcPagination) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) TaskAttributesDeleteRequest(com.netflix.titus.grpc.protogen.TaskAttributesDeleteRequest) Collections(java.util.Collections) Empty(com.google.protobuf.Empty) JobId(com.netflix.titus.grpc.protogen.JobId)

Example 2 with CallMetadata

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

the class AggregatingLoadbalancerService method addLoadBalancer.

@Override
public Completable addLoadBalancer(AddLoadBalancerRequest request, CallMetadata callMetadata) {
    JobId jobId = JobId.newBuilder().setId(request.getJobId()).build();
    final Observable<Empty> responseObservable = jobManagementServiceHelper.findJobInAllCells(jobId.getId(), callMetadata).flatMap(response -> singleCellCall(response.getCell(), (client, responseObserver) -> client.addLoadBalancer(request, responseObserver), callMetadata));
    return responseObservable.toCompletable();
}
Also used : Completable(rx.Completable) GetJobLoadBalancersResult(com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult) GetAllLoadBalancersRequest(com.netflix.titus.grpc.protogen.GetAllLoadBalancersRequest) GrpcJobQueryModelConverters.toPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toPagination) AddLoadBalancerRequest(com.netflix.titus.grpc.protogen.AddLoadBalancerRequest) GetAllLoadBalancersResult(com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult) StringExt(com.netflix.titus.common.util.StringExt) PageAggregationUtil.takeCombinedPage(com.netflix.titus.federation.service.PageAggregationUtil.takeCombinedPage) Singleton(javax.inject.Singleton) Observable(rx.Observable) Inject(javax.inject.Inject) Empty(com.google.protobuf.Empty) CallMetadataResolver(com.netflix.titus.runtime.endpoint.metadata.CallMetadataResolver) StreamObserver(io.grpc.stub.StreamObserver) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) Pair(com.netflix.titus.common.util.tuple.Pair) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) PageAggregationUtil.combinePagination(com.netflix.titus.federation.service.PageAggregationUtil.combinePagination) BiConsumer(java.util.function.BiConsumer) GrpcModelConverters(com.netflix.titus.runtime.loadbalancer.GrpcModelConverters) RemoveLoadBalancerRequest(com.netflix.titus.grpc.protogen.RemoveLoadBalancerRequest) LoadBalancerCursors(com.netflix.titus.runtime.loadbalancer.LoadBalancerCursors) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Cell(com.netflix.titus.api.federation.model.Cell) Pagination(com.netflix.titus.grpc.protogen.Pagination) GrpcUtil.createWrappedStub(com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil.createWrappedStub) Collectors(java.util.stream.Collectors) LoadBalancerServiceStub(com.netflix.titus.grpc.protogen.LoadBalancerServiceGrpc.LoadBalancerServiceStub) List(java.util.List) CellConnectorUtil.callToCell(com.netflix.titus.federation.service.CellConnectorUtil.callToCell) LoadBalancerServiceGrpc(com.netflix.titus.grpc.protogen.LoadBalancerServiceGrpc) GrpcJobQueryModelConverters.emptyGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.emptyGrpcPagination) AbstractStub(io.grpc.stub.AbstractStub) LoadBalancerService(com.netflix.titus.runtime.service.LoadBalancerService) JobId(com.netflix.titus.grpc.protogen.JobId) Empty(com.google.protobuf.Empty) JobId(com.netflix.titus.grpc.protogen.JobId)

Example 3 with CallMetadata

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

the class AggregatingLoadbalancerService method removeLoadBalancer.

@Override
public Completable removeLoadBalancer(RemoveLoadBalancerRequest removeLoadBalancerRequest, CallMetadata callMetadata) {
    JobId jobId = JobId.newBuilder().setId(removeLoadBalancerRequest.getJobId()).build();
    final Observable<Empty> responseObservable = jobManagementServiceHelper.findJobInAllCells(jobId.getId(), callMetadata).flatMap(response -> singleCellCall(response.getCell(), (client, responseObserver) -> client.removeLoadBalancer(removeLoadBalancerRequest, responseObserver), callMetadata));
    return responseObservable.toCompletable();
}
Also used : Completable(rx.Completable) GetJobLoadBalancersResult(com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult) GetAllLoadBalancersRequest(com.netflix.titus.grpc.protogen.GetAllLoadBalancersRequest) GrpcJobQueryModelConverters.toPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.toPagination) AddLoadBalancerRequest(com.netflix.titus.grpc.protogen.AddLoadBalancerRequest) GetAllLoadBalancersResult(com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult) StringExt(com.netflix.titus.common.util.StringExt) PageAggregationUtil.takeCombinedPage(com.netflix.titus.federation.service.PageAggregationUtil.takeCombinedPage) Singleton(javax.inject.Singleton) Observable(rx.Observable) Inject(javax.inject.Inject) Empty(com.google.protobuf.Empty) CallMetadataResolver(com.netflix.titus.runtime.endpoint.metadata.CallMetadataResolver) StreamObserver(io.grpc.stub.StreamObserver) TitusServiceException(com.netflix.titus.api.service.TitusServiceException) Pair(com.netflix.titus.common.util.tuple.Pair) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) PageAggregationUtil.combinePagination(com.netflix.titus.federation.service.PageAggregationUtil.combinePagination) BiConsumer(java.util.function.BiConsumer) GrpcModelConverters(com.netflix.titus.runtime.loadbalancer.GrpcModelConverters) RemoveLoadBalancerRequest(com.netflix.titus.grpc.protogen.RemoveLoadBalancerRequest) LoadBalancerCursors(com.netflix.titus.runtime.loadbalancer.LoadBalancerCursors) CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Cell(com.netflix.titus.api.federation.model.Cell) Pagination(com.netflix.titus.grpc.protogen.Pagination) GrpcUtil.createWrappedStub(com.netflix.titus.runtime.endpoint.common.grpc.GrpcUtil.createWrappedStub) Collectors(java.util.stream.Collectors) LoadBalancerServiceStub(com.netflix.titus.grpc.protogen.LoadBalancerServiceGrpc.LoadBalancerServiceStub) List(java.util.List) CellConnectorUtil.callToCell(com.netflix.titus.federation.service.CellConnectorUtil.callToCell) LoadBalancerServiceGrpc(com.netflix.titus.grpc.protogen.LoadBalancerServiceGrpc) GrpcJobQueryModelConverters.emptyGrpcPagination(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobQueryModelConverters.emptyGrpcPagination) AbstractStub(io.grpc.stub.AbstractStub) LoadBalancerService(com.netflix.titus.runtime.service.LoadBalancerService) JobId(com.netflix.titus.grpc.protogen.JobId) Empty(com.google.protobuf.Empty) JobId(com.netflix.titus.grpc.protogen.JobId)

Example 4 with CallMetadata

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

the class SpringCallMetadataInterceptorTest method expectCallMetadataAuthentication.

private com.netflix.titus.api.model.callmetadata.CallMetadata expectCallMetadataAuthentication() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    assertThat(authentication).isNotNull();
    assertThat(authentication).isInstanceOf(CallMetadataAuthentication.class);
    CallMetadataAuthentication callMetadataAuthentication = (CallMetadataAuthentication) authentication;
    CallMetadata callMetadata = callMetadataAuthentication.getCallMetadata();
    assertThat(callMetadata).isNotNull();
    assertThat(callMetadata.getCallReason()).isEqualTo(MY_REASON);
    return callMetadata;
}
Also used : CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) Authentication(org.springframework.security.core.Authentication)

Example 5 with CallMetadata

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

the class SimpleGrpcCallMetadataResolver method resolve.

@Override
public Optional<CallMetadata> resolve() {
    if (Context.current() == Context.ROOT) {
        // Not in GRPC server call.
        return Optional.empty();
    }
    CallMetadata forwardedCallMetadata = V3HeaderInterceptor.CALL_METADATA_CONTEXT_KEY.get();
    Caller directCaller = resolveDirectCallerInternal();
    // If we have CallMetadata instance, we can safely ignore other headers, except the direct caller.
    if (forwardedCallMetadata != null) {
        return Optional.of(forwardedCallMetadata.toBuilder().withCallPath(CollectionsExt.copyAndAdd(forwardedCallMetadata.getCallPath(), directCaller.getId())).withCallers(CollectionsExt.copyAndAdd(forwardedCallMetadata.getCallers(), directCaller)).build());
    }
    // No CellMetadata in header, so we must built it here.
    String callerId = V3HeaderInterceptor.CALLER_ID_CONTEXT_KEY.get();
    String callReason = getOrDefault(V3HeaderInterceptor.CALL_REASON_CONTEXT_KEY.get(), "reason not given");
    CallMetadata.Builder callMetadataBuilder = CallMetadata.newBuilder().withCallReason(callReason);
    if (callerId == null) {
        callMetadataBuilder.withCallerId(directCaller.getId()).withCallPath(Collections.singletonList(directCaller.getId())).withCallers(Collections.singletonList(directCaller));
    } else {
        Caller originalCaller = Caller.newBuilder().withId(callerId).withCallerType(CallerType.parseCallerType(callerId, V3HeaderInterceptor.CALLER_TYPE_CONTEXT_KEY.get())).build();
        callMetadataBuilder.withCallerId(callerId).withCallPath(asList(callerId, directCaller.getId())).withCallers(asList(originalCaller, directCaller));
    }
    return Optional.of(callMetadataBuilder.build());
}
Also used : CallMetadata(com.netflix.titus.api.model.callmetadata.CallMetadata) Caller(com.netflix.titus.api.model.callmetadata.Caller)

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