From 9ccc8e6965fc51c4663e159e64066bd5cc5f097f Mon Sep 17 00:00:00 2001 From: Jeremy Daggett Date: Mon, 18 Jul 2011 11:45:10 -0700 Subject: [PATCH 1/8] Add jeremy.txt --- jeremy.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 jeremy.txt diff --git a/jeremy.txt b/jeremy.txt new file mode 100644 index 0000000000..5d31edcb2d --- /dev/null +++ b/jeremy.txt @@ -0,0 +1 @@ +README HP \ No newline at end of file From 2bcf91a92ef94b48011eceb64cabe795b2097a07 Mon Sep 17 00:00:00 2001 From: Jeremy Daggett Date: Mon, 18 Jul 2011 11:45:10 -0700 Subject: [PATCH 2/8] Add jeremy.txt --- jeremy.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 jeremy.txt diff --git a/jeremy.txt b/jeremy.txt new file mode 100644 index 0000000000..5d31edcb2d --- /dev/null +++ b/jeremy.txt @@ -0,0 +1 @@ +README HP \ No newline at end of file From 877e095e1e0b5074d65bdf91c2514b4354027194 Mon Sep 17 00:00:00 2001 From: Jeremy Daggett Date: Tue, 8 Nov 2011 10:35:49 -0800 Subject: [PATCH 3/8] Initial sources for hpcloud-object-storage provider --- core/src/main/resources/rest.properties | 6 + providers/hpcloud-object-storage/README.txt | 25 +++ providers/hpcloud-object-storage/pom.xml | 170 ++++++++++++++++++ .../hpcloud/object/storage/CDNManagement.java | 40 +++++ .../HPCloudObjectStorageAsyncClient.java | 131 ++++++++++++++ .../storage/HPCloudObjectStorageClient.java | 63 +++++++ .../HPCloudObjectStorageContextBuilder.java | 61 +++++++ ...HPCloudObjectStoragePropertiesBuilder.java | 48 +++++ .../HPCloudObjectStorageProviderMetadata.java | 116 ++++++++++++ .../HPCloudObjectStorageAsyncBlobStore.java | 95 ++++++++++ .../HPCloudObjectStorageBlobStore.java | 79 ++++++++ ...udObjectStorageBlobStoreContextModule.java | 70 ++++++++ .../functions/EnableCDNAndCache.java | 53 ++++++ ...loudObjectStorageObjectToBlobMetadata.java | 50 ++++++ .../functions/PublicUriForObjectInfo.java | 58 ++++++ .../HPCloudObjectStorageRestClientModule.java | 74 ++++++++ .../storage/domain/ContainerCDNMetadata.java | 117 ++++++++++++ .../functions/ParseCDNUriFromHeaders.java | 46 +++++ .../ParseContainerCDNMetadataFromHeaders.java | 68 +++++++ .../options/ListCDNContainerOptions.java | 86 +++++++++ .../hpcloud/object/storage/package-info.java | 27 +++ .../HPCloudObjectStorageHeaders.java | 43 +++++ .../storage/reference/package-info.java | 25 +++ .../org.jclouds.providers.ProviderMetadata | 1 + .../HPCloudObjectStorageClientLiveTest.java | 148 +++++++++++++++ ...dObjectStorageBlobIntegrationLiveTest.java | 38 ++++ .../HPCloudObjectStorageBlobLiveTest.java | 30 ++++ ...jectStorageBlobMapIntegrationLiveTest.java | 30 ++++ ...PCloudObjectStorageBlobSignerLiveTest.java | 30 ++++ ...ctStorageContainerIntegrationLiveTest.java | 30 ++++ ...HPCloudObjectStorageContainerLiveTest.java | 30 ++++ ...rageInputStreamMapIntegrationLiveTest.java | 30 ++++ ...jectStorageServiceIntegrationLiveTest.java | 30 ++++ .../HPCloudObjectStorageTestInitializer.java | 32 ++++ ...erCDNMetadataListFromJsonResponseTest.java | 69 +++++++ .../src/test/resources/log4j.xml | 110 ++++++++++++ .../src/test/resources/test_list_cdn.json | 5 + providers/pom.xml | 2 + 38 files changed, 2166 insertions(+) create mode 100644 providers/hpcloud-object-storage/README.txt create mode 100644 providers/hpcloud-object-storage/pom.xml create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/CDNManagement.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClient.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageContextBuilder.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderMetadata.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/HPCloudObjectStorageAsyncBlobStore.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/HPCloudObjectStorageBlobStore.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/EnableCDNAndCache.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/HPCloudObjectStorageObjectToBlobMetadata.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/PublicUriForObjectInfo.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseCDNUriFromHeaders.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataFromHeaders.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/options/ListCDNContainerOptions.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/package-info.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/package-info.java create mode 100644 providers/hpcloud-object-storage/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageTestInitializer.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java create mode 100644 providers/hpcloud-object-storage/src/test/resources/log4j.xml create mode 100644 providers/hpcloud-object-storage/src/test/resources/test_list_cdn.json diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index 38119c9163..6ceb09c1fe 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -204,3 +204,9 @@ virtualbox.propertiesbuilder=org.jclouds.virtualbox.VirtualBoxPropertiesBuilder filesystem.contextbuilder=org.jclouds.filesystem.FilesystemBlobStoreContextBuilder filesystem.propertiesbuilder=org.jclouds.filesystem.FilesystemBlobStorePropertiesBuilder + +hpcloud-compute.contextbuilder=org.jclouds.hpcloud.compute.HPCloudComputeContextBuilder +hpcloud-compute.propertiesbuilder=org.jclouds.hpcloud.compute.HPCloudComputePropertiesBuilder + +hpcloud-object-storage.contextbuilder=org.jclouds.hpcloud.object.storage.HPCloudObjectStorageContextBuilder +hpcloud-object-storage.propertiesbuilder=org.jclouds.hpcloud.object.storage.HPCloudObjectStoragePropertiesBuilder diff --git a/providers/hpcloud-object-storage/README.txt b/providers/hpcloud-object-storage/README.txt new file mode 100644 index 0000000000..9920f494e3 --- /dev/null +++ b/providers/hpcloud-object-storage/README.txt @@ -0,0 +1,25 @@ +==== + Licensed to jclouds, Inc. (jclouds) under one or more + contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. jclouds 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. +==== + +# +# The jclouds API for HP Cloud Object Storage (https://manage.hpcloud.com/pages/build/docs/object-storage/overview). +# +# TODO: Implementation status. +# TODO: Supported features. +# TODO: Usage example. \ No newline at end of file diff --git a/providers/hpcloud-object-storage/pom.xml b/providers/hpcloud-object-storage/pom.xml new file mode 100644 index 0000000000..92802042ce --- /dev/null +++ b/providers/hpcloud-object-storage/pom.xml @@ -0,0 +1,170 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.3.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.provider + hpcloud-object-storage + jclouds HP Cloud Object Storage + jclouds components to access HP Cloud Services Object Storage + bundle + + + org.jclouds.hpcloud.object.storage.blobstore.integration.HPCloudObjectStorageTestInitializer + https://auth.api.rackspacecloud.com + 1.0 + ${test.rackspace.identity} + ${test.rackspace.credential} + + + + + + + org.jclouds.api + swift + ${project.version} + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds.common + openstack-common + ${project.version} + test-jar + test + + + org.jclouds + jclouds-blobstore + ${project.version} + test-jar + test + + + org.jclouds.api + swift + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-log4j + ${project.version} + test + + + log4j + log4j + 1.2.16 + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + + test.hpcloud-object-storage.endpoint + ${test.hpcloud-object-storage.endpoint} + + + test.hpcloud-object-storage.apiversion + ${test.hpcloud-object-storage.apiversion} + + + test.hpcloud-object-storage.identity + ${test.hpcloud-object-storage.identity} + + + test.hpcloud-object-storage.credential + ${test.hpcloud-object-storage.credential} + + + test.initializer + ${test.initializer} + + + jclouds.blobstore.httpstream.url + ${jclouds.blobstore.httpstream.url} + + + jclouds.blobstore.httpstream.md5 + ${jclouds.blobstore.httpstream.md5} + + + + + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId} + org.jclouds.hpcloud.object.storage.*;version="${project.version}" + org.jclouds.*;version="${project.version}",* + + + + + + + + diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/CDNManagement.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/CDNManagement.java new file mode 100644 index 0000000000..903d959924 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/CDNManagement.java @@ -0,0 +1,40 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Represents a component related to HP Cloud Services Content Delivery Network. + * + * @see HP Cloud Object Storage API + * @author Jeremy Daggett + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface CDNManagement { + +} \ No newline at end of file diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java new file mode 100644 index 0000000000..15c4abccb9 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java @@ -0,0 +1,131 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage; + +import java.net.URI; +import java.util.Set; +import java.util.concurrent.ExecutionException; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.HEAD; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound; +import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.object.storage.functions.ParseCDNUriFromHeaders; +import org.jclouds.hpcloud.object.storage.functions.ParseContainerCDNMetadataFromHeaders; +import org.jclouds.hpcloud.object.storage.options.ListCDNContainerOptions; +import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders; +import org.jclouds.openstack.filters.AuthenticateRequest; +import org.jclouds.openstack.swift.CommonSwiftAsyncClient; +import org.jclouds.openstack.swift.Storage; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.SkipEncoding; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to HP Cloud Object Storage via the REST API. + * + *

