Status status = Status.INTERNAL .withCause(actual) .withDescription(Throwables.getStackTraceAsString(actual)); responseObserver.onError(status.asException());
@Override public void commitManifest( ArtifactApi.CommitManifestRequest request, StreamObserver<ArtifactApi.CommitManifestResponse> responseObserver) { try { commitManifestOrThrow(request, responseObserver); } catch (StatusRuntimeException e) { responseObserver.onError(e); LOG.error("Failed to commit Manifest {}", request.getManifest(), e); } catch (Exception e) { responseObserver.onError( Status.INTERNAL .withCause(e) .withDescription(Throwables.getStackTraceAsString(e)) .asRuntimeException()); LOG.error("Failed to commit Manifest {}", request.getManifest(), e); } }
@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());
responseObserver.onError(e); } catch (Exception e) { responseObserver.onError(Status.INTERNAL.withCause(e).asException());
@Override public void onNext(ArtifactApi.PutArtifactRequest value) { try { if (writer == null) { if (!value.getContentCase().equals(ArtifactApi.PutArtifactRequest.ContentCase.METADATA)) { throw Status.INVALID_ARGUMENT .withDescription( String.format( "Expected the first %s to contain the Artifact Name, got %s", ArtifactApi.PutArtifactRequest.class.getSimpleName(), value.getContentCase())) .asRuntimeException(); } writer = createFile(value.getMetadata().getMetadata()); } else { writer.onNext(value); } } catch (StatusRuntimeException e) { responseObserver.onError(e); } catch (Exception e) { responseObserver.onError( Status.INTERNAL .withCause(e) .withDescription(Throwables.getStackTraceAsString(e)) .asRuntimeException()); } }