Search in sources :

Example 21 with AmazonServiceException

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

the class S3Backend method exists.

/**
     * Check if record identified by identifier exists in Amazon S3.
     */
@Override
public boolean exists(DataIdentifier identifier) throws DataStoreException {
    long start = System.currentTimeMillis();
    String key = getKeyName(identifier);
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        ObjectMetadata objectMetaData = s3service.getObjectMetadata(bucket, key);
        if (objectMetaData != null) {
            LOG.trace("exists [{}]: [true] took [{}] ms.", identifier, (System.currentTimeMillis() - start));
            return true;
        }
        return false;
    } catch (AmazonServiceException e) {
        if (e.getStatusCode() == 404 || e.getStatusCode() == 403) {
            LOG.debug("exists [{}]: [false] took [{}] ms.", identifier, (System.currentTimeMillis() - start));
            return false;
        }
        throw new DataStoreException("Error occured to getObjectMetadata for key [" + identifier.toString() + "]", 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)

Example 22 with AmazonServiceException

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

the class S3Backend method getRecord.

@Override
public DataRecord getRecord(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);
        S3DataRecord record = new S3DataRecord(this, s3service, bucket, identifier, object.getLastModified().getTime(), object.getContentLength());
        LOG.debug("Identifier [{}]'s getRecord = [{}] took [{}]ms.", identifier, record, (System.currentTimeMillis() - start));
        return record;
    } catch (AmazonServiceException e) {
        if (e.getStatusCode() == 404 || e.getStatusCode() == 403) {
            LOG.info("getRecord: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)

Example 23 with AmazonServiceException

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

the class S3Backend method read.

@Override
public InputStream read(DataIdentifier identifier) throws DataStoreException {
    long start = System.currentTimeMillis();
    String key = getKeyName(identifier);
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        S3Object object = s3service.getObject(bucket, key);
        InputStream in = object.getObjectContent();
        LOG.debug("[{}] read took [{}]ms", identifier, (System.currentTimeMillis() - start));
        return in;
    } catch (AmazonServiceException e) {
        throw new DataStoreException("Object not found: " + key, e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) InputStream(java.io.InputStream) AmazonServiceException(com.amazonaws.AmazonServiceException) S3Object(com.amazonaws.services.s3.model.S3Object)

Example 24 with AmazonServiceException

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

the class S3Backend method deleteRecord.

@Override
public void deleteRecord(DataIdentifier identifier) throws DataStoreException {
    long start = System.currentTimeMillis();
    String key = getKeyName(identifier);
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        s3service.deleteObject(bucket, key);
        LOG.debug("Identifier [{}] deleted. It took [{}]ms.", new Object[] { identifier, (System.currentTimeMillis() - start) });
    } catch (AmazonServiceException e) {
        throw new DataStoreException("Could not getLastModified of dataIdentifier " + identifier, e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 25 with AmazonServiceException

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

the class DynamoDBStore method waitForTableToBeDeleted.

/**
   * Waits up to 6 minutes to confirm if a table has been deleted or not
   * 
   * @param pTableName
   */
private void waitForTableToBeDeleted(String pTableName) {
    LOG.debug("Waiting for " + pTableName + " to be deleted.");
    long startTime = System.currentTimeMillis();
    long endTime = startTime + WAIT_TIME;
    while (System.currentTimeMillis() < endTime) {
        try {
            Thread.sleep(SLEEP_DELETE_TIME);
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(pTableName);
            TableDescription tableDescription = getDynamoDBClient().describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            LOG.debug(pTableName + " - current state: " + tableStatus);
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == true)
                return;
            LOG.error(ase.getMessage());
        }
    }
    LOG.debug(pTableName + " deleted.");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) GoraException(org.apache.gora.util.GoraException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

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