All commands return a ListenableFuture of the result. Any exceptions incurred + * during processing will be wrapped in an {@link ExecutionException} as documented in + * {@link ListenableFuture#get()}. + * + * @see HPCloudObjectStorageClient + * @see HP Cloud Object Storage API + * @author Jeremy Daggett + */ +@SkipEncoding('/') +@RequestFilters(AuthenticateRequest.class) +@Endpoint(Storage.class) +public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient { + + /** + * @see HPCloudObjectStorageClient#listCDNContainers(ListCDNContainerOptions) + */ + @GET + @Consumes(MediaType.APPLICATION_JSON) + @QueryParams(keys = "format", values = "json") + @Path("/") + @Endpoint(CDNManagement.class) + ListenableFuture> listCDNContainers(ListCDNContainerOptions... options); + + // TODO: Container name is not included in CDN HEAD response headers, so we cannot populate it here. + /** + * @see HPCloudObjectStorageClient#getCDNMetadata(String) + */ + @HEAD + @ResponseParser(ParseContainerCDNMetadataFromHeaders.class) + @ExceptionParser(ReturnNullOnContainerNotFound.class) + @Path("/{container}") + @Endpoint(CDNManagement.class) + ListenableFuture getCDNMetadata(@PathParam("container") String container); + + /** + * @see HPCloudObjectStorageClient#enableCDN(String, long) + */ + @PUT + @Path("/{container}") + @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "True") + @ResponseParser(ParseCDNUriFromHeaders.class) + @Endpoint(CDNManagement.class) + ListenableFuture enableCDN(@PathParam("container") String container, + @HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl); + + /** + * @see HPCloudObjectStorageClient#enableCDN(String) + */ + @PUT + @Path("/{container}") + @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "True") + @ResponseParser(ParseCDNUriFromHeaders.class) + @Endpoint(CDNManagement.class) + ListenableFuture enableCDN(@PathParam("container") String container); + + /** + * @see HPCloudObjectStorageClient#updateCDN(String, long) + */ + @POST + @Path("/{container}") + @ResponseParser(ParseCDNUriFromHeaders.class) + @Endpoint(CDNManagement.class) + ListenableFuture updateCDN(@PathParam("container") String container, + @HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl); + + /** + * @see HPCloudObjectStorageClient#disableCDN(String) + */ + @POST + @Path("/{container}") + @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "False") + @Endpoint(CDNManagement.class) + ListenableFuture disableCDN(@PathParam("container") String container); + +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClient.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClient.java new file mode 100644 index 0000000000..a92474fc16 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClient.java @@ -0,0 +1,63 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage; + +import java.net.URI; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.object.storage.options.ListCDNContainerOptions; +import org.jclouds.openstack.swift.CommonSwiftClient; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides synchronous access to HP Cloud Object Storage via the REST API. + * + *

All commands return a ListenableFuture of the result. Any exceptions incurred + * during processing will be wrapped in an {@link ExecutionException} as documented in + * {@link ListenableFuture#get()}. + * + * @see HPCloudObjectStorageClient + * @see HP Cloud Object Storage API + * @author Jeremy Daggett + */ +@Timeout(duration = 120, timeUnit = TimeUnit.SECONDS) +public interface HPCloudObjectStorageClient extends CommonSwiftClient { + + Set listCDNContainers(ListCDNContainerOptions... options); + + ContainerCDNMetadata getCDNMetadata(String container); + + URI enableCDN(String container, long ttl); + + URI enableCDN(String container); + + URI updateCDN(String container, long ttl); + + boolean disableCDN(String container); + + /*boolean isContainerPublic(String container); + + boolean setContainerACL(String container); + */ +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageContextBuilder.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageContextBuilder.java new file mode 100644 index 0000000000..36ea793ddf --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageContextBuilder.java @@ -0,0 +1,61 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage; + +import java.util.List; +import java.util.Properties; + +import org.jclouds.blobstore.BlobStoreContextBuilder; +import org.jclouds.hpcloud.object.storage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule; +import org.jclouds.hpcloud.object.storage.config.HPCloudObjectStorageRestClientModule; +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; + +import com.google.inject.Injector; +import com.google.inject.Module; + +/** + * Creates {@link HPCloudObjectStorageBlobStore} or {@link Injector} instances based on the most + * commonly requested arguments. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + *

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole, Andrew Newdigate + * @see HPCloudObjectStorageBlobStore + */ +public class HPCloudObjectStorageContextBuilder extends BlobStoreContextBuilder { + + public HPCloudObjectStorageContextBuilder(Properties props) { + super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class, props); + } + + @Override + protected void addContextModule(List modules) { + modules.add(new HPCloudObjectStorageBlobStoreContextModule()); + } + + @Override + protected void addClientModule(List modules) { + modules.add(new HPCloudObjectStorageRestClientModule()); + } +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java new file mode 100644 index 0000000000..3c9f33b4e4 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java @@ -0,0 +1,48 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage; + +import static org.jclouds.Constants.PROPERTY_API_VERSION; +import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; + +import java.util.Properties; + +import org.jclouds.PropertiesBuilder; + +/** + * + * @author Jeremy Daggtt + */ +public class HPCloudObjectStoragePropertiesBuilder extends PropertiesBuilder { + + public HPCloudObjectStoragePropertiesBuilder(Properties properties) { + super(properties); + } + + @Override + protected Properties defaultProperties() { + Properties properties = super.defaultProperties(); + properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); + properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.objects.hpcloudsvc.com/auth/v1.0/"); + properties.setProperty(PROPERTY_API_VERSION, "1.1"); + return properties; + } + +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderMetadata.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderMetadata.java new file mode 100644 index 0000000000..37a3cb714b --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderMetadata.java @@ -0,0 +1,116 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage; + +import com.google.common.collect.ImmutableSet; + +import java.net.URI; +import java.util.Set; + +import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.providers.ProviderMetadata; + +/** + * Implementation of {@link org.jclouds.providers.ProviderMetadata} for HP Cloud Services Object Storage + * + * @author Jeremy Daggett + */ +public class HPCloudObjectStorageProviderMetadata extends BaseProviderMetadata { + + /** + * {@inheritDoc} + */ + @Override + public String getId() { + return "hpcloud-object-storage"; + } + + /** + * {@inheritDoc} + */ + @Override + public String getType() { + return ProviderMetadata.BLOBSTORE_TYPE; + } + + /** + * {@inheritDoc} + */ + @Override + public String getName() { + return "HP Cloud Services Object Storage"; + } + + /** + * {@inheritDoc} + */ + @Override + public String getIdentityName() { + return "Account ID"; + } + + /** + * {@inheritDoc} + */ + @Override + public String getCredentialName() { + return "Access Key"; + } + + /** + * {@inheritDoc} + */ + @Override + public URI getHomepage() { + return URI.create("http://hpcloud.com"); + } + + /** + * {@inheritDoc} + */ + @Override + public URI getConsole() { + return URI.create("https://manage.hpcloud.com/objects/us-west"); + } + + /** + * {@inheritDoc} + */ + @Override + public URI getApiDocumentation() { + return URI.create("https://manage.hpcloud.com/pages/build/docs/object-storage/api"); + } + + /** + * {@inheritDoc} + */ + @Override + public Set getLinkedServices() { + return ImmutableSet.of("hpcloud-object-storage", "hpcloud-compute"); + } + + /** + * {@inheritDoc} + */ + @Override + public Set getIso3166Codes() { + return ImmutableSet.of("US-NV"); + } + +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/HPCloudObjectStorageAsyncBlobStore.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/HPCloudObjectStorageAsyncBlobStore.java new file mode 100644 index 0000000000..025aaba838 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/HPCloudObjectStorageAsyncBlobStore.java @@ -0,0 +1,95 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore; + +import java.util.Set; +import java.util.concurrent.ExecutorService; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Provider; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.functions.BlobToHttpGetOptions; +import org.jclouds.blobstore.options.CreateContainerOptions; +import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; +import org.jclouds.blobstore.util.BlobUtils; +import org.jclouds.collect.Memoized; +import org.jclouds.concurrent.Futures; +import org.jclouds.domain.Location; +import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageAsyncClient; +import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient; +import org.jclouds.hpcloud.object.storage.blobstore.functions.EnableCDNAndCache; +import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; +import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions; +import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; +import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceList; +import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceMetadata; +import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlob; +import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore { + private final EnableCDNAndCache enableCDNAndCache; + + @Inject + protected HPCloudObjectStorageAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, Supplier defaultLocation, + @Memoized Supplier> locations, HPCloudObjectStorageClient sync, HPCloudObjectStorageAsyncClient async, + ContainerToResourceMetadata container2ResourceMd, + BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, + ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, + ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, + Provider fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache) { + super(context, blobUtils, service, defaultLocation, locations, sync, async, container2ResourceMd, + container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd, + blob2ObjectGetOptions, fetchBlobMetadataProvider); + this.enableCDNAndCache = enableCDNAndCache; + } + + @Override + public ListenableFuture createContainerInLocation(Location location, final String container, + CreateContainerOptions options) { + + ListenableFuture returnVal = createContainerInLocation(location, container); + if (options.isPublicRead()) + return Futures.compose(createContainerInLocation(location, container), new Function() { + + @Override + public Boolean apply(Boolean input) { + if (Boolean.TRUE.equals(input)) { + return enableCDNAndCache.apply(container) != null; + } + return false; + } + + }, service); + return returnVal; + } +} \ No newline at end of file diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/HPCloudObjectStorageBlobStore.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/HPCloudObjectStorageBlobStore.java new file mode 100644 index 0000000000..d80b721c6a --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/HPCloudObjectStorageBlobStore.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore; + +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; + +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.functions.BlobToHttpGetOptions; +import org.jclouds.blobstore.options.CreateContainerOptions; +import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata; +import org.jclouds.blobstore.util.BlobUtils; +import org.jclouds.collect.Memoized; +import org.jclouds.domain.Location; +import org.jclouds.hpcloud.object.storage.blobstore.functions.EnableCDNAndCache; +import org.jclouds.openstack.swift.CommonSwiftClient; +import org.jclouds.openstack.swift.blobstore.SwiftBlobStore; +import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions; +import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; +import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceList; +import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceMetadata; +import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlob; +import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata; + +import com.google.common.base.Supplier; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class HPCloudObjectStorageBlobStore extends SwiftBlobStore { + + private EnableCDNAndCache enableCDNAndCache; + + @Inject + protected HPCloudObjectStorageBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier defaultLocation, + @Memoized Supplier> locations, CommonSwiftClient sync, + ContainerToResourceMetadata container2ResourceMd, + BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, + ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, + ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, + Provider fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache) { + super(context, blobUtils, defaultLocation, locations, sync, container2ResourceMd, container2ContainerListOptions, + container2ResourceList, object2Blob, blob2Object, object2BlobMd, blob2ObjectGetOptions, + fetchBlobMetadataProvider); + this.enableCDNAndCache = enableCDNAndCache; + + } + + @Override + public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) { + try { + return createContainerInLocation(location, container); + } finally { + if (options.isPublicRead()) + enableCDNAndCache.apply(container); + } + } +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java new file mode 100644 index 0000000000..8306e22bab --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.config; + +import java.net.URI; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import javax.inject.Singleton; + +import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient; +import org.jclouds.hpcloud.object.storage.blobstore.HPCloudObjectStorageAsyncBlobStore; +import org.jclouds.hpcloud.object.storage.blobstore.HPCloudObjectStorageBlobStore; +import org.jclouds.hpcloud.object.storage.blobstore.functions.HPCloudObjectStorageObjectToBlobMetadata; +import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata; +import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; +import org.jclouds.openstack.swift.blobstore.SwiftBlobStore; +import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; +import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata; + +import com.google.common.base.Function; +import com.google.common.collect.MapMaker; +import com.google.inject.Provides; + +/** + * + * @author Adrian Cole + */ +public class HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreContextModule { + + @Provides + @Singleton + protected Map cdnContainer(final HPCloudObjectStorageClient client) { + return new MapMaker().expireAfterWrite(30, TimeUnit.SECONDS).makeComputingMap(new Function() { + public URI apply(String container) { + ContainerCDNMetadata md = client.getCDNMetadata(container); + return md != null ? md.getCDNUri() : null; + } + + @Override + public String toString() { + return "getCDNMetadata()"; + } + }); + } + + @Override + protected void configure() { + super.configure(); + bind(SwiftBlobStore.class).to(HPCloudObjectStorageBlobStore.class); + bind(SwiftAsyncBlobStore.class).to(HPCloudObjectStorageAsyncBlobStore.class); + bind(ObjectToBlobMetadata.class).to(HPCloudObjectStorageObjectToBlobMetadata.class); + } +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/EnableCDNAndCache.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/EnableCDNAndCache.java new file mode 100644 index 0000000000..3781a696d1 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/EnableCDNAndCache.java @@ -0,0 +1,53 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.functions; + +import java.net.URI; +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient; + +import com.google.common.base.Function; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class EnableCDNAndCache implements Function { + private final Map cdnContainer; + private final HPCloudObjectStorageClient sync; + + @Inject + public EnableCDNAndCache(HPCloudObjectStorageClient sync, Map cdnContainer) { + this.sync = sync; + this.cdnContainer = cdnContainer; + } + + @Override + public URI apply(String input) { + URI uri = sync.enableCDN(input); + cdnContainer.put(input, uri); + return uri; + } + +} \ No newline at end of file diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/HPCloudObjectStorageObjectToBlobMetadata.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/HPCloudObjectStorageObjectToBlobMetadata.java new file mode 100644 index 0000000000..1fd094e48f --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/HPCloudObjectStorageObjectToBlobMetadata.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.functions; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.blobstore.domain.MutableBlobMetadata; +import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy; +import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata; +import org.jclouds.openstack.swift.domain.ObjectInfo; + +/** + * @author Adrian Cole + */ +@Singleton +public class HPCloudObjectStorageObjectToBlobMetadata extends ObjectToBlobMetadata { + private final PublicUriForObjectInfo publicUriForObjectInfo; + + @Inject + public HPCloudObjectStorageObjectToBlobMetadata(IfDirectoryReturnNameStrategy ifDirectoryReturnName, + PublicUriForObjectInfo publicUriForObjectInfo) { + super(ifDirectoryReturnName); + this.publicUriForObjectInfo = publicUriForObjectInfo; + } + + public MutableBlobMetadata apply(ObjectInfo from) { + if (from == null) + return null; + MutableBlobMetadata to = super.apply(from); + to.setPublicUri(publicUriForObjectInfo.apply(from)); + return to; + } +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/PublicUriForObjectInfo.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/PublicUriForObjectInfo.java new file mode 100644 index 0000000000..6b6c5464fa --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/blobstore/functions/PublicUriForObjectInfo.java @@ -0,0 +1,58 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.functions; + +import java.net.URI; +import java.util.Map; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; +import javax.ws.rs.core.UriBuilder; + +import org.jclouds.openstack.swift.domain.ObjectInfo; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class PublicUriForObjectInfo implements Function { + private final Map cdnContainer; + private final Provider uriBuilders; + + @Inject + public PublicUriForObjectInfo(Map cdnContainer, Provider uriBuilders) { + this.cdnContainer = cdnContainer; + this.uriBuilders = uriBuilders; + } + + public URI apply(ObjectInfo from) { + if (from == null) + return null; + try { + return uriBuilders.get().uri(cdnContainer.get(from.getContainer())).path(from.getName()).replaceQuery("") + .build(); + } catch (NullPointerException e) { + // MapMaker constructed maps are not allowed to return null; + return null; + } + } +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java new file mode 100644 index 0000000000..36ee4a3988 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java @@ -0,0 +1,74 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.config; + +import java.net.URI; + +import javax.inject.Singleton; + +import org.jclouds.hpcloud.object.storage.CDNManagement; +import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageAsyncClient; +import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient; +import org.jclouds.http.RequiresHttp; +import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse; +import org.jclouds.openstack.reference.AuthHeaders; +import org.jclouds.openstack.swift.CommonSwiftAsyncClient; +import org.jclouds.openstack.swift.CommonSwiftClient; +import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule; +import org.jclouds.rest.ConfiguresRestClient; + +import com.google.inject.Provides; + +/** + * + * @author Adrian Cole + */ +@ConfiguresRestClient +@RequiresHttp +public class HPCloudObjectStorageRestClientModule extends BaseSwiftRestClientModule { + + public HPCloudObjectStorageRestClientModule() { + super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class); + } + + @Provides + @Singleton + CommonSwiftClient provideCommonSwiftClient(HPCloudObjectStorageClient in) { + return in; + } + + @Provides + @Singleton + CommonSwiftAsyncClient provideCommonSwiftClient(HPCloudObjectStorageAsyncClient in) { + return in; + } + + @Provides + @Singleton + @CDNManagement + protected URI provideCDNUrl(AuthenticationResponse response) { + /* FIXFIX - We need to have an external config for the CDN URI + + if (response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL) == null) { + return URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/"); + } + */ + return response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL); + } +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java new file mode 100644 index 0000000000..d2656d9801 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java @@ -0,0 +1,117 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.domain; + +import java.net.URI; + +/** + * + * @author James Murty + * + */ +public class ContainerCDNMetadata implements Comparable { + + private String name; + private boolean cdn_enabled; + private long ttl; + private URI cdn_uri; + private String referrer_acl; + private String useragent_acl; + private boolean log_retention; + + public ContainerCDNMetadata(String name, boolean cdnEnabled, long ttl, URI cdnUri) { + this.name = name; + this.cdn_enabled = cdnEnabled; + this.ttl = ttl; + this.cdn_uri = cdnUri; + } + + public ContainerCDNMetadata() { + } + + /** + * Beware: The container name is not available from HEAD CDN responses and will be null. return + * the name of the container to which these CDN settings apply. + */ + public String getName() { + return name; + } + + public URI getCDNUri() { + return cdn_uri; + } + + public long getTTL() { + return ttl; + } + + public boolean isCDNEnabled() { + return cdn_enabled; + } + + public int compareTo(ContainerCDNMetadata o) { + if (getName() == null) + return -1; + return (this == o) ? 0 : getName().compareTo(o.getName()); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cdn_uri == null) ? 0 : cdn_uri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ContainerCDNMetadata other = (ContainerCDNMetadata) obj; + if (cdn_uri == null) { + if (other.cdn_uri != null) + return false; + } else if (!cdn_uri.equals(other.cdn_uri)) + return false; + return true; + } + + public String getReferrerACL() { + return referrer_acl; + } + + public String getUseragentACL() { + return useragent_acl; + } + + public boolean isLogRetention() { + return log_retention; + } + + @Override + public String toString() { + return String.format( + "[name=%s, cdn_uri=%s, cdn_enabled=%s, log_retention=%s, referrer_acl=%s, ttl=%s, useragent_acl=%s]", + name, cdn_uri, cdn_enabled, log_retention, referrer_acl, ttl, useragent_acl); + } +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseCDNUriFromHeaders.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseCDNUriFromHeaders.java new file mode 100644 index 0000000000..58df966b25 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseCDNUriFromHeaders.java @@ -0,0 +1,46 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.swift.domain.AccountMetadata; + +import com.google.common.base.Function; + +/** + * This parses {@link AccountMetadata} from HTTP headers. + * + * @author James Murty + */ +public class ParseCDNUriFromHeaders implements Function { + + /** + * parses the http response headers to provide the CDN URI string. + */ + public URI apply(final HttpResponse from) { + String cdnUri = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CDN_URI), + HPCloudObjectStorageHeaders.CDN_URI); + return URI.create(cdnUri); + } +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataFromHeaders.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataFromHeaders.java new file mode 100644 index 0000000000..4509c025fe --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataFromHeaders.java @@ -0,0 +1,68 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.swift.domain.AccountMetadata; +import org.jclouds.rest.InvocationContext; + +import com.google.common.base.Function; + +/** + * This parses {@link AccountMetadata} from HTTP headers. + * + * @author James Murty + */ +public class ParseContainerCDNMetadataFromHeaders implements + Function, InvocationContext { + + private HttpRequest request; + + /** + * parses the http response headers to create a new {@link ContainerCDNMetadata} object. + */ + public ContainerCDNMetadata apply(final HttpResponse from) { + String cdnUri = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CDN_URI), + HPCloudObjectStorageHeaders.CDN_URI); + String cdnTTL = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CDN_TTL), + HPCloudObjectStorageHeaders.CDN_TTL); + String cdnEnabled = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CDN_ENABLED), + HPCloudObjectStorageHeaders.CDN_ENABLED); + if (cdnUri == null) { + // CDN is not, and has never, been enabled for this container. + return null; + } else { + return new ContainerCDNMetadata(request.getEndpoint().getPath(), Boolean + .parseBoolean(cdnEnabled), Long.parseLong(cdnTTL), URI.create(cdnUri)); + } + } + + @Override + public ParseContainerCDNMetadataFromHeaders setContext(HttpRequest request) { + this.request = request; + return this; + } +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/options/ListCDNContainerOptions.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/options/ListCDNContainerOptions.java new file mode 100644 index 0000000000..5c45f5e73e --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/options/ListCDNContainerOptions.java @@ -0,0 +1,86 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.options; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import org.jclouds.http.options.BaseHttpRequestOptions; + + +/** + * Contains options supported in the REST API for the GET CDN containers operation. + */ +public class ListCDNContainerOptions extends BaseHttpRequestOptions { + public static final ListCDNContainerOptions NONE = new ListCDNContainerOptions(); + + public ListCDNContainerOptions enabledOnly() { + queryParameters.put("enabled_only", "true"); + return this; + } + + /** + * Indicates where to begin listing the identity's containers. The list will only include + * containers whose names occur lexicographically after the marker. This is convenient for + * pagination: To get the next page of results use the last container name of the current + * page as the marker. + */ + public ListCDNContainerOptions afterMarker(String marker) { + queryParameters.put("marker", checkNotNull(marker, "marker")); + return this; + } + + + /** + * The maximum number of containers that will be included in the response body. + * The server might return fewer than this many containers, but will not return more. + */ + public ListCDNContainerOptions maxResults(int limit) { + checkState(limit >= 0, "limit must be >= 0"); + checkState(limit <= 10000, "limit must be <= 10000"); + queryParameters.put("limit", Integer.toString(limit)); + return this; + } + + public static class Builder { + + public static ListCDNContainerOptions enabledOnly() { + ListCDNContainerOptions options = new ListCDNContainerOptions(); + return options.enabledOnly(); + } + + /** + * @see ListCDNContainerOptions#afterMarker(String) + */ + public static ListCDNContainerOptions afterMarker(String marker) { + ListCDNContainerOptions options = new ListCDNContainerOptions(); + return options.afterMarker(marker); + } + + /** + * @see ListCDNContainerOptions#limit(int) + */ + public static ListCDNContainerOptions maxResults(int limit) { + ListCDNContainerOptions options = new ListCDNContainerOptions(); + return options.maxResults(limit); + } + + } + +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/package-info.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/package-info.java new file mode 100644 index 0000000000..12f8f21b7d --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/package-info.java @@ -0,0 +1,27 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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. + */ + +/** + * This package contains an HP Cloud Object Storage client implemented by {@link org.jclouds.http.HttpCommandExecutorService} commands. + * + * @see + * + * @author Jeremy Daggett + */ +package org.jclouds.hpcloud.object.storage; diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java new file mode 100644 index 0000000000..17969b2ce8 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java @@ -0,0 +1,43 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.reference; + +import org.jclouds.openstack.swift.reference.SwiftHeaders; + + +/** + * Additional headers specified by HP Cloud Object Storage REST API. + * + * @see + * @author Jeremy Daggett + * + */ +public interface HPCloudObjectStorageHeaders extends SwiftHeaders { + + public static final String CDN_ENABLED = "X-CDN-Enabled"; + public static final String CDN_LOG_RETENTION = "X-Log-Retention"; + public static final String CDN_REFERRER_ACL = "X-Referrer-ACL"; + public static final String CDN_TTL = "X-TTL"; + public static final String CDN_URI = "X-CDN-URI"; + public static final String CDN_USER_AGENT_ACL = "X-User-Agent-ACL"; + + public static final String CONTAINER_READ = "X-Container-Read"; + public static final String CONTAINER_WRITE = "X-Container-Write"; + +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/package-info.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/package-info.java new file mode 100644 index 0000000000..3d650cf66b --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/package-info.java @@ -0,0 +1,25 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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. + */ + +/** + * This package contains properties and reference data used in HP Cloud Object Storage. + * + * @author Jeremy Daggett + */ +package org.jclouds.hpcloud.object.storage.reference; diff --git a/providers/hpcloud-object-storage/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/providers/hpcloud-object-storage/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000000..1869899e4a --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.hpcloud.object.storage.HPCloudObjectStorageProviderMetadata diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java new file mode 100644 index 0000000000..79b7c82863 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java @@ -0,0 +1,148 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.Set; + +import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient; +import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.object.storage.options.ListCDNContainerOptions; +import org.jclouds.openstack.swift.CommonSwiftClientLiveTest; +import org.jclouds.openstack.swift.domain.SwiftObject; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTest { + + @Override + public HPCloudObjectStorageClient getApi() { + return (HPCloudObjectStorageClient) context.getProviderSpecificContext().getApi(); + } + + @Override + protected void testGetObjectContentType(SwiftObject getBlob) { + //lovely new bug.. should be text/plain + assertEquals(getBlob.getInfo().getContentType(), "application/x-www-form-urlencoded"); + } + + @Test + public void testCDNOperations() throws Exception { + final long minimumTTL = 60 * 60; // The minimum TTL is 1 hour + + // Create two new containers for testing + final String containerNameWithCDN = getContainerName(); + final String containerNameWithoutCDN = getContainerName(); + try { + try { + getApi().disableCDN(containerNameWithCDN); + getApi().disableCDN(containerNameWithoutCDN); + } catch (Exception e) { + + } + ContainerCDNMetadata cdnMetadata = null; + + // Enable CDN with PUT for one container + final URI cdnUri = getApi().enableCDN(containerNameWithCDN); + assertTrue(cdnUri != null); + + // Confirm CDN is enabled via HEAD request and has default TTL + cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN); + + assertTrue(cdnMetadata.isCDNEnabled()); + + assertEquals(cdnMetadata.getCDNUri(), cdnUri); + + + cdnMetadata = getApi().getCDNMetadata(containerNameWithoutCDN); + assert cdnMetadata == null || !cdnMetadata.isCDNEnabled() : containerNameWithoutCDN + + " should not have metadata"; + + assert getApi().getCDNMetadata("DoesNotExist") == null; + + // List CDN metadata for containers, and ensure all CDN info is + // available for enabled + // container + Set cdnMetadataList = getApi().listCDNContainers(); + assertTrue(cdnMetadataList.size() >= 1); + + final long initialTTL = cdnMetadata.getTTL(); + assertTrue(cdnMetadataList.contains(new ContainerCDNMetadata(containerNameWithCDN, true, initialTTL, cdnUri))); + + // Test listing with options + cdnMetadataList = getApi().listCDNContainers(ListCDNContainerOptions.Builder.enabledOnly()); + assertTrue(Iterables.all(cdnMetadataList, new Predicate() { + public boolean apply(ContainerCDNMetadata cdnMetadata) { + return cdnMetadata.isCDNEnabled(); + } + })); + + cdnMetadataList = getApi().listCDNContainers( + ListCDNContainerOptions.Builder.afterMarker( + containerNameWithCDN.substring(0, containerNameWithCDN.length() - 1)).maxResults(1)); + assertEquals(cdnMetadataList.size(), 1); + + // Enable CDN with PUT for the same container, this time with a custom + // TTL + long ttl = 4000; + getApi().enableCDN(containerNameWithCDN, ttl); + + cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN); + + assertTrue(cdnMetadata.isCDNEnabled()); + + assertEquals(cdnMetadata.getTTL(), ttl); + + // Check POST by updating TTL settings + ttl = minimumTTL; + getApi().updateCDN(containerNameWithCDN, minimumTTL); + + cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN); + assertTrue(cdnMetadata.isCDNEnabled()); + + assertEquals(cdnMetadata.getTTL(), minimumTTL); + + // Confirm that minimum allowed value for TTL is 3600, lower values are + // ignored. + getApi().updateCDN(containerNameWithCDN, 3599L); + cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN); + assertEquals(cdnMetadata.getTTL(), 3599L); + + // Disable CDN with POST + assertTrue(getApi().disableCDN(containerNameWithCDN)); + + cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN); + assertEquals(cdnMetadata.isCDNEnabled(), false); + } finally { + recycleContainer(containerNameWithCDN); + recycleContainer(containerNameWithoutCDN); + } + } + +} diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java new file mode 100644 index 0000000000..151ad03407 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java @@ -0,0 +1,38 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.integration; + +import org.jclouds.blobstore.domain.Blob; +import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobIntegrationLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = "live") +public class HPCloudObjectStorageBlobIntegrationLiveTest extends SwiftBlobIntegrationLiveTest { + @Override + protected void checkContentDisposition(Blob blob, String contentDisposition) { + assert blob.getPayload().getContentMetadata().getContentDisposition().startsWith(contentDisposition) : blob + .getPayload().getContentMetadata().getContentDisposition(); + assert blob.getMetadata().getContentMetadata().getContentDisposition().startsWith(contentDisposition) : blob + .getMetadata().getContentMetadata().getContentDisposition(); + } + +} diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java new file mode 100644 index 0000000000..7d6fbe68c3 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = { "live" }) +public class HPCloudObjectStorageBlobLiveTest extends SwiftBlobLiveTest { + +} diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java new file mode 100644 index 0000000000..241b758035 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobMapIntegrationLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = "live") +public class HPCloudObjectStorageBlobMapIntegrationLiveTest extends SwiftBlobMapIntegrationLiveTest { + +} diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java new file mode 100644 index 0000000000..6eb63b4622 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobSignerLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = { "live" }) +public class HPCloudObjectStorageBlobSignerLiveTest extends SwiftBlobSignerLiveTest { + +} diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java new file mode 100644 index 0000000000..a251c48a60 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftContainerIntegrationLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = "live") +public class HPCloudObjectStorageContainerIntegrationLiveTest extends SwiftContainerIntegrationLiveTest { + +} diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java new file mode 100644 index 0000000000..4acb6e7986 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.integration; + +import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = { "live" }) +public class HPCloudObjectStorageContainerLiveTest extends BaseContainerLiveTest { + +} diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java new file mode 100644 index 0000000000..049cb3f145 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftInputStreamMapIntegrationLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = "live") +public class HPCloudObjectStorageInputStreamMapIntegrationLiveTest extends SwiftInputStreamMapIntegrationLiveTest { + +} diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java new file mode 100644 index 0000000000..f2d438efe1 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftServiceIntegrationLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = "live") +public class HPCloudObjectStorageServiceIntegrationLiveTest extends SwiftServiceIntegrationLiveTest { + +} diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageTestInitializer.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageTestInitializer.java new file mode 100644 index 0000000000..4fb4fc3675 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/blobstore/integration/HPCloudObjectStorageTestInitializer.java @@ -0,0 +1,32 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftTestInitializer; + +/** + * @author Jeremy Daggett + */ +public class HPCloudObjectStorageTestInitializer extends SwiftTestInitializer { + + public HPCloudObjectStorageTestInitializer() { + provider = "hpcloud-object-storage"; + } + +} diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java new file mode 100644 index 0000000000..40aa7b2ed5 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java @@ -0,0 +1,69 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.functions; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.util.Set; +import java.util.SortedSet; + +import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.io.Payloads; +import org.jclouds.json.config.GsonModule; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSortedSet; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code ParseContainerCDNMetadataListFromJsonResponse} + * + * @author Jeremy Daggett + */ +@Test(groups = "unit") +public class ParseContainerCDNMetadataListFromJsonResponseTest { + Injector i = Guice.createInjector(new GsonModule()); + + @Test + public void testApplyInputStream() { + + InputStream is = getClass().getResourceAsStream("/test_list_cdn.json"); + + Set expects = ImmutableSortedSet.of( + new ContainerCDNMetadata("hpcloud-blobstore.testCDNOperationsContainerWithCDN", false, 3600, + URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")), + new ContainerCDNMetadata("hpcloud-blobstore5", true, 28800, + URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/")), + new ContainerCDNMetadata("hpcloud-cfcdnint.testCDNOperationsContainerWithCDN", false, 3600, + URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/"))); + + ParseJson> parser = i.getInstance(Key + .get(new TypeLiteral>>() { + })); + + assertEquals(parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is))), expects); + } +} diff --git a/providers/hpcloud-object-storage/src/test/resources/log4j.xml b/providers/hpcloud-object-storage/src/test/resources/log4j.xml new file mode 100644 index 0000000000..12f6512542 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/resources/log4j.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/providers/hpcloud-object-storage/src/test/resources/test_list_cdn.json b/providers/hpcloud-object-storage/src/test/resources/test_list_cdn.json new file mode 100644 index 0000000000..48e3c3759c --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/resources/test_list_cdn.json @@ -0,0 +1,5 @@ +[ +{"name":"hpcloud-blobstore.testCDNOperationsContainerWithCDN","cdn_enabled":"false","ttl":3600,"cdn_uri":"https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/","referrer_acl":"","useragent_acl":"", "log_retention":"false"}, +{"name":"hpcloud-blobstore5","cdn_enabled":"true","ttl":28800,"cdn_uri":"https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/","referrer_acl":"","useragent_acl":"", "log_retention":"false"}, +{"name":"hpcloud-cfcdnint.testCDNOperationsContainerWithCDN","cdn_enabled":"false","ttl":3600,"cdn_uri":"https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/","referrer_acl":"","useragent_acl":"", "log_retention":"false"} +] \ No newline at end of file diff --git a/providers/pom.xml b/providers/pom.xml index 4f4c5af23a..c467195fa7 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -65,5 +65,7 @@ aws-cloudwatch go2cloud-jhb1 softlayer + + hpcloud-object-storage From 89925e5142261b773875b10c8d952dfeed9e0866 Mon Sep 17 00:00:00 2001 From: Jeremy Daggett Date: Tue, 8 Nov 2011 11:29:09 -0800 Subject: [PATCH 4/8] Updated properties to reflect hpcloud --- providers/hpcloud-object-storage/pom.xml | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/providers/hpcloud-object-storage/pom.xml b/providers/hpcloud-object-storage/pom.xml index 92802042ce..764ae42ab8 100644 --- a/providers/hpcloud-object-storage/pom.xml +++ b/providers/hpcloud-object-storage/pom.xml @@ -34,17 +34,11 @@ bundle - org.jclouds.hpcloud.object.storage.blobstore.integration.HPCloudObjectStorageTestInitializer - https://auth.api.rackspacecloud.com - 1.0 - ${test.rackspace.identity} - ${test.rackspace.credential} - - + org.jclouds.hpcloud.object.storage.blobstore.integration.HPCloudObjectStorageTestInitializer + ${test.hpcloud-object-storage.endpoint} + 1.1 + ${test.hpcloud-object-storage.identity} + ${test.hpcloud-object-storage.credential} From 0441fc4bdfcc8631ebfff4d584c87a7b03a5f0b8 Mon Sep 17 00:00:00 2001 From: Jeremy Daggett Date: Tue, 8 Nov 2011 13:31:38 -0800 Subject: [PATCH 5/8] Should extend SwiftPropertiesBuilder instead of PropertiesBuilder --- .../object/storage/HPCloudObjectStoragePropertiesBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java index 3c9f33b4e4..753204b323 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java @@ -24,13 +24,13 @@ import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; import java.util.Properties; -import org.jclouds.PropertiesBuilder; +import org.jclouds.openstack.swift.SwiftPropertiesBuilder; /** * * @author Jeremy Daggtt */ -public class HPCloudObjectStoragePropertiesBuilder extends PropertiesBuilder { +public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilder { public HPCloudObjectStoragePropertiesBuilder(Properties properties) { super(properties); From d1c2b9a0b46fafe30e3c766ab2f8a19174fda802 Mon Sep 17 00:00:00 2001 From: Jeremy Daggett Date: Fri, 11 Nov 2011 11:22:04 -0800 Subject: [PATCH 6/8] CDN support changes: fixed parsing issues, initial change for externalizing CDN URL --- allblobstore/pom.xml | 5 +++ jeremy.txt | 1 - .../HPCloudObjectStorageAsyncClient.java | 3 +- ...HPCloudObjectStoragePropertiesBuilder.java | 11 ++++-- .../HPCloudObjectStorageRestClientModule.java | 15 +++++--- .../storage/domain/ContainerCDNMetadata.java | 3 ++ .../HPCloudObjectStorageConstants.java | 34 +++++++++++++++++ .../HPCloudObjectStorageHeaders.java | 6 +-- .../HPCloudObjectStorageClientLiveTest.java | 19 ++++++++-- .../HPCloudObjectStorageProviderTest.java | 37 +++++++++++++++++++ 10 files changed, 115 insertions(+), 19 deletions(-) delete mode 100644 jeremy.txt create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageConstants.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderTest.java diff --git a/allblobstore/pom.xml b/allblobstore/pom.xml index e034fc9f35..42308dd280 100644 --- a/allblobstore/pom.xml +++ b/allblobstore/pom.xml @@ -100,5 +100,10 @@ filesystem ${project.version} + + org.jclouds.provider + hpcloud-object-storage + ${project.version} + diff --git a/jeremy.txt b/jeremy.txt deleted file mode 100644 index 5d31edcb2d..0000000000 --- a/jeremy.txt +++ /dev/null @@ -1 +0,0 @@ -README HP \ No newline at end of file diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java index 15c4abccb9..ed793ebee7 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java @@ -77,7 +77,6 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient @Endpoint(CDNManagement.class) ListenableFuture> listCDNContainers(ListCDNContainerOptions... options); - // TODO: Container name is not included in CDN HEAD response headers, so we cannot populate it here. /** * @see HPCloudObjectStorageClient#getCDNMetadata(String) */ @@ -122,7 +121,7 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient /** * @see HPCloudObjectStorageClient#disableCDN(String) */ - @POST + @PUT @Path("/{container}") @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "False") @Endpoint(CDNManagement.class) diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java index 753204b323..5a48afedb2 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java @@ -21,14 +21,15 @@ package org.jclouds.hpcloud.object.storage; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; +import static org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageConstants.PROPERTY_CDN_ENDPOINT; import java.util.Properties; +import org.jclouds.openstack.OpenStackAuthAsyncClient; import org.jclouds.openstack.swift.SwiftPropertiesBuilder; /** - * - * @author Jeremy Daggtt + * @author Jeremy Daggett */ public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilder { @@ -40,8 +41,10 @@ public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilde protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); - properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.objects.hpcloudsvc.com/auth/v1.0/"); - properties.setProperty(PROPERTY_API_VERSION, "1.1"); + properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.objects.hpcloudsvc.com/auth/"); + properties.setProperty(PROPERTY_API_VERSION, OpenStackAuthAsyncClient.VERSION); + properties.setProperty(PROPERTY_CDN_ENDPOINT, ""); + return properties; } diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java index 36ee4a3988..2675c9fe57 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java @@ -20,6 +20,7 @@ package org.jclouds.hpcloud.object.storage.config; import java.net.URI; +import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.hpcloud.object.storage.CDNManagement; @@ -33,6 +34,8 @@ import org.jclouds.openstack.swift.CommonSwiftClient; import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule; import org.jclouds.rest.ConfiguresRestClient; +import com.google.common.annotations.VisibleForTesting; +import com.google.inject.Inject; import com.google.inject.Provides; /** @@ -42,7 +45,7 @@ import com.google.inject.Provides; @ConfiguresRestClient @RequiresHttp public class HPCloudObjectStorageRestClientModule extends BaseSwiftRestClientModule { - + public HPCloudObjectStorageRestClientModule() { super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class); } @@ -63,12 +66,14 @@ public class HPCloudObjectStorageRestClientModule extends BaseSwiftRestClientMod @Singleton @CDNManagement protected URI provideCDNUrl(AuthenticationResponse response) { - /* FIXFIX - We need to have an external config for the CDN URI + @Named("jclouds.hpcloud-object-storage.cdn.endpoint") + @VisibleForTesting + String cdnEndpoint = "https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/"; if (response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL) == null) { - return URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/"); - } - */ + return URI.create(cdnEndpoint); + } + return response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL); } } diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java index d2656d9801..203bd6679c 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java @@ -20,6 +20,8 @@ package org.jclouds.hpcloud.object.storage.domain; import java.net.URI; +import com.google.gson.annotations.SerializedName; + /** * * @author James Murty @@ -30,6 +32,7 @@ public class ContainerCDNMetadata implements Comparable { private String name; private boolean cdn_enabled; private long ttl; + @SerializedName("x-cdn-uri") private URI cdn_uri; private String referrer_acl; private String useragent_acl; diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageConstants.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageConstants.java new file mode 100644 index 0000000000..88ba53d09b --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageConstants.java @@ -0,0 +1,34 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.reference; + + +/** + * Configuration properties and constants used by HP Cloud Object Storage. + * + * @author Jeremy Daggett + */ +public interface HPCloudObjectStorageConstants { + + /** + * The CDN Endpoint property + */ + public static final String PROPERTY_CDN_ENDPOINT = "jclouds.hpcloud-object-storage.cdn.endpoint"; + +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java index 17969b2ce8..d0726970e8 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java @@ -30,11 +30,11 @@ import org.jclouds.openstack.swift.reference.SwiftHeaders; */ public interface HPCloudObjectStorageHeaders extends SwiftHeaders { - public static final String CDN_ENABLED = "X-CDN-Enabled"; + public static final String CDN_ENABLED = "X-Cdn-Enabled"; public static final String CDN_LOG_RETENTION = "X-Log-Retention"; public static final String CDN_REFERRER_ACL = "X-Referrer-ACL"; - public static final String CDN_TTL = "X-TTL"; - public static final String CDN_URI = "X-CDN-URI"; + public static final String CDN_TTL = "X-Ttl"; + public static final String CDN_URI = "X-Cdn-Uri"; public static final String CDN_USER_AGENT_ACL = "X-User-Agent-ACL"; public static final String CONTAINER_READ = "X-Container-Read"; diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java index 79b7c82863..e83957ae56 100644 --- a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java @@ -40,7 +40,7 @@ import com.google.common.collect.Iterables; */ @Test(groups = "live") public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTest { - + @Override public HPCloudObjectStorageClient getApi() { return (HPCloudObjectStorageClient) context.getProviderSpecificContext().getApi(); @@ -48,10 +48,19 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes @Override protected void testGetObjectContentType(SwiftObject getBlob) { - //lovely new bug.. should be text/plain - assertEquals(getBlob.getInfo().getContentType(), "application/x-www-form-urlencoded"); + assertEquals(getBlob.getInfo().getContentType(), "application/unknown"); } + @Test + public void testListCDNContainers() { + try { + Set cdnMetadataList = getApi().listCDNContainers(); + System.err.println(cdnMetadataList); + } catch (Exception e) { + e.printStackTrace(); + } + } + @Test public void testCDNOperations() throws Exception { final long minimumTTL = 60 * 60; // The minimum TTL is 1 hour @@ -64,7 +73,7 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes getApi().disableCDN(containerNameWithCDN); getApi().disableCDN(containerNameWithoutCDN); } catch (Exception e) { - + e.printStackTrace(); } ContainerCDNMetadata cdnMetadata = null; @@ -139,6 +148,8 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN); assertEquals(cdnMetadata.isCDNEnabled(), false); + } catch (Exception e) { + e.printStackTrace(); } finally { recycleContainer(containerNameWithCDN); recycleContainer(containerNameWithoutCDN); diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderTest.java new file mode 100644 index 0000000000..8c1608b9df --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderTest.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage; + +import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.ProviderMetadata; +import org.testng.annotations.Test; + +/** + * The HPCloudObjectStorageProviderTest tests the {@link org.jclouds.hpcloud.object.storage.HPCloudObjectStorageProviderMetadata} class. + * + * @author Jeremy Daggett + */ +@Test(groups = "unit", testName = "HPCloudObjectStorageProviderTest") +public class HPCloudObjectStorageProviderTest extends BaseProviderMetadataTest { + + public HPCloudObjectStorageProviderTest() { + super(new HPCloudObjectStorageProviderMetadata(), ProviderMetadata.BLOBSTORE_TYPE); + } + +} \ No newline at end of file From d151e6bee40a0d8f4879d7cee3930afc1068332b Mon Sep 17 00:00:00 2001 From: Jeremy Daggett Date: Mon, 14 Nov 2011 21:25:54 -0800 Subject: [PATCH 7/8] Updated files from other git repo for Swift public ACL --- .../swift/domain/ContainerMetadata.java | 65 ++++++++++---- ...arseContainerListFromJsonResponseTest.java | 4 +- .../swift/internal/StubSwiftAsyncClient.java | 2 +- .../HPCloudObjectStorageAsyncClient.java | 22 ++++- .../storage/HPCloudObjectStorageClient.java | 16 ++-- .../HPCloudObjectStorageRestClientModule.java | 1 - .../ParseContainerCDNMetadataFromHeaders.java | 11 ++- .../ParseContainerMetadataFromHeaders.java | 90 +++++++++++++++++++ .../options/CreateContainerOptions.java | 82 +++++++++++++++++ 9 files changed, 264 insertions(+), 29 deletions(-) create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerMetadataFromHeaders.java create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/options/CreateContainerOptions.java diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/domain/ContainerMetadata.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/domain/ContainerMetadata.java index 9934f70397..7fb36a64f8 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/domain/ContainerMetadata.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/domain/ContainerMetadata.java @@ -18,6 +18,14 @@ */ package org.jclouds.openstack.swift.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Map; + +import com.google.common.collect.Maps; +import com.google.gson.annotations.SerializedName; + /** * @@ -28,14 +36,20 @@ public class ContainerMetadata implements Comparable { private String name; private long count; private long bytes; + @SerializedName("X-Container-Read") + private String readACL; + //private Map metadata = Maps.newLinkedHashMap(); + public ContainerMetadata() { } - public ContainerMetadata(String name, long count, long bytes) { - setName(name); - setBytes(bytes); - setCount(count); + public ContainerMetadata(String name, long count, long bytes, String readACL) { + this.name = name; + this.count = count; + this.bytes = bytes; + this.readACL = readACL; + //this.metadata = metadata; } public long getCount() { @@ -43,25 +57,40 @@ public class ContainerMetadata implements Comparable { } public void setCount(long count) { - this.count = count; + this.count = count; + } + + public String getName() { + return name; } public void setName(String name) { this.name = name; } - - public String getName() { - return name; - } - - public void setBytes(long bytes) { - this.bytes = bytes; - } - + public long getBytes() { return bytes; } - + + public void setBytes(long bytes) { + this.bytes = bytes; + } + + public boolean isPublic() { + if (readACL == null) + return false; + return readACL.equals(".r:*,.rlistings"); + } + + public void setReadACL(String readACL) { + this.readACL = readACL; + + } + /*public Map getMetadata() { + return metadata; + } + */ + @Override public int hashCode() { final int prime = 31; @@ -99,4 +128,10 @@ public class ContainerMetadata implements Comparable { return (this == o) ? 0 : getName().compareTo(o.getName()); } + @Override + public String toString() { + return "ContainerMetadata [name=" + name + ", count=" + count + ", bytes=" + + bytes + ", isPublic=" + isPublic() + "]"; + } + } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/functions/ParseContainerListFromJsonResponseTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/functions/ParseContainerListFromJsonResponseTest.java index 874b38cc21..0c873558e3 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/functions/ParseContainerListFromJsonResponseTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/functions/ParseContainerListFromJsonResponseTest.java @@ -51,8 +51,8 @@ public class ParseContainerListFromJsonResponseTest { InputStream is = Strings2 .toInputStream("[ {\"name\":\"test_container_1\",\"count\":2,\"bytes\":78}, {\"name\":\"test_container_2\",\"count\":1,\"bytes\":17} ] "); - List expects = ImmutableList.of(new ContainerMetadata("test_container_1", 2, 78), - new ContainerMetadata("test_container_2", 1, 17)); + List expects = ImmutableList.of(new ContainerMetadata("test_container_1", 2, 78, null), + new ContainerMetadata("test_container_2", 1, 17, null)); ParseJson> parser = i.getInstance(Key .get(new TypeLiteral>>() { })); diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java index 977ab650c5..d0605a909f 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java @@ -146,7 +146,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient { return immediateFuture(Sets.newHashSet(Iterables.transform(blobStore.getContainerToBlobs().keySet(), new Function() { public ContainerMetadata apply(String name) { - return new ContainerMetadata(name, -1, -1); + return new ContainerMetadata(name, -1, -1, null); } }))); } diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java index ed793ebee7..63f7864724 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java @@ -36,11 +36,14 @@ import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound; import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata; import org.jclouds.hpcloud.object.storage.functions.ParseCDNUriFromHeaders; import org.jclouds.hpcloud.object.storage.functions.ParseContainerCDNMetadataFromHeaders; +import org.jclouds.hpcloud.object.storage.functions.ParseContainerMetadataFromHeaders; +import org.jclouds.hpcloud.object.storage.options.CreateContainerOptions; import org.jclouds.hpcloud.object.storage.options.ListCDNContainerOptions; import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders; import org.jclouds.openstack.filters.AuthenticateRequest; import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.Storage; +import org.jclouds.openstack.swift.domain.ContainerMetadata; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.Headers; @@ -76,7 +79,7 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient @Path("/") @Endpoint(CDNManagement.class) ListenableFuture> listCDNContainers(ListCDNContainerOptions... options); - + /** * @see HPCloudObjectStorageClient#getCDNMetadata(String) */ @@ -86,6 +89,23 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient @Path("/{container}") @Endpoint(CDNManagement.class) ListenableFuture getCDNMetadata(@PathParam("container") String container); + + /** + * @see HPCloudObjectStorageClient#getCDNMetadata(String) + */ + @HEAD + @ResponseParser(ParseContainerMetadataFromHeaders.class) + @ExceptionParser(ReturnNullOnContainerNotFound.class) + @Path("/{container}") + ListenableFuture getContainerMetadata(@PathParam("container") String container); + + /** + * @see HPCloudObjectStorageClient#createContainer + */ + @PUT + @Path("/{container}") + ListenableFuture createContainer(@PathParam("container") String container, + CreateContainerOptions... options); /** * @see HPCloudObjectStorageClient#enableCDN(String, long) diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClient.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClient.java index a92474fc16..d8118a3e4a 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClient.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClient.java @@ -25,8 +25,10 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.object.storage.options.CreateContainerOptions; import org.jclouds.hpcloud.object.storage.options.ListCDNContainerOptions; import org.jclouds.openstack.swift.CommonSwiftClient; +import org.jclouds.openstack.swift.domain.ContainerMetadata; import com.google.common.util.concurrent.ListenableFuture; @@ -43,11 +45,15 @@ import com.google.common.util.concurrent.ListenableFuture; */ @Timeout(duration = 120, timeUnit = TimeUnit.SECONDS) public interface HPCloudObjectStorageClient extends CommonSwiftClient { - + + boolean createContainer(String container, CreateContainerOptions... options); + Set listCDNContainers(ListCDNContainerOptions... options); ContainerCDNMetadata getCDNMetadata(String container); - + + ContainerMetadata getContainerMetadata(String container); + URI enableCDN(String container, long ttl); URI enableCDN(String container); @@ -55,9 +61,5 @@ public interface HPCloudObjectStorageClient extends CommonSwiftClient { URI updateCDN(String container, long ttl); boolean disableCDN(String container); - - /*boolean isContainerPublic(String container); - - boolean setContainerACL(String container); - */ + } diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java index 2675c9fe57..83cdc6381e 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java @@ -35,7 +35,6 @@ import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule; import org.jclouds.rest.ConfiguresRestClient; import com.google.common.annotations.VisibleForTesting; -import com.google.inject.Inject; import com.google.inject.Provides; /** diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataFromHeaders.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataFromHeaders.java index 4509c025fe..43a237cb5d 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataFromHeaders.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerCDNMetadataFromHeaders.java @@ -19,7 +19,9 @@ package org.jclouds.hpcloud.object.storage.functions; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Lists.newArrayList; +import java.util.List; import java.net.URI; import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata; @@ -30,6 +32,8 @@ import org.jclouds.openstack.swift.domain.AccountMetadata; import org.jclouds.rest.InvocationContext; import com.google.common.base.Function; +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; /** * This parses {@link AccountMetadata} from HTTP headers. @@ -52,10 +56,13 @@ public class ParseContainerCDNMetadataFromHeaders implements String cdnEnabled = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CDN_ENABLED), HPCloudObjectStorageHeaders.CDN_ENABLED); if (cdnUri == null) { - // CDN is not, and has never, been enabled for this container. + // CDN is not enabled for this container. return null; } else { - return new ContainerCDNMetadata(request.getEndpoint().getPath(), Boolean + // just need the name from the path + List parts = newArrayList(Splitter.on('/').split(request.getEndpoint().getPath())); + + return new ContainerCDNMetadata(parts.get(parts.size()-1), Boolean .parseBoolean(cdnEnabled), Long.parseLong(cdnTTL), URI.create(cdnUri)); } } diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerMetadataFromHeaders.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerMetadataFromHeaders.java new file mode 100644 index 0000000000..9e701e1f21 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/functions/ParseContainerMetadataFromHeaders.java @@ -0,0 +1,90 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.functions; + +import static com.google.common.base.Preconditions.checkArgument; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.jclouds.blobstore.reference.BlobStoreConstants; +import org.jclouds.date.DateService; +import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.swift.domain.ContainerMetadata; +import org.jclouds.rest.InvocationContext; +import org.jclouds.rest.internal.GeneratedHttpRequest; + +import com.google.common.base.Function; + +/** + * This parses @{link {@link org.jclouds.hpcloud.object.storage.domain.ContainerMetadata} from + * HTTP headers. + * + * @author Jeremy Daggett + */ +public class ParseContainerMetadataFromHeaders implements Function, + InvocationContext { + + private final DateService dateParser; + private final String metadataPrefix; + private GeneratedHttpRequest request; + + @Inject + public ParseContainerMetadataFromHeaders(DateService dateParser, + @Named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX) String metadataPrefix) { + this.dateParser = dateParser; + this.metadataPrefix = metadataPrefix; + } + + public ContainerMetadata apply(HttpResponse from) { + ContainerMetadata to = new ContainerMetadata(); + + to.setName(request.getArgs().get(0).toString()); + + to.setReadACL(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CONTAINER_READ)); + + to.setBytes(new Long(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CONTAINER_BYTES_USED))); + to.setCount(new Long(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CONTAINER_OBJECT_COUNT))); + + //addUserMetadataTo(from, to); + + return to; + } + + /* + @VisibleForTesting + void addUserMetadataTo(HttpResponse from, ContainerMetadata metadata) { + for (Entry header : from.getHeaders().entries()) { + if (header.getKey() != null && header.getKey().startsWith(metadataPrefix)) + metadata.getMetadata().put((header.getKey().substring(metadataPrefix.length())).toLowerCase(), + header.getValue()); + } + } + */ + + @Override + public ParseContainerMetadataFromHeaders setContext(HttpRequest request) { + checkArgument(request instanceof GeneratedHttpRequest, "note this handler requires a GeneratedHttpRequest"); + this.request = (GeneratedHttpRequest) request; + return this; + } + +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/options/CreateContainerOptions.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/options/CreateContainerOptions.java new file mode 100644 index 0000000000..9abd4097f1 --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/options/CreateContainerOptions.java @@ -0,0 +1,82 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.options; + +import java.util.Map.Entry; + +import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders; +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.collect.Multimap; + +/** + * Contains options supported in the REST API for the Create Container operation. + * + * This specifically enabes the Swift ACL for public reads using the 'X-Container-Read' + * header. This should be refactored into the Swift API. + * + * @author Jeremy Daggett + */ +public class CreateContainerOptions extends BaseHttpRequestOptions { + public static final CreateContainerOptions NONE = new CreateContainerOptions(); + + /** + * A name-value pair to associate with the container as metadata. + */ + public CreateContainerOptions withMetadata(Multimap metadata) { + for (Entry entry : metadata.entries()) { + System.err.println(entry.getValue()); + if (entry.getKey().startsWith(HPCloudObjectStorageHeaders.USER_METADATA_PREFIX)) + this.headers.put(entry.getKey(), entry.getValue()); + else + this.headers.put(HPCloudObjectStorageHeaders.USER_METADATA_PREFIX + entry.getKey(), + entry.getValue()); + } + return this; + } + + + /** + * Indicates whether a container may be accessed publicly + */ + public CreateContainerOptions withPublicAccess() { + this.headers.put(HPCloudObjectStorageHeaders.CONTAINER_READ, ".r:*,.rlistings"); + return this; + } + + public static class Builder { + + /** + * @see CreateContainerOptions#withPublicAccess + */ + public static CreateContainerOptions withPublicAccess() { + CreateContainerOptions options = new CreateContainerOptions(); + return options.withPublicAccess(); + } + + /** + * @see CreateContainerOptions#withMetadata(Multimap) + */ + public static CreateContainerOptions withMetadata(Multimap metadata) { + CreateContainerOptions options = new CreateContainerOptions(); + return (CreateContainerOptions) options.withMetadata(metadata); + } + + } +} From 86217ed60c7c2f622566408380e879e098d24a65 Mon Sep 17 00:00:00 2001 From: Jeremy Daggett Date: Mon, 14 Nov 2011 21:28:25 -0800 Subject: [PATCH 8/8] Added test file for CreateContainerOptions --- .../options/CreateContainerOptionsTest.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/options/CreateContainerOptionsTest.java diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/options/CreateContainerOptionsTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/options/CreateContainerOptionsTest.java new file mode 100644 index 0000000000..f0f2f8fbb6 --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/options/CreateContainerOptionsTest.java @@ -0,0 +1,70 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.object.storage.options; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMultimap; + +/** + * Tests behavior of {@code CreateContainerOptions} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class CreateContainerOptionsTest { + + public void testPublicAccess() { + CreateContainerOptions options = new CreateContainerOptions().withPublicAccess(); + assertEquals(ImmutableList.of(".r:*,.rlistings"), options.buildRequestHeaders().get( + "X-Container-Read")); + } + + public void testPublicAccessStatic() { + CreateContainerOptions options = CreateContainerOptions.Builder.withPublicAccess(); + assertEquals(ImmutableList.of(".r:*,.rlistings"), options.buildRequestHeaders().get( + "X-Container-Read")); + } + + public void testMetadata() { + CreateContainerOptions options = new CreateContainerOptions().withMetadata(ImmutableMultimap + .of("test", "foo")); + assertEquals(ImmutableList.of("foo"), options.buildRequestHeaders().get( + HPCloudObjectStorageHeaders.USER_METADATA_PREFIX + "test")); + } + + public void testMetadataAlreadyPrefixed() { + CreateContainerOptions options = new CreateContainerOptions().withMetadata(ImmutableMultimap + .of(HPCloudObjectStorageHeaders.USER_METADATA_PREFIX + "test", "foo")); + assertEquals(ImmutableList.of("foo"), options.buildRequestHeaders().get( + HPCloudObjectStorageHeaders.USER_METADATA_PREFIX + "test")); + } + + public void testMetadataStatic() { + CreateContainerOptions options = CreateContainerOptions.Builder + .withMetadata(ImmutableMultimap.of("test", "foo")); + assertEquals(ImmutableList.of("foo"), options.buildRequestHeaders().get( + HPCloudObjectStorageHeaders.USER_METADATA_PREFIX + "test")); + } + +}