mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 15:08:28 +00:00
Issue 86: refactored code up to storage level for create options and metadata listing
git-svn-id: http://jclouds.googlecode.com/svn/trunk@1882 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
6373d05d2f
commit
6a8c3d160c
@ -32,10 +32,12 @@ import javax.ws.rs.PUT;
|
|||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.domain.ContainerMetadataList;
|
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
|
||||||
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
||||||
import org.jclouds.azure.storage.blob.xml.AccountNameEnumerationResultsHandler;
|
import org.jclouds.azure.storage.blob.xml.AccountNameEnumerationResultsHandler;
|
||||||
|
import org.jclouds.azure.storage.domain.MetadataList;
|
||||||
import org.jclouds.azure.storage.filters.SharedKeyAuthentication;
|
import org.jclouds.azure.storage.filters.SharedKeyAuthentication;
|
||||||
|
import org.jclouds.azure.storage.options.CreateOptions;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.options.ListOptions;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
||||||
import org.jclouds.rest.Header;
|
import org.jclouds.rest.Header;
|
||||||
@ -71,7 +73,7 @@ public interface AzureBlobConnection {
|
|||||||
@XMLResponseParser(AccountNameEnumerationResultsHandler.class)
|
@XMLResponseParser(AccountNameEnumerationResultsHandler.class)
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@Query(key = "comp", value = "list")
|
@Query(key = "comp", value = "list")
|
||||||
ContainerMetadataList listContainers(ListOptions... listOptions);
|
MetadataList<ContainerMetadata> listContainers(ListOptions... listOptions);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Create Container operation creates a new container under the specified account. If the
|
* The Create Container operation creates a new container under the specified account. If the
|
||||||
@ -121,7 +123,7 @@ public interface AzureBlobConnection {
|
|||||||
@PUT
|
@PUT
|
||||||
@Path("$root")
|
@Path("$root")
|
||||||
@Query(key = "restype", value = "container")
|
@Query(key = "restype", value = "container")
|
||||||
boolean createRootContainer(CreateContainerOptions... options);// TODO public is not supported!
|
boolean createRootContainer(CreateOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -3,9 +3,9 @@ package org.jclouds.azure.storage.blob;
|
|||||||
import org.jclouds.cloud.CloudContext;
|
import org.jclouds.cloud.CloudContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an authenticated context to Cloud Files.
|
* Represents an authenticated context to Azure Blob Service.
|
||||||
*
|
*
|
||||||
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
* @see <a href="http://msdn.microsoft.com/en-us/library/dd135733.aspx" />
|
||||||
* @see AzureBlobConnection
|
* @see AzureBlobConnection
|
||||||
* @see CloudContext
|
* @see CloudContext
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package org.jclouds.azure.storage.blob.options;
|
package org.jclouds.azure.storage.blob.options;
|
||||||
|
|
||||||
import java.util.Map.Entry;
|
import org.jclouds.azure.storage.options.CreateOptions;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
|
||||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
@ -14,7 +11,7 @@ import com.google.common.collect.Multimap;
|
|||||||
* mutator (if needed):
|
* mutator (if needed):
|
||||||
* <p/>
|
* <p/>
|
||||||
* <code>
|
* <code>
|
||||||
* import static org.jclouds.azure.storage.blob.options.PutBucketOptions.Builder.*
|
* import static org.jclouds.azure.storage.blob.options.CreateContainerOptions.Builder.*
|
||||||
* import org.jclouds.azure.storage.blob.AzureBlobConnection;
|
* import org.jclouds.azure.storage.blob.AzureBlobConnection;
|
||||||
* <p/>
|
* <p/>
|
||||||
* AzureBlobConnection connection = // get connection
|
* AzureBlobConnection connection = // get connection
|
||||||
@ -24,9 +21,14 @@ import com.google.common.collect.Multimap;
|
|||||||
* @see <a href="http://msdn.microsoft.com/en-us/library/dd179466.aspx" />
|
* @see <a href="http://msdn.microsoft.com/en-us/library/dd179466.aspx" />
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class CreateContainerOptions extends BaseHttpRequestOptions {
|
public class CreateContainerOptions extends CreateOptions {
|
||||||
public static final CreateContainerOptions NONE = new CreateContainerOptions();
|
public static final CreateContainerOptions NONE = new CreateContainerOptions();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CreateContainerOptions withMetadata(Multimap<String, String> metadata) {
|
||||||
|
return (CreateContainerOptions) super.withMetadata(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether a container may be accessed publicly
|
* Indicates whether a container may be accessed publicly
|
||||||
*/
|
*/
|
||||||
@ -35,23 +37,6 @@ public class CreateContainerOptions extends BaseHttpRequestOptions {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A name-value pair to associate with the container as metadata.
|
|
||||||
*
|
|
||||||
* Note that these are stored at the server under the prefix: x-ms-meta-
|
|
||||||
*/
|
|
||||||
public CreateContainerOptions withMetadata(Multimap<String, String> metadata) {
|
|
||||||
for (Entry<String, String> entry : metadata.entries()) {
|
|
||||||
if (entry.getKey().startsWith(AzureStorageHeaders.USER_METADATA_PREFIX))
|
|
||||||
headers.put(entry.getKey(), entry.getValue());
|
|
||||||
else
|
|
||||||
headers
|
|
||||||
.put(AzureStorageHeaders.USER_METADATA_PREFIX + entry.getKey(), entry
|
|
||||||
.getValue());
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,7 +52,7 @@ public class CreateContainerOptions extends BaseHttpRequestOptions {
|
|||||||
*/
|
*/
|
||||||
public static CreateContainerOptions withMetadata(Multimap<String, String> metadata) {
|
public static CreateContainerOptions withMetadata(Multimap<String, String> metadata) {
|
||||||
CreateContainerOptions options = new CreateContainerOptions();
|
CreateContainerOptions options = new CreateContainerOptions();
|
||||||
return options.withMetadata(metadata);
|
return (CreateContainerOptions) options.withMetadata(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
|
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
|
||||||
import org.jclouds.azure.storage.blob.domain.ContainerMetadataList;
|
import org.jclouds.azure.storage.domain.MetadataList;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.util.DateService;
|
import org.jclouds.util.DateService;
|
||||||
@ -45,7 +45,7 @@ import com.google.inject.Inject;
|
|||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class AccountNameEnumerationResultsHandler extends
|
public class AccountNameEnumerationResultsHandler extends
|
||||||
ParseSax.HandlerWithResult<ContainerMetadataList> {
|
ParseSax.HandlerWithResult<MetadataList<ContainerMetadata>> {
|
||||||
|
|
||||||
private List<ContainerMetadata> containerMetadata = new ArrayList<ContainerMetadata>();
|
private List<ContainerMetadata> containerMetadata = new ArrayList<ContainerMetadata>();
|
||||||
private String prefix;
|
private String prefix;
|
||||||
@ -65,8 +65,9 @@ public class AccountNameEnumerationResultsHandler extends
|
|||||||
this.dateParser = dateParser;
|
this.dateParser = dateParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContainerMetadataList getResult() {
|
public MetadataList<ContainerMetadata> getResult() {
|
||||||
return new ContainerMetadataList(prefix, marker, maxResults, containerMetadata, nextMarker);
|
return new MetadataList<ContainerMetadata>(prefix, marker, maxResults, containerMetadata,
|
||||||
|
nextMarker);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endElement(String uri, String name, String qName) {
|
public void endElement(String uri, String name, String qName) {
|
||||||
@ -74,10 +75,13 @@ public class AccountNameEnumerationResultsHandler extends
|
|||||||
maxResults = Integer.parseInt(currentText.toString().trim());
|
maxResults = Integer.parseInt(currentText.toString().trim());
|
||||||
} else if (qName.equals("Marker")) {
|
} else if (qName.equals("Marker")) {
|
||||||
marker = currentText.toString().trim();
|
marker = currentText.toString().trim();
|
||||||
|
marker = (marker.equals("")) ? null : marker;
|
||||||
} else if (qName.equals("Prefix")) {
|
} else if (qName.equals("Prefix")) {
|
||||||
prefix = currentText.toString().trim();
|
prefix = currentText.toString().trim();
|
||||||
|
prefix = (prefix.equals("")) ? null : prefix;
|
||||||
} else if (qName.equals("NextMarker")) {
|
} else if (qName.equals("NextMarker")) {
|
||||||
nextMarker = currentText.toString().trim();
|
nextMarker = currentText.toString().trim();
|
||||||
|
nextMarker = (nextMarker.equals("")) ? null : nextMarker;
|
||||||
} else if (qName.equals("Container")) {
|
} else if (qName.equals("Container")) {
|
||||||
containerMetadata.add(new ContainerMetadata(currentUrl, currentLastModified, currentETag));
|
containerMetadata.add(new ContainerMetadata(currentUrl, currentLastModified, currentETag));
|
||||||
currentUrl = null;
|
currentUrl = null;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.jclouds.azure.storage.blob.xml;
|
package org.jclouds.azure.storage.blob.xml;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.domain.ContainerMetadataList;
|
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
|
||||||
|
import org.jclouds.azure.storage.domain.MetadataList;
|
||||||
import org.jclouds.azure.storage.xml.AzureStorageParserFactory;
|
import org.jclouds.azure.storage.xml.AzureStorageParserFactory;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
|
||||||
@ -17,12 +18,12 @@ import com.google.inject.Provider;
|
|||||||
public class AzureBlobParserFactory extends AzureStorageParserFactory {
|
public class AzureBlobParserFactory extends AzureStorageParserFactory {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private GenericParseFactory<ContainerMetadataList> parseContainerMetadataListFactory;
|
private GenericParseFactory<MetadataList<ContainerMetadata>> parseContainerMetadataListFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Provider<AccountNameEnumerationResultsHandler> containerMetaListHandlerProvider;
|
Provider<AccountNameEnumerationResultsHandler> containerMetaListHandlerProvider;
|
||||||
|
|
||||||
public ParseSax<ContainerMetadataList> createContainerMetadataListParser() {
|
public ParseSax<MetadataList<ContainerMetadata>> createContainerMetadataListParser() {
|
||||||
return parseContainerMetadataListFactory.create(containerMetaListHandlerProvider.get());
|
return parseContainerMetadataListFactory.create(containerMetaListHandlerProvider.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,8 @@
|
|||||||
package org.jclouds.azure.storage.blob.xml.config;
|
package org.jclouds.azure.storage.blob.xml.config;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.domain.ContainerMetadataList;
|
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
|
||||||
import org.jclouds.azure.storage.blob.xml.AccountNameEnumerationResultsHandler;
|
import org.jclouds.azure.storage.blob.xml.AccountNameEnumerationResultsHandler;
|
||||||
|
import org.jclouds.azure.storage.domain.MetadataList;
|
||||||
import org.jclouds.azure.storage.xml.AzureStorageParserFactory;
|
import org.jclouds.azure.storage.xml.AzureStorageParserFactory;
|
||||||
import org.jclouds.azure.storage.xml.config.AzureStorageParserModule;
|
import org.jclouds.azure.storage.xml.config.AzureStorageParserModule;
|
||||||
import org.jclouds.command.ConfiguresResponseTransformer;
|
import org.jclouds.command.ConfiguresResponseTransformer;
|
||||||
@ -17,13 +18,13 @@ import com.google.inject.assistedinject.FactoryProvider;
|
|||||||
*/
|
*/
|
||||||
@ConfiguresResponseTransformer
|
@ConfiguresResponseTransformer
|
||||||
public class AzureBlobParserModule extends AzureStorageParserModule {
|
public class AzureBlobParserModule extends AzureStorageParserModule {
|
||||||
protected final TypeLiteral<AzureStorageParserFactory.GenericParseFactory<ContainerMetadataList>> accountNameEnumerationResultsHandler = new TypeLiteral<AzureStorageParserFactory.GenericParseFactory<ContainerMetadataList>>() {
|
protected final TypeLiteral<AzureStorageParserFactory.GenericParseFactory<MetadataList<ContainerMetadata>>> accountNameEnumerationResultsHandler = new TypeLiteral<AzureStorageParserFactory.GenericParseFactory<MetadataList<ContainerMetadata>>>() {
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void bindParserImplementationsToReturnTypes() {
|
protected void bindParserImplementationsToReturnTypes() {
|
||||||
super.bindParserImplementationsToReturnTypes();
|
super.bindParserImplementationsToReturnTypes();
|
||||||
bind(new TypeLiteral<ParseSax.HandlerWithResult<ContainerMetadataList>>() {
|
bind(new TypeLiteral<ParseSax.HandlerWithResult<MetadataList<ContainerMetadata>>>() {
|
||||||
}).to(AccountNameEnumerationResultsHandler.class);
|
}).to(AccountNameEnumerationResultsHandler.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ public class AzureBlobParserModule extends AzureStorageParserModule {
|
|||||||
super.bindCallablesThatReturnParseResults();
|
super.bindCallablesThatReturnParseResults();
|
||||||
bind(accountNameEnumerationResultsHandler).toProvider(
|
bind(accountNameEnumerationResultsHandler).toProvider(
|
||||||
FactoryProvider.newFactory(accountNameEnumerationResultsHandler,
|
FactoryProvider.newFactory(accountNameEnumerationResultsHandler,
|
||||||
new TypeLiteral<ParseSax<ContainerMetadataList>>() {
|
new TypeLiteral<ParseSax<MetadataList<ContainerMetadata>>>() {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,9 @@ import java.net.URL;
|
|||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.AzureStorageResponseException;
|
import org.jclouds.azure.storage.AzureStorageResponseException;
|
||||||
import org.jclouds.azure.storage.blob.domain.ContainerMetadataList;
|
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
|
||||||
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
||||||
|
import org.jclouds.azure.storage.domain.MetadataList;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.options.ListOptions;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
@ -48,9 +49,9 @@ public class AzureBlobConnectionLiveTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testListContainers() throws Exception {
|
public void testListContainers() throws Exception {
|
||||||
|
|
||||||
ContainerMetadataList response = connection.listContainers();
|
MetadataList<ContainerMetadata> response = connection.listContainers();
|
||||||
assert null != response;
|
assert null != response;
|
||||||
long initialContainerCount = response.getContainerMetadata().size();
|
long initialContainerCount = response.getMetadata().size();
|
||||||
assertTrue(initialContainerCount >= 0);
|
assertTrue(initialContainerCount >= 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -73,9 +74,9 @@ public class AzureBlobConnectionLiveTest {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ContainerMetadataList response = connection.listContainers();
|
MetadataList<ContainerMetadata> response = connection.listContainers();
|
||||||
assert null != response;
|
assert null != response;
|
||||||
long containerCount = response.getContainerMetadata().size();
|
long containerCount = response.getMetadata().size();
|
||||||
assertTrue(containerCount >= 1);
|
assertTrue(containerCount >= 1);
|
||||||
// TODO ... check to see the container actually exists
|
// TODO ... check to see the container actually exists
|
||||||
}
|
}
|
||||||
@ -128,10 +129,10 @@ public class AzureBlobConnectionLiveTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testListContainersWithOptions() throws Exception {
|
public void testListContainersWithOptions() throws Exception {
|
||||||
|
|
||||||
ContainerMetadataList response = connection.listContainers(ListOptions.Builder.prefix(
|
MetadataList<ContainerMetadata> response = connection.listContainers(ListOptions.Builder
|
||||||
privateContainer).maxResults(1));
|
.prefix(privateContainer).maxResults(1));
|
||||||
assert null != response;
|
assert null != response;
|
||||||
long initialContainerCount = response.getContainerMetadata().size();
|
long initialContainerCount = response.getMetadata().size();
|
||||||
assertTrue(initialContainerCount >= 0);
|
assertTrue(initialContainerCount >= 0);
|
||||||
assertEquals(privateContainer, response.getPrefix());
|
assertEquals(privateContainer, response.getPrefix());
|
||||||
assertEquals(1, response.getMaxResults());
|
assertEquals(1, response.getMaxResults());
|
||||||
|
@ -12,6 +12,7 @@ import javax.ws.rs.HttpMethod;
|
|||||||
|
|
||||||
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
||||||
import org.jclouds.azure.storage.blob.xml.config.AzureBlobParserModule;
|
import org.jclouds.azure.storage.blob.xml.config.AzureBlobParserModule;
|
||||||
|
import org.jclouds.azure.storage.options.CreateOptions;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.options.ListOptions;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
import org.jclouds.concurrent.WithinThreadExecutorService;
|
import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||||
@ -45,6 +46,8 @@ public class AzureBlobConnectionTest {
|
|||||||
.getClass();
|
.getClass();
|
||||||
private static final Class<? extends CreateContainerOptions[]> createContainerOptionsVarargsClass = new CreateContainerOptions[] {}
|
private static final Class<? extends CreateContainerOptions[]> createContainerOptionsVarargsClass = new CreateContainerOptions[] {}
|
||||||
.getClass();
|
.getClass();
|
||||||
|
private static final Class<? extends CreateOptions[]> createOptionsVarargsClass = new CreateOptions[] {}
|
||||||
|
.getClass();
|
||||||
|
|
||||||
public void testListContainers() throws SecurityException, NoSuchMethodException {
|
public void testListContainers() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobConnection.class
|
Method method = AzureBlobConnection.class
|
||||||
@ -142,7 +145,7 @@ public class AzureBlobConnectionTest {
|
|||||||
|
|
||||||
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException {
|
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobConnection.class.getMethod("createRootContainer",
|
Method method = AzureBlobConnection.class.getMethod("createRootContainer",
|
||||||
createContainerOptionsVarargsClass);
|
createOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
URI endpoint = URI.create("http://localhost");
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
@ -176,7 +179,7 @@ public class AzureBlobConnectionTest {
|
|||||||
|
|
||||||
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException {
|
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = AzureBlobConnection.class.getMethod("createRootContainer",
|
Method method = AzureBlobConnection.class.getMethod("createRootContainer",
|
||||||
createContainerOptionsVarargsClass);
|
createOptionsVarargsClass);
|
||||||
URI endpoint = URI.create("http://localhost");
|
URI endpoint = URI.create("http://localhost");
|
||||||
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
HttpRequest httpMethod = processor.createRequest(endpoint, method,
|
||||||
new Object[] { withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
new Object[] { withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
||||||
|
@ -29,7 +29,7 @@ import java.io.InputStream;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
|
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
|
||||||
import org.jclouds.azure.storage.blob.domain.ContainerMetadataList;
|
import org.jclouds.azure.storage.domain.MetadataList;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
@ -46,30 +46,11 @@ public class AccountNameEnumerationResultsHandlerTest extends BaseHandlerTest {
|
|||||||
|
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_containers.xml");
|
InputStream is = getClass().getResourceAsStream("/test_list_containers.xml");
|
||||||
ContainerMetadataList list = new ContainerMetadataList(null, null, 3, ImmutableList.of(
|
MetadataList<ContainerMetadata> list = new MetadataList<ContainerMetadata>(null, null, 3,
|
||||||
new ContainerMetadata(URI.create("http://myaccount.blob.core.windows.net/audio"),
|
ImmutableList.of(new ContainerMetadata(URI
|
||||||
dateService.rfc822DateParse("Wed, 13 Aug 2008 20:39:39 GMT"), HttpUtils
|
.create("http://myaccount.blob.core.windows.net/audio"), dateService
|
||||||
.fromHexString("0x8CACB9BD7C6B1B2")), new ContainerMetadata(URI
|
.rfc822DateParse("Wed, 13 Aug 2008 20:39:39 GMT"), HttpUtils
|
||||||
.create("http://myaccount.blob.core.windows.net/images"), dateService
|
.fromHexString("0x8CACB9BD7C6B1B2")), new ContainerMetadata(URI
|
||||||
.rfc822DateParse("Wed, 14 Aug 2008 20:39:39 GMT"), HttpUtils
|
|
||||||
.fromHexString("0x8CACB9BD7C1EEEC")), new ContainerMetadata(URI
|
|
||||||
.create("http://myaccount.blob.core.windows.net/textfiles"), dateService
|
|
||||||
.rfc822DateParse("Wed, 15 Aug 2008 20:39:39 GMT"), HttpUtils
|
|
||||||
.fromHexString("0x8CACB9BD7BACAC3"))
|
|
||||||
|
|
||||||
), "video");
|
|
||||||
ParseSax<ContainerMetadataList> parser = parserFactory.createContainerMetadataListParser();
|
|
||||||
ContainerMetadataList result = parser.parse(is);
|
|
||||||
assertEquals(result, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testApplyInputStreamWithOptions() {
|
|
||||||
InputStream is = getClass().getResourceAsStream("/test_list_containers_options.xml");
|
|
||||||
ContainerMetadataList list = new ContainerMetadataList("prefix", "marker", 1, ImmutableList
|
|
||||||
.of(new ContainerMetadata(
|
|
||||||
URI.create("http://myaccount.blob.core.windows.net/audio"), dateService
|
|
||||||
.rfc822DateParse("Wed, 13 Aug 2008 20:39:39 GMT"), HttpUtils
|
|
||||||
.fromHexString("0x8CACB9BD7C6B1B2")), new ContainerMetadata(URI
|
|
||||||
.create("http://myaccount.blob.core.windows.net/images"), dateService
|
.create("http://myaccount.blob.core.windows.net/images"), dateService
|
||||||
.rfc822DateParse("Wed, 14 Aug 2008 20:39:39 GMT"), HttpUtils
|
.rfc822DateParse("Wed, 14 Aug 2008 20:39:39 GMT"), HttpUtils
|
||||||
.fromHexString("0x8CACB9BD7C1EEEC")), new ContainerMetadata(URI
|
.fromHexString("0x8CACB9BD7C1EEEC")), new ContainerMetadata(URI
|
||||||
@ -78,8 +59,30 @@ public class AccountNameEnumerationResultsHandlerTest extends BaseHandlerTest {
|
|||||||
.fromHexString("0x8CACB9BD7BACAC3"))
|
.fromHexString("0x8CACB9BD7BACAC3"))
|
||||||
|
|
||||||
), "video");
|
), "video");
|
||||||
ParseSax<ContainerMetadataList> parser = parserFactory.createContainerMetadataListParser();
|
ParseSax<MetadataList<ContainerMetadata>> parser = parserFactory
|
||||||
ContainerMetadataList result = parser.parse(is);
|
.createContainerMetadataListParser();
|
||||||
|
MetadataList<ContainerMetadata> result = parser.parse(is);
|
||||||
|
assertEquals(result, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testApplyInputStreamWithOptions() {
|
||||||
|
InputStream is = getClass().getResourceAsStream("/test_list_containers_options.xml");
|
||||||
|
MetadataList<ContainerMetadata> list = new MetadataList<ContainerMetadata>("prefix",
|
||||||
|
"marker", 1, ImmutableList.of(new ContainerMetadata(URI
|
||||||
|
.create("http://myaccount.blob.core.windows.net/audio"), dateService
|
||||||
|
.rfc822DateParse("Wed, 13 Aug 2008 20:39:39 GMT"), HttpUtils
|
||||||
|
.fromHexString("0x8CACB9BD7C6B1B2")), new ContainerMetadata(URI
|
||||||
|
.create("http://myaccount.blob.core.windows.net/images"), dateService
|
||||||
|
.rfc822DateParse("Wed, 14 Aug 2008 20:39:39 GMT"), HttpUtils
|
||||||
|
.fromHexString("0x8CACB9BD7C1EEEC")), new ContainerMetadata(URI
|
||||||
|
.create("http://myaccount.blob.core.windows.net/textfiles"), dateService
|
||||||
|
.rfc822DateParse("Wed, 15 Aug 2008 20:39:39 GMT"), HttpUtils
|
||||||
|
.fromHexString("0x8CACB9BD7BACAC3"))
|
||||||
|
|
||||||
|
), "video");
|
||||||
|
ParseSax<MetadataList<ContainerMetadata>> parser = parserFactory
|
||||||
|
.createContainerMetadataListParser();
|
||||||
|
MetadataList<ContainerMetadata> result = parser.parse(is);
|
||||||
assertEquals(result, list);
|
assertEquals(result, list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.blob.domain;
|
package org.jclouds.azure.storage.domain;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -30,36 +30,20 @@ import java.util.List;
|
|||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ContainerMetadataList {
|
public class MetadataList<T> {
|
||||||
private String prefix;
|
private final String prefix;
|
||||||
private String marker;
|
private final String marker;
|
||||||
private int maxResults;
|
private final int maxResults;
|
||||||
private List<ContainerMetadata> containerMetadata;
|
private final List<T> metadata;
|
||||||
private String nextMarker;
|
private final String nextMarker;
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ContainerMetadataList [containerMetadata=" + containerMetadata + ", marker=" + marker
|
|
||||||
+ ", maxResults=" + maxResults + ", nextMarker=" + nextMarker + ", prefix=" + prefix
|
|
||||||
+ "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContainerMetadataList(String prefix, String marker, int maxResults,
|
|
||||||
List<ContainerMetadata> containerMetadata, String nextMarker) {
|
|
||||||
this.prefix = prefix;
|
|
||||||
this.marker = marker;
|
|
||||||
this.maxResults = maxResults;
|
|
||||||
this.containerMetadata = containerMetadata;
|
|
||||||
this.nextMarker = nextMarker;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((containerMetadata == null) ? 0 : containerMetadata.hashCode());
|
|
||||||
result = prime * result + ((marker == null) ? 0 : marker.hashCode());
|
result = prime * result + ((marker == null) ? 0 : marker.hashCode());
|
||||||
result = prime * result + maxResults;
|
result = prime * result + maxResults;
|
||||||
|
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
||||||
result = prime * result + ((nextMarker == null) ? 0 : nextMarker.hashCode());
|
result = prime * result + ((nextMarker == null) ? 0 : nextMarker.hashCode());
|
||||||
result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
|
result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
|
||||||
return result;
|
return result;
|
||||||
@ -73,12 +57,7 @@ public class ContainerMetadataList {
|
|||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
ContainerMetadataList other = (ContainerMetadataList) obj;
|
MetadataList<?> other = (MetadataList<?>) obj;
|
||||||
if (containerMetadata == null) {
|
|
||||||
if (other.containerMetadata != null)
|
|
||||||
return false;
|
|
||||||
} else if (!containerMetadata.equals(other.containerMetadata))
|
|
||||||
return false;
|
|
||||||
if (marker == null) {
|
if (marker == null) {
|
||||||
if (other.marker != null)
|
if (other.marker != null)
|
||||||
return false;
|
return false;
|
||||||
@ -86,6 +65,11 @@ public class ContainerMetadataList {
|
|||||||
return false;
|
return false;
|
||||||
if (maxResults != other.maxResults)
|
if (maxResults != other.maxResults)
|
||||||
return false;
|
return false;
|
||||||
|
if (metadata == null) {
|
||||||
|
if (other.metadata != null)
|
||||||
|
return false;
|
||||||
|
} else if (!metadata.equals(other.metadata))
|
||||||
|
return false;
|
||||||
if (nextMarker == null) {
|
if (nextMarker == null) {
|
||||||
if (other.nextMarker != null)
|
if (other.nextMarker != null)
|
||||||
return false;
|
return false;
|
||||||
@ -99,40 +83,35 @@ public class ContainerMetadataList {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrefix(String prefix) {
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "MetadataList [metadata=" + metadata + ", marker=" + marker + ", maxResults="
|
||||||
|
+ maxResults + ", nextMarker=" + nextMarker + ", prefix=" + prefix + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataList(String prefix, String marker, int maxResults, List<T> metadata,
|
||||||
|
String nextMarker) {
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
|
this.marker = marker;
|
||||||
|
this.maxResults = maxResults;
|
||||||
|
this.metadata = metadata;
|
||||||
|
this.nextMarker = nextMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrefix() {
|
public String getPrefix() {
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMarker(String marker) {
|
|
||||||
this.marker = marker;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMarker() {
|
public String getMarker() {
|
||||||
return marker;
|
return marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxResults(int maxResults) {
|
|
||||||
this.maxResults = maxResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxResults() {
|
public int getMaxResults() {
|
||||||
return maxResults;
|
return maxResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContainerMetadata(List<ContainerMetadata> containerMetadata) {
|
public List<T> getMetadata() {
|
||||||
this.containerMetadata = containerMetadata;
|
return metadata;
|
||||||
}
|
|
||||||
|
|
||||||
public List<ContainerMetadata> getContainerMetadata() {
|
|
||||||
return containerMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNextMarker(String nextMarker) {
|
|
||||||
this.nextMarker = nextMarker;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNextMarker() {
|
public String getNextMarker() {
|
@ -0,0 +1,59 @@
|
|||||||
|
package org.jclouds.azure.storage.options;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains common options supported in the REST API for the Create operation. <h2>
|
||||||
|
* Usage</h2> The recommended way to instantiate a CreateOptions object is to statically import
|
||||||
|
* CreateOptions.* and invoke a static creation method followed by an instance mutator (if
|
||||||
|
* needed):
|
||||||
|
* <p/>
|
||||||
|
* <code>
|
||||||
|
* import static org.jclouds.azure.storage.options.CreateOptions.Builder.*
|
||||||
|
* import org.jclouds.azure.storage.queue.AzureQueueConnection;
|
||||||
|
* <p/>
|
||||||
|
* AzureQueueConnection connection = // get connection
|
||||||
|
* Multimap<String,String> metadata = // ...
|
||||||
|
* boolean createdWithPublicAcl = connection.createQueue("containerName", withMetdata(metadata));
|
||||||
|
* <code> *
|
||||||
|
*
|
||||||
|
* @see <a href="http://msdn.microsoft.com/en-us/library/dd179466.aspx" />
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class CreateOptions extends BaseHttpRequestOptions {
|
||||||
|
public static final CreateOptions NONE = new CreateOptions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A name-value pair to associate with the container as metadata.
|
||||||
|
*
|
||||||
|
* Note that these are stored at the server under the prefix: x-ms-meta-
|
||||||
|
*/
|
||||||
|
public CreateOptions withMetadata(Multimap<String, String> metadata) {
|
||||||
|
for (Entry<String, String> entry : metadata.entries()) {
|
||||||
|
if (entry.getKey().startsWith(AzureStorageHeaders.USER_METADATA_PREFIX))
|
||||||
|
headers.put(entry.getKey(), entry.getValue());
|
||||||
|
else
|
||||||
|
headers
|
||||||
|
.put(AzureStorageHeaders.USER_METADATA_PREFIX + entry.getKey(), entry
|
||||||
|
.getValue());
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see CreateOptions#withMetadata(Multimap<String, String>)
|
||||||
|
*/
|
||||||
|
public static CreateOptions withMetadata(Multimap<String, String> metadata) {
|
||||||
|
CreateOptions options = new CreateOptions();
|
||||||
|
return options.withMetadata(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package org.jclouds.azure.storage.options;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code CreateOptions}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "azurequeue.CreateOptionsTest")
|
||||||
|
public class CreateOptionsTest {
|
||||||
|
|
||||||
|
public void testMetadata() {
|
||||||
|
CreateOptions options = new CreateOptions().withMetadata(ImmutableMultimap.of(
|
||||||
|
"test", "foo"));
|
||||||
|
assertEquals(ImmutableList.of("foo"), options.buildRequestHeaders().get(
|
||||||
|
AzureStorageHeaders.USER_METADATA_PREFIX + "test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMetadataAlreadyPrefixed() {
|
||||||
|
CreateOptions options = new CreateOptions().withMetadata(ImmutableMultimap.of(
|
||||||
|
AzureStorageHeaders.USER_METADATA_PREFIX + "test", "foo"));
|
||||||
|
assertEquals(ImmutableList.of("foo"), options.buildRequestHeaders().get(
|
||||||
|
AzureStorageHeaders.USER_METADATA_PREFIX + "test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMetadataStatic() {
|
||||||
|
CreateOptions options = CreateOptions.Builder.withMetadata(ImmutableMultimap.of(
|
||||||
|
"test", "foo"));
|
||||||
|
assertEquals(ImmutableList.of("foo"), options.buildRequestHeaders().get(
|
||||||
|
AzureStorageHeaders.USER_METADATA_PREFIX + "test"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user