Search in sources :

Example 1 with CcmException

use of com.sequenceiq.cloudbreak.ccm.exception.CcmException in project cloudbreak by hortonworks.

the class MinaSshdManagementClient method listMinaSshdServices.

/**
 * 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, "requestId should not be null.");
    checkNotNull(accountId, "accountId should not be null.");
    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;
}
Also used : ListMinaSshdServicesResponse(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.ListMinaSshdServicesResponse) Status(io.grpc.Status) CcmException(com.sequenceiq.cloudbreak.ccm.exception.CcmException) ArrayList(java.util.ArrayList) ListMinaSshdServicesRequest(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.ListMinaSshdServicesRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) MinaSshdManagementBlockingStub(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementGrpc.MinaSshdManagementBlockingStub) MinaSshdService(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.MinaSshdService)

Example 2 with CcmException

use of com.sequenceiq.cloudbreak.ccm.exception.CcmException in project cloudbreak by hortonworks.

the class RetryUtil method buildRetryer.

/**
 * Builds a retryer.
 *
 * @param actionDescription a description of the action being performed
 * @param waitUntilTime     the latest time to wait to perform the action
 * @param sleepTimeMs       the sleep time in millisecond for retries
 * @param exceptionClass    the class of exception to throw
 * @param logger            the logger
 * @param <T>               the type of object returned
 * @return the retryer
 */
private static <T> Retryer<T> buildRetryer(String actionDescription, ZonedDateTime waitUntilTime, long sleepTimeMs, Class<? extends CcmException> exceptionClass, Logger logger) {
    StopStrategy stop;
    if (waitUntilTime != null) {
        // Given the time at which waiting should stop,
        // get the available number of millis from this instant
        stop = StopStrategyFactory.waitUntilDateTime(waitUntilTime);
        logger.info("Trying until {} to {}", waitUntilTime, actionDescription);
    } else {
        stop = StopStrategies.neverStop();
        logger.warn("Unbounded wait to {}", actionDescription);
    }
    WaitStrategy wait = WaitStrategies.fixedWait(sleepTimeMs, TimeUnit.MILLISECONDS);
    logger.info("Checking every {} milliseconds", sleepTimeMs);
    return RetryerBuilder.<T>newBuilder().retryIfException(t -> exceptionClass.isInstance(t) && ((CcmException) t).isRetryable()).retryIfResult(Objects::isNull).withStopStrategy(stop).withWaitStrategy(wait).build();
}
Also used : CcmException(com.sequenceiq.cloudbreak.ccm.exception.CcmException) StopStrategy(com.github.rholder.retry.StopStrategy) WaitStrategy(com.github.rholder.retry.WaitStrategy)

Example 3 with CcmException

use of com.sequenceiq.cloudbreak.ccm.exception.CcmException in project cloudbreak by hortonworks.

the class GrpcMinaSshdManagementClient method generateAndRegisterSshTunnelingKeyPair.

/**
 * Wraps call to generateAndRegisterSshTunnelingKeyPair, with retries to tolerate transient failures.
 *
 * @param requestId         the request ID for the request
 * @param actorCrn          the actor CRN
 * @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
 * @throws InterruptedException if the action is interrupted
 */
public MinaSshdManagementProto.GenerateAndRegisterSshTunnelingKeyPairResponse generateAndRegisterSshTunnelingKeyPair(String requestId, String actorCrn, String accountId, String minaSshdServiceId, String keyId) throws CcmException, InterruptedException {
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        MinaSshdManagementClient client = makeClient(channelWrapper.getChannel(), actorCrn);
        ZonedDateTime waitUntilTime = ZonedDateTime.now(clock).plus(minaSshdManagementClientConfig.getTimeoutMs(), ChronoUnit.MILLIS);
        int pollingIntervalMillis = minaSshdManagementClientConfig.getPollingIntervalMs();
        String actionDescription = "generate tunneling key pair for accountId " + accountId;
        Supplier<CcmException> timeoutExceptionSupplier = () -> new CcmException(String.format("Timed out while trying to %s", actionDescription), true);
        return RetryUtil.performWithRetries(() -> client.generateAndRegisterSshTunnelingKeyPair(requestId, accountId, minaSshdServiceId, keyId), actionDescription, waitUntilTime, pollingIntervalMillis, CcmException.class, timeoutExceptionSupplier, LOGGER);
    }
}
Also used : CcmException(com.sequenceiq.cloudbreak.ccm.exception.CcmException) ZonedDateTime(java.time.ZonedDateTime) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)

