JCLOUDS-651: Add Swift server-side copyBlob

This has some limitations as discussed in JCLOUDS-872.
This commit is contained in:
Andrew Gaul 2015-03-29 21:51:03 -07:00
parent b4897c6689
commit 70eac74140
1 changed files with 28 additions and 0 deletions

View File

@ -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<Map<String, String>> 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);