Search in sources :

Example 36 with AmazonS3Exception

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

the class DefaultS3OutputStream method doCompleteMultipart.

protected void doCompleteMultipart(S3BlobStore blobStore, String bucketName, String blobName, String uploadId, List<PartETag> parts) throws AmazonS3Exception {
    CompleteMultipartUploadRequest request = new CompleteMultipartUploadRequest(bucketName, blobName, uploadId, parts);
    blobStore.client().completeMultipartUpload(request);
}
Also used : CompleteMultipartUploadRequest(com.amazonaws.services.s3.model.CompleteMultipartUploadRequest)

Example 37 with AmazonS3Exception

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

the class TestAmazonS3 method getObject.

@Override
public S3Object getObject(String bucketName, String key) throws AmazonClientException, AmazonServiceException {
    if (shouldFail(bucketName, key, readFailureRate)) {
        logger.info("--> random read failure on getObject method: throwing an exception for [bucket={}, key={}]", bucketName, key);
        AmazonS3Exception ex = new AmazonS3Exception("Random S3 read exception");
        ex.setStatusCode(404);
        throw ex;
    } else {
        return super.getObject(bucketName, key);
    }
}
Also used : AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception)

Example 38 with AmazonS3Exception

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

the class MockAmazonS3 method getObject.

@Override
public S3Object getObject(GetObjectRequest getObjectRequest) throws AmazonClientException {
    if (getObjectHttpCode != SC_OK) {
        AmazonS3Exception exception = new AmazonS3Exception("Failing getObject call with " + getObjectHttpCode);
        exception.setStatusCode(getObjectHttpCode);
        throw exception;
    }
    return null;
}
Also used : AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception)

Example 39 with AmazonS3Exception

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

the class TestPrestoS3FileSystem method testReadRetryCounters.

@SuppressWarnings({ "ResultOfMethodCallIgnored", "OverlyStrongTypeCast", "ConstantConditions" })
@Test
public void testReadRetryCounters() throws Exception {
    try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) {
        int maxRetries = 2;
        MockAmazonS3 s3 = new MockAmazonS3();
        s3.setGetObjectHttpErrorCode(SC_INTERNAL_SERVER_ERROR);
        Configuration configuration = new Configuration();
        configuration.set(S3_MAX_BACKOFF_TIME, "1ms");
        configuration.set(S3_MAX_RETRY_TIME, "5s");
        configuration.setInt(S3_MAX_CLIENT_RETRIES, maxRetries);
        fs.initialize(new URI("s3n://test-bucket/"), configuration);
        fs.setS3Client(s3);
        try (FSDataInputStream inputStream = fs.open(new Path("s3n://test-bucket/test"))) {
            inputStream.read();
        } catch (Throwable expected) {
            assertInstanceOf(expected, AmazonS3Exception.class);
            assertEquals(((AmazonS3Exception) expected).getStatusCode(), SC_INTERNAL_SERVER_ERROR);
            assertEquals(PrestoS3FileSystem.getFileSystemStats().getReadRetries().getTotalCount(), maxRetries);
            assertEquals(PrestoS3FileSystem.getFileSystemStats().getGetObjectRetries().getTotalCount(), (maxRetries + 1L) * maxRetries);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) ClientConfiguration(com.amazonaws.ClientConfiguration) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 40 with AmazonS3Exception

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

the class TestS3AExceptionTranslation method test301ContainsEndpoint.

@Test
public void test301ContainsEndpoint() throws Exception {
    AmazonS3Exception s3Exception = createS3Exception("wrong endpoint", 301, Collections.singletonMap(S3AUtils.ENDPOINT_KEY, "bucket.s3-us-west-2.amazonaws.com"));
    AWSS3IOException ex = (AWSS3IOException) verifyTranslated(AWSS3IOException.class, s3Exception);
    assertEquals(301, ex.getStatusCode());
    assertNotNull(ex.getMessage());
    assertTrue(ex.getMessage().contains("bucket.s3-us-west-2.amazonaws.com"));
    assertTrue(ex.getMessage().contains(ENDPOINT));
}
Also used : AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) Test(org.junit.Test)

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