Search in sources :

Example 6 with AmazonS3Exception

use of com.amazonaws.services.s3.model.AmazonS3Exception in project elasticsearch by elastic.

the class DefaultS3OutputStream method doUploadMultipart.

protected PartETag doUploadMultipart(S3BlobStore blobStore, String bucketName, String blobName, String uploadId, InputStream is, int length, boolean lastPart) throws AmazonS3Exception {
    UploadPartRequest request = new UploadPartRequest().withBucketName(bucketName).withKey(blobName).withUploadId(uploadId).withPartNumber(multipartChunks).withInputStream(is).withPartSize(length).withLastPart(lastPart);
    UploadPartResult response = blobStore.client().uploadPart(request);
    return response.getPartETag();
}
Also used : UploadPartResult(com.amazonaws.services.s3.model.UploadPartResult) UploadPartRequest(com.amazonaws.services.s3.model.UploadPartRequest)

Example 7 with AmazonS3Exception

use of com.amazonaws.services.s3.model.AmazonS3Exception in project elasticsearch by elastic.

the class S3BlobContainer method move.

@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
    try {
        CopyObjectRequest request = new CopyObjectRequest(blobStore.bucket(), buildKey(sourceBlobName), blobStore.bucket(), buildKey(targetBlobName));
        if (blobStore.serverSideEncryption()) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setNewObjectMetadata(objectMetadata);
        }
        SocketAccess.doPrivilegedVoid(() -> {
            blobStore.client().copyObject(request);
            blobStore.client().deleteObject(blobStore.bucket(), buildKey(sourceBlobName));
        });
    } catch (AmazonS3Exception e) {
        throw new IOException(e);
    }
}
Also used : CopyObjectRequest(com.amazonaws.services.s3.model.CopyObjectRequest) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 8 with AmazonS3Exception

use of com.amazonaws.services.s3.model.AmazonS3Exception in project hadoop by apache.

the class S3AUtils method translateException.

/**
   * Translate an exception raised in an operation into an IOException.
   * The specific type of IOException depends on the class of
   * {@link AmazonClientException} passed in, and any status codes included
   * in the operation. That is: HTTP error codes are examined and can be
   * used to build a more specific response.
   * @param operation operation
   * @param path path operated on (may be null)
   * @param exception amazon exception raised
   * @return an IOE which wraps the caught exception.
   */
@SuppressWarnings("ThrowableInstanceNeverThrown")
public static IOException translateException(String operation, String path, AmazonClientException exception) {
    String message = String.format("%s%s: %s", operation, path != null ? (" on " + path) : "", exception);
    if (!(exception instanceof AmazonServiceException)) {
        if (containsInterruptedException(exception)) {
            return (IOException) new InterruptedIOException(message).initCause(exception);
        }
        return new AWSClientIOException(message, exception);
    } else {
        IOException ioe;
        AmazonServiceException ase = (AmazonServiceException) exception;
        // this exception is non-null if the service exception is an s3 one
        AmazonS3Exception s3Exception = ase instanceof AmazonS3Exception ? (AmazonS3Exception) ase : null;
        int status = ase.getStatusCode();
        switch(status) {
            case 301:
                if (s3Exception != null) {
                    if (s3Exception.getAdditionalDetails() != null && s3Exception.getAdditionalDetails().containsKey(ENDPOINT_KEY)) {
                        message = String.format("Received permanent redirect response to " + "endpoint %s.  This likely indicates that the S3 endpoint " + "configured in %s does not match the AWS region containing " + "the bucket.", s3Exception.getAdditionalDetails().get(ENDPOINT_KEY), ENDPOINT);
                    }
                    ioe = new AWSS3IOException(message, s3Exception);
                } else {
                    ioe = new AWSServiceIOException(message, ase);
                }
                break;
            // permissions
            case 401:
            case 403:
                ioe = new AccessDeniedException(path, null, message);
                ioe.initCause(ase);
                break;
            // the object isn't there
            case 404:
            case 410:
                ioe = new FileNotFoundException(message);
                ioe.initCause(ase);
                break;
            // a shorter one while it is being read.
            case 416:
                ioe = new EOFException(message);
                break;
            default:
                // no specific exit code. Choose an IOE subclass based on the class
                // of the caught exception
                ioe = s3Exception != null ? new AWSS3IOException(message, s3Exception) : new AWSServiceIOException(message, ase);
                break;
        }
        return ioe;
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) AccessDeniedException(java.nio.file.AccessDeniedException) AmazonServiceException(com.amazonaws.AmazonServiceException) FileNotFoundException(java.io.FileNotFoundException) EOFException(java.io.EOFException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception)

Example 9 with AmazonS3Exception

use of com.amazonaws.services.s3.model.AmazonS3Exception in project hadoop by apache.

the class TestS3AExceptionTranslation method createS3Exception.

private static AmazonS3Exception createS3Exception(String message, int code, Map<String, String> additionalDetails) {
    AmazonS3Exception source = new AmazonS3Exception(message);
    source.setStatusCode(code);
    source.setAdditionalDetails(additionalDetails);
    return source;
}
Also used : AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception)

Example 10 with AmazonS3Exception

use of com.amazonaws.services.s3.model.AmazonS3Exception in project presto by prestodb.

the class MockAmazonS3 method getObjectMetadata.

@Override
public ObjectMetadata getObjectMetadata(String bucketName, String key) throws AmazonClientException {
    if (getObjectMetadataHttpCode != SC_OK) {
        AmazonS3Exception exception = new AmazonS3Exception("Failing getObjectMetadata call with " + getObjectMetadataHttpCode);
        exception.setStatusCode(getObjectMetadataHttpCode);
        throw exception;
    }
    return null;
}
Also used : AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception)

Aggregations

AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)62 IOException (java.io.IOException)23 Test (org.junit.Test)13 FileNotFoundException (java.io.FileNotFoundException)10 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)9 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)9 AmazonServiceException (com.amazonaws.AmazonServiceException)8 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)7 GetObjectMetadataRequest (com.amazonaws.services.s3.model.GetObjectMetadataRequest)6 S3Object (com.amazonaws.services.s3.model.S3Object)6 S3TestUtils.buildMockedS3FileSystem (org.apache.beam.sdk.io.aws.s3.S3TestUtils.buildMockedS3FileSystem)6 AmazonClientException (com.amazonaws.AmazonClientException)5 InterruptedIOException (java.io.InterruptedIOException)5 ArrayList (java.util.ArrayList)5 Path (org.apache.hadoop.fs.Path)5 ClientConfiguration (com.amazonaws.ClientConfiguration)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)4 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)4 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)4 URI (java.net.URI)4