JCLOUDS-651: Azure copy object content metadata

This commit is contained in:
Andrew Gaul 2015-04-06 22:06:14 -07:00
parent 40ba156937
commit a761f4cfa1
3 changed files with 97 additions and 6 deletions

View File

@ -46,6 +46,7 @@ import org.jclouds.azure.storage.reference.AzureStorageHeaders;
import org.jclouds.azureblob.binders.BindAzureBlobMetadataToRequest;
import org.jclouds.azureblob.binders.BindAzureBlobMetadataToMultipartRequest;
import org.jclouds.azureblob.binders.BindAzureBlocksToRequest;
import org.jclouds.azureblob.binders.BindAzureContentMetadataToRequest;
import org.jclouds.azureblob.binders.BindAzureCopyOptionsToRequest;
import org.jclouds.azureblob.binders.BindPublicAccessToRequest;
import org.jclouds.azureblob.domain.AzureBlob;
@ -70,6 +71,7 @@ import org.jclouds.azureblob.xml.ContainerNameEnumerationResultsHandler;
import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix;
import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.options.GetOptions;
import org.jclouds.io.ContentMetadata;
import org.jclouds.io.Payload;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
@ -413,6 +415,15 @@ public interface AzureBlobClient extends Closeable {
@PathParam("container") @ParamValidators(ContainerNameValidator.class) String container,
@PathParam("name") String name);
@Named("SetBlobProperties")
@PUT
@Path("{container}/{name}")
@QueryParams(keys = { "comp" }, values = { "metadata" })
@ResponseParser(ParseETagHeader.class)
String setBlobProperties(
@PathParam("container") @ParamValidators(ContainerNameValidator.class) String container,
@PathParam("name") String name,
@BinderParam(BindAzureContentMetadataToRequest.class) ContentMetadata contentMetadata);
@Named("SetBlobMetadata")
@PUT

View File

@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.azureblob.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.io.ContentMetadata;
import org.jclouds.rest.Binder;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimaps;
@Singleton
public class BindAzureContentMetadataToRequest implements Binder {
public BindAzureContentMetadataToRequest() {
}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(checkNotNull(input, "input") instanceof ContentMetadata,
"this binder is only valid for ContentMetadata");
checkNotNull(request, "request");
ContentMetadata contentMetadata = (ContentMetadata) input;
ImmutableMap.Builder<String, String> headers = ImmutableMap.builder();
String contentType = contentMetadata.getContentType();
if (contentType != null) {
headers.put("x-ms-blob-type", contentType);
}
String contentDisposition = contentMetadata.getContentDisposition();
if (contentDisposition != null) {
headers.put("x-ms-blob-content-disposition", contentDisposition);
}
return (R) request.toBuilder().replaceHeaders(Multimaps.forMap(headers.build())).build();
}
}

View File

@ -60,11 +60,13 @@ import org.jclouds.blobstore.util.BlobUtils;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.http.options.GetOptions;
import org.jclouds.io.ContentMetadata;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import org.jclouds.io.ContentMetadataBuilder;
import org.jclouds.io.Payload;
@Singleton
@ -233,13 +235,32 @@ public class AzureBlobStore extends BaseBlobStore {
URI source = context.getSigner().signGetBlob(fromContainer, fromName).getEndpoint();
sync.copyBlob(source, toContainer, toName, azureOptions.build());
String eTag = sync.getBlobProperties(toContainer, toName).getETag();
ContentMetadataBuilder builder = ContentMetadataBuilder.create();
// TODO: Azure does not allow updating system metadata during copy - call SetBlobProperties (not yet implemented)
// TODO: content disposition
// TODO: content encoding
// TODO: content language
// TODO: content type
String eTag = null;
Optional<ContentMetadata> contentMetadata = options.getContentMetadata();
if (contentMetadata.isPresent()) {
String contentDisposition = contentMetadata.get().getContentDisposition();
if (contentDisposition != null) {
builder.contentDisposition(contentDisposition);
}
String contentType = contentMetadata.get().getContentType();
if (contentType != null) {
builder.contentType(contentType);
}
eTag = sync.setBlobProperties(toContainer, toName, builder.build());
}
if (userMetadata.isPresent()) {
eTag = sync.setBlobMetadata(toContainer, toName, userMetadata.get());
}
if (eTag == null) {
eTag = sync.getBlobProperties(toContainer, toName).getETag();
}
return eTag;
}