use of com.amazonaws.AmazonClientException in project xm-ms-entity by xm-online.
the class AmazonS3Template method save.
/**
* Save a file using authenticated session credentials.
*
* @param key is the name of the file to save in the bucket
* @param inputStream is the file that will be saved
*/
public void save(String key, InputStream inputStream) throws IOException {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType(URLConnection.guessContentTypeFromStream(inputStream));
PutObjectRequest request = new PutObjectRequest(bucket, key, inputStream, metadata);
request.setCannedAcl(CannedAccessControlList.PublicRead);
request.getRequestClientOptions().setReadLimit(Integer.MAX_VALUE);
Upload upload = getTransferManager().upload(request);
try {
upload.waitForUploadResult();
} catch (AmazonClientException ex) {
throw new IOException(ex);
} catch (InterruptedException ex) {
// reset interrupted status
Thread.currentThread().interrupt();
// continue interrupt
throw new IllegalStateException(ex);
}
}
use of com.amazonaws.AmazonClientException in project alluxio by Alluxio.
the class S3AUnderFileSystem method copyObject.
@Override
protected boolean copyObject(String src, String dst) {
LOG.debug("Copying {} to {}", src, dst);
// Retry copy for a few times, in case some AWS internal errors happened during copy.
int retries = 3;
for (int i = 0; i < retries; i++) {
try {
CopyObjectRequest request = new CopyObjectRequest(mBucketName, src, mBucketName, dst);
if (mUfsConf.getBoolean(PropertyKey.UNDERFS_S3_SERVER_SIDE_ENCRYPTION_ENABLED)) {
ObjectMetadata meta = new ObjectMetadata();
meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
request.setNewObjectMetadata(meta);
}
mManager.copy(request).waitForCopyResult();
return true;
} catch (AmazonClientException | InterruptedException e) {
LOG.error("Failed to copy file {} to {}", src, dst, e);
if (i != retries - 1) {
LOG.error("Retrying copying file {} to {}", src, dst);
}
}
}
LOG.error("Failed to copy file {} to {}, after {} retries", src, dst, retries);
return false;
}
use of com.amazonaws.AmazonClientException in project alluxio by Alluxio.
the class S3AUnderFileSystem method getObjectListingChunkV1.
// Get next chunk of listing result.
private ObjectListing getObjectListingChunkV1(ListObjectsRequest request) throws IOException {
ObjectListing result;
try {
// Query S3 for the next batch of objects.
result = mClient.listObjects(request);
// Advance the request continuation token to the next set of objects.
request.setMarker(result.getNextMarker());
} catch (AmazonClientException e) {
throw new IOException(e);
}
return result;
}
use of com.amazonaws.AmazonClientException in project alluxio by Alluxio.
the class S3AUnderFileSystem method deleteObjects.
@Override
protected List<String> deleteObjects(List<String> keys) throws IOException {
if (!mUfsConf.getBoolean(PropertyKey.UNDERFS_S3_BULK_DELETE_ENABLED)) {
return super.deleteObjects(keys);
}
Preconditions.checkArgument(keys != null && keys.size() <= getListingChunkLengthMax());
try {
List<DeleteObjectsRequest.KeyVersion> keysToDelete = new ArrayList<>();
for (String key : keys) {
keysToDelete.add(new DeleteObjectsRequest.KeyVersion(key));
}
DeleteObjectsResult deletedObjectsResult = mClient.deleteObjects(new DeleteObjectsRequest(mBucketName).withKeys(keysToDelete));
List<String> deletedObjects = new ArrayList<>();
for (DeleteObjectsResult.DeletedObject deletedObject : deletedObjectsResult.getDeletedObjects()) {
deletedObjects.add(deletedObject.getKey());
}
return deletedObjects;
} catch (AmazonClientException e) {
throw new IOException(e);
}
}
use of com.amazonaws.AmazonClientException in project alluxio by Alluxio.
the class S3AUnderFileSystem method createEmptyObject.
@Override
public boolean createEmptyObject(String key) {
try {
ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(0);
meta.setContentMD5(DIR_HASH);
meta.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
mClient.putObject(new PutObjectRequest(mBucketName, key, new ByteArrayInputStream(new byte[0]), meta));
return true;
} catch (AmazonClientException e) {
LOG.error("Failed to create object: {}", key, e);
return false;
}
}
Aggregations