Search in sources :

Example 6 with CcmException

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

the class MinaSshdManagementClient method acquireMinaSshdService.

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

Example 7 with CcmException

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

the class MinaSshdManagementClient method unregisterSshTunnelingKey.

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

Example 8 with CcmException

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

the class GrpcMinaSshdManagementClient method acquireMinaSshdServiceAndWaitUntilReady.

/**
 * Attempts to acquire a minasshd service for the specified account. If it is not available immediately,
 * polls until it is acquires a ready service, is interrupted, times out, or there are no pending minasshd service instances.
 *
 * @param requestId the request ID for the request
 * @param actorCrn  the actor CRN
 * @param accountId the account ID
 * @return the minasshd service
 * @throws InterruptedException if the thread is interrupted
 * @throws CcmException         if the initial acquisition fails, if the timeout is reached, or if all minasshd service instances are in a FAILED state
 */
public MinaSshdService acquireMinaSshdServiceAndWaitUntilReady(String requestId, String actorCrn, String accountId) throws InterruptedException, CcmException {
    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 = "acquire MinaSSHD service for accountId " + accountId;
        Supplier<CcmException> timeoutExceptionSupplier = () -> new CcmException(String.format("Timed out while trying to %s", actionDescription), true);
        // First call acquireMinaSshdService, with retries in case of transient failures.
        MinaSshdService initialService = RetryUtil.performWithRetries(() -> client.acquireMinaSshdService(requestId, accountId), actionDescription, waitUntilTime, pollingIntervalMillis, CcmException.class, timeoutExceptionSupplier, LOGGER);
        // If the minasshd service was pre-existing, it is in the initial call result
        return getValidMinaSshdService(actionDescription, initialService).orElse(awaitValidMinaSshdService(() -> client.listMinaSshdServices(requestId, accountId, Collections.singletonList(initialService.getMinaSshdServiceId())), actionDescription, waitUntilTime, pollingIntervalMillis, timeoutExceptionSupplier).orElseThrow(() -> new CcmException(String.format("Failed while trying to %s", actionDescription), false)));
    }
}
Also used : CcmException(com.sequenceiq.cloudbreak.ccm.exception.CcmException) ZonedDateTime(java.time.ZonedDateTime) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper) MinaSshdService(com.cloudera.thunderhead.service.minasshdmanagement.MinaSshdManagementProto.MinaSshdService)

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