Search in sources :

Example 1 with IamInternalServerErrorException

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;
        }
    }
}
Also used : IamInternalServerErrorException(bio.terra.service.iam.exception.IamInternalServerErrorException) ApiException(org.broadinstitute.dsde.workbench.client.sam.ApiException) IamInternalServerErrorException(bio.terra.service.iam.exception.IamInternalServerErrorException) ApiException(org.broadinstitute.dsde.workbench.client.sam.ApiException)

Aggregations

IamInternalServerErrorException (bio.terra.service.iam.exception.IamInternalServerErrorException)1 ApiException (org.broadinstitute.dsde.workbench.client.sam.ApiException)1