CDN support changes: fixed parsing issues, initial change for externalizing CDN URL

This commit is contained in:
Jeremy Daggett 2011-11-11 11:22:04 -08:00
parent da4ce8689e
commit 3984d1057d
10 changed files with 115 additions and 19 deletions

View File

@ -100,5 +100,10 @@
<artifactId>filesystem</artifactId> <artifactId>filesystem</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>hpcloud-object-storage</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1 +0,0 @@
README HP

View File

@ -77,7 +77,6 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient
@Endpoint(CDNManagement.class) @Endpoint(CDNManagement.class)
ListenableFuture<? extends Set<ContainerCDNMetadata>> listCDNContainers(ListCDNContainerOptions... options); ListenableFuture<? extends Set<ContainerCDNMetadata>> listCDNContainers(ListCDNContainerOptions... options);
// TODO: Container name is not included in CDN HEAD response headers, so we cannot populate it here.
/** /**
* @see HPCloudObjectStorageClient#getCDNMetadata(String) * @see HPCloudObjectStorageClient#getCDNMetadata(String)
*/ */
@ -122,7 +121,7 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient
/** /**
* @see HPCloudObjectStorageClient#disableCDN(String) * @see HPCloudObjectStorageClient#disableCDN(String)
*/ */
@POST @PUT
@Path("/{container}") @Path("/{container}")
@Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "False") @Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "False")
@Endpoint(CDNManagement.class) @Endpoint(CDNManagement.class)

View File

@ -21,14 +21,15 @@ package org.jclouds.hpcloud.object.storage;
import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT; import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; 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 java.util.Properties;
import org.jclouds.openstack.OpenStackAuthAsyncClient;
import org.jclouds.openstack.swift.SwiftPropertiesBuilder; import org.jclouds.openstack.swift.SwiftPropertiesBuilder;
/** /**
* * @author Jeremy Daggett
* @author Jeremy Daggtt
*/ */
public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilder { public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilder {
@ -40,8 +41,10 @@ public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilde
protected Properties defaultProperties() { protected Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV"); 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_ENDPOINT, "https://region-a.geo-1.objects.hpcloudsvc.com/auth/");
properties.setProperty(PROPERTY_API_VERSION, "1.1"); properties.setProperty(PROPERTY_API_VERSION, OpenStackAuthAsyncClient.VERSION);
properties.setProperty(PROPERTY_CDN_ENDPOINT, "");
return properties; return properties;
} }

View File

@ -20,6 +20,7 @@ package org.jclouds.hpcloud.object.storage.config;
import java.net.URI; import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.hpcloud.object.storage.CDNManagement; 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.openstack.swift.config.BaseSwiftRestClientModule;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -63,12 +66,14 @@ public class HPCloudObjectStorageRestClientModule extends BaseSwiftRestClientMod
@Singleton @Singleton
@CDNManagement @CDNManagement
protected URI provideCDNUrl(AuthenticationResponse response) { 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) { 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); return response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL);
} }
} }

View File

@ -20,6 +20,8 @@ package org.jclouds.hpcloud.object.storage.domain;
import java.net.URI; import java.net.URI;
import com.google.gson.annotations.SerializedName;
/** /**
* *
* @author James Murty * @author James Murty
@ -30,6 +32,7 @@ public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
private String name; private String name;
private boolean cdn_enabled; private boolean cdn_enabled;
private long ttl; private long ttl;
@SerializedName("x-cdn-uri")
private URI cdn_uri; private URI cdn_uri;
private String referrer_acl; private String referrer_acl;
private String useragent_acl; private String useragent_acl;

View File

@ -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";
}

View File

@ -30,11 +30,11 @@ import org.jclouds.openstack.swift.reference.SwiftHeaders;
*/ */
public interface HPCloudObjectStorageHeaders extends 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_LOG_RETENTION = "X-Log-Retention";
public static final String CDN_REFERRER_ACL = "X-Referrer-ACL"; public static final String CDN_REFERRER_ACL = "X-Referrer-ACL";
public static final String CDN_TTL = "X-TTL"; public static final String CDN_TTL = "X-Ttl";
public static final String CDN_URI = "X-CDN-URI"; 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 CDN_USER_AGENT_ACL = "X-User-Agent-ACL";
public static final String CONTAINER_READ = "X-Container-Read"; public static final String CONTAINER_READ = "X-Container-Read";

View File

@ -48,8 +48,17 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes
@Override @Override
protected void testGetObjectContentType(SwiftObject getBlob) { protected void testGetObjectContentType(SwiftObject getBlob) {
//lovely new bug.. should be text/plain assertEquals(getBlob.getInfo().getContentType(), "application/unknown");
assertEquals(getBlob.getInfo().getContentType(), "application/x-www-form-urlencoded"); }
@Test
public void testListCDNContainers() {
try {
Set<ContainerCDNMetadata> cdnMetadataList = getApi().listCDNContainers();
System.err.println(cdnMetadataList);
} catch (Exception e) {
e.printStackTrace();
}
} }
@Test @Test
@ -64,7 +73,7 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes
getApi().disableCDN(containerNameWithCDN); getApi().disableCDN(containerNameWithCDN);
getApi().disableCDN(containerNameWithoutCDN); getApi().disableCDN(containerNameWithoutCDN);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
} }
ContainerCDNMetadata cdnMetadata = null; ContainerCDNMetadata cdnMetadata = null;
@ -139,6 +148,8 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes
cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN); cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN);
assertEquals(cdnMetadata.isCDNEnabled(), false); assertEquals(cdnMetadata.isCDNEnabled(), false);
} catch (Exception e) {
e.printStackTrace();
} finally { } finally {
recycleContainer(containerNameWithCDN); recycleContainer(containerNameWithCDN);
recycleContainer(containerNameWithoutCDN); recycleContainer(containerNameWithoutCDN);

View File

@ -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);
}
}