Search in sources :

Example 1 with JobManagementServiceGrpc

use of com.netflix.titus.grpc.protogen.JobManagementServiceGrpc in project titus-control-plane by Netflix.

the class AggregatingJobServiceGateway method createJob.

@Override
public Observable<String> createJob(JobDescriptor jobDescriptor, CallMetadata callMetadata) {
    Cell cell = router.routeKey(jobDescriptor).orElse(null);
    if (cell == null) {
        // This should never happen in a correctly setup system.
        return Observable.error(new IllegalStateException("Internal system error. Routing rule not found"));
    }
    logger.debug("Routing JobDescriptor {} to Cell {}", jobDescriptor, cell);
    Optional<JobManagementServiceStub> optionalClient = CellConnectorUtil.toStub(cell, cellConnector, JobManagementServiceGrpc::newStub);
    if (!optionalClient.isPresent()) {
        return Observable.error(TitusServiceException.cellNotFound(cell.getName()));
    }
    JobManagementServiceStub client = optionalClient.get();
    JobDescriptor.Builder jobDescriptorBuilder = addStackName(jobDescriptor.toBuilder());
    jobDescriptorBuilder = removeFederationAttributes(jobDescriptorBuilder);
    jobDescriptorBuilder = addRoutingCell(jobDescriptorBuilder, cell);
    JobDescriptor jd = jobDescriptorBuilder.build();
    return createRequestObservable(emitter -> {
        StreamObserver<JobId> streamObserver = GrpcUtil.createClientResponseObserver(emitter, jobId -> emitter.onNext(jobId.getId()), emitter::onError, emitter::onCompleted);
        wrap(client, callMetadata).createJob(jd, streamObserver);
    }, grpcConfiguration.getRequestTimeoutMs());
}
Also used : JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) Cell(com.netflix.titus.api.federation.model.Cell) CellConnectorUtil.callToCell(com.netflix.titus.federation.service.CellConnectorUtil.callToCell) JobId(com.netflix.titus.grpc.protogen.JobId) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub)

Example 2 with JobManagementServiceGrpc

use of com.netflix.titus.grpc.protogen.JobManagementServiceGrpc in project titus-control-plane by Netflix.

the class AggregatingJobServiceGateway method observeJobs.

@Override
public Observable<JobChangeNotification> observeJobs(ObserveJobsQuery query, CallMetadata callMetadata) {
    final Observable<JobChangeNotification> observable = createRequestObservable(delegate -> {
        Emitter<JobChangeNotification> emitter = new EmitterWithMultipleSubscriptions<>(delegate);
        Map<Cell, JobManagementServiceStub> clients = CellConnectorUtil.stubs(cellConnector, JobManagementServiceGrpc::newStub);
        final CountDownLatch markersEmitted = new CallbackCountDownLatch(clients.size(), () -> emitter.onNext(buildJobSnapshotEndMarker()));
        clients.forEach((cell, client) -> {
            StreamObserver<JobChangeNotification> streamObserver = new FilterOutFirstMarker(emitter, markersEmitted);
            wrapWithNoDeadline(client, callMetadata).observeJobs(query, streamObserver);
        });
    });
    return observable.map(this::addStackName);
}
Also used : EmitterWithMultipleSubscriptions(com.netflix.titus.common.util.rx.EmitterWithMultipleSubscriptions) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) CallbackCountDownLatch(com.netflix.titus.common.util.concurrency.CallbackCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) CallbackCountDownLatch(com.netflix.titus.common.util.concurrency.CallbackCountDownLatch) Cell(com.netflix.titus.api.federation.model.Cell) CellConnectorUtil.callToCell(com.netflix.titus.federation.service.CellConnectorUtil.callToCell) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub)

Aggregations

Cell (com.netflix.titus.api.federation.model.Cell)2 CellConnectorUtil.callToCell (com.netflix.titus.federation.service.CellConnectorUtil.callToCell)2 JobManagementServiceGrpc (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc)2 JobManagementServiceStub (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub)2 CallbackCountDownLatch (com.netflix.titus.common.util.concurrency.CallbackCountDownLatch)1 EmitterWithMultipleSubscriptions (com.netflix.titus.common.util.rx.EmitterWithMultipleSubscriptions)1 JobChangeNotification (com.netflix.titus.grpc.protogen.JobChangeNotification)1 JobDescriptor (com.netflix.titus.grpc.protogen.JobDescriptor)1 JobId (com.netflix.titus.grpc.protogen.JobId)1 CountDownLatch (java.util.concurrent.CountDownLatch)1