Java Code Examples for io.grpc.StatusRuntimeException#getMessage()

The following examples show how to use io.grpc.StatusRuntimeException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KMSEncryptionProvider.java    From credhub with Apache License 2.0 6 votes vote down vote up
@Override
public String decrypt(final EncryptionKey key, final byte[] encryptedValue, final byte[] nonce) throws Exception {
  final DecryptRequest request = DecryptRequest.newBuilder().setCipher(ByteString.copyFrom(encryptedValue)).build();
  final DecryptResponse response;
  try {
    response = blockingStub.decrypt(request);
  } catch (final StatusRuntimeException e) {
    if (e.getStatus().getCode() == Status.Code.INVALID_ARGUMENT) {
      throw new AEADBadTagException(e.getMessage());
    }
    LOGGER.error("Error for request: " + request.getCipher(), e);
    throw e;
  }

  return response.getPlain().toString(CHARSET);
}
 
Example 2
Source File: StatusErrors.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public static StatusError throwable(final Throwable t) {
    if (t instanceof StatusRuntimeException) {
        StatusRuntimeException exception = (StatusRuntimeException) t;
        if (exception.getStatus().getCode() == Status.UNAVAILABLE.getCode()) {
            final String causeMessage = findCauseMessage(t, CONNECTION_REFUSED_MESSAGE, 2);
            if (causeMessage != null) {
                final String message = exception.getStatus().getDescription() + ": " + causeMessage;
                return new SimpleStatusError(message, t);
            }
        } else if (exception.getStatus().getCode() == Status.CANCELLED.getCode()) {
            if (exception.getMessage() != null && exception.getMessage().startsWith(CANCELLED_BEFORE_RECEIVING_HALF_CLOSE)) {
                return new SimpleStatusError(CANCELLED_BEFORE_RECEIVING_HALF_CLOSE, t);
            }
        }
    }
    return new DefaultStatusError(t);
}
 
Example 3
Source File: AbstractGrpcClient.java    From onos with Apache License 2.0 6 votes vote down vote up
protected void handleRpcError(Throwable throwable, String opDescription) {
    if (throwable instanceof StatusRuntimeException) {
        final StatusRuntimeException sre = (StatusRuntimeException) throwable;
        final String logMsg;
        if (sre.getCause() == null) {
            logMsg = sre.getMessage();
        } else {
            logMsg = format("%s (%s)", sre.getMessage(), sre.getCause().toString());
        }
        log.warn("Error while performing {} on {}: {}",
                 opDescription, deviceId, logMsg);
        log.debug("", throwable);
        return;
    }
    log.error(format("Exception while performing %s on %s",
                     opDescription, deviceId), throwable);
}
 
Example 4
Source File: MinaSshdManagementClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps call to acquireMinaSshdService.
 *
 * @param requestId the request ID for the request
 * @param accountId the account ID
 * @return the minasshd service
 * @throws CcmException if an exception occurs
 */
public MinaSshdService acquireMinaSshdService(String requestId, String accountId) throws CcmException {
    checkNotNull(requestId);
    checkNotNull(accountId);

    MinaSshdManagementBlockingStub blockingStub = newStub(requestId);
    AcquireMinaSshdServiceRequest.Builder requestBuilder = AcquireMinaSshdServiceRequest.newBuilder()
            .setAccountId(accountId);

    try {
        LOGGER.debug("Calling acquireMinaSshdService with requestId: {}, accountId: {}",
                requestId, accountId);
        AcquireMinaSshdServiceResponse response = blockingStub.acquireMinaSshdService(requestBuilder.build());
        if (response == null) {
            throw new CcmException("Got null response from MinaSshdManagementService acquireMinaSshdService gRPC call", false);
        } else {
            MinaSshdService minaSshdService = response.getMinaSshdService();
            if (minaSshdService == null) {
                throw new CcmException("Got null minasshd service in MinaSshdManagementService acquireMinaSshdService gRPC response", false);
            } else {
                return minaSshdService;
            }
        }
    } catch (StatusRuntimeException e) {
        String message = "MinaSshdManagementService acquireMinaSshdService gRPC call failed: " + e.getMessage();
        Status status = e.getStatus();
        Status.Code code = status.getCode();
        boolean retryable = GrpcUtil.isRetryable(code);
        LOGGER.debug("Got status code: {}, retryable: {}", code, retryable);
        throw new CcmException(message, e, retryable);
    }
}
 
Example 5
Source File: MinaSshdManagementClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps call to generateAndRegisterSshTunnelingKeyPair.
 *
 * @param requestId         the request ID for the request
 * @param accountId         the account ID
 * @param minaSshdServiceId the minasshd service ID
 * @param keyId             the key ID
 * @return the response containing the key pair
 * @throws CcmException if an exception occurs
 */
