Search in sources :

Example 1 with RetriableException

use of com.instaclustr.esop.impl.retry.Retrier.RetriableException in project esop by instaclustr.

the class BaseS3Restorer method downloadFile.

@Override
public void downloadFile(final Path localPath, final RemoteObjectReference objectReference) throws Exception {
    RetrierFactory.getRetrier(request.retry).submit(() -> {
        try {
            Files.createDirectories(localPath.getParent());
            final GetObjectRequest getObjectRequest = new GetObjectRequest(request.storageLocation.bucket, objectReference.canonicalPath);
            try {
                transferManager.download(getObjectRequest, localPath.toFile(), new DownloadProgressListener(objectReference)).waitForCompletion();
            } catch (final Exception ex) {
                Files.deleteIfExists(localPath);
                throw ex;
            }
        } catch (final AmazonServiceException ex) {
            if (ex.getStatusCode() > 500) {
                throw new RetriableException(ex.getMessage(), ex);
            }
            if (ex.getStatusCode() == 404) {
                logger.error("Remote object reference {} does not exist.", objectReference);
            }
            throw ex;
        } catch (final AmazonClientException ex) {
            throw new RetriableException(format("Error in S3 client while downloading %s", objectReference.objectKey), ex);
        } catch (final IOException | InterruptedException ex) {
            throw new RuntimeException(ex);
        }
    });
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) RetriableException(com.instaclustr.esop.impl.retry.Retrier.RetriableException) IOException(java.io.IOException) AmazonClientException(com.amazonaws.AmazonClientException) RetriableException(com.instaclustr.esop.impl.retry.Retrier.RetriableException)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1 RetriableException (com.instaclustr.esop.impl.retry.Retrier.RetriableException)1 IOException (java.io.IOException)1