@Override public void cancel(CancelJobRequest request, StreamObserver<CancelJobResponse> responseObserver) { LOG.trace("{} {}", CancelJobRequest.class.getSimpleName(), request); responseObserver.onError( Status.NOT_FOUND .withDescription(String.format("Unknown Job ID %s", request.getJobId())) .asException()); }
.withCause(actual) .withDescription(Throwables.getStackTraceAsString(actual)); responseObserver.onError(status.asException());
Status.INVALID_ARGUMENT .withDescription(String.format("Unknown Preparation Id %s", preparationId)) .asException()); return; responseObserver.onError(e); } catch (Exception e) { responseObserver.onError(Status.INTERNAL.withCause(e).asException());
@Override public void getStateStream( GetJobStateRequest request, StreamObserver<GetJobStateResponse> responseObserver) { LOG.trace("{} {}", GetJobStateRequest.class.getSimpleName(), request); String invocationId = request.getJobId(); try { Thread.sleep(WAIT_MS); Enum state = jobStates.getOrDefault(request.getJobId(), Enum.UNRECOGNIZED); responseObserver.onNext(GetJobStateResponse.newBuilder().setState(state).build()); while (Enum.RUNNING.equals(state)) { Thread.sleep(WAIT_MS); state = jobStates.getOrDefault(request.getJobId(), Enum.UNRECOGNIZED); } responseObserver.onNext(GetJobStateResponse.newBuilder().setState(state).build()); } catch (Exception e) { String errMessage = String.format("Encountered Unexpected Exception for Invocation %s", invocationId); LOG.error(errMessage, e); responseObserver.onError(Status.INTERNAL.withCause(e).asException()); } responseObserver.onCompleted(); }
@Override public void getArtifact( ArtifactApi.GetArtifactRequest request, StreamObserver<ArtifactApi.ArtifactChunk> responseObserver) { try { ByteBuffer artifact = getArtifact(request.getName()); do { responseObserver.onNext( ArtifactChunk.newBuilder() .setData( ByteString.copyFrom( artifact, Math.min(artifact.remaining(), DEFAULT_CHUNK_SIZE))) .build()); } while (artifact.hasRemaining()); responseObserver.onCompleted(); } catch (FileNotFoundException e) { responseObserver.onError( Status.INVALID_ARGUMENT .withDescription(String.format("No such artifact %s", request.getName())) .withCause(e) .asException()); } catch (Exception e) { responseObserver.onError( Status.INTERNAL .withDescription( String.format("Could not retrieve artifact with name %s", request.getName())) .withCause(e) .asException()); } }
@Override public final void getManifest( ArtifactApi.GetManifestRequest request, StreamObserver<GetManifestResponse> responseObserver) { try { responseObserver.onNext(GetManifestResponse.newBuilder().setManifest(manifest).build()); responseObserver.onCompleted(); } catch (Exception e) { responseObserver.onError(Status.INTERNAL.withCause(e).asException()); } }
} catch (Exception e) { LOG.error("Could not prepare job with name {}", request.getJobName(), e); responseObserver.onError(Status.INTERNAL.withCause(e).asException());