From a76e93502fb4018e9f175fe9d38b5f3134724cd3 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 2 Jan 2015 22:16:59 +0100 Subject: [PATCH] Implement BlobContainer.move() In elasticsearch master (2.0) a new method `move(String sourceBlobName, String targetBlobName)` has been added to `BlobContainer`. Closes #152. --- .../cloud/aws/blobstore/S3BlobContainer.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobContainer.java b/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobContainer.java index d560ceca348..bac558ee854 100644 --- a/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobContainer.java +++ b/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobContainer.java @@ -20,10 +20,7 @@ package org.elasticsearch.cloud.aws.blobstore; import com.amazonaws.AmazonClientException; -import com.amazonaws.services.s3.model.AmazonS3Exception; -import com.amazonaws.services.s3.model.ObjectListing; -import com.amazonaws.services.s3.model.S3Object; -import com.amazonaws.services.s3.model.S3ObjectSummary; +import com.amazonaws.services.s3.model.*; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.blobstore.BlobMetaData; import org.elasticsearch.common.blobstore.BlobPath; @@ -134,6 +131,24 @@ public class S3BlobContainer extends AbstractBlobContainer { return blobsBuilder.build(); } + @Override + public void move(String sourceBlobName, String targetBlobName) throws IOException { + try { + CopyObjectRequest request = new CopyObjectRequest(blobStore.bucket(), buildKey(sourceBlobName), + blobStore.bucket(), buildKey(targetBlobName)); + + if (blobStore.serverSideEncryption()) { + ObjectMetadata objectMetadata = new ObjectMetadata(); + objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); + request.setNewObjectMetadata(objectMetadata); + } + blobStore.client().copyObject(request); + blobStore.client().deleteObject(blobStore.bucket(), buildKey(sourceBlobName)); + } catch (AmazonS3Exception e){ + throw new IOException(e); + } + } + @Override public ImmutableMap listBlobs() throws IOException { return listBlobsByPrefix(null);