Search in sources :

Example 86 with AmazonClientException

use of com.amazonaws.AmazonClientException in project alluxio by Alluxio.

the class S3ALowLevelOutputStream method completeMultiPartUpload.

/**
 * Completes multipart upload.
 */
protected void completeMultiPartUpload(AmazonS3 s3Client, String uploadId) throws IOException {
    AmazonClientException lastException;
    CompleteMultipartUploadRequest completeRequest = new CompleteMultipartUploadRequest(mBucketName, mKey, uploadId, mTags);
    do {
        try {
            s3Client.completeMultipartUpload(completeRequest);
            LOG.debug("Completed multipart upload for key {} and id '{}' with {} partitions.", mKey, uploadId, mTags.size());
            return;
        } catch (AmazonClientException e) {
            lastException = e;
        }
    } while (mRetryPolicy.attempt());
    // than the allowed retry count
    throw new IOException("Unable to complete multipart upload with id '" + uploadId + "' to " + mKey, lastException);
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) IOException(java.io.IOException) CompleteMultipartUploadRequest(com.amazonaws.services.s3.model.CompleteMultipartUploadRequest)

Example 87 with AmazonClientException

use of com.amazonaws.AmazonClientException in project alluxio by Alluxio.

the class S3ALowLevelOutputStream method execUpload.

/**
 * Executes the upload part request.
 *
 * @param request the upload part request
 */
protected void execUpload(AmazonS3 s3Client, UploadPartRequest request) {
    File file = request.getFile();
    ListenableFuture<PartETag> futureTag = mExecutor.submit((Callable) () -> {
        PartETag partETag;
        AmazonClientException lastException;
        try {
            do {
                try {
                    partETag = s3Client.uploadPart(request).getPartETag();
                    return partETag;
                } catch (AmazonClientException e) {
                    lastException = e;
                }
            } while (mRetryPolicy.attempt());
        } finally {
            // Delete the uploaded or failed to upload file
            if (!file.delete()) {
                LOG.error("Failed to delete temporary file @ {}", file.getPath());
            }
        }
        throw new IOException("Fail to upload part " + request.getPartNumber() + " to " + request.getKey(), lastException);
    });
    mTagFutures.add(futureTag);
    LOG.debug("Submit upload part request. key={}, partNum={}, file={}, fileSize={}, lastPart={}.", mKey, request.getPartNumber(), file.getPath(), file.length(), request.isLastPart());
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) IOException(java.io.IOException) File(java.io.File) PartETag(com.amazonaws.services.s3.model.PartETag)

Example 88 with AmazonClientException

use of com.amazonaws.AmazonClientException in project alluxio by Alluxio.

the class S3ALowLevelOutputStream method abortMultiPartUpload.

/**
 * Aborts multipart upload.
 */
protected void abortMultiPartUpload(AmazonS3 s3Client, String uploadId) {
    AmazonClientException lastException;
    do {
        try {
            s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(mBucketName, mKey, uploadId));
            LOG.warn("Aborted multipart upload for key {} and id '{}' to bucket {}", mKey, uploadId, mBucketName);
            return;
        } catch (AmazonClientException e) {
            lastException = e;
        }
    } while (mRetryPolicy.attempt());
    // This point is only reached if the operation failed more
    // than the allowed retry count
    LOG.warn("Unable to abort multipart upload for key '{}' and id '{}' to bucket {}. " + "You may need to enable the periodical cleanup by setting property {}" + "to be true.", mKey, uploadId, mBucketName, PropertyKey.UNDERFS_CLEANUP_ENABLED.getName(), lastException);
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) AbortMultipartUploadRequest(com.amazonaws.services.s3.model.AbortMultipartUploadRequest)

Example 89 with AmazonClientException

use of com.amazonaws.AmazonClientException in project alluxio by Alluxio.

the class S3ALowLevelOutputStream method initMultiPartUpload.

/**
 * Initializes multipart upload.
 */
private void initMultiPartUpload(AmazonS3 s3Client) throws IOException {
    // Generate the object metadata by setting server side encryption, md5 checksum,
    // and encoding as octet stream since no assumptions are made about the file type
    ObjectMetadata meta = new ObjectMetadata();
    if (mSseEnabled) {
        meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    }
    if (mHash != null) {
        meta.setContentMD5(Base64.encodeAsString(mHash.digest()));
    }
    meta.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
    AmazonClientException lastException;
    InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(mBucketName, mKey).withObjectMetadata(meta);
    do {
        try {
            mUploadId = s3Client.initiateMultipartUpload(initRequest).getUploadId();
            return;
        } catch (AmazonClientException e) {
            lastException = e;
        }
    } while (mRetryPolicy.attempt());
    // than the allowed retry count
    throw new IOException("Unable to init multipart upload to " + mKey, lastException);
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) InitiateMultipartUploadRequest(com.amazonaws.services.s3.model.InitiateMultipartUploadRequest) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 90 with AmazonClientException

use of com.amazonaws.AmazonClientException in project druid by druid-io.

the class AWSClientUtilTest method testNonRecoverableException_RuntimeException.

@Test
public void testNonRecoverableException_RuntimeException() {
    AmazonClientException ex = new AmazonClientException(new RuntimeException());
    Assert.assertFalse(AWSClientUtil.isClientExceptionRecoverable(ex));
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) Test(org.junit.Test)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)202 IOException (java.io.IOException)70 AmazonServiceException (com.amazonaws.AmazonServiceException)32 ArrayList (java.util.ArrayList)32 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)23 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)19 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)17 HashMap (java.util.HashMap)16 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)14 Test (org.junit.Test)14 SienaException (siena.SienaException)12 AWSCredentials (com.amazonaws.auth.AWSCredentials)11 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)11 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)11 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)11 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)10 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)10 InterruptedIOException (java.io.InterruptedIOException)10 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)9 File (java.io.File)9