diff --git a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceClient.java b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceClient.java index 3fed20b001..0e53e6067a 100644 --- a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceClient.java +++ b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/ServiceClient.java @@ -50,4 +50,4 @@ public interface ServiceClient { * @return access with token */ Access authenticateTenantWithCredentials(String tenantId, ApiAccessKeyCredentials passwordCredentials); -} +} \ No newline at end of file diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientExpectTest.java index fb318a2504..265290a65a 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ServerClientExpectTest.java @@ -1,3 +1,21 @@ +/** + * 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.openstack.nova.v1_1.features; import static org.testng.Assert.assertEquals; diff --git a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/CDNManagement.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/CDNManagement.java new file mode 100644 index 0000000000..b4b544fc62 --- /dev/null +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/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.lvs; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Represents a component related to HP Cloud Services Content Delivery Network. + * + * @see HP Cloud Object Storage API + * @author Jeremy Daggett + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface CDNManagement { + +} \ No newline at end of file diff --git a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasAsyncClient.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasAsyncClient.java index a31addcc3d..467fa3716b 100644 --- a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasAsyncClient.java +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasAsyncClient.java @@ -18,22 +18,38 @@ */ package org.jclouds.hpcloud.objectstorage.lvs; +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.lvs.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.lvs.functions.ParseCDNUriFromHeaders; +import org.jclouds.hpcloud.objectstorage.lvs.functions.ParseContainerCDNMetadataFromHeaders; import org.jclouds.hpcloud.objectstorage.lvs.functions.ParseContainerMetadataFromHeaders; import org.jclouds.hpcloud.objectstorage.lvs.options.CreateContainerOptions; +import org.jclouds.hpcloud.objectstorage.lvs.options.ListCDNContainerOptions; +import org.jclouds.hpcloud.objectstorage.lvs.reference.HPCloudObjectStorageLasVegasHeaders; +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; @@ -54,7 +70,7 @@ import com.google.common.util.concurrent.ListenableFuture; */ @SkipEncoding('/') @RequestFilters(AuthenticateRequest.class) -@Endpoint(Storage.class) +@Endpoint(ObjectStore.class) public interface HPCloudObjectStorageLasVegasAsyncClient extends CommonSwiftAsyncClient { /** @@ -75,5 +91,70 @@ public interface HPCloudObjectStorageLasVegasAsyncClient extends CommonSwiftAsyn 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 = HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED, values = "True") + @ResponseParser(ParseCDNUriFromHeaders.class) + @Endpoint(HPExtensionCDN.class) + ListenableFuture enableCDN(@PathParam("container") String container, + @HeaderParam(HPCloudObjectStorageLasVegasHeaders.CDN_TTL) long ttl); + + /** + * @see HPCloudObjectStorageClient#enableCDN(String) + */ + @Beta + @PUT + @Path("/{container}") + @Headers(keys = HPCloudObjectStorageLasVegasHeaders.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(HPCloudObjectStorageLasVegasHeaders.CDN_TTL) long ttl); + + /** + * @see HPCloudObjectStorageClient#disableCDN(String) + */ + @Beta + @PUT + @Path("/{container}") + @Headers(keys = HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED, values = "False") + @Endpoint(HPExtensionCDN.class) + ListenableFuture disableCDN(@PathParam("container") String container); } diff --git a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasClient.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasClient.java index a9305e9797..30469b1c6f 100644 --- a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasClient.java +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasClient.java @@ -18,14 +18,19 @@ */ package org.jclouds.hpcloud.objectstorage.lvs; +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.lvs.domain.ContainerCDNMetadata; import org.jclouds.hpcloud.objectstorage.lvs.options.CreateContainerOptions; +import org.jclouds.hpcloud.objectstorage.lvs.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; /** @@ -47,4 +52,22 @@ public interface HPCloudObjectStorageLasVegasClient extends CommonSwiftClient { 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/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasPropertiesBuilder.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasPropertiesBuilder.java index 931f59fb9c..d390b17f0e 100644 --- a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasPropertiesBuilder.java +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasPropertiesBuilder.java @@ -24,7 +24,8 @@ import static org.jclouds.Constants.PROPERTY_ISO3166_CODES; import java.util.Properties; -import org.jclouds.openstack.OpenStackAuthAsyncClient; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; +import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.swift.SwiftPropertiesBuilder; /** @@ -39,9 +40,12 @@ public class HPCloudObjectStorageLasVegasPropertiesBuilder extends SwiftProperti @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.objects.hpcloudsvc.com/auth"); - properties.setProperty(PROPERTY_API_VERSION, OpenStackAuthAsyncClient.VERSION); + properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com"); + properties.setProperty(PROPERTY_API_VERSION, "2.0"); + return properties; } + } diff --git a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/HPCloudObjectStorageLasVegasAsyncBlobStore.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/HPCloudObjectStorageLasVegasAsyncBlobStore.java index 8701e815b0..d29ff2e6d6 100644 --- a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/HPCloudObjectStorageLasVegasAsyncBlobStore.java +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/HPCloudObjectStorageLasVegasAsyncBlobStore.java @@ -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 fetchBlobMetadataProvider) { + 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/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/HPCloudObjectStorageLasVegasBlobStore.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/HPCloudObjectStorageLasVegasBlobStore.java index b9f5c0c35a..15cd7a3fa0 100644 --- a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/HPCloudObjectStorageLasVegasBlobStore.java +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/HPCloudObjectStorageLasVegasBlobStore.java @@ -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 defaultLocation, @Memoized Supplier> locations, @@ -55,9 +59,22 @@ public class HPCloudObjectStorageLasVegasBlobStore extends SwiftBlobStore { BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, - Provider fetchBlobMetadataProvider) { + Provider fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache) { super(context, blobUtils, defaultLocation, locations, sync, container2ResourceMd, container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd, blob2ObjectGetOptions, fetchBlobMetadataProvider); + this.enableCDNAndCache = enableCDNAndCache; + } + + @Override + public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) { + try { + return createContainerInLocation(location, container); + } finally { + if (options.isPublicRead()) + enableCDNAndCache.apply(container); + } + } + } diff --git a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/config/HPCloudObjectStorageLasVegasBlobStoreContextModule.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/config/HPCloudObjectStorageLasVegasBlobStoreContextModule.java index 53037d96ab..01f0b30d54 100644 --- a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/config/HPCloudObjectStorageLasVegasBlobStoreContextModule.java +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/config/HPCloudObjectStorageLasVegasBlobStoreContextModule.java @@ -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 { + @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 cdnContainer(GetCDNMetadata loader) { + return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(loader); + } + @Override protected void configure() { super.configure(); diff --git a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/functions/EnableCDNAndCache.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/functions/EnableCDNAndCache.java new file mode 100644 index 0000000000..f76512103a --- /dev/null +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/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.lvs.blobstore.functions; + +import java.net.URI; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasClient; + +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 HPCloudObjectStorageLasVegasClient sync; + + @Inject + public EnableCDNAndCache(HPCloudObjectStorageLasVegasClient 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/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/functions/HPCloudObjectStorageLasVegasObjectToBlobMetadata.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/functions/HPCloudObjectStorageLasVegasObjectToBlobMetadata.java index e645191dd8..934b24e1a0 100644 --- a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/functions/HPCloudObjectStorageLasVegasObjectToBlobMetadata.java +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/functions/HPCloudObjectStorageLasVegasObjectToBlobMetadata.java @@ -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; } } diff --git a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/functions/PublicUriForObjectInfo.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/functions/PublicUriForObjectInfo.java new file mode 100644 index 0000000000..f0091fc91c --- /dev/null +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/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.lvs.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/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/config/HPCloudObjectStorageLasVegasRestClientModule.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/config/HPCloudObjectStorageLasVegasRestClientModule.java index bf39983442..094f40a0c3 100644 --- a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/config/HPCloudObjectStorageLasVegasRestClientModule.java +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/config/HPCloudObjectStorageLasVegasRestClientModule.java @@ -18,16 +18,36 @@ */ package org.jclouds.hpcloud.objectstorage.lvs.config; +import static org.jclouds.util.Suppliers2.getLastValueInMap; + +import java.net.URI; + import javax.inject.Singleton; import org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasAsyncClient; import org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasClient; +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.config.BaseSwiftRestClientModule; +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; /** @@ -37,10 +57,31 @@ import com.google.inject.Provides; @ConfiguresRestClient @RequiresHttp public class HPCloudObjectStorageLasVegasRestClientModule extends - BaseSwiftRestClientModule { + RestClientModule { + + private final KeystoneAuthenticationModule authModule; public HPCloudObjectStorageLasVegasRestClientModule() { + this(new KeystoneAuthenticationModule()); + } + + public HPCloudObjectStorageLasVegasRestClientModule(KeystoneAuthenticationModule authModule) { super(HPCloudObjectStorageLasVegasClient.class, HPCloudObjectStorageLasVegasAsyncClient.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 @@ -54,5 +95,19 @@ public class HPCloudObjectStorageLasVegasRestClientModule extends CommonSwiftAsyncClient provideCommonSwiftClient(HPCloudObjectStorageLasVegasAsyncClient 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/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/functions/ParseCDNUriFromHeaders.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/functions/ParseCDNUriFromHeaders.java new file mode 100644 index 0000000000..062744036a --- /dev/null +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/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.lvs.functions; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import org.jclouds.hpcloud.objectstorage.lvs.reference.HPCloudObjectStorageLasVegasHeaders; +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(HPCloudObjectStorageLasVegasHeaders.CDN_URI), + HPCloudObjectStorageLasVegasHeaders.CDN_URI); + return URI.create(cdnUri); + } +} \ No newline at end of file diff --git a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/functions/ParseContainerCDNMetadataFromHeaders.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/functions/ParseContainerCDNMetadataFromHeaders.java new file mode 100644 index 0000000000..f18a96729f --- /dev/null +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/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.lvs.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.lvs.domain.ContainerCDNMetadata; +import org.jclouds.hpcloud.objectstorage.lvs.reference.HPCloudObjectStorageLasVegasHeaders; +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(HPCloudObjectStorageLasVegasHeaders.CDN_URI), + HPCloudObjectStorageLasVegasHeaders.CDN_URI); + String cdnTTL = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageLasVegasHeaders.CDN_TTL), + HPCloudObjectStorageLasVegasHeaders.CDN_TTL); + String cdnEnabled = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED), + HPCloudObjectStorageLasVegasHeaders.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/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/reference/HPCloudObjectStorageLasVegasConstants.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/reference/HPCloudObjectStorageLasVegasConstants.java index 70ef5f5ba0..6167afa1af 100644 --- a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/reference/HPCloudObjectStorageLasVegasConstants.java +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/reference/HPCloudObjectStorageLasVegasConstants.java @@ -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"; } diff --git a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/reference/HPCloudObjectStorageLasVegasHeaders.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/reference/HPCloudObjectStorageLasVegasHeaders.java index 2e805b13f6..99403094d8 100644 --- a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/reference/HPCloudObjectStorageLasVegasHeaders.java +++ b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/objectstorage/lvs/reference/HPCloudObjectStorageLasVegasHeaders.java @@ -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"; + } diff --git a/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/services/HPExtensionBlockStore.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/services/HPExtensionBlockStore.java new file mode 100644 index 0000000000..333aa3ad5c --- /dev/null +++ b/providers/hpcloud-objectstorage-lvs/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/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/services/HPExtensionCDN.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/services/HPExtensionCDN.java new file mode 100644 index 0000000000..5922838983 --- /dev/null +++ b/providers/hpcloud-objectstorage-lvs/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/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/services/HPExtentionServiceType.java b/providers/hpcloud-objectstorage-lvs/src/main/java/org/jclouds/hpcloud/services/HPExtentionServiceType.java new file mode 100644 index 0000000000..311117a390 --- /dev/null +++ b/providers/hpcloud-objectstorage-lvs/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/providers/hpcloud-objectstorage-lvs/src/test/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasClientLiveTest.java b/providers/hpcloud-objectstorage-lvs/src/test/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasClientLiveTest.java index 3f598ace2a..0c394d4139 100644 --- a/providers/hpcloud-objectstorage-lvs/src/test/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasClientLiveTest.java +++ b/providers/hpcloud-objectstorage-lvs/src/test/java/org/jclouds/hpcloud/objectstorage/lvs/HPCloudObjectStorageLasVegasClientLiveTest.java @@ -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 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/providers/hpcloud-objectstorage-lvs/src/test/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/integration/HPCloudObjectStorageLasVegasContainerLiveTest.java b/providers/hpcloud-objectstorage-lvs/src/test/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/integration/HPCloudObjectStorageLasVegasContainerLiveTest.java index 84583af635..1e765bca0f 100644 --- a/providers/hpcloud-objectstorage-lvs/src/test/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/integration/HPCloudObjectStorageLasVegasContainerLiveTest.java +++ b/providers/hpcloud-objectstorage-lvs/src/test/java/org/jclouds/hpcloud/objectstorage/lvs/blobstore/integration/HPCloudObjectStorageLasVegasContainerLiveTest.java @@ -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(); } diff --git a/resources/NOTICE.txt b/resources/NOTICE.txt index 03b15270e5..b0a56c74b6 100644 --- a/resources/NOTICE.txt +++ b/resources/NOTICE.txt @@ -60,3 +60,7 @@ distributed under the GNU Lesser GPL License, Version 3.0. This product includes aopalliance (http://aopalliance.sourceforge.net/) distributed in the Public Domain + +This product includes software developed at Hewlett-Packard +Copyright (c) 2011-2012 Hewlett-Packard Development Company, L.P +