Search in sources :

Example 11 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project camel by apache.

the class AmazonS3ClientMock method putObject.

@SuppressWarnings("resource")
@Override
public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws AmazonClientException, AmazonServiceException {
    putObjectRequests.add(putObjectRequest);
    S3Object s3Object = new S3Object();
    s3Object.setBucketName(putObjectRequest.getBucketName());
    s3Object.setKey(putObjectRequest.getKey());
    if (putObjectRequest.getFile() != null) {
        try {
            s3Object.setObjectContent(new FileInputStream(putObjectRequest.getFile()));
        } catch (FileNotFoundException e) {
            throw new AmazonServiceException("Cannot store the file object.", e);
        }
    } else {
        s3Object.setObjectContent(putObjectRequest.getInputStream());
    }
    objects.add(s3Object);
    PutObjectResult putObjectResult = new PutObjectResult();
    putObjectResult.setETag("3a5c8b1ad448bca04584ecb55b836264");
    return putObjectResult;
}
Also used : PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) FileNotFoundException(java.io.FileNotFoundException) AmazonServiceException(com.amazonaws.AmazonServiceException) S3Object(com.amazonaws.services.s3.model.S3Object) FileInputStream(java.io.FileInputStream)

Example 12 with AmazonServiceException

use of com.amazonaws.AmazonServiceException 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 13 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project hadoop by apache.

the class TestS3AExceptionTranslation method testGenericServiceS3Exception.

@Test
public void testGenericServiceS3Exception() throws Exception {
    // service exception of no known type
    AmazonServiceException ase = new AmazonServiceException("unwind");
    ase.setStatusCode(500);
    AWSServiceIOException ex = (AWSServiceIOException) verifyTranslated(AWSServiceIOException.class, ase);
    assertEquals(500, ex.getStatusCode());
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) Test(org.junit.Test)

Example 14 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project SimianArmy by Netflix.

the class AWSClient method terminateInstance.

/** {@inheritDoc} */
@Override
public void terminateInstance(String instanceId) {
    Validate.notEmpty(instanceId);
    LOGGER.info(String.format("Terminating instance %s in region %s.", instanceId, region));
    try {
        ec2Client().terminateInstances(new TerminateInstancesRequest(Arrays.asList(instanceId)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidInstanceID.NotFound")) {
            throw new NotFoundException("AWS instance " + instanceId + " not found", e);
        }
        throw e;
    }
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) NotFoundException(com.netflix.simianarmy.NotFoundException)

Example 15 with AmazonServiceException

use of com.amazonaws.AmazonServiceException in project jackrabbit-oak by apache.

the class S3Backend method getLastModified.

@Override
public long getLastModified(DataIdentifier identifier) throws DataStoreException {
    long start = System.currentTimeMillis();
    String key = getKeyName(identifier);
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        ObjectMetadata object = s3service.getObjectMetadata(bucket, key);
        long lastModified = object.getLastModified().getTime();
        LOG.debug("Identifier [{}]'s lastModified = [{}] took [{}]ms.", new Object[] { identifier, lastModified, (System.currentTimeMillis() - start) });
        return lastModified;
    } catch (AmazonServiceException e) {
        if (e.getStatusCode() == 404 || e.getStatusCode() == 403) {
            LOG.info("getLastModified:Identifier [{}] not found. Took [{}] ms.", identifier, (System.currentTimeMillis() - start));
        }
        throw new DataStoreException(e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) AmazonServiceException(com.amazonaws.AmazonServiceException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)109 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)21 AmazonS3 (com.amazonaws.services.s3.AmazonS3)15 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)15 AmazonClientException (com.amazonaws.AmazonClientException)13 IOException (java.io.IOException)12 Collection (java.util.Collection)12 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)11 File (java.io.File)10 Message (org.apache.camel.Message)10 ArrayList (java.util.ArrayList)8 S3Object (com.amazonaws.services.s3.model.S3Object)7 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)7 FileNotFoundException (java.io.FileNotFoundException)7 Copy (com.amazonaws.services.s3.transfer.Copy)6 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)5 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)5 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)5 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)4