use of bio.terra.service.iam.exception.IamInternalServerErrorException in project jade-data-repo by DataBiosphere.
the class SamRetry method perform.
<T> T perform(SamFunction<T> function) throws InterruptedException {
while (true) {
try {
// Simulate a socket timeout for testing
configService.fault(ConfigEnum.SAM_TIMEOUT_FAULT, () -> {
throw new ApiException("fault insertion", HttpStatusCodes.STATUS_CODE_SERVER_ERROR, null, null);
});
return function.apply();
} catch (ApiException ex) {
RuntimeException rex = SamIam.convertSAMExToDataRepoEx((ApiException) ex);
if (!(rex instanceof IamInternalServerErrorException)) {
throw rex;
}
logger.info("SamRetry: caught retry-able exception: " + ex);
// sleep, then we give up and re-throw.
if (operationTimeout.minusSeconds(retrySeconds).isBefore(now())) {
logger.error("SamRetry: operation timed out after " + operationTimeout.toString());
throw rex;
}
} catch (Exception ex) {
throw new IamInternalServerErrorException("Unexpected exception type: " + ex.toString(), ex);
}
// Retry
logger.info("SamRetry: sleeping " + retrySeconds + " seconds");
TimeUnit.SECONDS.sleep(retrySeconds);
retrySeconds = retrySeconds + retrySeconds;
if (retrySeconds > retryMaxWait) {
retrySeconds = retryMaxWait;
}
}
}
Aggregations