Skip to content
This repository was archived by the owner on Jul 25, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion providers/azureblob/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<properties>
<test.azureblob.endpoint>https://${jclouds.identity}.blob.core.windows.net</test.azureblob.endpoint>
<test.azureblob.api-version>2012-02-12</test.azureblob.api-version>
<test.azureblob.api-version>2013-08-15</test.azureblob.api-version>
<test.azureblob.build-version />
<test.azureblob.identity>${test.azure.identity}</test.azureblob.identity>
<test.azureblob.credential>${test.azure.credential}</test.azureblob.credential>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected Builder() {
.name("Microsoft Azure Blob Service API")
.identityName("Account Name")
.credentialName("Access Key")
.version("2012-02-12")
.version("2013-08-15")
.defaultEndpoint("https://${jclouds.identity}.blob.core.windows.net")
.documentation(URI.create("http://msdn.microsoft.com/en-us/library/dd135733.aspx"))
.defaultProperties(AzureBlobApiMetadata.defaultProperties())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ BlobProperties getBlobProperties(
@PUT
@Path("{container}/{name}")
@QueryParams(keys = { "comp" }, values = { "metadata" })
void setBlobMetadata(
@ResponseParser(ParseETagHeader.class)
String setBlobMetadata(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically this represents an interface change although practically it does not.

@PathParam("container") @ParamValidators(ContainerNameValidator.class) String container,
@PathParam("name") String name, @BinderParam(BindMapToHeadersWithPrefix.class) Map<String, String> metadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
// bind BlockList-specific headers
ImmutableMap.Builder<String, String> headers = ImmutableMap.builder();
ContentMetadata contentMetadata = blob.getProperties().getContentMetadata();
// TODO: bind x-ms-blob-content-disposition after upgrading to API 2013-08-15
String contentDisposition = contentMetadata.getContentDisposition();
if (contentDisposition != null) {
headers.put("x-ms-blob-content-disposition", contentDisposition);
}
String contentEncoding = contentMetadata.getContentEncoding();
if (contentEncoding != null) {
headers.put("x-ms-blob-content-encoding", contentEncoding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public <R extends HttpRequest> R bindToRequest(R request, Object input) {

headers.put("x-ms-blob-type", blob.getProperties().getType().toString());

String contentDisposition = blob.getPayload().getContentMetadata().getContentDisposition();
if (contentDisposition != null) {
headers.put("x-ms-blob-content-disposition", contentDisposition);
}

switch (blob.getProperties().getType()) {
case PAGE_BLOB:
headers.put(HttpHeaders.CONTENT_LENGTH, "0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
*/
package org.jclouds.azureblob.xml;

import static com.google.common.base.Throwables.propagate;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.Map;
import java.util.SortedSet;
Expand Down Expand Up @@ -50,7 +53,7 @@ public class AccountNameEnumerationResultsHandler extends
private String marker;
private int maxResults;
private String nextMarker;
private URI currentUrl;
private String currentName;
private Date currentLastModified;
private String currentETag;
private boolean inMetadata;
Expand All @@ -75,7 +78,7 @@ public void startElement(String uri, String localName, String qName, Attributes
} else if (qName.equals("Metadata")) {
inMetadata = true;
} else if (qName.equals("EnumerationResults")) {
accountUrl = URI.create(attributes.getValue("AccountName").toString().trim());
accountUrl = URI.create(attributes.getValue("ServiceEndpoint").trim());
}
}

Expand All @@ -101,14 +104,20 @@ public void endElement(String uri, String name, String qName) {
nextMarker = currentText.toString().trim();
nextMarker = (nextMarker.equals("")) ? null : nextMarker;
} else if (qName.equals("Container")) {
URI currentUrl;
try {
currentUrl = new URI(accountUrl.getScheme(), accountUrl.getHost(), "/" + currentName, null);
} catch (URISyntaxException use) {
throw propagate(use);
}
containerMetadata.add(new ContainerPropertiesImpl(currentUrl, currentLastModified,
currentETag, currentMetadata));
currentUrl = null;
currentName = null;
currentLastModified = null;
currentETag = null;
currentMetadata = Maps.newHashMap();
} else if (qName.equals("Url")) {
currentUrl = URI.create(currentText.toString().trim());
} else if (qName.equals("Name")) {
currentName = currentText.toString().trim();
} else if (qName.equals("Last-Modified")) {
currentLastModified = dateParser.rfc822DateParse(currentText.toString().trim());
} else if (qName.equals("Etag")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class ContainerNameEnumerationResultsHandler extends ParseSax.HandlerWith
private String marker;
private int maxResults;
private String nextMarker;
private URI currentUrl;
private URI containerUrl;
private Date currentLastModified;
private String currentETag;
Expand Down Expand Up @@ -103,7 +102,7 @@ public void startElement(String uri, String localName, String qName, Attributes
inBlob = true;
inMetadata = true;
} else if (qName.equals("EnumerationResults")) {
containerUrl = URI.create(attributes.getValue("ContainerName").toString().trim());
containerUrl = URI.create(attributes.getValue("ServiceEndpoint").trim() + attributes.getValue("ContainerName").trim());
}
}

Expand Down Expand Up @@ -131,14 +130,14 @@ public void endElement(String uri, String name, String qName) {
} else if (qName.equals("LeaseStatus")) {
currentLeaseStatus = LeaseStatus.fromValue(currentText.toString().trim());
} else if (qName.equals("Blob")) {
URI currentUrl = uriBuilder(containerUrl + "/" + currentName).build();
BlobProperties md = new BlobPropertiesImpl(currentBlobType, currentName, containerUrl.getPath().replace("/",
""), currentUrl, currentLastModified, currentETag, currentSize, currentContentType,
currentContentMD5, currentContentEncoding, currentContentLanguage, currentExpires,
currentLeaseStatus, currentMetadata);
blobMetadata.add(md);
currentBlobType = null;
currentName = null;
currentUrl = null;
currentLastModified = null;
currentETag = null;
currentSize = -1;
Expand All @@ -149,8 +148,6 @@ public void endElement(String uri, String name, String qName) {
currentLeaseStatus = null;
currentExpires = null;
currentMetadata = Maps.newHashMap();
} else if (qName.equals("Url")) {
currentUrl = uriBuilder(currentText.toString().trim()).build();
} else if (qName.equals("Last-Modified")) {
currentLastModified = dateParser.rfc822DateParse(currentText.toString().trim());
} else if (qName.equals("Etag")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.net.URI;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;

import org.jclouds.azure.storage.AzureStorageResponseException;
Expand Down Expand Up @@ -231,54 +232,41 @@ public void testObjectOperations() throws Exception {

// Test HEAD of object
BlobProperties metadata = getApi().getBlobProperties(privateContainer, object.getProperties().getName());
// TODO assertEquals(metadata.getName(),
// object.getProperties().getName());
// we can't check this while hacking around lack of content-md5, as GET of
// the first byte will
// show incorrect length 1, the returned size, as opposed to the real
// length. This is an ok
// tradeoff, as a container list will contain the correct size of the
// objects in an
// inexpensive fashion
// http://code.google.com/p/jclouds/issues/detail?id=92
// assertEquals(metadata.getSize(), data.length());
assertEquals(metadata.getName(), object.getProperties().getName());
assertEquals(metadata.getContentMetadata().getContentLength(), Long.valueOf(data.length()));
assertEquals(metadata.getContentMetadata().getContentType(), "text/plain");
// Azure doesn't return the Content-MD5 on head request..
assertEquals(base16().lowerCase().encode(md5),
assertEquals(base16().lowerCase().encode(metadata.getContentMetadata().getContentMD5()),
base16().lowerCase().encode(object.getProperties().getContentMetadata().getContentMD5()));
assertEquals(metadata.getETag(), newEtag);
assertEquals(metadata.getMetadata().entrySet().size(), 1);
assertEquals(metadata.getMetadata().get("mykey"), "metadata-value");

// // Test POST to update object's metadata
// Multimap<String, String> userMetadata = LinkedHashMultimap.create();
// userMetadata.put("New-Metadata-1", "value-1");
// userMetadata.put("New-Metadata-2", "value-2");
// assertTrue(getApi().setBlobProperties(privateContainer,
// object.getProperties().getName(),
// userMetadata));
// Test POST to update object's metadata
Map<String, String> userMetadata = ImmutableMap.<String, String>builder()
.put("new_metadata_1", "value-1")
.put("new_metadata_2", "value-2")
.build();
String eTag = getApi().setBlobMetadata(privateContainer, object.getProperties().getName(), userMetadata);
assertThat(eTag).isNotNull();

// Azure ETag are timestamps not content hash
String eTag2 = getApi().setBlobMetadata(privateContainer, object.getProperties().getName(), userMetadata);
assertThat(eTag2).isNotNull().isNotEqualTo(eTag);

// Test GET of missing object
assert getApi().getBlob(privateContainer, "non-existent-object") == null;

// Test GET of object (including updated metadata)
AzureBlob getBlob = getApi().getBlob(privateContainer, object.getProperties().getName());
assertEquals(Strings2.toStringAndClose(getBlob.getPayload().openStream()), data);
// TODO assertEquals(getBlob.getName(), object.getProperties().getName());
assertEquals(getBlob.getProperties().getName(), object.getProperties().getName());
assertEquals(getBlob.getPayload().getContentMetadata().getContentLength(), Long.valueOf(data.length()));
assertEquals(getBlob.getProperties().getContentMetadata().getContentType(), "text/plain");
assertEquals(base16().lowerCase().encode(md5),
base16().lowerCase().encode(getBlob.getProperties().getContentMetadata().getContentMD5()));
assertEquals(newEtag, getBlob.getProperties().getETag());
// wait until we can update metadata
// assertEquals(getBlob.getProperties().getMetadata().entries().size(),
// 2);
// assertEquals(
// Iterables.getLast(getBlob.getProperties().getMetadata().get("New-Metadata-1")),
// "value-1");
// assertEquals(
// Iterables.getLast(getBlob.getProperties().getMetadata().get("New-Metadata-2")),
// "value-2");
assertEquals(getBlob.getProperties().getMetadata().size(), 2);
assertEquals(getBlob.getProperties().getMetadata().get("new_metadata_1"), "value-1");
assertEquals(getBlob.getProperties().getMetadata().get("new_metadata_2"), "value-2");
assertEquals(metadata.getMetadata().entrySet().size(), 1);
assertEquals(metadata.getMetadata().get("mykey"), "metadata-value");

Expand All @@ -290,7 +278,9 @@ public void testObjectOperations() throws Exception {
.maxResults(1).includeMetadata());
assertEquals(response.size(), 1);
assertEquals(Iterables.getOnlyElement(response).getName(), object.getProperties().getName());
assertEquals(Iterables.getOnlyElement(response).getMetadata(), ImmutableMap.of("mykey", "metadata-value"));
assertEquals(Iterables.getOnlyElement(response).getMetadata().size(), 2);
assertEquals(Iterables.getOnlyElement(response).getMetadata().get("new_metadata_1"), "value-1");
assertEquals(Iterables.getOnlyElement(response).getMetadata().get("new_metadata_2"), "value-2");

// Test PUT with invalid ETag (as if object's data was corrupted in
// transit)
Expand Down
Loading