From 1e60ab4d1f36e939f7ca77d4ffb519a7bacf4750 Mon Sep 17 00:00:00 2001 From: Mike Arnold Date: Tue, 20 Mar 2012 11:37:26 -0500 Subject: [PATCH 1/4] initial create of hpcloud-objectstorage to labs project --- core/src/main/resources/rest.properties | 3 + .../HPCloudComputePropertiesBuilder.java | 8 +- labs/hpcloud-objectstorage/README.txt | 25 +++ labs/hpcloud-objectstorage/pom.xml | 169 ++++++++++++++++++ .../hpcloud/objectstorage/CDNManagement.java | 40 +++++ .../HPCloudObjectStorageAsyncClient.java | 160 +++++++++++++++++ .../HPCloudObjectStorageClient.java | 73 ++++++++ .../HPCloudObjectStorageContextBuilder.java | 61 +++++++ ...HPCloudObjectStoragePropertiesBuilder.java | 51 ++++++ .../HPCloudObjectStorageProviderMetadata.java | 116 ++++++++++++ .../HPCloudObjectStorageAsyncBlobStore.java | 95 ++++++++++ .../HPCloudObjectStorageBlobStore.java | 80 +++++++++ ...udObjectStorageBlobStoreContextModule.java | 97 ++++++++++ .../functions/EnableCDNAndCache.java | 53 ++++++ ...loudObjectStorageObjectToBlobMetadata.java | 53 ++++++ .../functions/PublicUriForObjectInfo.java | 63 +++++++ .../HPCloudObjectStorageRestClientModule.java | 113 ++++++++++++ .../domain/ContainerCDNMetadata.java | 120 +++++++++++++ .../functions/ParseCDNUriFromHeaders.java | 46 +++++ .../ParseContainerCDNMetadataFromHeaders.java | 74 ++++++++ .../ParseContainerMetadataFromHeaders.java | 77 ++++++++ .../options/CreateContainerOptions.java | 81 +++++++++ .../options/ListCDNContainerOptions.java | 86 +++++++++ .../hpcloud/objectstorage/package-info.java | 27 +++ .../HPCloudObjectStorageConstants.java | 32 ++++ .../HPCloudObjectStorageHeaders.java | 40 +++++ .../objectstorage/reference/package-info.java | 25 +++ .../services/HPExtensionBlockStore.java | 41 +++++ .../hpcloud/services/HPExtensionCDN.java | 41 +++++ .../services/HPExtentionServiceType.java | 43 +++++ .../org.jclouds.providers.ProviderMetadata | 1 + .../HPCloudObjectStorageClientLiveTest.java | 145 +++++++++++++++ .../HPCloudObjectStorageProviderTest.java | 37 ++++ ...dObjectStorageBlobIntegrationLiveTest.java | 38 ++++ .../HPCloudObjectStorageBlobLiveTest.java | 30 ++++ ...jectStorageBlobMapIntegrationLiveTest.java | 30 ++++ ...PCloudObjectStorageBlobSignerLiveTest.java | 30 ++++ ...ctStorageContainerIntegrationLiveTest.java | 30 ++++ ...HPCloudObjectStorageContainerLiveTest.java | 38 ++++ ...rageInputStreamMapIntegrationLiveTest.java | 30 ++++ ...jectStorageServiceIntegrationLiveTest.java | 38 ++++ .../HPCloudObjectStorageTestInitializer.java | 32 ++++ ...erCDNMetadataListFromJsonResponseTest.java | 69 +++++++ .../options/CreateContainerOptionsTest.java | 70 ++++++++ .../src/test/resources/log4j.xml | 110 ++++++++++++ .../src/test/resources/test_list_cdn.json | 5 + labs/pom.xml | 2 + 47 files changed, 2724 insertions(+), 4 deletions(-) create mode 100644 labs/hpcloud-objectstorage/README.txt create mode 100644 labs/hpcloud-objectstorage/pom.xml create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/CDNManagement.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageAsyncClient.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClient.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageContextBuilder.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/EnableCDNAndCache.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/HPCloudObjectStorageObjectToBlobMetadata.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/PublicUriForObjectInfo.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/ContainerCDNMetadata.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseCDNUriFromHeaders.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataFromHeaders.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerMetadataFromHeaders.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptions.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/options/ListCDNContainerOptions.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/package-info.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/HPCloudObjectStorageConstants.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/HPCloudObjectStorageHeaders.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/package-info.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtensionBlockStore.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtensionCDN.java create mode 100644 labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtentionServiceType.java create mode 100644 labs/hpcloud-objectstorage/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageTestInitializer.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptionsTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/resources/log4j.xml create mode 100644 labs/hpcloud-objectstorage/src/test/resources/test_list_cdn.json diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index ec8471e594..cba4d5208d 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -243,5 +243,8 @@ filesystem.propertiesbuilder=org.jclouds.filesystem.FilesystemBlobStorePropertie hpcloud-objectstorage-lvs.contextbuilder=org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasContextBuilder hpcloud-objectstorage-lvs.propertiesbuilder=org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasPropertiesBuilder +hpcloud-objectstorage.contextbuilder=org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageContextBuilder +hpcloud-objectstorage.propertiesbuilder=org.jclouds.hpcloud.objectstorage.HPCloudObjectStoragePropertiesBuilder + hpcloud-compute.contextbuilder=org.jclouds.openstack.nova.v1_1.NovaContextBuilder hpcloud-compute.propertiesbuilder=org.jclouds.hpcloud.compute.HPCloudComputePropertiesBuilder diff --git a/labs/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputePropertiesBuilder.java b/labs/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputePropertiesBuilder.java index e252d09b6f..3a1981e964 100644 --- a/labs/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputePropertiesBuilder.java +++ b/labs/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputePropertiesBuilder.java @@ -18,13 +18,13 @@ */ package org.jclouds.hpcloud.compute; -import static org.jclouds.Constants.PROPERTY_ENDPOINT; -import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; +import org.jclouds.openstack.nova.v1_1.NovaPropertiesBuilder; +import org.jclouds.openstack.nova.v1_1.reference.NovaConstants; import java.util.Properties; -import org.jclouds.openstack.nova.v1_1.NovaPropertiesBuilder; -import org.jclouds.openstack.nova.v1_1.reference.NovaConstants; +import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; /** * diff --git a/labs/hpcloud-objectstorage/README.txt b/labs/hpcloud-objectstorage/README.txt new file mode 100644 index 0000000000..9920f494e3 --- /dev/null +++ b/labs/hpcloud-objectstorage/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/labs/hpcloud-objectstorage/pom.xml b/labs/hpcloud-objectstorage/pom.xml new file mode 100644 index 0000000000..682ee878d9 --- /dev/null +++ b/labs/hpcloud-objectstorage/pom.xml @@ -0,0 +1,169 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.5.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.labs + hpcloud-objectstorage + jclouds HP Cloud Object Storage + jclouds components to access HP Cloud Services Object Storage + bundle + + + org.jclouds.hpcloud.objectstorage.blobstore.integration.HPCloudObjectStorageTestInitializer + https://region-a.geo-1.identity.hpcloudsvc.com:35357 + 1.0 + + FIXME_IDENTITY + FIXME_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-objectstorage.endpoint + ${test.hpcloud-objectstorage.endpoint} + + + test.hpcloud-objectstorage.api-version + ${test.hpcloud-objectstorage.api-version} + + + test.hpcloud-objectstorage.build-version + ${test.hpcloud-objectstorage.build-version} + + + test.hpcloud-objectstorage.identity + ${test.hpcloud-objectstorage.identity} + + + test.hpcloud-objectstorage.credential + ${test.hpcloud-objectstorage.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.objectstorage*;version="${project.version}" + org.jclouds*;version="${project.version}",* + + + + + + + + diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/CDNManagement.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/CDNManagement.java new file mode 100644 index 0000000000..b6cc630e8e --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/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.objectstorage; + +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/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageAsyncClient.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageAsyncClient.java new file mode 100644 index 0000000000..753f0bd44a --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageAsyncClient.java @@ -0,0 +1,160 @@ +/** + * 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.objectstorage; + +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.objectstorage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.functions.ParseCDNUriFromHeaders; +import org.jclouds.hpcloud.objectstorage.functions.ParseContainerCDNMetadataFromHeaders; +import org.jclouds.hpcloud.objectstorage.functions.ParseContainerMetadataFromHeaders; +import org.jclouds.hpcloud.objectstorage.options.CreateContainerOptions; +import org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions; +import org.jclouds.hpcloud.objectstorage.reference.HPCloudObjectStorageHeaders; +import org.jclouds.hpcloud.services.HPExtensionCDN; +import org.jclouds.openstack.filters.AuthenticateRequest; +import org.jclouds.openstack.services.ObjectStore; +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; +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.annotations.Beta; +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 java.util.concurrent.ExecutionException} as documented in + * {@link ListenableFuture#get()}. + * + * @see HPCloudObjectStorageClient + * @see HP Cloud Object Storage API + * @author Jeremy Daggett + */ +@SkipEncoding('/') +@RequestFilters(AuthenticateRequest.class) +@Endpoint(ObjectStore.class) +public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient { + + /** + * @see HPCloudObjectStorageClient#getCDNMetadata(String) + */ + @Beta + @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#listCDNContainers(ListCDNContainerOptions) + */ + @Beta + @GET + @Consumes(MediaType.APPLICATION_JSON) + @QueryParams(keys = "format", values = "json") + @Path("/") + @Endpoint(HPExtensionCDN.class) + ListenableFuture> listCDNContainers(ListCDNContainerOptions... options); + + /** + * @see HPCloudObjectStorageClient#getCDNMetadata(String) + */ + @Beta + @HEAD + @ResponseParser(ParseContainerCDNMetadataFromHeaders.class) + @ExceptionParser(ReturnNullOnContainerNotFound.class) + @Path("/{container}") + @Endpoint(HPExtensionCDN.class) + ListenableFuture getCDNMetadata(@PathParam("container") String container); + + /** + * @see HPCloudObjectStorageClient#enableCDN(String, long) + */ + @Beta + @PUT + @Path("/{container}") + @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "True") + @ResponseParser(ParseCDNUriFromHeaders.class) + @Endpoint(HPExtensionCDN.class) + ListenableFuture enableCDN(@PathParam("container") String container, + @HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl); + + /** + * @see HPCloudObjectStorageClient#enableCDN(String) + */ + @Beta + @PUT + @Path("/{container}") + @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "True") + @ResponseParser(ParseCDNUriFromHeaders.class) + @Endpoint(HPExtensionCDN.class) + ListenableFuture enableCDN(@PathParam("container") String container); + + /** + * @see HPCloudObjectStorageClient#updateCDN(String, long) + */ + @Beta + @POST + @Path("/{container}") + @ResponseParser(ParseCDNUriFromHeaders.class) + @Endpoint(HPExtensionCDN.class) + ListenableFuture updateCDN(@PathParam("container") String container, + @HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl); + + /** + * @see HPCloudObjectStorageClient#disableCDN(String) + */ + @Beta + @PUT + @Path("/{container}") + @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "False") + @Endpoint(HPExtensionCDN.class) + ListenableFuture disableCDN(@PathParam("container") String container); + +} diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClient.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClient.java new file mode 100644 index 0000000000..ce9dbb85d9 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClient.java @@ -0,0 +1,73 @@ +/** + * 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.objectstorage; + +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.objectstorage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.options.CreateContainerOptions; +import org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions; +import org.jclouds.openstack.swift.CommonSwiftClient; +import org.jclouds.openstack.swift.domain.ContainerMetadata; + +import com.google.common.annotations.Beta; +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 java.util.concurrent.ExecutionException} as documented in {@link ListenableFuture#get()}. + * + * @see org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient + * @see HP Cloud Object + * Storage API + * @author Jeremy Daggett + */ +@Timeout(duration = 120, timeUnit = TimeUnit.SECONDS) +public interface HPCloudObjectStorageClient extends CommonSwiftClient { + + boolean createContainer(String container, CreateContainerOptions... options); + + ContainerMetadata getContainerMetadata(String container); + + @Beta + Set listCDNContainers(ListCDNContainerOptions... options); + + @Beta + ContainerCDNMetadata getCDNMetadata(String container); + + @Beta + URI enableCDN(String container, long ttl); + + @Beta + URI enableCDN(String container); + + @Beta + URI updateCDN(String container, long ttl); + + @Beta + boolean disableCDN(String container); + +} diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageContextBuilder.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageContextBuilder.java new file mode 100644 index 0000000000..79d8d76d48 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/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.objectstorage; + +import java.util.List; +import java.util.Properties; + +import org.jclouds.blobstore.BlobStoreContextBuilder; +import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule; +import org.jclouds.hpcloud.objectstorage.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/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java new file mode 100644 index 0000000000..4a85630c93 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java @@ -0,0 +1,51 @@ +/** + * 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.objectstorage; + +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.openstack.keystone.v2_0.config.KeystoneProperties; +import org.jclouds.openstack.services.ServiceType; +import org.jclouds.openstack.swift.SwiftPropertiesBuilder; + +/** + * @author Jeremy Daggett + */ +public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilder { + + public HPCloudObjectStoragePropertiesBuilder(Properties properties) { + super(properties); + } + + @Override + protected Properties defaultProperties() { + Properties properties = super.defaultProperties(); + properties.setProperty(KeystoneProperties.SERVICE_TYPE, ServiceType.OBJECT_STORE); + properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); + properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:"); + properties.setProperty(PROPERTY_API_VERSION, "2.0"); + + return properties; + } + +} diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java new file mode 100644 index 0000000000..661debdaab --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/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.objectstorage; + +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-objectstorage-lvs"; + } + + /** + * {@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 "email:tenantId"; + } + + /** + * {@inheritDoc} + */ + @Override + public String getCredentialName() { + return "API 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("TODO"); + } + + /** + * {@inheritDoc} + */ + @Override + public Set getLinkedServices() { + return ImmutableSet.of("hpcloud-compute", "hpcloud-objectstorage"); + } + + /** + * {@inheritDoc} + */ + @Override + public Set getIso3166Codes() { + return ImmutableSet.of("US-NV"); + } + +} diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageAsyncBlobStore.java new file mode 100644 index 0000000000..ed305371de --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.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.objectstorage.HPCloudObjectStorageAsyncClient; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; +import org.jclouds.hpcloud.objectstorage.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; + } +} diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java new file mode 100644 index 0000000000..378e52541b --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobStore.java @@ -0,0 +1,80 @@ +/** + * 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.objectstorage.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.objectstorage.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/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java new file mode 100644 index 0000000000..9895aa2c3f --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/config/HPCloudObjectStorageBlobStoreContextModule.java @@ -0,0 +1,97 @@ +/** + * 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.objectstorage.blobstore.config; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; +import org.jclouds.hpcloud.objectstorage.blobstore.HPCloudObjectStorageAsyncBlobStore; +import org.jclouds.hpcloud.objectstorage.blobstore.HPCloudObjectStorageBlobStore; +import org.jclouds.hpcloud.objectstorage.blobstore.functions.HPCloudObjectStorageObjectToBlobMetadata; +import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata; +import org.jclouds.http.HttpResponseException; +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.annotations.Beta; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.inject.Provides; + +import org.jclouds.logging.Logger; + +/** + * + * @author Adrian Cole + */ +public class HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreContextModule { + + @Beta + @Singleton + public static final class GetCDNMetadata extends CacheLoader { + @Resource + protected Logger logger = Logger.NULL; + + private final HPCloudObjectStorageClient client; + + @Inject + public GetCDNMetadata(HPCloudObjectStorageClient client) { + this.client = client; + } + + @Override + public URI load(String container) { + try { + ContainerCDNMetadata md = client.getCDNMetadata(container); + return md != null ? md.getCDNUri() : null; + } catch (HttpResponseException e) { + // TODO: this is due to beta status + logger.trace("couldn't get cdn metadata for %s: %s", container, e.getMessage()); + return null; + } + } + + @Override + public String toString() { + return "getCDNMetadata()"; + } + } + + @Provides + @Singleton + protected LoadingCache cdnContainer(GetCDNMetadata loader) { + return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(loader); + } + + @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/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/EnableCDNAndCache.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/EnableCDNAndCache.java new file mode 100644 index 0000000000..1453332078 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.blobstore.functions; + +import java.net.URI; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; + +import com.google.common.base.Function; +import com.google.common.cache.LoadingCache; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class EnableCDNAndCache implements Function { + private final LoadingCache cdnContainer; + private final HPCloudObjectStorageClient sync; + + @Inject + public EnableCDNAndCache(HPCloudObjectStorageClient sync, LoadingCache 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/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/HPCloudObjectStorageObjectToBlobMetadata.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/HPCloudObjectStorageObjectToBlobMetadata.java new file mode 100644 index 0000000000..385fe01483 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/HPCloudObjectStorageObjectToBlobMetadata.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.objectstorage.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/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/PublicUriForObjectInfo.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/PublicUriForObjectInfo.java new file mode 100644 index 0000000000..3f8978af90 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/PublicUriForObjectInfo.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.objectstorage.blobstore.functions; + +import java.net.URI; + +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; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; + +/** + * @author Adrian Cole + */ +@Singleton +public class PublicUriForObjectInfo implements Function { + private final LoadingCache cdnContainer; + private final Provider uriBuilders; + + @Inject + public PublicUriForObjectInfo(LoadingCache 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.getUnchecked(from.getContainer())).path(from.getName()).replaceQuery("") + .build(); + } catch (CacheLoader.InvalidCacheLoadException e) { + // nulls not permitted from cache loader + return null; + } catch (NullPointerException e) { + // nulls not permitted from cache loader + // TODO this shouldn't occur when the above exception is reliably presented + return null; + } + } +} \ No newline at end of file diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java new file mode 100644 index 0000000000..c8cc3a1058 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java @@ -0,0 +1,113 @@ +/** + * 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.objectstorage.config; + +import static org.jclouds.util.Suppliers2.getLastValueInMap; + +import java.net.URI; + +import javax.inject.Singleton; + +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncClient; +import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; +import org.jclouds.hpcloud.services.HPExtensionCDN; +import org.jclouds.hpcloud.services.HPExtentionServiceType; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.RequiresHttp; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; +import org.jclouds.json.config.GsonModule.DateAdapter; +import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import org.jclouds.location.suppliers.RegionIdToURISupplier; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; +import org.jclouds.openstack.services.ServiceType; +import org.jclouds.openstack.swift.CommonSwiftAsyncClient; +import org.jclouds.openstack.swift.CommonSwiftClient; +import org.jclouds.openstack.swift.Storage; +import org.jclouds.openstack.swift.config.SwiftObjectModule; +import org.jclouds.openstack.swift.handlers.ParseSwiftErrorFromHttpResponse; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.annotations.ApiVersion; +import org.jclouds.rest.config.RestClientModule; + +import com.google.common.base.Supplier; +import com.google.inject.Provides; + +/** + * + * @author Adrian Cole + */ +@ConfiguresRestClient +@RequiresHttp +public class HPCloudObjectStorageRestClientModule extends + RestClientModule { + + private final KeystoneAuthenticationModule authModule; + + public HPCloudObjectStorageRestClientModule() { + this(new KeystoneAuthenticationModule()); + } + + public HPCloudObjectStorageRestClientModule(KeystoneAuthenticationModule authModule) { + super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class); + this.authModule = authModule; + } + + protected void configure() { + install(authModule); + install(new SwiftObjectModule()); + bind(DateAdapter.class).to(Iso8601DateAdapter.class); + super.configure(); + } + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSwiftErrorFromHttpResponse.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseSwiftErrorFromHttpResponse.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseSwiftErrorFromHttpResponse.class); + } + + @Provides + @Singleton + CommonSwiftClient provideCommonSwiftClient(HPCloudObjectStorageClient in) { + return in; + } + + @Provides + @Singleton + CommonSwiftAsyncClient provideCommonSwiftClient(HPCloudObjectStorageAsyncClient in) { + return in; + } + + @Provides + @Singleton + @HPExtensionCDN + protected Supplier provideCDNUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) { + return getLastValueInMap(factory.createForApiTypeAndVersion(HPExtentionServiceType.CDN, apiVersion)); + } + + @Provides + @Singleton + @Storage + protected Supplier provideStorageUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) { + return getLastValueInMap(factory.createForApiTypeAndVersion(ServiceType.OBJECT_STORE, apiVersion)); + } + +} diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/ContainerCDNMetadata.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/ContainerCDNMetadata.java new file mode 100644 index 0000000000..14949d6a82 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/domain/ContainerCDNMetadata.java @@ -0,0 +1,120 @@ +/** + * 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.objectstorage.domain; + +import java.net.URI; + +import com.google.gson.annotations.SerializedName; + +/** + * + * @author James Murty + * + */ +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; + 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/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseCDNUriFromHeaders.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseCDNUriFromHeaders.java new file mode 100644 index 0000000000..96993e5835 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import org.jclouds.hpcloud.objectstorage.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); + } +} \ No newline at end of file diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataFromHeaders.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataFromHeaders.java new file mode 100644 index 0000000000..77c124a202 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataFromHeaders.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.objectstorage.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Lists.newArrayList; + +import java.net.URI; +import java.util.List; + +import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.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; +import com.google.common.base.Splitter; + +/** + * 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 enabled for this container. + return null; + } else { + // 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)); + } + } + + @Override + public ParseContainerCDNMetadataFromHeaders setContext(HttpRequest request) { + this.request = request; + return this; + } +} \ No newline at end of file diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerMetadataFromHeaders.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerMetadataFromHeaders.java new file mode 100644 index 0000000000..33cecddf46 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerMetadataFromHeaders.java @@ -0,0 +1,77 @@ +/** + * 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.objectstorage.functions; + +import static com.google.common.base.Preconditions.checkArgument; + +import java.util.Map.Entry; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.swift.domain.ContainerMetadata; +import org.jclouds.openstack.swift.reference.SwiftHeaders; +import org.jclouds.rest.InvocationContext; +import org.jclouds.rest.internal.GeneratedHttpRequest; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Function; + +/** + * This parses @{link {@link org.jclouds.hpcloud.objectstorage.domain.ContainerMetadata} from + * HTTP headers. + * + * @author Jeremy Daggett + */ +public class ParseContainerMetadataFromHeaders implements Function, + InvocationContext { + private GeneratedHttpRequest request; + + public ContainerMetadata apply(HttpResponse from) { + ContainerMetadata to = new ContainerMetadata(); + + to.setName(request.getArgs().get(0).toString()); + + to.setReadACL(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_READ)); + + to.setBytes(new Long(from.getFirstHeaderOrNull(SwiftHeaders.CONTAINER_BYTES_USED))); + to.setCount(new Long(from.getFirstHeaderOrNull(SwiftHeaders.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(SwiftHeaders.CONTAINER_METADATA_PREFIX)) + metadata.getMetadata().put((header.getKey().substring(SwiftHeaders.CONTAINER_METADATA_PREFIX.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/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptions.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptions.java new file mode 100644 index 0000000000..29a293bb52 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptions.java @@ -0,0 +1,81 @@ +/** + * 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.objectstorage.options; + +import java.util.Map; +import java.util.Map.Entry; + +import org.jclouds.http.options.BaseHttpRequestOptions; +import org.jclouds.openstack.swift.reference.SwiftHeaders; + +/** + * 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(Map metadata) { + for (Entry entry : metadata.entrySet()) { + if (entry.getKey().startsWith(SwiftHeaders.CONTAINER_METADATA_PREFIX)) { + this.headers.put(entry.getKey(), entry.getValue()); + } else { + this.headers.put(SwiftHeaders.CONTAINER_METADATA_PREFIX + entry.getKey(), + entry.getValue()); + } + } + return this; + } + + + /** + * Indicates whether a container may be accessed publicly + */ + public CreateContainerOptions withPublicAccess() { + this.headers.put(SwiftHeaders.CONTAINER_READ, ".r:*,.rlistings"); + return this; + } + + public static class Builder { + + /** + * @see org.jclouds.hpcloud.objectstorage.options.CreateContainerOptions#withPublicAccess + */ + public static CreateContainerOptions withPublicAccess() { + CreateContainerOptions options = new CreateContainerOptions(); + return options.withPublicAccess(); + } + + /** + * @see org.jclouds.hpcloud.objectstorage.options.CreateContainerOptions#withMetadata(Multimap) + */ + public static CreateContainerOptions withMetadata(Map metadata) { + CreateContainerOptions options = new CreateContainerOptions(); + return (CreateContainerOptions) options.withMetadata(metadata); + } + + } +} diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/options/ListCDNContainerOptions.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/options/ListCDNContainerOptions.java new file mode 100644 index 0000000000..13e2c92e41 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.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 org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions#afterMarker(String) + */ + public static ListCDNContainerOptions afterMarker(String marker) { + ListCDNContainerOptions options = new ListCDNContainerOptions(); + return options.afterMarker(marker); + } + + /** + * @see org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions#limit(int) + */ + public static ListCDNContainerOptions maxResults(int limit) { + ListCDNContainerOptions options = new ListCDNContainerOptions(); + return options.maxResults(limit); + } + + } + +} diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/package-info.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/package-info.java new file mode 100644 index 0000000000..cc22fc6ea1 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/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.objectstorage; diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/HPCloudObjectStorageConstants.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/HPCloudObjectStorageConstants.java new file mode 100644 index 0000000000..957a38d545 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/HPCloudObjectStorageConstants.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.objectstorage.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-objectstorage-lvs.cdn.endpoint"; +} diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/HPCloudObjectStorageHeaders.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/HPCloudObjectStorageHeaders.java new file mode 100644 index 0000000000..c553baefba --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/HPCloudObjectStorageHeaders.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.objectstorage.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"; + +} diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/package-info.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/reference/package-info.java new file mode 100644 index 0000000000..f2ceb68f04 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.reference; diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtensionBlockStore.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtensionBlockStore.java new file mode 100644 index 0000000000..333aa3ad5c --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtensionBlockStore.java @@ -0,0 +1,41 @@ +/** + * 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.services; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * HP Extension Block Store Service + * + * @author Jeremy Daggett + * @see + * @see HPExtensionServiceType#BLOCK_STORE + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface HPExtensionBlockStore { + +} \ No newline at end of file diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtensionCDN.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtensionCDN.java new file mode 100644 index 0000000000..5922838983 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtensionCDN.java @@ -0,0 +1,41 @@ +/** + * 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.services; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * CDN + * + * @author Jeremy Daggett + * @see + * @see HPExtensionServiceType#CDN + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface HPExtensionCDN { + +} \ No newline at end of file diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtentionServiceType.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtentionServiceType.java new file mode 100644 index 0000000000..311117a390 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/services/HPExtentionServiceType.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, Name 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.services; + +import org.jclouds.openstack.services.ServiceType; + +/** + * An HP Extension Service, such as CDN, or Block Store Service. + * A service provides one or more endpoints through which users can access resources and perform + * (presumably useful) operations. + * + * @author Jeremy Daggett + * @see + */ +public interface HPExtentionServiceType extends ServiceType { + /** + * CDN + */ + public static final String CDN = "hpext:cdn"; + /** + * Block Storage + */ + public static final String BLOCK_STORE = "hpext:block-store"; + +} \ No newline at end of file diff --git a/labs/hpcloud-objectstorage/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/labs/hpcloud-objectstorage/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000000..f937926f6b --- /dev/null +++ b/labs/hpcloud-objectstorage/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageProviderMetadata diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java new file mode 100644 index 0000000000..0c394d4139 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java @@ -0,0 +1,145 @@ +/** + * 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.objectstorage.lvs; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.Set; + +import org.jclouds.hpcloud.objectstorage.lvs.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.lvs.options.ListCDNContainerOptions; +import org.jclouds.openstack.swift.CommonSwiftClientLiveTest; +import org.jclouds.openstack.swift.domain.SwiftObject; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "HPCloudObjectStorageLasVegasClientLiveTest") +public class HPCloudObjectStorageLasVegasClientLiveTest extends CommonSwiftClientLiveTest { + + @Override + public HPCloudObjectStorageLasVegasClient getApi() { + return (HPCloudObjectStorageLasVegasClient) context.getProviderSpecificContext().getApi(); + } + + @Override + protected void testGetObjectContentType(SwiftObject getBlob) { + assertEquals(getBlob.getInfo().getContentType(), "application/x-www-form-urlencoded"); + } + + // CDN service due to go live Q1 2012 + @Test(enabled = true) + 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) { + e.printStackTrace(); + } + 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 FIXFIX 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); + } catch (Exception e) { + e.printStackTrace(); + } finally { + recycleContainer(containerNameWithCDN); + recycleContainer(containerNameWithoutCDN); + } + } + +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java new file mode 100644 index 0000000000..c068997061 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.lvs; + +import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.ProviderMetadata; +import org.testng.annotations.Test; + +/** + * The HPCloudObjectStorageLasVegasProviderTest tests the {@link org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasProviderMetadata} class. + * + * @author Jeremy Daggett + */ +@Test(groups = "unit", testName = "HPCloudObjectStorageLasVegasProviderTest") +public class HPCloudObjectStorageLasVegasProviderTest extends BaseProviderMetadataTest { + + public HPCloudObjectStorageLasVegasProviderTest() { + super(new HPCloudObjectStorageLasVegasProviderMetadata(), ProviderMetadata.BLOBSTORE_TYPE); + } + +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java new file mode 100644 index 0000000000..8778fda3b1 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.lvs.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 HPCloudObjectStorageLasVegasBlobIntegrationLiveTest 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/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java new file mode 100644 index 0000000000..4be59d2247 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.lvs.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = { "live" }) +public class HPCloudObjectStorageLasVegasBlobLiveTest extends SwiftBlobLiveTest { + +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java new file mode 100644 index 0000000000..ef113697ed --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.lvs.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobMapIntegrationLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = "live") +public class HPCloudObjectStorageLasVegasBlobMapIntegrationLiveTest extends SwiftBlobMapIntegrationLiveTest { + +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java new file mode 100644 index 0000000000..f4c40f806b --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.lvs.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobSignerLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = { "live" }) +public class HPCloudObjectStorageLasVegasBlobSignerLiveTest extends SwiftBlobSignerLiveTest { + +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java new file mode 100644 index 0000000000..8917ef071a --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.lvs.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftContainerIntegrationLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = "live") +public class HPCloudObjectStorageLasVegasContainerIntegrationLiveTest extends SwiftContainerIntegrationLiveTest { + +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java new file mode 100644 index 0000000000..1e765bca0f --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.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.objectstorage.lvs.blobstore.integration; + +import java.io.IOException; +import java.net.MalformedURLException; + +import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = { "live" }) +public class HPCloudObjectStorageLasVegasContainerLiveTest extends BaseContainerLiveTest { + + @Test(enabled = false) + //@Test(expectedExceptions=UnsupportedOperationException.class) + public void testPublicAccess() throws MalformedURLException, InterruptedException, IOException { + super.testPublicAccess(); + } +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java new file mode 100644 index 0000000000..415f58aa32 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.lvs.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftInputStreamMapIntegrationLiveTest; +import org.testng.annotations.Test; + +/** + * @author Jeremy Daggett + */ +@Test(groups = "live") +public class HPCloudObjectStorageLasVegasInputStreamMapIntegrationLiveTest extends SwiftInputStreamMapIntegrationLiveTest { + +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java new file mode 100644 index 0000000000..50cfade7eb --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.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.objectstorage.lvs.blobstore.integration; + +import java.util.Set; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftServiceIntegrationLiveTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * @author Jeremy Daggett + */ +@Test(groups = "live") +public class HPCloudObjectStorageLasVegasServiceIntegrationLiveTest extends SwiftServiceIntegrationLiveTest { + @Override + protected Set getIso3166Codes() { + return ImmutableSet. of("US-NV"); + } + +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageTestInitializer.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageTestInitializer.java new file mode 100644 index 0000000000..5e4407d44a --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.lvs.blobstore.integration; + +import org.jclouds.openstack.swift.blobstore.integration.SwiftTestInitializer; + +/** + * @author Jeremy Daggett + */ +public class HPCloudObjectStorageLasVegasTestInitializer extends SwiftTestInitializer { + + public HPCloudObjectStorageLasVegasTestInitializer() { + provider = "hpcloud-objectstorage-lvs"; + } + +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java new file mode 100644 index 0000000000..87719f7964 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.lvs.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.objectstorage.lvs.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/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptionsTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptionsTest.java new file mode 100644 index 0000000000..4548eaaeaa --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/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.objectstorage.lvs.options; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.openstack.swift.reference.SwiftHeaders; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +/** + * 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(ImmutableMap + .of("test", "foo")); + assertEquals(ImmutableList.of("foo"), options.buildRequestHeaders().get( + SwiftHeaders.CONTAINER_METADATA_PREFIX + "test")); + } + + public void testMetadataAlreadyPrefixed() { + CreateContainerOptions options = new CreateContainerOptions().withMetadata(ImmutableMap + .of(SwiftHeaders.CONTAINER_METADATA_PREFIX + "test", "foo")); + assertEquals(ImmutableList.of("foo"), options.buildRequestHeaders().get( + SwiftHeaders.CONTAINER_METADATA_PREFIX + "test")); + } + + public void testMetadataStatic() { + CreateContainerOptions options = CreateContainerOptions.Builder + .withMetadata(ImmutableMap.of("test", "foo")); + assertEquals(ImmutableList.of("foo"), options.buildRequestHeaders().get( + SwiftHeaders.CONTAINER_METADATA_PREFIX + "test")); + } + +} diff --git a/labs/hpcloud-objectstorage/src/test/resources/log4j.xml b/labs/hpcloud-objectstorage/src/test/resources/log4j.xml new file mode 100644 index 0000000000..12f6512542 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/resources/log4j.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/labs/hpcloud-objectstorage/src/test/resources/test_list_cdn.json b/labs/hpcloud-objectstorage/src/test/resources/test_list_cdn.json new file mode 100644 index 0000000000..48e3c3759c --- /dev/null +++ b/labs/hpcloud-objectstorage/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/labs/pom.xml b/labs/pom.xml index 8583a8824d..285406d415 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -40,5 +40,7 @@ elb aws-elb savvis-symphonyvpdc + hpcloud-objectstorage + hpcloud-compute From 094c106f8785742db450b0b630a53a9e7788a50d Mon Sep 17 00:00:00 2001 From: Mike Arnold Date: Tue, 20 Mar 2012 11:44:50 -0500 Subject: [PATCH 2/4] adding port number for identity service --- .../objectstorage/HPCloudObjectStoragePropertiesBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java index 4a85630c93..ddc16fbfa6 100644 --- a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java @@ -42,7 +42,7 @@ public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilde Properties properties = super.defaultProperties(); properties.setProperty(KeystoneProperties.SERVICE_TYPE, ServiceType.OBJECT_STORE); properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); - properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:"); + properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:35357"); properties.setProperty(PROPERTY_API_VERSION, "2.0"); return properties; From b01a88cf8b5912edcb44a3bbf3d38df65417e49e Mon Sep 17 00:00:00 2001 From: Mike Arnold Date: Tue, 20 Mar 2012 11:46:04 -0500 Subject: [PATCH 3/4] changing a few more references to vegas --- .../jclouds/hpcloud/compute/HPCloudComputeProviderMetadata.java | 2 +- .../objectstorage/HPCloudObjectStorageProviderMetadata.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/labs/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderMetadata.java b/labs/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderMetadata.java index 37e5f808cb..46a61786ab 100644 --- a/labs/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderMetadata.java +++ b/labs/hpcloud-compute/src/main/java/org/jclouds/hpcloud/compute/HPCloudComputeProviderMetadata.java @@ -103,7 +103,7 @@ public class HPCloudComputeProviderMetadata extends BaseProviderMetadata { */ @Override public Set getLinkedServices() { - return ImmutableSet.of("hpcloud-compute", "hpcloud-objectstorage-lvs"); + return ImmutableSet.of("hpcloud-compute", "hpcloud-objectstorage"); } /** diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java index 661debdaab..056cbb7b42 100644 --- a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderMetadata.java @@ -38,7 +38,7 @@ public class HPCloudObjectStorageProviderMetadata extends BaseProviderMetadata { */ @Override public String getId() { - return "hpcloud-objectstorage-lvs"; + return "hpcloud-objectstorage"; } /** From f1bbfde1b28eea1793d5252f3d93a9c6d58cd89b Mon Sep 17 00:00:00 2001 From: Mike Arnold Date: Tue, 20 Mar 2012 15:26:11 -0500 Subject: [PATCH 4/4] fixing tests after changing provider and adding Expect test for the provider --- ...HPCloudObjectStoragePropertiesBuilder.java | 14 +-- .../HPCloudObjectStorageRestClientModule.java | 23 +++-- .../HPCloudObjectStorageClientLiveTest.java | 14 +-- .../HPCloudObjectStorageProviderTest.java | 12 +-- ...dObjectStorageBlobIntegrationLiveTest.java | 4 +- .../HPCloudObjectStorageBlobLiveTest.java | 4 +- ...jectStorageBlobMapIntegrationLiveTest.java | 4 +- ...PCloudObjectStorageBlobSignerLiveTest.java | 4 +- ...ctStorageContainerIntegrationLiveTest.java | 4 +- ...HPCloudObjectStorageContainerLiveTest.java | 4 +- ...rageInputStreamMapIntegrationLiveTest.java | 4 +- ...jectStorageServiceIntegrationLiveTest.java | 4 +- .../HPCloudObjectStorageTestInitializer.java | 6 +- ...erCDNMetadataListFromJsonResponseTest.java | 4 +- .../HPCloudObjectStorageExpectTest.java | 65 +++++++++++++ .../internal/KeystoneFixture.java | 92 +++++++++++++++++++ .../options/CreateContainerOptionsTest.java | 2 +- 17 files changed, 214 insertions(+), 50 deletions(-) create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/HPCloudObjectStorageExpectTest.java create mode 100644 labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/KeystoneFixture.java diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java index ddc16fbfa6..23094b5367 100644 --- a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStoragePropertiesBuilder.java @@ -39,12 +39,14 @@ public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilde @Override protected Properties defaultProperties() { - Properties properties = super.defaultProperties(); - properties.setProperty(KeystoneProperties.SERVICE_TYPE, ServiceType.OBJECT_STORE); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); - properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:35357"); - properties.setProperty(PROPERTY_API_VERSION, "2.0"); - + Properties properties = super.defaultProperties(); + properties.setProperty(KeystoneProperties.SERVICE_TYPE, ServiceType.OBJECT_STORE); + // TODO: this doesn't actually do anything yet. + properties.setProperty(KeystoneProperties.VERSION, "2.0"); + properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); + properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:35357"); + properties.setProperty(PROPERTY_API_VERSION, "1.0"); + return properties; } diff --git a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java index c8cc3a1058..d2d54efd0b 100644 --- a/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java +++ b/labs/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java @@ -24,6 +24,7 @@ import java.net.URI; import javax.inject.Singleton; +import com.google.inject.Scopes; import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncClient; import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageClient; import org.jclouds.hpcloud.services.HPExtensionCDN; @@ -35,8 +36,12 @@ import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.ServerError; import org.jclouds.json.config.GsonModule.DateAdapter; import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import org.jclouds.location.suppliers.ImplicitLocationSupplier; import org.jclouds.location.suppliers.RegionIdToURISupplier; +import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstRegionOptionallyMatchingRegionId; +import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; +import org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToURIFromAccessForTypeAndVersionSupplier; import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.CommonSwiftClient; @@ -59,24 +64,24 @@ import com.google.inject.Provides; public class HPCloudObjectStorageRestClientModule extends RestClientModule { - private final KeystoneAuthenticationModule authModule; - public HPCloudObjectStorageRestClientModule() { - this(new KeystoneAuthenticationModule()); - } - - public HPCloudObjectStorageRestClientModule(KeystoneAuthenticationModule authModule) { super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class); - this.authModule = authModule; } protected void configure() { - install(authModule); install(new SwiftObjectModule()); bind(DateAdapter.class).to(Iso8601DateAdapter.class); super.configure(); } - + + @Override + protected void installLocations() { + super.installLocations(); + // TODO: select this from KeystoneProperties.VERSION; + install(KeystoneAuthenticationModule.forRegions()); + bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstRegionOptionallyMatchingRegionId.class).in(Scopes.SINGLETON); + } + @Override protected void bindErrorHandlers() { bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSwiftErrorFromHttpResponse.class); diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java index 0c394d4139..39f5ee1b98 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageClientLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs; +package org.jclouds.hpcloud.objectstorage; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -24,8 +24,8 @@ import static org.testng.Assert.assertTrue; import java.net.URI; import java.util.Set; -import org.jclouds.hpcloud.objectstorage.lvs.domain.ContainerCDNMetadata; -import org.jclouds.hpcloud.objectstorage.lvs.options.ListCDNContainerOptions; +import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions; import org.jclouds.openstack.swift.CommonSwiftClientLiveTest; import org.jclouds.openstack.swift.domain.SwiftObject; import org.testng.annotations.Test; @@ -34,12 +34,12 @@ import org.testng.annotations.Test; * * @author Adrian Cole */ -@Test(groups = "live", testName = "HPCloudObjectStorageLasVegasClientLiveTest") -public class HPCloudObjectStorageLasVegasClientLiveTest extends CommonSwiftClientLiveTest { +@Test(groups = "live", testName = "HPCloudObjectStorageClientLiveTest") +public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTest { @Override - public HPCloudObjectStorageLasVegasClient getApi() { - return (HPCloudObjectStorageLasVegasClient) context.getProviderSpecificContext().getApi(); + public HPCloudObjectStorageClient getApi() { + return (HPCloudObjectStorageClient) context.getProviderSpecificContext().getApi(); } @Override diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java index c068997061..b552bd06e4 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageProviderTest.java @@ -16,22 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs; +package org.jclouds.hpcloud.objectstorage; import org.jclouds.providers.BaseProviderMetadataTest; import org.jclouds.providers.ProviderMetadata; import org.testng.annotations.Test; /** - * The HPCloudObjectStorageLasVegasProviderTest tests the {@link org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasProviderMetadata} class. + * The HPCloudObjectStorageProviderTest tests the {@link org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageProviderMetadata} class. * * @author Jeremy Daggett */ -@Test(groups = "unit", testName = "HPCloudObjectStorageLasVegasProviderTest") -public class HPCloudObjectStorageLasVegasProviderTest extends BaseProviderMetadataTest { +@Test(groups = "unit", testName = "HPCloudObjectStorageProviderTest") +public class HPCloudObjectStorageProviderTest extends BaseProviderMetadataTest { - public HPCloudObjectStorageLasVegasProviderTest() { - super(new HPCloudObjectStorageLasVegasProviderMetadata(), ProviderMetadata.BLOBSTORE_TYPE); + public HPCloudObjectStorageProviderTest() { + super(new HPCloudObjectStorageProviderMetadata(), ProviderMetadata.BLOBSTORE_TYPE); } } diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java index 8778fda3b1..d500d58aa0 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobIntegrationLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration; +package org.jclouds.hpcloud.objectstorage.blobstore.integration; import org.jclouds.blobstore.domain.Blob; import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobIntegrationLiveTest; @@ -26,7 +26,7 @@ import org.testng.annotations.Test; * @author Jeremy Daggett */ @Test(groups = "live") -public class HPCloudObjectStorageLasVegasBlobIntegrationLiveTest extends SwiftBlobIntegrationLiveTest { +public class HPCloudObjectStorageBlobIntegrationLiveTest extends SwiftBlobIntegrationLiveTest { @Override protected void checkContentDisposition(Blob blob, String contentDisposition) { assert blob.getPayload().getContentMetadata().getContentDisposition().startsWith(contentDisposition) : blob diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java index 4be59d2247..d56de82499 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration; +package org.jclouds.hpcloud.objectstorage.blobstore.integration; import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobLiveTest; import org.testng.annotations.Test; @@ -25,6 +25,6 @@ import org.testng.annotations.Test; * @author Jeremy Daggett */ @Test(groups = { "live" }) -public class HPCloudObjectStorageLasVegasBlobLiveTest extends SwiftBlobLiveTest { +public class HPCloudObjectStorageBlobLiveTest extends SwiftBlobLiveTest { } diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java index ef113697ed..88a67ddae6 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobMapIntegrationLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration; +package org.jclouds.hpcloud.objectstorage.blobstore.integration; import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobMapIntegrationLiveTest; import org.testng.annotations.Test; @@ -25,6 +25,6 @@ import org.testng.annotations.Test; * @author Jeremy Daggett */ @Test(groups = "live") -public class HPCloudObjectStorageLasVegasBlobMapIntegrationLiveTest extends SwiftBlobMapIntegrationLiveTest { +public class HPCloudObjectStorageBlobMapIntegrationLiveTest extends SwiftBlobMapIntegrationLiveTest { } diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java index f4c40f806b..21b6e07f56 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageBlobSignerLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration; +package org.jclouds.hpcloud.objectstorage.blobstore.integration; import org.jclouds.openstack.swift.blobstore.integration.SwiftBlobSignerLiveTest; import org.testng.annotations.Test; @@ -25,6 +25,6 @@ import org.testng.annotations.Test; * @author Jeremy Daggett */ @Test(groups = { "live" }) -public class HPCloudObjectStorageLasVegasBlobSignerLiveTest extends SwiftBlobSignerLiveTest { +public class HPCloudObjectStorageBlobSignerLiveTest extends SwiftBlobSignerLiveTest { } diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java index 8917ef071a..73e717d4a3 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerIntegrationLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration; +package org.jclouds.hpcloud.objectstorage.blobstore.integration; import org.jclouds.openstack.swift.blobstore.integration.SwiftContainerIntegrationLiveTest; import org.testng.annotations.Test; @@ -25,6 +25,6 @@ import org.testng.annotations.Test; * @author Jeremy Daggett */ @Test(groups = "live") -public class HPCloudObjectStorageLasVegasContainerIntegrationLiveTest extends SwiftContainerIntegrationLiveTest { +public class HPCloudObjectStorageContainerIntegrationLiveTest extends SwiftContainerIntegrationLiveTest { } diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java index 1e765bca0f..44e70e3159 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageContainerLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration; +package org.jclouds.hpcloud.objectstorage.blobstore.integration; import java.io.IOException; import java.net.MalformedURLException; @@ -28,7 +28,7 @@ import org.testng.annotations.Test; * @author Jeremy Daggett */ @Test(groups = { "live" }) -public class HPCloudObjectStorageLasVegasContainerLiveTest extends BaseContainerLiveTest { +public class HPCloudObjectStorageContainerLiveTest extends BaseContainerLiveTest { @Test(enabled = false) //@Test(expectedExceptions=UnsupportedOperationException.class) diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java index 415f58aa32..34907f3417 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageInputStreamMapIntegrationLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration; +package org.jclouds.hpcloud.objectstorage.blobstore.integration; import org.jclouds.openstack.swift.blobstore.integration.SwiftInputStreamMapIntegrationLiveTest; import org.testng.annotations.Test; @@ -25,6 +25,6 @@ import org.testng.annotations.Test; * @author Jeremy Daggett */ @Test(groups = "live") -public class HPCloudObjectStorageLasVegasInputStreamMapIntegrationLiveTest extends SwiftInputStreamMapIntegrationLiveTest { +public class HPCloudObjectStorageInputStreamMapIntegrationLiveTest extends SwiftInputStreamMapIntegrationLiveTest { } diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java index 50cfade7eb..5b28ee5c55 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageServiceIntegrationLiveTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration; +package org.jclouds.hpcloud.objectstorage.blobstore.integration; import java.util.Set; @@ -29,7 +29,7 @@ import com.google.common.collect.ImmutableSet; * @author Jeremy Daggett */ @Test(groups = "live") -public class HPCloudObjectStorageLasVegasServiceIntegrationLiveTest extends SwiftServiceIntegrationLiveTest { +public class HPCloudObjectStorageServiceIntegrationLiveTest extends SwiftServiceIntegrationLiveTest { @Override protected Set getIso3166Codes() { return ImmutableSet. of("US-NV"); diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageTestInitializer.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageTestInitializer.java index 5e4407d44a..cc64b10643 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageTestInitializer.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/blobstore/integration/HPCloudObjectStorageTestInitializer.java @@ -16,16 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.blobstore.integration; +package org.jclouds.hpcloud.objectstorage.blobstore.integration; import org.jclouds.openstack.swift.blobstore.integration.SwiftTestInitializer; /** * @author Jeremy Daggett */ -public class HPCloudObjectStorageLasVegasTestInitializer extends SwiftTestInitializer { +public class HPCloudObjectStorageTestInitializer extends SwiftTestInitializer { - public HPCloudObjectStorageLasVegasTestInitializer() { + public HPCloudObjectStorageTestInitializer() { provider = "hpcloud-objectstorage-lvs"; } diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java index 87719f7964..8bc5b33d20 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/functions/ParseContainerCDNMetadataListFromJsonResponseTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.functions; +package org.jclouds.hpcloud.objectstorage.functions; import static org.testng.Assert.assertEquals; @@ -25,7 +25,7 @@ import java.net.URI; import java.util.Set; import java.util.SortedSet; -import org.jclouds.hpcloud.objectstorage.lvs.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.domain.ContainerCDNMetadata; import org.jclouds.http.HttpResponse; import org.jclouds.http.functions.ParseJson; import org.jclouds.io.Payloads; diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/HPCloudObjectStorageExpectTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/HPCloudObjectStorageExpectTest.java new file mode 100644 index 0000000000..4ed6ddc274 --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/HPCloudObjectStorageExpectTest.java @@ -0,0 +1,65 @@ +package org.jclouds.hpcloud.objectstorage.internal; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; +import org.jclouds.blobstore.BlobStore; +import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.BlobStoreContextFactory; +import org.jclouds.domain.Location; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.logging.config.NullLoggingModule; +import org.jclouds.rest.BaseRestClientExpectTest; +import org.testng.annotations.Test; + +import java.net.URI; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +@Test(groups = "unit", testName = "HPCloudObjectStorageExpectTest") +public class HPCloudObjectStorageExpectTest extends BaseRestClientExpectTest { + + + protected HttpRequest keystoneAuthWithUsernameAndPassword; + protected HttpRequest keystoneAuthWithAccessKeyAndSecretKey; + protected String authToken; + protected HttpResponse responseWithKeystoneAccess; + + public HPCloudObjectStorageExpectTest() { + provider = "hpcloud-objectstorage"; + keystoneAuthWithUsernameAndPassword = KeystoneFixture.INSTANCE.initialAuthWithUsernameAndPassword(identity, + credential); + keystoneAuthWithAccessKeyAndSecretKey = KeystoneFixture.INSTANCE.initialAuthWithAccessKeyAndSecretKey(identity, + credential); + authToken = KeystoneFixture.INSTANCE.getAuthToken(); + responseWithKeystoneAccess = KeystoneFixture.INSTANCE.responseWithAccess(); + + identity = KeystoneFixture.INSTANCE.getTenantName() + ":" + identity; + } + + public BlobStore createClient(Function fn, Module module, Properties props) { + return new BlobStoreContextFactory(setupRestProperties()) + .createContext(provider, identity, credential, ImmutableSet.of(new ExpectModule(fn), + new NullLoggingModule(), module), props) + .getBlobStore(); + } + + public void testListObjectsWhenResponseIs2xx() throws Exception { + Map requestResponseMap = ImmutableMap. builder().put( + keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess).build(); + + BlobStore clientWhenServersExist = requestsSendResponses(requestResponseMap); + + Set locations = clientWhenServersExist.listAssignableLocations(); + assertNotNull(locations); + assertEquals(locations.size(), 1); + assertEquals(locations.iterator().next().getId(), "region-a.geo-1"); + } +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/KeystoneFixture.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/KeystoneFixture.java new file mode 100644 index 0000000000..3811ea6a9c --- /dev/null +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/internal/KeystoneFixture.java @@ -0,0 +1,92 @@ +/** + * 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.objectstorage.internal; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.net.HttpHeaders; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payload; +import org.jclouds.util.Strings2; + +import java.io.IOException; +import java.net.URI; + +import static java.lang.String.format; +import static org.jclouds.rest.BaseRestClientExpectTest.payloadFromStringWithContentType; + +/** + * Base class for writing HP Cloud Object Storage Rest Client Expect tests + * + * @author Michael Arnold + */ +public enum KeystoneFixture { + INSTANCE; + + public String getTenantName(){ + return "12346637803162"; + } + + public HttpRequest initialAuthWithUsernameAndPassword(String username, String password){ + return HttpRequest + .builder() + .method("POST") + .endpoint(URI.create("https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens")) + .headers(ImmutableMultimap.of(HttpHeaders.ACCEPT, "application/json")) + .payload( + payloadFromStringWithContentType( + format( + "{\"auth\":{\"passwordCredentials\":{\"username\":\"%s\",\"password\":\"%s\"},\"tenantName\":\"%s\"}}", + username, password, getTenantName()), "application/json")).build(); + } + + public HttpRequest initialAuthWithAccessKeyAndSecretKey(String accessKey, String secretKey){ + return HttpRequest + .builder() + .method("POST") + .endpoint(URI.create("https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/tokens")) + .headers(ImmutableMultimap.of(HttpHeaders.ACCEPT, "application/json")) + .payload( + payloadFromStringWithContentType( + format( + "{\"auth\":{\"apiAccessKeyCredentials\":{\"accessKey\":\"%s\",\"secretKey\":\"%s\"},\"tenantName\":\"%s\"}}", + accessKey, secretKey, getTenantName()), "application/json")).build(); + } + + public String getAuthToken(){ + return "Auth_4f173437e4b013bee56d1007"; + } + + public HttpResponse responseWithAccess(){ + return HttpResponse.builder().statusCode(200).message("HTTP/1.1 200").payload( + payloadFromResourceWithContentType("/keystoneAuthResponse.json", "application/json")).build(); + } + + + public Payload payloadFromResourceWithContentType(String resource, String contentType) { + try { + return payloadFromStringWithContentType(Strings2.toStringAndClose(getClass().getResourceAsStream(resource)), + contentType); + } catch (IOException e) { + throw Throwables.propagate(e); + } + + } +} diff --git a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptionsTest.java b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptionsTest.java index 4548eaaeaa..1238aa345b 100644 --- a/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptionsTest.java +++ b/labs/hpcloud-objectstorage/src/test/java/org/jclouds/hpcloud/objectstorage/options/CreateContainerOptionsTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.jclouds.hpcloud.objectstorage.lvs.options; +package org.jclouds.hpcloud.objectstorage.options; import static org.testng.Assert.assertEquals;