public GenerateAndRegisterSshTunnelingKeyPairResponse generateAndRegisterSshTunnelingKeyPair(
        String requestId, String accountId, String minaSshdServiceId, String keyId) throws CcmException {
    checkNotNull(requestId);
    checkNotNull(accountId);
    checkNotNull(minaSshdServiceId);
    checkNotNull(keyId);

    MinaSshdManagementBlockingStub blockingStub = newStub(requestId);
    GenerateAndRegisterSshTunnelingKeyPairRequest.Builder requestBuilder = GenerateAndRegisterSshTunnelingKeyPairRequest.newBuilder()
            .setAccountId(accountId)
            .setMinaSshdServiceId(minaSshdServiceId)
            .setKeyId(keyId);

    try {
        LOGGER.debug("Calling generateAndRegisterSshTunnelingKeyPair with requestId: {}, accountId: {}, minaSshdServiceId: {}, keyId: {}",
                requestId, accountId, minaSshdServiceId, keyId);
        GenerateAndRegisterSshTunnelingKeyPairResponse response = blockingStub.generateAndRegisterSshTunnelingKeyPair(requestBuilder.build());
        if (response == null) {
            throw new CcmException("Got null response from MinaSshdManagementService generateAndRegisterSshTunnelingKeyPair gRPC call", false);
        } else {
            return response;
        }
    } catch (StatusRuntimeException e) {
        String message = "MinaSshdManagementService generateAndRegisterSshTunnelingKeyPair gRPC call failed: " + e.getMessage();
        Status status = e.getStatus();
        Status.Code code = status.getCode();
        boolean retryable = GrpcUtil.isRetryable(code);
        LOGGER.debug("Got status code: {}, retryable: {}", code, retryable);
        throw new CcmException(message, e, retryable);
    }
}
 
Example 6
Source File: MinaSshdManagementClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps call to unregisterSshTunnelingKey.
 *
 * @param requestId         the request ID for the request
 * @param minaSshdServiceId the minasshd service ID
 * @param keyId             the key ID
 * @return the response
 * @throws CcmException if an exception occurs
 */
public UnregisterSshTunnelingKeyResponse unregisterSshTunnelingKey(
        String requestId, String minaSshdServiceId, String keyId) throws CcmException {
    checkNotNull(requestId);
    checkNotNull(minaSshdServiceId);
    checkNotNull(keyId);

    MinaSshdManagementBlockingStub blockingStub = newStub(requestId);
    UnregisterSshTunnelingKeyRequest.Builder requestBuilder = UnregisterSshTunnelingKeyRequest.newBuilder()
            .setMinaSshdServiceId(minaSshdServiceId)
            .setKeyId(keyId);

    try {
        LOGGER.debug("Calling unregisterSshTunnelingKey with requestId: {}, minaSshdServiceId: {}, keyId: {}",
                requestId, minaSshdServiceId, keyId);
        UnregisterSshTunnelingKeyResponse response = blockingStub.unregisterSshTunnelingKey(requestBuilder.build());
        if (response == null) {
            throw new CcmException("Got null response from MinaSshdManagementService unregisterSshTunnelingKey gRPC call", false);
        } else {
            return response;
        }
    } catch (StatusRuntimeException e) {
        String message = "MinaSshdManagementService unregisterSshTunnelingKey gRPC call failed: " + e.getMessage();
        Status status = e.getStatus();
        Status.Code code = status.getCode();
        boolean retryable = GrpcUtil.isRetryable(code);
        LOGGER.debug("Got status code: {}, retryable: {}", code, retryable);
        throw new CcmException(message, e, retryable);
    }
}
 
Example 7
Source File: MinaSshdManagementClient.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
/**
 * Wraps calls to listMinaSshdServices with an account ID.
 *
 * @param requestId  the request ID for the request
 * @param accountId  the account ID
 * @param serviceIds the minasshd services to list. if null or empty then all minasshd services will be listed
 * @return the list of minasshd services
 */
public List<MinaSshdService> listMinaSshdServices(String requestId, String accountId, List<String> serviceIds) throws CcmException {
    checkNotNull(requestId);
    checkNotNull(accountId);

    List<MinaSshdService> groups = new ArrayList<>();

    MinaSshdManagementBlockingStub minaSshdManagementBlockingStub = newStub(requestId);

    ListMinaSshdServicesRequest.Builder requestBuilder = ListMinaSshdServicesRequest.newBuilder()
            .setAccountId(accountId)
            .setPageSize(minaSshdManagementClientConfig.getListMinaSshdServicesPageSize());

    if (serviceIds != null && !serviceIds.isEmpty()) {
        requestBuilder.addAllId(serviceIds);
    }

    ListMinaSshdServicesResponse response;
    do {
        try {
            LOGGER.debug("Calling listMinaSshdServices with requestId: {}, accountId: {}, serviceIds: [{}]",
                    requestId, accountId, serviceIds);
            response = minaSshdManagementBlockingStub.listMinaSshdServices(requestBuilder.build());
            if (response == null) {
                throw new CcmException("Got null response from MinaSshdManagementService listMinaSshdServices gRPC call", false);
            } else {
                List<MinaSshdService> minaSshdServices = response.getMinaSshdServiceList();
                if (minaSshdServices == null) {
                    throw new CcmException("Got null minasshd services in MinaSshdManagementService listMinaSshdServices gRPC response", false);
                } else {
                    groups.addAll(minaSshdServices);
                }
            }
        } catch (StatusRuntimeException e) {
            String message = "MinaSshdManagementService listMinaSshdServices gRPC call failed: " + e.getMessage();
            Status status = e.getStatus();
            Status.Code code = status.getCode();
            boolean retryable = GrpcUtil.isRetryable(code);
            LOGGER.debug("Got status code: {}, retryable: {}", code, retryable);
            throw new CcmException(message, e, retryable);
        }
        requestBuilder.setPageToken(response.getNextPageToken());
    } while (response.hasNextPageToken());

    return groups;
}