Search in sources :

Example 1 with RetryPolicyContext

use of com.amazonaws.retry.v2.RetryPolicyContext in project aws-msk-iam-auth by aws.

the class MSKCredentialProvider method loadCredentialsWithRetry.

private AWSCredentials loadCredentialsWithRetry() {
    RetryPolicyContext retryPolicyContext = RetryPolicyContext.builder().build();
    boolean shouldTry = true;
    try {
        while (shouldTry) {
            try {
                AWSCredentials credentials = compositeDelegate.getCredentials();
                if (credentials == null) {
                    throw new SdkClientException("Composite delegate returned empty credentials.");
                }
                return credentials;
            } catch (SdkBaseException se) {
                log.warn("Exception loading credentials. Retry Attempts: {}", retryPolicyContext.retriesAttempted(), se);
                retryPolicyContext = createRetryPolicyContext(se, retryPolicyContext.retriesAttempted());
                shouldTry = retryPolicy.shouldRetry(retryPolicyContext);
                if (shouldTry) {
                    Thread.sleep(retryPolicy.computeDelayBeforeNextRetry(retryPolicyContext));
                    retryPolicyContext = createRetryPolicyContext(retryPolicyContext.exception(), retryPolicyContext.retriesAttempted() + 1);
                } else {
                    throw se;
                }
            }
        }
        throw new SdkClientException("loadCredentialsWithRetry in unexpected location " + retryPolicyContext.totalRequests(), retryPolicyContext.exception());
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        throw new RuntimeException("Interrupted while waiting for credentials.", ie);
    }
}
Also used : SdkClientException(com.amazonaws.SdkClientException) SdkBaseException(com.amazonaws.SdkBaseException) RetryPolicyContext(com.amazonaws.retry.v2.RetryPolicyContext) AWSCredentials(com.amazonaws.auth.AWSCredentials)

Aggregations

SdkBaseException (com.amazonaws.SdkBaseException)1 SdkClientException (com.amazonaws.SdkClientException)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 RetryPolicyContext (com.amazonaws.retry.v2.RetryPolicyContext)1