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);
}
}
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);
}
}
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)));
}
}
Aggregations