From 3984d1057defecbdcedabaf886fc67c195cf3bb6 Mon Sep 17 00:00:00 2001 From: Jeremy Daggett Date: Fri, 11 Nov 2011 11:22:04 -0800 Subject: [PATCH] CDN support changes: fixed parsing issues, initial change for externalizing CDN URL --- allblobstore/pom.xml | 5 +++ jeremy.txt | 1 - .../HPCloudObjectStorageAsyncClient.java | 3 +- ...HPCloudObjectStoragePropertiesBuilder.java | 11 ++++-- .../HPCloudObjectStorageRestClientModule.java | 15 +++++--- .../storage/domain/ContainerCDNMetadata.java | 3 ++ .../HPCloudObjectStorageConstants.java | 34 +++++++++++++++++ .../HPCloudObjectStorageHeaders.java | 6 +-- .../HPCloudObjectStorageClientLiveTest.java | 19 ++++++++-- .../HPCloudObjectStorageProviderTest.java | 37 +++++++++++++++++++ 10 files changed, 115 insertions(+), 19 deletions(-) delete mode 100644 jeremy.txt create mode 100644 providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageConstants.java create mode 100644 providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderTest.java diff --git a/allblobstore/pom.xml b/allblobstore/pom.xml index e034fc9f35..42308dd280 100644 --- a/allblobstore/pom.xml +++ b/allblobstore/pom.xml @@ -100,5 +100,10 @@ filesystem ${project.version} + + org.jclouds.provider + hpcloud-object-storage + ${project.version} + diff --git a/jeremy.txt b/jeremy.txt deleted file mode 100644 index 5d31edcb2d..0000000000 --- a/jeremy.txt +++ /dev/null @@ -1 +0,0 @@ -README HP \ No newline at end of file diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java index 15c4abccb9..ed793ebee7 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageAsyncClient.java @@ -77,7 +77,6 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient @Endpoint(CDNManagement.class) ListenableFuture> listCDNContainers(ListCDNContainerOptions... options); - // TODO: Container name is not included in CDN HEAD response headers, so we cannot populate it here. /** * @see HPCloudObjectStorageClient#getCDNMetadata(String) */ @@ -122,7 +121,7 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient /** * @see HPCloudObjectStorageClient#disableCDN(String) */ - @POST + @PUT @Path("/{container}") @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "False") @Endpoint(CDNManagement.class) diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java index 753204b323..5a48afedb2 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStoragePropertiesBuilder.java @@ -21,14 +21,15 @@ package org.jclouds.hpcloud.object.storage; import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_ENDPOINT; import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; +import static org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageConstants.PROPERTY_CDN_ENDPOINT; import java.util.Properties; +import org.jclouds.openstack.OpenStackAuthAsyncClient; import org.jclouds.openstack.swift.SwiftPropertiesBuilder; /** - * - * @author Jeremy Daggtt + * @author Jeremy Daggett */ public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilder { @@ -40,8 +41,10 @@ public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilde protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); - properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.objects.hpcloudsvc.com/auth/v1.0/"); - properties.setProperty(PROPERTY_API_VERSION, "1.1"); + properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.objects.hpcloudsvc.com/auth/"); + properties.setProperty(PROPERTY_API_VERSION, OpenStackAuthAsyncClient.VERSION); + properties.setProperty(PROPERTY_CDN_ENDPOINT, ""); + return properties; } diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java index 36ee4a3988..2675c9fe57 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/config/HPCloudObjectStorageRestClientModule.java @@ -20,6 +20,7 @@ package org.jclouds.hpcloud.object.storage.config; import java.net.URI; +import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.hpcloud.object.storage.CDNManagement; @@ -33,6 +34,8 @@ import org.jclouds.openstack.swift.CommonSwiftClient; import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule; import org.jclouds.rest.ConfiguresRestClient; +import com.google.common.annotations.VisibleForTesting; +import com.google.inject.Inject; import com.google.inject.Provides; /** @@ -42,7 +45,7 @@ import com.google.inject.Provides; @ConfiguresRestClient @RequiresHttp public class HPCloudObjectStorageRestClientModule extends BaseSwiftRestClientModule { - + public HPCloudObjectStorageRestClientModule() { super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class); } @@ -63,12 +66,14 @@ public class HPCloudObjectStorageRestClientModule extends BaseSwiftRestClientMod @Singleton @CDNManagement protected URI provideCDNUrl(AuthenticationResponse response) { - /* FIXFIX - We need to have an external config for the CDN URI + @Named("jclouds.hpcloud-object-storage.cdn.endpoint") + @VisibleForTesting + String cdnEndpoint = "https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/"; if (response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL) == null) { - return URI.create("https://cdnmgmt.hpcloud.net:8080/v1/AUTH_test/"); - } - */ + return URI.create(cdnEndpoint); + } + return response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL); } } diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java index d2656d9801..203bd6679c 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/domain/ContainerCDNMetadata.java @@ -20,6 +20,8 @@ package org.jclouds.hpcloud.object.storage.domain; import java.net.URI; +import com.google.gson.annotations.SerializedName; + /** * * @author James Murty @@ -30,6 +32,7 @@ public class ContainerCDNMetadata implements Comparable { private String name; private boolean cdn_enabled; private long ttl; + @SerializedName("x-cdn-uri") private URI cdn_uri; private String referrer_acl; private String useragent_acl; diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageConstants.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageConstants.java new file mode 100644 index 0000000000..88ba53d09b --- /dev/null +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageConstants.java @@ -0,0 +1,34 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.hpcloud.object.storage.reference; + + +/** + * Configuration properties and constants used by HP Cloud Object Storage. + * + * @author Jeremy Daggett + */ +public interface HPCloudObjectStorageConstants { + + /** + * The CDN Endpoint property + */ + public static final String PROPERTY_CDN_ENDPOINT = "jclouds.hpcloud-object-storage.cdn.endpoint"; + +} diff --git a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java index 17969b2ce8..d0726970e8 100644 --- a/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java +++ b/providers/hpcloud-object-storage/src/main/java/org/jclouds/hpcloud/object/storage/reference/HPCloudObjectStorageHeaders.java @@ -30,11 +30,11 @@ import org.jclouds.openstack.swift.reference.SwiftHeaders; */ public interface HPCloudObjectStorageHeaders extends SwiftHeaders { - public static final String CDN_ENABLED = "X-CDN-Enabled"; + public static final String CDN_ENABLED = "X-Cdn-Enabled"; public static final String CDN_LOG_RETENTION = "X-Log-Retention"; public static final String CDN_REFERRER_ACL = "X-Referrer-ACL"; - public static final String CDN_TTL = "X-TTL"; - public static final String CDN_URI = "X-CDN-URI"; + public static final String CDN_TTL = "X-Ttl"; + public static final String CDN_URI = "X-Cdn-Uri"; public static final String CDN_USER_AGENT_ACL = "X-User-Agent-ACL"; public static final String CONTAINER_READ = "X-Container-Read"; diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java index 79b7c82863..e83957ae56 100644 --- a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageClientLiveTest.java @@ -40,7 +40,7 @@ import com.google.common.collect.Iterables; */ @Test(groups = "live") public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTest { - + @Override public HPCloudObjectStorageClient getApi() { return (HPCloudObjectStorageClient) context.getProviderSpecificContext().getApi(); @@ -48,10 +48,19 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes @Override protected void testGetObjectContentType(SwiftObject getBlob) { - //lovely new bug.. should be text/plain - assertEquals(getBlob.getInfo().getContentType(), "application/x-www-form-urlencoded"); + assertEquals(getBlob.getInfo().getContentType(), "application/unknown"); } + @Test + public void testListCDNContainers() { + try { + Set cdnMetadataList = getApi().listCDNContainers(); + System.err.println(cdnMetadataList); + } catch (Exception e) { + e.printStackTrace(); + } + } + @Test public void testCDNOperations() throws Exception { final long minimumTTL = 60 * 60; // The minimum TTL is 1 hour @@ -64,7 +73,7 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes getApi().disableCDN(containerNameWithCDN); getApi().disableCDN(containerNameWithoutCDN); } catch (Exception e) { - + e.printStackTrace(); } ContainerCDNMetadata cdnMetadata = null; @@ -139,6 +148,8 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN); assertEquals(cdnMetadata.isCDNEnabled(), false); + } catch (Exception e) { + e.printStackTrace(); } finally { recycleContainer(containerNameWithCDN); recycleContainer(containerNameWithoutCDN); diff --git a/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderTest.java b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderTest.java new file mode 100644 index 0000000000..8c1608b9df --- /dev/null +++ b/providers/hpcloud-object-storage/src/test/java/org/jclouds/hpcloud/object/storage/HPCloudObjectStorageProviderTest.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.hpcloud.object.storage; + +import org.jclouds.providers.BaseProviderMetadataTest; +import org.jclouds.providers.ProviderMetadata; +import org.testng.annotations.Test; + +/** + * The HPCloudObjectStorageProviderTest tests the {@link org.jclouds.hpcloud.object.storage.HPCloudObjectStorageProviderMetadata} class. + * + * @author Jeremy Daggett + */ +@Test(groups = "unit", testName = "HPCloudObjectStorageProviderTest") +public class HPCloudObjectStorageProviderTest extends BaseProviderMetadataTest { + + public HPCloudObjectStorageProviderTest() { + super(new HPCloudObjectStorageProviderMetadata(), ProviderMetadata.BLOBSTORE_TYPE); + } + +} \ No newline at end of file