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