From 70eac7414033c5cffb19ec33a2695624ae9657aa Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sun, 29 Mar 2015 21:51:03 -0700 Subject: [PATCH] JCLOUDS-651: Add Swift server-side copyBlob This has some limitations as discussed in JCLOUDS-872. --- .../blobstore/RegionScopedSwiftBlobStore.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java index d535569044..4516264c47 100644 --- a/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java +++ b/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java @@ -25,6 +25,7 @@ import static org.jclouds.location.predicates.LocationPredicates.idEquals; import static org.jclouds.openstack.swift.v1.options.PutOptions.Builder.metadata; import java.util.List; +import java.util.Map; import java.util.Set; import javax.inject.Inject; @@ -44,6 +45,7 @@ import org.jclouds.blobstore.domain.internal.BlobBuilderImpl; import org.jclouds.blobstore.domain.internal.BlobImpl; import org.jclouds.blobstore.domain.internal.PageSetImpl; import org.jclouds.blobstore.functions.BlobToHttpGetOptions; +import org.jclouds.blobstore.options.CopyOptions; import org.jclouds.blobstore.options.CreateContainerOptions; import org.jclouds.blobstore.options.GetOptions; import org.jclouds.blobstore.options.ListContainerOptions; @@ -228,6 +230,32 @@ public class RegionScopedSwiftBlobStore implements BlobStore { return objectApi.put(blob.getMetadata().getName(), blob.getPayload(), metadata(blob.getMetadata().getUserMetadata())); } + @Override + public String copyBlob(String fromContainer, String fromName, String toContainer, String toName, + CopyOptions options) { + ObjectApi objectApi = api.getObjectApi(regionId, toContainer); + + boolean copied = objectApi.copy(toName, fromContainer, fromName); + if (!copied) { + throw new RuntimeException("could not copy blob"); + } + + // TODO: content disposition + // TODO: content encoding + // TODO: content language + // TODO: content type + + Optional> userMetadata = options.getUserMetadata(); + if (userMetadata.isPresent()) { + boolean updated = objectApi.updateMetadata(toName, userMetadata.get()); + if (!updated) { + throw new RuntimeException("could not copy blob"); + } + } + + return objectApi.getWithoutBody(toName).getETag(); + } + @Override public BlobMetadata blobMetadata(String container, String name) { SwiftObject object = api.getObjectApi(regionId, container).get(name);