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