use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project beam by apache.
the class BeamFnControlService method getProcessBundleDescriptor.
@Override
public void getProcessBundleDescriptor(BeamFnApi.GetProcessBundleDescriptorRequest request, StreamObserver<BeamFnApi.ProcessBundleDescriptor> responseObserver) {
String bundleDescriptorId = request.getProcessBundleDescriptorId();
LOG.info("getProcessBundleDescriptor request with id {}", bundleDescriptorId);
BeamFnApi.ProcessBundleDescriptor descriptor = processBundleDescriptors.get(bundleDescriptorId);
if (descriptor == null) {
String msg = String.format("ProcessBundleDescriptor with id %s not found", bundleDescriptorId);
responseObserver.onError(new StatusException(Status.NOT_FOUND.withDescription(msg)));
LOG.error(msg);
} else {
responseObserver.onNext(descriptor);
responseObserver.onCompleted();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project beam by apache.
the class BeamFnDataGrpcService method data.
@Override
public StreamObserver<Elements> data(final StreamObserver<Elements> outboundObserver) {
String sdkWorkerId = headerAccessor.getSdkWorkerId();
LOG.info("Beam Fn Data client connected for clientId {}", sdkWorkerId);
BeamFnDataGrpcMultiplexer multiplexer = new BeamFnDataGrpcMultiplexer(apiServiceDescriptor, OutboundObserverFactory.trivial(), (StreamObserver<BeamFnApi.Elements> inboundObserver) -> streamObserverFactory.apply(outboundObserver));
// First client that connects completes this future
getClientFuture(sdkWorkerId).complete(multiplexer);
try {
// incoming messages are sent to the single multiplexer instance.
return getClientFuture(sdkWorkerId).get().getInboundObserver();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project beam by apache.
the class InMemoryJobService method prepare.
@Override
public void prepare(PrepareJobRequest request, StreamObserver<PrepareJobResponse> responseObserver) {
try {
LOG.trace("{} {}", PrepareJobRequest.class.getSimpleName(), request);
// insert preparation
String preparationId = String.format("%s_%s", request.getJobName(), UUID.randomUUID().toString());
Struct pipelineOptions = request.getPipelineOptions();
if (pipelineOptions == null) {
throw new NullPointerException("Encountered null pipeline options.");
}
LOG.trace("PIPELINE OPTIONS {} {}", pipelineOptions.getClass(), pipelineOptions);
JobPreparation preparation = JobPreparation.builder().setId(preparationId).setPipeline(request.getPipeline()).setOptions(pipelineOptions).build();
JobPreparation previous = preparations.putIfAbsent(preparationId, preparation);
if (previous != null) {
// this should never happen with a UUID
String errMessage = String.format("A job with the preparation ID \"%s\" already exists.", preparationId);
StatusException exception = Status.NOT_FOUND.withDescription(errMessage).asException();
responseObserver.onError(exception);
return;
}
String stagingSessionToken = stagingServiceTokenProvider.apply(preparationId);
stagingSessionTokens.putIfAbsent(preparationId, stagingSessionToken);
stagingService.getService().registerJob(stagingSessionToken, Maps.transformValues(request.getPipeline().getComponents().getEnvironmentsMap(), RunnerApi.Environment::getDependenciesList));
// send response
PrepareJobResponse response = PrepareJobResponse.newBuilder().setPreparationId(preparationId).setArtifactStagingEndpoint(stagingServiceDescriptor).setStagingSessionToken(stagingSessionToken).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (Exception e) {
LOG.error("Could not prepare job with name {}", request.getJobName(), e);
responseObserver.onError(Status.INTERNAL.withCause(e).asException());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project beam by apache.
the class InMemoryJobService method getJobs.
@Override
public void getJobs(GetJobsRequest request, StreamObserver<GetJobsResponse> responseObserver) {
LOG.trace("{} {}", GetJobsRequest.class.getSimpleName(), request);
try {
List<JobInfo> result = new ArrayList<>();
for (JobInvocation invocation : invocations.values()) {
result.add(invocation.toProto());
}
GetJobsResponse response = GetJobsResponse.newBuilder().addAllJobInfo(result).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (Exception e) {
LOG.error("Encountered Unexpected Exception", e);
responseObserver.onError(Status.INTERNAL.withCause(e).asException());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver in project beam by apache.
the class InMemoryJobService method describePipelineOptions.
@Override
public void describePipelineOptions(DescribePipelineOptionsRequest request, StreamObserver<DescribePipelineOptionsResponse> responseObserver) {
LOG.trace("{} {}", DescribePipelineOptionsRequest.class.getSimpleName(), request);
try {
DescribePipelineOptionsResponse response = DescribePipelineOptionsResponse.newBuilder().addAllOptions(PipelineOptionsFactory.describe(PipelineOptionsFactory.getRegisteredOptions())).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (Exception e) {
LOG.error("Error describing pipeline options", e);
responseObserver.onError(Status.INTERNAL.withCause(e).asException());
}
}
Aggregations