use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project instrumentation-java by census-instrumentation.
the class OcAgentMetricsServiceExportRpcHandler method onComplete.
// Marks this export stream as completed with an optional error.
// Once onComplete is called, this OcAgentMetricsServiceExportRpcHandler instance can be discarded
// and GC'ed in the worker thread.
synchronized void onComplete(@javax.annotation.Nullable Throwable error) {
if (isCompleted()) {
return;
}
// TODO(songya): add Runnable
Status status;
if (error == null) {
status = Status.OK;
} else if (error instanceof StatusRuntimeException) {
status = ((StatusRuntimeException) error).getStatus();
} else {
status = Status.UNKNOWN;
}
terminateStatus = status;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project alluxio by Alluxio.
the class AbstractClient method retryRPCInternal.
private synchronized <V> V retryRPCInternal(RetryPolicy retryPolicy, RpcCallable<V> rpc, Supplier<Void> onRetry) throws AlluxioStatusException {
Exception ex = null;
while (retryPolicy.attempt()) {
if (mClosed) {
throw new FailedPreconditionException("Client is closed");
}
connect();
try {
return rpc.call();
} catch (StatusRuntimeException e) {
AlluxioStatusException se = AlluxioStatusException.fromStatusRuntimeException(e);
if (se.getStatusCode() == Status.Code.UNAVAILABLE || se.getStatusCode() == Status.Code.CANCELLED || se.getStatusCode() == Status.Code.UNAUTHENTICATED || e.getCause() instanceof UnresolvedAddressException) {
ex = se;
} else {
throw se;
}
}
LOG.debug("Rpc failed ({}): ", retryPolicy.getAttemptCount(), ex);
onRetry.get();
disconnect();
}
throw new UnavailableException("Failed after " + retryPolicy.getAttemptCount() + " attempts: " + ex.toString(), ex);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project instrumentation-java by census-instrumentation.
the class OcAgentTraceServiceExportRpcHandler method onComplete.
// Marks this export stream as completed with an optional error.
// Once onComplete is called, this OcAgentTraceServiceExportRpcHandler instance can be discarded
// and GC'ed in the worker thread.
synchronized void onComplete(@javax.annotation.Nullable Throwable error) {
if (isCompleted()) {
return;
}
// TODO(songya): add Runnable
Status status;
if (error == null) {
status = Status.OK;
} else if (error instanceof StatusRuntimeException) {
status = ((StatusRuntimeException) error).getStatus();
} else {
status = Status.UNKNOWN;
}
terminateStatus = status;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project alluxio by Alluxio.
the class SnapshotReplicationManagerTest method uploadFailure.
/**
* Simulates a {@link SnapshotUploader} error.
*/
@Test
public void uploadFailure() throws Exception {
before(2);
List<Follower> followers = new ArrayList<>(mFollowers.values());
Follower firstFollower = followers.get(0);
Follower secondFollower = followers.get(1);
// create default 0, 1 snapshot
createSnapshotFile(firstFollower.mStore);
// preferable to the default 0, 1 snapshot
createSnapshotFile(secondFollower.mStore, 0, 2);
// make sure to error out when requesting the better snapshot from secondFollower
Mockito.doAnswer(mock -> {
SingleFileSnapshotInfo snapshot = secondFollower.mStore.getLatestSnapshot();
StreamObserver<UploadSnapshotPResponse> responseObserver = SnapshotUploader.forFollower(secondFollower.mStore, snapshot);
StreamObserver<UploadSnapshotPRequest> requestObserver = mClient.uploadSnapshot(responseObserver);
responseObserver.onError(new StatusRuntimeException(Status.UNAVAILABLE));
requestObserver.onNext(UploadSnapshotPRequest.newBuilder().setData(SnapshotData.newBuilder().setSnapshotTerm(snapshot.getTerm()).setSnapshotIndex(snapshot.getIndex()).setOffset(0)).build());
return null;
}).when(secondFollower.mSnapshotManager).sendSnapshotToLeader();
mLeaderSnapshotManager.maybeCopySnapshotFromFollower();
CommonUtils.waitFor("leader snapshot to complete", () -> mLeaderSnapshotManager.maybeCopySnapshotFromFollower() != -1, mWaitOptions);
// verify that the leader still requests and gets second best snapshot
validateSnapshotFile(mLeaderStore);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project beam by apache.
the class GrpcWindmillServer method callWithBackoff.
private <ResponseT> ResponseT callWithBackoff(Supplier<ResponseT> function) {
BackOff backoff = grpcBackoff();
int rpcErrors = 0;
while (true) {
try {
return function.get();
} catch (StatusRuntimeException e) {
try {
if (++rpcErrors % 20 == 0) {
LOG.warn("Many exceptions calling gRPC. Last exception: {} with status {}", e, e.getStatus());
}
if (!BackOffUtils.next(Sleeper.DEFAULT, backoff)) {
throw new WindmillServerStub.RpcException(e);
}
} catch (IOException | InterruptedException i) {
if (i instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
WindmillServerStub.RpcException rpcException = new WindmillServerStub.RpcException(e);
rpcException.addSuppressed(i);
throw rpcException;
}
}
}
}
Aggregations