use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class OkHttpClientTransportTest method ping_failsIfTransportFails.
@Test
public void ping_failsIfTransportFails() throws Exception {
initTransport();
PingCallbackImpl callback = new PingCallbackImpl();
clientTransport.ping(callback, MoreExecutors.directExecutor());
assertEquals(1, getTransportStats(clientTransport).keepAlivesSent);
assertEquals(0, callback.invocationCount);
clientTransport.onException(new IOException());
// ping failed on error
assertEquals(1, callback.invocationCount);
assertTrue(callback.failureCause instanceof StatusException);
assertEquals(Status.Code.UNAVAILABLE, ((StatusException) callback.failureCause).getStatus().getCode());
// now that handler is in terminal state, all future pings fail immediately
callback = new PingCallbackImpl();
clientTransport.ping(callback, MoreExecutors.directExecutor());
assertEquals(1, getTransportStats(clientTransport).keepAlivesSent);
assertEquals(1, callback.invocationCount);
assertTrue(callback.failureCause instanceof StatusException);
assertEquals(Status.Code.UNAVAILABLE, ((StatusException) callback.failureCause).getStatus().getCode());
shutdownAndVerify();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project pinpoint by naver.
the class GrpcCommandService method commandEcho.
@Override
public void commandEcho(PCmdEchoResponse echoResponse, StreamObserver<Empty> responseObserver) {
final Long transportId = getTransportId();
PinpointGrpcServer pinpointGrpcServer = grpcServerRepository.get(transportId);
if (pinpointGrpcServer != null) {
echoService.handle(pinpointGrpcServer, echoResponse, responseObserver);
responseObserver.onNext(Empty.getDefaultInstance());
responseObserver.onCompleted();
} else {
logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getAgentInfo().getAgentKey(), transportId);
responseObserver.onError(new StatusException(Status.NOT_FOUND));
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project pinpoint by naver.
the class GrpcCommandService method handleCommandV2.
@Override
public StreamObserver<PCmdMessage> handleCommandV2(StreamObserver<PCmdRequest> requestObserver) {
final Long transportId = getTransportId();
final AgentInfo agentInfo = getAgentInfo();
final List<Integer> supportCommandCodeList = getSupportCommandCodeList();
logger.info("{} => local. handleCommandV2(). transportId:{}, supportCommandCodeList{}", agentInfo, transportId, supportCommandCodeList);
if (supportCommandCodeList == Header.SUPPORT_COMMAND_CODE_LIST_NOT_EXIST) {
logger.warn("handleCommandV2() not allow empty Header:{}. Connection will be disconnected.", Header.SUPPORT_COMMAND_CODE.name());
requestObserver.onError(new StatusException(Status.INVALID_ARGUMENT));
return DisabledStreamObserver.instance();
}
final PinpointGrpcServer pinpointGrpcServer = registerNewPinpointGrpcServer(requestObserver, agentInfo, transportId);
if (pinpointGrpcServer == null) {
return handleServerRegistrationFailed(requestObserver, agentInfo, transportId);
}
final ServerCallStreamObserver<PCmdRequest> serverCallStreamObserver = (ServerCallStreamObserver<PCmdRequest>) requestObserver;
serverCallStreamObserver.setOnReadyHandler(new Runnable() {
public void run() {
if (serverCallStreamObserver.isReady()) {
logger.info("{} => local. ready() transportId:{}", agentInfo.getAgentKey(), transportId);
pinpointGrpcServer.connected();
registerAgentCommandList(pinpointGrpcServer, supportCommandCodeList);
}
pinpointGrpcServer.setOnCloseHandler(new Runnable() {
@Override
public void run() {
unregisterPinpointGrpcServer(transportId);
}
});
}
});
final StreamObserver<PCmdMessage> responseObserver = new StreamObserver<PCmdMessage>() {
@Override
public void onNext(PCmdMessage value) {
if (value.hasFailMessage()) {
PCmdResponse failMessage = value.getFailMessage();
pinpointGrpcServer.handleFail(failMessage);
}
}
@Override
public void onError(Throwable t) {
handleOnError(t, pinpointGrpcServer, agentInfo);
}
@Override
public void onCompleted() {
handleOnCompleted(pinpointGrpcServer, agentInfo);
}
};
return responseObserver;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project pinpoint by naver.
the class GrpcCommandService method handleCommand.
@Override
public StreamObserver<PCmdMessage> handleCommand(StreamObserver<PCmdRequest> requestObserver) {
final Long transportId = getTransportId();
final AgentInfo agentInfo = getAgentInfo();
logger.info("{} => local. handleCommand(). transportId:{}.", agentInfo, transportId);
final List<Integer> supportCommandCodeList = getSupportCommandCodeList();
if (supportCommandCodeList != Header.SUPPORT_COMMAND_CODE_LIST_NOT_EXIST) {
logger.warn("handleCommand() not support included Header:{}. Connection will be disconnected.", Header.SUPPORT_COMMAND_CODE.name());
requestObserver.onError(new StatusException(Status.INVALID_ARGUMENT));
return DisabledStreamObserver.instance();
}
final PinpointGrpcServer pinpointGrpcServer = registerNewPinpointGrpcServer(requestObserver, agentInfo, transportId);
if (pinpointGrpcServer == null) {
return handleServerRegistrationFailed(requestObserver, agentInfo, transportId);
}
final ServerCallStreamObserver<PCmdRequest> serverCallStreamObserver = (ServerCallStreamObserver<PCmdRequest>) requestObserver;
serverCallStreamObserver.setOnReadyHandler(new Runnable() {
public void run() {
if (serverCallStreamObserver.isReady()) {
logger.info("{} => local. ready() transportId:{}", agentInfo.getAgentKey(), transportId);
pinpointGrpcServer.connected();
}
pinpointGrpcServer.setOnCloseHandler(new Runnable() {
@Override
public void run() {
unregisterPinpointGrpcServer(transportId);
}
});
}
});
final StreamObserver<PCmdMessage> responseObserver = new StreamObserver<PCmdMessage>() {
@Override
public void onNext(PCmdMessage value) {
// old operation for handshake
if (value.hasHandshakeMessage()) {
List<Integer> supportCommandServiceKeyList = value.getHandshakeMessage().getSupportCommandServiceKeyList();
registerAgentCommandList(pinpointGrpcServer, supportCommandServiceKeyList);
} else if (value.hasFailMessage()) {
PCmdResponse failMessage = value.getFailMessage();
pinpointGrpcServer.handleFail(failMessage);
}
}
@Override
public void onError(Throwable t) {
handleOnError(t, pinpointGrpcServer, agentInfo);
}
@Override
public void onCompleted() {
handleOnCompleted(pinpointGrpcServer, agentInfo);
}
};
return responseObserver;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project pinpoint by naver.
the class GrpcCommandService method commandActiveThreadDump.
@Override
public void commandActiveThreadDump(PCmdActiveThreadDumpRes activeThreadDumpRes, StreamObserver<Empty> responseObserver) {
final Long transportId = getTransportId();
PinpointGrpcServer pinpointGrpcServer = grpcServerRepository.get(transportId);
if (pinpointGrpcServer != null) {
activeThreadDumpService.handle(pinpointGrpcServer, activeThreadDumpRes, responseObserver);
responseObserver.onNext(Empty.getDefaultInstance());
responseObserver.onCompleted();
} else {
logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getAgentInfo().getAgentKey(), transportId);
responseObserver.onError(new StatusException(Status.NOT_FOUND));
}
}
Aggregations