Example 4 with CcmException

use of com.sequenceiq.cloudbreak.ccm.exception.CcmException in project cloudbreak by hortonworks.

the class GrpcMinaSshdManagementClient method unregisterSshTunnelingKey.

/**
 * Wraps call to unregisterSshTunnelingKey, with retries to tolerate transient failures.
 *
 * @param requestId the request ID for the request
 * @param actorCrn  the actor CRN
 * @param accountId the account ID
 * @param keyId     the key ID
 * @param minaSshdServiceId minaSshdServiceId
 * @return the response
 * @throws CcmException         if an exception occurs
 * @throws InterruptedException if the action is interrupted
 */
public MinaSshdManagementProto.UnregisterSshTunnelingKeyResponse unregisterSshTunnelingKey(String requestId, String actorCrn, String accountId, String keyId, String minaSshdServiceId) throws CcmException, InterruptedException {
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        MinaSshdManagementClient client = makeClient(channelWrapper.getChannel(), actorCrn);
        ZonedDateTime waitUntilTime = ZonedDateTime.now(clock).plus(minaSshdManagementClientConfig.getTimeoutMs(), ChronoUnit.MILLIS);
        int pollingIntervalMillis = minaSshdManagementClientConfig.getPollingIntervalMs();
        String actionDescription = "deregister tunneling key " + keyId;
        Supplier<CcmException> timeoutExceptionSupplier = () -> new CcmException(String.format("Timed out while trying to %s", actionDescription), true);
        return RetryUtil.performWithRetries(() -> client.unregisterSshTunnelingKey(requestId, minaSshdServiceId, keyId), actionDescription, waitUntilTime, pollingIntervalMillis, CcmException.class, timeoutExceptionSupplier, LOGGER);
    }
}
Also used : CcmException(com.sequenceiq.cloudbreak.ccm.exception.CcmException) ZonedDateTime(java.time.ZonedDateTime) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)

Example 5 with CcmException

use of com.sequenceiq.cloudbreak.ccm.exception.CcmException in project cloudbreak by hortonworks.

the class MinaSshdManagementClient method generateAndRegisterSshTunnelingKeyPair.

/**
 * 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, "requestId should not be null.");
    checkNotNull(accountId, "accountId should not be null.");
    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);
    }
}
Also used : Status(io.grpc.Status) CcmException(com.sequenceiq.cloudbreak.ccm.exception.CcmException) GenerateAndRegisterSshTunnelingKeyPairRequest(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.GenerateAndRegisterSshTunnelingKeyPairRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) MinaSshdManagementBlockingStub(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementGrpc.MinaSshdManagementBlockingStub) GenerateAndRegisterSshTunnelingKeyPairResponse(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.GenerateAndRegisterSshTunnelingKeyPairResponse)

Aggregations

CcmException (com.sequenceiq.cloudbreak.ccm.exception.CcmException)8 MinaSshdManagementBlockingStub (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementGrpc.MinaSshdManagementBlockingStub)4 Status (io.grpc.Status)4 StatusRuntimeException (io.grpc.StatusRuntimeException)4 MinaSshdService (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.MinaSshdService)3 ManagedChannelWrapper (com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)3 ZonedDateTime (java.time.ZonedDateTime)3 AcquireMinaSshdServiceRequest (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.AcquireMinaSshdServiceRequest)1 AcquireMinaSshdServiceResponse (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.AcquireMinaSshdServiceResponse)1 GenerateAndRegisterSshTunnelingKeyPairRequest (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.GenerateAndRegisterSshTunnelingKeyPairRequest)1 GenerateAndRegisterSshTunnelingKeyPairResponse (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.GenerateAndRegisterSshTunnelingKeyPairResponse)1 ListMinaSshdServicesRequest (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.ListMinaSshdServicesRequest)1 ListMinaSshdServicesResponse (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.ListMinaSshdServicesResponse)1 UnregisterSshTunnelingKeyRequest (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.UnregisterSshTunnelingKeyRequest)1 UnregisterSshTunnelingKeyResponse (com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.UnregisterSshTunnelingKeyResponse)1 StopStrategy (com.github.rholder.retry.StopStrategy)1 WaitStrategy (com.github.rholder.retry.WaitStrategy)1 ArrayList (java.util.ArrayList)1