mirror of https://github.com/apache/jclouds.git
removed CDN support for now
This commit is contained in:
parent
aa99223558
commit
18e43fb6f4
|
@ -1,40 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.hpcloud.object.storage;
|
||||
|
||||
import 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,36 +18,22 @@
|
|||
*/
|
||||
package org.jclouds.hpcloud.object.storage;
|
||||
|
||||
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.object.storage.domain.ContainerCDNMetadata;
|
||||
import org.jclouds.hpcloud.object.storage.functions.ParseCDNUriFromHeaders;
|
||||
import org.jclouds.hpcloud.object.storage.functions.ParseContainerCDNMetadataFromHeaders;
|
||||
import org.jclouds.hpcloud.object.storage.functions.ParseContainerMetadataFromHeaders;
|
||||
import org.jclouds.hpcloud.object.storage.options.CreateContainerOptions;
|
||||
import org.jclouds.hpcloud.object.storage.options.ListCDNContainerOptions;
|
||||
import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders;
|
||||
import org.jclouds.openstack.filters.AuthenticateRequest;
|
||||
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;
|
||||
|
@ -71,28 +57,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
@Endpoint(Storage.class)
|
||||
public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient {
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#listCDNContainers(ListCDNContainerOptions)
|
||||
*/
|
||||
@Beta
|
||||
@GET
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@QueryParams(keys = "format", values = "json")
|
||||
@Path("/")
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<? extends Set<ContainerCDNMetadata>> listCDNContainers(ListCDNContainerOptions... options);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#getCDNMetadata(String)
|
||||
*/
|
||||
@Beta
|
||||
@HEAD
|
||||
@ResponseParser(ParseContainerCDNMetadataFromHeaders.class)
|
||||
@ExceptionParser(ReturnNullOnContainerNotFound.class)
|
||||
@Path("/{container}")
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<ContainerCDNMetadata> getCDNMetadata(@PathParam("container") String container);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#getCDNMetadata(String)
|
||||
*/
|
||||
|
@ -111,48 +75,5 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient
|
|||
ListenableFuture<Boolean> createContainer(@PathParam("container") String container,
|
||||
CreateContainerOptions... options);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#enableCDN(String, long)
|
||||
*/
|
||||
@Beta
|
||||
@PUT
|
||||
@Path("/{container}")
|
||||
@Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "True")
|
||||
@ResponseParser(ParseCDNUriFromHeaders.class)
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<URI> enableCDN(@PathParam("container") String container,
|
||||
@HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#enableCDN(String)
|
||||
*/
|
||||
@Beta
|
||||
@PUT
|
||||
@Path("/{container}")
|
||||
@Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "True")
|
||||
@ResponseParser(ParseCDNUriFromHeaders.class)
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<URI> enableCDN(@PathParam("container") String container);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#updateCDN(String, long)
|
||||
*/
|
||||
@Beta
|
||||
@POST
|
||||
@Path("/{container}")
|
||||
@ResponseParser(ParseCDNUriFromHeaders.class)
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<URI> updateCDN(@PathParam("container") String container,
|
||||
@HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#disableCDN(String)
|
||||
*/
|
||||
@Beta
|
||||
@PUT
|
||||
@Path("/{container}")
|
||||
@Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "False")
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<Boolean> disableCDN(@PathParam("container") String container);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,19 +18,14 @@
|
|||
*/
|
||||
package org.jclouds.hpcloud.object.storage;
|
||||
|
||||
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.object.storage.domain.ContainerCDNMetadata;
|
||||
import org.jclouds.hpcloud.object.storage.options.CreateContainerOptions;
|
||||
import org.jclouds.hpcloud.object.storage.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;
|
||||
|
||||
/**
|
||||
|
@ -52,22 +47,4 @@ public interface HPCloudObjectStorageClient 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);
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.hpcloud.object.storage;
|
|||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
|
||||
import static org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageConstants.PROPERTY_CDN_ENDPOINT;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -43,13 +42,6 @@ public class HPCloudObjectStoragePropertiesBuilder extends SwiftPropertiesBuilde
|
|||
properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV");
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.objects.hpcloudsvc.com/auth");
|
||||
properties.setProperty(PROPERTY_API_VERSION, OpenStackAuthAsyncClient.VERSION);
|
||||
properties.setProperty(PROPERTY_CDN_ENDPOINT, "https://region-a.geo-1.cdnmgmt.hpcloudsvc.com");
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected HPCloudObjectStoragePropertiesBuilder withCDNEndpoint(String endpoint) {
|
||||
properties.setProperty(PROPERTY_CDN_ENDPOINT, endpoint);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,15 +29,12 @@ 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.object.storage.HPCloudObjectStorageAsyncClient;
|
||||
import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient;
|
||||
import org.jclouds.hpcloud.object.storage.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;
|
||||
|
@ -46,9 +43,7 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -56,7 +51,6 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
*/
|
||||
@Singleton
|
||||
public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
|
||||
private final EnableCDNAndCache enableCDNAndCache;
|
||||
|
||||
@Inject
|
||||
protected HPCloudObjectStorageAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||
|
@ -66,30 +60,10 @@ public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
|
|||
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
||||
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
||||
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
|
||||
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache) {
|
||||
Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
||||
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,12 +26,10 @@ 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.object.storage.blobstore.functions.EnableCDNAndCache;
|
||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||
import org.jclouds.openstack.swift.blobstore.SwiftBlobStore;
|
||||
import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions;
|
||||
|
@ -50,30 +48,16 @@ import com.google.common.base.Supplier;
|
|||
@Singleton
|
||||
public class HPCloudObjectStorageBlobStore extends SwiftBlobStore {
|
||||
|
||||
private EnableCDNAndCache enableCDNAndCache;
|
||||
|
||||
@Inject
|
||||
protected HPCloudObjectStorageBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
|
||||
@Memoized Supplier<Set<? extends Location>> locations, CommonSwiftClient sync,
|
||||
ContainerToResourceMetadata container2ResourceMd,
|
||||
protected HPCloudObjectStorageBlobStore(BlobStoreContext context, BlobUtils blobUtils,
|
||||
Supplier<Location> defaultLocation, @Memoized Supplier<Set<? extends Location>> locations,
|
||||
CommonSwiftClient sync, ContainerToResourceMetadata container2ResourceMd,
|
||||
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
|
||||
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
|
||||
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
|
||||
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache) {
|
||||
Provider<FetchBlobMetadata> fetchBlobMetadataProvider) {
|
||||
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,74 +18,20 @@
|
|||
*/
|
||||
package org.jclouds.hpcloud.object.storage.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.object.storage.HPCloudObjectStorageClient;
|
||||
import org.jclouds.hpcloud.object.storage.blobstore.HPCloudObjectStorageAsyncBlobStore;
|
||||
import org.jclouds.hpcloud.object.storage.blobstore.HPCloudObjectStorageBlobStore;
|
||||
import org.jclouds.hpcloud.object.storage.blobstore.functions.HPCloudObjectStorageObjectToBlobMetadata;
|
||||
import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.Logger;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreContextModule {
|
||||
|
||||
@Beta
|
||||
@Singleton
|
||||
public static final class GetCDNMetadata extends CacheLoader<String, URI> {
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final HPCloudObjectStorageClient client;
|
||||
|
||||
@Inject
|
||||
public GetCDNMetadata(HPCloudObjectStorageClient 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();
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.hpcloud.object.storage.blobstore.functions;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient;
|
||||
|
||||
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 HPCloudObjectStorageClient sync;
|
||||
|
||||
@Inject
|
||||
public EnableCDNAndCache(HPCloudObjectStorageClient 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -31,20 +31,16 @@ import org.jclouds.openstack.swift.domain.ObjectInfo;
|
|||
*/
|
||||
@Singleton
|
||||
public class HPCloudObjectStorageObjectToBlobMetadata extends ObjectToBlobMetadata {
|
||||
private final PublicUriForObjectInfo publicUriForObjectInfo;
|
||||
|
||||
@Inject
|
||||
public HPCloudObjectStorageObjectToBlobMetadata(IfDirectoryReturnNameStrategy ifDirectoryReturnName,
|
||||
PublicUriForObjectInfo publicUriForObjectInfo) {
|
||||
public HPCloudObjectStorageObjectToBlobMetadata(IfDirectoryReturnNameStrategy ifDirectoryReturnName) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.hpcloud.object.storage.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,19 +18,11 @@
|
|||
*/
|
||||
package org.jclouds.hpcloud.object.storage.config;
|
||||
|
||||
import static org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageConstants.PROPERTY_CDN_ENDPOINT;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.hpcloud.object.storage.CDNManagement;
|
||||
import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageAsyncClient;
|
||||
import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
|
||||
import org.jclouds.openstack.reference.AuthHeaders;
|
||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||
import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule;
|
||||
|
@ -44,8 +36,9 @@ import com.google.inject.Provides;
|
|||
*/
|
||||
@ConfiguresRestClient
|
||||
@RequiresHttp
|
||||
public class HPCloudObjectStorageRestClientModule extends BaseSwiftRestClientModule<HPCloudObjectStorageClient, HPCloudObjectStorageAsyncClient> {
|
||||
|
||||
public class HPCloudObjectStorageRestClientModule extends
|
||||
BaseSwiftRestClientModule<HPCloudObjectStorageClient, HPCloudObjectStorageAsyncClient> {
|
||||
|
||||
public HPCloudObjectStorageRestClientModule() {
|
||||
super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class);
|
||||
}
|
||||
|
@ -62,15 +55,4 @@ public class HPCloudObjectStorageRestClientModule extends BaseSwiftRestClientMod
|
|||
return in;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@CDNManagement
|
||||
protected URI provideCDNUrl(AuthenticationResponse response, @Named(PROPERTY_CDN_ENDPOINT) String cdnEndpoint) {
|
||||
|
||||
if (response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL) == null) {
|
||||
return URI.create(cdnEndpoint + response.getServices().get(AuthHeaders.STORAGE_URL).getPath());
|
||||
}
|
||||
// Placeholder for when the Object Storage service returns the CDN Management URL in the headers
|
||||
return response.getServices().get(AuthHeaders.CDN_MANAGEMENT_URL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.hpcloud.object.storage.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders;
|
||||
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(HPCloudObjectStorageHeaders.CDN_URI),
|
||||
HPCloudObjectStorageHeaders.CDN_URI);
|
||||
return URI.create(cdnUri);
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.hpcloud.object.storage.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.object.storage.domain.ContainerCDNMetadata;
|
||||
import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders;
|
||||
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(HPCloudObjectStorageHeaders.CDN_URI),
|
||||
HPCloudObjectStorageHeaders.CDN_URI);
|
||||
String cdnTTL = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CDN_TTL),
|
||||
HPCloudObjectStorageHeaders.CDN_TTL);
|
||||
String cdnEnabled = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CDN_ENABLED),
|
||||
HPCloudObjectStorageHeaders.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;
|
||||
}
|
||||
}
|
|
@ -26,9 +26,4 @@ package org.jclouds.hpcloud.object.storage.reference;
|
|||
*/
|
||||
public interface HPCloudObjectStorageConstants {
|
||||
|
||||
/**
|
||||
* The CDN Endpoint property
|
||||
*/
|
||||
public static final String PROPERTY_CDN_ENDPOINT = "jclouds.hpcloud-object-storage.cdn.endpoint";
|
||||
|
||||
}
|
||||
|
|
|
@ -29,12 +29,5 @@ import org.jclouds.openstack.swift.reference.SwiftHeaders;
|
|||
*
|
||||
*/
|
||||
public interface HPCloudObjectStorageHeaders extends SwiftHeaders {
|
||||
|
||||
public static final String CDN_ENABLED = "X-Cdn-Enabled";
|
||||
public static final String CDN_LOG_RETENTION = "X-Log-Retention";
|
||||
public static final String CDN_REFERRER_ACL = "X-Referrer-ACL";
|
||||
public static final String CDN_TTL = "X-Ttl";
|
||||
public static final String CDN_URI = "X-Cdn-Uri";
|
||||
public static final String CDN_USER_AGENT_ACL = "X-User-Agent-ACL";
|
||||
|
||||
}
|
||||
|
|
|
@ -19,13 +19,7 @@
|
|||
package org.jclouds.hpcloud.object.storage;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata;
|
||||
import org.jclouds.hpcloud.object.storage.options.ListCDNContainerOptions;
|
||||
import org.jclouds.openstack.swift.CommonSwiftClientLiveTest;
|
||||
import org.jclouds.openstack.swift.domain.SwiftObject;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -47,99 +41,4 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes
|
|||
assertEquals(getBlob.getInfo().getContentType(), "application/x-www-form-urlencoded");
|
||||
}
|
||||
|
||||
// CDN service due to go live Q1 2012
|
||||
@Test(enabled = false)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue