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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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.");
}
Aggregations