mirror of https://github.com/apache/jclouds.git
Additional CDN changes
This commit is contained in:
parent
96ff7d137a
commit
4241c9239a
|
@ -21,6 +21,7 @@ package org.jclouds.hpcloud.objectstorage.lvs;
|
|||
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.objectstorage.lvs.reference.HPCloudObjectStorageLasVegasConstants.PROPERTY_CDN_ENDPOINT;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -42,6 +43,13 @@ public class HPCloudObjectStorageLasVegasPropertiesBuilder extends SwiftProperti
|
|||
properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV");
|
||||
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, "https://region-a.geo-1.cdnmgmt.hpcloudsvc.com");
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected HPCloudObjectStorageLasVegasPropertiesBuilder withCDNEndpoint(String endpoint) {
|
||||
properties.setProperty(PROPERTY_CDN_ENDPOINT, endpoint);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,12 +29,15 @@ 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.lvs.HPCloudObjectStorageLasVegasAsyncClient;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasClient;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.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;
|
||||
|
@ -43,7 +46,9 @@ import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceMetada
|
|||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -51,6 +56,7 @@ import com.google.common.base.Supplier;
|
|||
*/
|
||||
@Singleton
|
||||
public class HPCloudObjectStorageLasVegasAsyncBlobStore extends SwiftAsyncBlobStore {
|
||||
private final EnableCDNAndCache enableCDNAndCache;
|
||||
|
||||
@Inject
|
||||
protected HPCloudObjectStorageLasVegasAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||
|
@ -60,10 +66,30 @@ public class HPCloudObjectStorageLasVegasAsyncBlobStore extends SwiftAsyncBlobSt
|
|||
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
||||
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
||||
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
|
||||
Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
||||
Provider<FetchBlobMetadata> 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<Boolean> createContainerInLocation(Location location, final String container,
|
||||
CreateContainerOptions options) {
|
||||
|
||||
ListenableFuture<Boolean> returnVal = createContainerInLocation(location, container);
|
||||
if (options.isPublicRead())
|
||||
return Futures.compose(createContainerInLocation(location, container), new Function<Boolean, Boolean>() {
|
||||
|
||||
@Override
|
||||
public Boolean apply(Boolean input) {
|
||||
if (Boolean.TRUE.equals(input)) {
|
||||
return enableCDNAndCache.apply(container) != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}, service);
|
||||
return returnVal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,10 +26,12 @@ 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.lvs.blobstore.functions.EnableCDNAndCache;
|
||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||
import org.jclouds.openstack.swift.blobstore.SwiftBlobStore;
|
||||
import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions;
|
||||
|
@ -48,6 +50,8 @@ import com.google.common.base.Supplier;
|
|||
@Singleton
|
||||
public class HPCloudObjectStorageLasVegasBlobStore extends SwiftBlobStore {
|
||||
|
||||
private EnableCDNAndCache enableCDNAndCache;
|
||||
|
||||
@Inject
|
||||
protected HPCloudObjectStorageLasVegasBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||
Supplier<Location> defaultLocation, @Memoized Supplier<Set<? extends Location>> locations,
|
||||
|
@ -55,9 +59,22 @@ public class HPCloudObjectStorageLasVegasBlobStore extends SwiftBlobStore {
|
|||
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
||||
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
||||
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
|
||||
Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
||||
Provider<FetchBlobMetadata> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,20 +18,75 @@
|
|||
*/
|
||||
package org.jclouds.hpcloud.objectstorage.lvs.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.lvs.HPCloudObjectStorageLasVegasClient;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.blobstore.HPCloudObjectStorageLasVegasAsyncBlobStore;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.blobstore.HPCloudObjectStorageLasVegasBlobStore;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.blobstore.functions.HPCloudObjectStorageLasVegasObjectToBlobMetadata;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.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 HPCloudObjectStorageLasVegasBlobStoreContextModule extends SwiftBlobStoreContextModule {
|
||||
|
||||
@Beta
|
||||
@Singleton
|
||||
public static final class GetCDNMetadata extends CacheLoader<String, URI> {
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final HPCloudObjectStorageLasVegasClient client;
|
||||
|
||||
@Inject
|
||||
public GetCDNMetadata(HPCloudObjectStorageLasVegasClient 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<String, URI> cdnContainer(GetCDNMetadata loader) {
|
||||
return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(loader);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
|
|
|
@ -32,15 +32,22 @@ import org.jclouds.openstack.swift.domain.ObjectInfo;
|
|||
@Singleton
|
||||
public class HPCloudObjectStorageLasVegasObjectToBlobMetadata extends ObjectToBlobMetadata {
|
||||
|
||||
private final PublicUriForObjectInfo publicUriForObjectInfo;
|
||||
|
||||
@Inject
|
||||
public HPCloudObjectStorageLasVegasObjectToBlobMetadata(IfDirectoryReturnNameStrategy ifDirectoryReturnName) {
|
||||
public HPCloudObjectStorageLasVegasObjectToBlobMetadata(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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,19 @@
|
|||
*/
|
||||
package org.jclouds.hpcloud.objectstorage.lvs.config;
|
||||
|
||||
import static org.jclouds.hpcloud.objectstorage.lvs.reference.HPCloudObjectStorageLasVegasConstants.PROPERTY_CDN_ENDPOINT;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.CDNManagement;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasAsyncClient;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasClient;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
||||
import org.jclouds.openstack.reference.AuthHeaders;
|
||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||
import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule;
|
||||
|
@ -55,4 +63,15 @@ public class HPCloudObjectStorageLasVegasRestClientModule extends
|
|||
return in;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@CDNManagement
|
||||
protected URI provideCDNUrl(AuthenticationResponse response, @Named(PROPERTY_CDN_ENDPOINT) String cdnEndpoint) {
|
||||
|
||||
if (response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL) == null) {
|
||||
return URI.create(cdnEndpoint + response.getServices().get(AuthHeaders.STORAGE_URL).getPath());
|
||||
}
|
||||
// Placeholder for when the Object Storage service returns the CDN Management URL in the headers
|
||||
return response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,5 +25,8 @@ package org.jclouds.hpcloud.objectstorage.lvs.reference;
|
|||
* @author Jeremy Daggett
|
||||
*/
|
||||
public interface HPCloudObjectStorageLasVegasConstants {
|
||||
|
||||
/**
|
||||
* The CDN Endpoint property
|
||||
*/
|
||||
public static final String PROPERTY_CDN_ENDPOINT = "jclouds.hpcloud-objectstorage-lvs.cdn.endpoint";
|
||||
}
|
||||
|
|
|
@ -30,4 +30,11 @@ import org.jclouds.openstack.swift.reference.SwiftHeaders;
|
|||
*/
|
||||
public interface HPCloudObjectStorageLasVegasHeaders 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";
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,13 @@
|
|||
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;
|
||||
|
@ -41,4 +47,99 @@ public class HPCloudObjectStorageLasVegasClientLiveTest extends CommonSwiftClien
|
|||
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<ContainerCDNMetadata> 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<ContainerCDNMetadata>() { 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ import org.testng.annotations.Test;
|
|||
@Test(groups = { "live" })
|
||||
public class HPCloudObjectStorageLasVegasContainerLiveTest extends BaseContainerLiveTest {
|
||||
|
||||
@Test(expectedExceptions=UnsupportedOperationException.class)
|
||||
@Test(enabled = false)
|
||||
//@Test(expectedExceptions=UnsupportedOperationException.class)
|
||||
public void testPublicAccess() throws MalformedURLException, InterruptedException, IOException {
|
||||
super.testPublicAccess();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue