mirror of https://github.com/apache/jclouds.git
HP Cloud Identity Services/CDN
This commit is contained in:
commit
14b46dd126
|
@ -52,7 +52,7 @@ public class Service implements Comparable<Service> {
|
|||
protected Set<Endpoint> endpoints = ImmutableSet.of();
|
||||
|
||||
/**
|
||||
* @see Service#getId()
|
||||
* @see Service#getType()
|
||||
*/
|
||||
public Builder type(String type) {
|
||||
this.type = checkNotNull(type, "type");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 <a href="https://manage.hpcloud.com/pages/build/docs/object-storage/api">HP Cloud Object Storage API</a>
|
||||
* @author Jeremy Daggett
|
||||
*
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Qualifier
|
||||
public @interface CDNManagement {
|
||||
|
||||
}
|
|
@ -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<Boolean> 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<? extends Set<ContainerCDNMetadata>> listCDNContainers(ListCDNContainerOptions... options);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#getCDNMetadata(String)
|
||||
*/
|
||||
@Beta
|
||||
@HEAD
|
||||
@ResponseParser(ParseContainerCDNMetadataFromHeaders.class)
|
||||
@ExceptionParser(ReturnNullOnContainerNotFound.class)
|
||||
@Path("/{container}")
|
||||
@Endpoint(HPExtensionCDN.class)
|
||||
ListenableFuture<ContainerCDNMetadata> 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<URI> 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<URI> enableCDN(@PathParam("container") String container);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#updateCDN(String, long)
|
||||
*/
|
||||
@Beta
|
||||
@POST
|
||||
@Path("/{container}")
|
||||
@ResponseParser(ParseCDNUriFromHeaders.class)
|
||||
@Endpoint(HPExtensionCDN.class)
|
||||
ListenableFuture<URI> 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<Boolean> disableCDN(@PathParam("container") String container);
|
||||
|
||||
}
|
||||
|
|
|
@ -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<ContainerCDNMetadata> 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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<String, URI> {
|
||||
private final LoadingCache<String, URI> cdnContainer;
|
||||
private final HPCloudObjectStorageLasVegasClient sync;
|
||||
|
||||
@Inject
|
||||
public EnableCDNAndCache(HPCloudObjectStorageLasVegasClient sync, LoadingCache<String, URI> cdnContainer) {
|
||||
this.sync = sync;
|
||||
this.cdnContainer = cdnContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI apply(String input) {
|
||||
URI uri = sync.enableCDN(input);
|
||||
cdnContainer.put(input, uri);
|
||||
return uri;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ObjectInfo, URI> {
|
||||
private final LoadingCache<String, URI> cdnContainer;
|
||||
private final Provider<UriBuilder> uriBuilders;
|
||||
|
||||
@Inject
|
||||
public PublicUriForObjectInfo(LoadingCache<String, URI> cdnContainer, Provider<UriBuilder> 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<HPCloudObjectStorageLasVegasClient, HPCloudObjectStorageLasVegasAsyncClient> {
|
||||
RestClientModule<HPCloudObjectStorageLasVegasClient, HPCloudObjectStorageLasVegasAsyncClient> {
|
||||
|
||||
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
|
||||
|
@ -55,4 +96,18 @@ public class HPCloudObjectStorageLasVegasRestClientModule extends
|
|||
return in;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@HPExtensionCDN
|
||||
protected Supplier<URI> provideCDNUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
|
||||
return getLastValueInMap(factory.createForApiTypeAndVersion(HPExtentionServiceType.CDN, apiVersion));
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Storage
|
||||
protected Supplier<URI> provideStorageUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
|
||||
return getLastValueInMap(factory.createForApiTypeAndVersion(ServiceType.OBJECT_STORE, apiVersion));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<HttpResponse, URI> {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -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<HttpResponse, ContainerCDNMetadata>, InvocationContext<ParseContainerCDNMetadataFromHeaders> {
|
||||
|
||||
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<String> 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;
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
|
||||
}
|
||||
|
|
|
@ -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 <a href="http://docs.openstack.org/api/openstack-typeentity-service/2.0/content/Identity-Service-Concepts-e1362.html"
|
||||
* />
|
||||
* @see HPExtensionServiceType#BLOCK_STORE
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Qualifier
|
||||
public @interface HPExtensionBlockStore {
|
||||
|
||||
}
|
|
@ -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 <a href="http://docs.openstack.org/api/openstack-typeentity-service/2.0/content/Identity-Service-Concepts-e1362.html"
|
||||
* />
|
||||
* @see HPExtensionServiceType#CDN
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Qualifier
|
||||
public @interface HPExtensionCDN {
|
||||
|
||||
}
|
|
@ -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 <a href="http://docs.openstack.org/api/openstack-typeentity-service/2.0/content/Identity-Service-Concepts-e1362.html"
|
||||
* />
|
||||
*/
|
||||
public interface HPExtentionServiceType extends ServiceType {
|
||||
/**
|
||||
* CDN
|
||||
*/
|
||||
public static final String CDN = "hpext:cdn";
|
||||
/**
|
||||
* Block Storage
|
||||
*/
|
||||
public static final String BLOCK_STORE = "hpext:block-store";
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue