JCLOUDS-296 unasync legacy cloudfiles provider.

This commit is contained in:
Adrian Cole 2014-10-03 19:12:56 -07:00 committed by Adrian Cole
parent bbad831c00
commit 0ab1988a7f
10 changed files with 149 additions and 382 deletions

View File

@ -21,31 +21,18 @@ import java.util.Properties;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.cloudfiles.blobstore.config.CloudFilesBlobStoreContextModule;
import org.jclouds.cloudfiles.config.CloudFilesRestClientModule;
import org.jclouds.cloudfiles.config.CloudFilesRestClientModule.StorageAndCDNManagementEndpointModule;
import org.jclouds.cloudfiles.config.CloudFilesHttpApiModule;
import org.jclouds.cloudfiles.config.CloudFilesHttpApiModule.StorageAndCDNManagementEndpointModule;
import org.jclouds.openstack.swift.SwiftApiMetadata;
import org.jclouds.openstack.swift.blobstore.SwiftBlobSigner;
import org.jclouds.openstack.swift.blobstore.config.TemporaryUrlExtensionModule;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Implementation of {@link ApiMetadata} for Rackspace Cloud Files API
*/
public class CloudFilesApiMetadata extends SwiftApiMetadata {
/**
* @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(CloudFilesClient.class)} as
* {@link CloudFilesAsyncClient} interface will be removed in jclouds 1.7.
*/
@Deprecated
public static final TypeToken<org.jclouds.rest.RestContext<CloudFilesClient, CloudFilesAsyncClient>> CONTEXT_TOKEN = new TypeToken<org.jclouds.rest.RestContext<CloudFilesClient, CloudFilesAsyncClient>>() {
private static final long serialVersionUID = 1L;
};
@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
@ -64,20 +51,19 @@ public class CloudFilesApiMetadata extends SwiftApiMetadata {
return properties;
}
public static class Builder extends SwiftApiMetadata.Builder<Builder> {
@SuppressWarnings("deprecation")
public static class Builder extends SwiftApiMetadata.Builder<CloudFilesClient, Builder> {
protected Builder() {
super(CloudFilesClient.class, CloudFilesAsyncClient.class);
super(CloudFilesClient.class);
id("cloudfiles")
.name("Rackspace Cloud Files API")
.identityName("Username")
.credentialName("API Key")
.documentation(URI.create("http://docs.rackspacecloud.com/files/api/v1/cfdevguide_d5/content/ch01.html"))
.defaultProperties(CloudFilesApiMetadata.defaultProperties())
.context(CONTEXT_TOKEN)
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(StorageAndCDNManagementEndpointModule.class)
.add(CloudFilesRestClientModule.class)
.add(CloudFilesHttpApiModule.class)
.add(CloudFilesBlobStoreContextModule.class)
.add(CloudFilesTemporaryUrlExtensionModule.class).build());
}
@ -93,10 +79,10 @@ public class CloudFilesApiMetadata extends SwiftApiMetadata {
}
}
public static class CloudFilesTemporaryUrlExtensionModule extends TemporaryUrlExtensionModule<CloudFilesAsyncClient> {
public static class CloudFilesTemporaryUrlExtensionModule extends TemporaryUrlExtensionModule<CloudFilesClient> {
@Override
protected void bindRequestSigner() {
bind(BlobRequestSigner.class).to(new TypeLiteral<SwiftBlobSigner<CloudFilesAsyncClient>>() {
bind(BlobRequestSigner.class).to(new TypeLiteral<SwiftBlobSigner<CloudFilesClient>>() {
});
}
}

View File

@ -1,214 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.cloudfiles;
import java.net.URI;
import java.util.Set;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
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.BlobStoreFallbacks.NullOnContainerNotFound;
import org.jclouds.cloudfiles.binders.BindIterableToHeadersWithPurgeCDNObjectEmail;
import org.jclouds.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.cloudfiles.functions.ParseCdnUriFromHeaders;
import org.jclouds.cloudfiles.functions.ParseContainerCDNMetadataFromHeaders;
import org.jclouds.cloudfiles.options.ListCdnContainerOptions;
import org.jclouds.cloudfiles.reference.CloudFilesHeaders;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.SwiftAsyncClient;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.Fallback;
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 com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to Cloud Files via their REST API.
* <p/>
* All commands return a ListenableFuture of the result from Cloud Files. Any exceptions incurred
* during processing will be backend in an {@link ExecutionException} as documented in
* {@link ListenableFuture#get()}.
*
* @see CloudFilesClient
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090812.pdf" />
* @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(CloudFilesClient.class)} as
* {@link CloudFilesAsyncClient} interface will be removed in jclouds 1.7.
*/
@Deprecated
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface CloudFilesAsyncClient extends SwiftAsyncClient {
/**
* @see CloudFilesClient#listCDNContainers
*/
@Named("ListCDNEnabledContainers")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/")
@Endpoint(CDNManagement.class)
ListenableFuture<? extends Set<ContainerCDNMetadata>> listCDNContainers(ListCdnContainerOptions... options);
/**
* @see CloudFilesClient#getCDNMetadata
*/
@Named("ListCDNEnabledContainerMetadata")
@HEAD
@ResponseParser(ParseContainerCDNMetadataFromHeaders.class)
@Fallback(NullOnContainerNotFound.class)
@Path("/{container}")
@Endpoint(CDNManagement.class)
ListenableFuture<ContainerCDNMetadata> getCDNMetadata(@PathParam("container") String container);
/**
* @see CloudFilesClient#enableCDN(String, long, boolean);
*/
@Named("CDNEnableContainer")
@PUT
@Path("/{container}")
@Headers(keys = CloudFilesHeaders.CDN_ENABLED, values = "True")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
ListenableFuture<URI> enableCDN(@PathParam("container") String container,
@HeaderParam(CloudFilesHeaders.CDN_TTL) long ttl,
@HeaderParam(CloudFilesHeaders.CDN_LOG_RETENTION) boolean logRetention);
/**
* @see CloudFilesClient#enableCDN(String, long);
*/
@Named("CDNEnableContainer")
@PUT
@Path("/{container}")
@Headers(keys = CloudFilesHeaders.CDN_ENABLED, values = "True")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
ListenableFuture<URI> enableCDN(@PathParam("container") String container,
@HeaderParam(CloudFilesHeaders.CDN_TTL) long ttl);
/**
* @see CloudFilesClient#enableCDN(String)
*/
@Named("CDNEnableContainer")
@PUT
@Path("/{container}")
@Headers(keys = CloudFilesHeaders.CDN_ENABLED, values = "True")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
ListenableFuture<URI> enableCDN(@PathParam("container") String container);
/**
* @see CloudFilesClient#updateCDN(long, boolean)
*/
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
ListenableFuture<URI> updateCDN(@PathParam("container") String container,
@HeaderParam(CloudFilesHeaders.CDN_TTL) long ttl,
@HeaderParam(CloudFilesHeaders.CDN_LOG_RETENTION) boolean logRetention);
/**
* @see CloudFilesClient#updateCDN(boolean)
*/
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
ListenableFuture<URI> updateCDN(@PathParam("container") String container,
@HeaderParam(CloudFilesHeaders.CDN_LOG_RETENTION) boolean logRetention);
/**
* @see CloudFilesClient#updateCDN(long)
*/
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
ListenableFuture<URI> updateCDN(@PathParam("container") String container,
@HeaderParam(CloudFilesHeaders.CDN_TTL) long ttl);
/**
* @see CloudFilesClient#disableCDN
*/
@Named("DisableCDNEnabledContainer")
@POST
@Path("/{container}")
@Headers(keys = CloudFilesHeaders.CDN_ENABLED, values = "False")
@Endpoint(CDNManagement.class)
ListenableFuture<Boolean> disableCDN(@PathParam("container") String container);
/**
* @see CloudFilesClient#purgeCDNObject(String, String, Iterable)
*/
@Named("PurgeCDNEnabledObject")
@DELETE
@Path("/{container}/{object}")
@Headers(keys = CloudFilesHeaders.CDN_CONTAINER_PURGE_OBJECT_EMAIL, values = "{email}")
@Endpoint(CDNManagement.class)
ListenableFuture<Boolean> purgeCDNObject(@PathParam("container") String container,
@PathParam("object") String object,
@BinderParam(BindIterableToHeadersWithPurgeCDNObjectEmail.class) Iterable<String> emails);
/**
* @see CloudFilesClient#purgeCDNObject(String, String)
*/
@Named("PurgeCDNEnabledObject")
@DELETE
@Path("/{container}/{object}")
@Endpoint(CDNManagement.class)
ListenableFuture<Boolean> purgeCDNObject(@PathParam("container") String container,
@PathParam("object") String object);
/**
* @see CloudFilesClient#setCDNStaticWebsiteIndex
*/
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@Headers(keys = CloudFilesHeaders.CDN_WEBSITE_INDEX, values = "{index}")
ListenableFuture<Boolean> setCDNStaticWebsiteIndex(@PathParam("container") String container,
@PathParam("index") String index);
/**
* @see CloudFilesClient#setCDNStaticWebsiteError
*/
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@Headers(keys = CloudFilesHeaders.CDN_WEBSITE_ERROR, values = "{error}")
ListenableFuture<Boolean> setCDNStaticWebsiteError(@PathParam("container") String container,
@PathParam("error") String error);
}

View File

@ -16,23 +16,59 @@
*/
package org.jclouds.cloudfiles;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.jclouds.blobstore.BlobStoreFallbacks.NullOnContainerNotFound;
import static org.jclouds.cloudfiles.reference.CloudFilesHeaders.CDN_CONTAINER_PURGE_OBJECT_EMAIL;
import static org.jclouds.cloudfiles.reference.CloudFilesHeaders.CDN_ENABLED;
import static org.jclouds.cloudfiles.reference.CloudFilesHeaders.CDN_LOG_RETENTION;
import static org.jclouds.cloudfiles.reference.CloudFilesHeaders.CDN_TTL;
import static org.jclouds.cloudfiles.reference.CloudFilesHeaders.CDN_WEBSITE_ERROR;
import static org.jclouds.cloudfiles.reference.CloudFilesHeaders.CDN_WEBSITE_INDEX;
import java.net.URI;
import java.util.Set;
import org.jclouds.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.cloudfiles.options.ListCdnContainerOptions;
import org.jclouds.openstack.swift.SwiftClient;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
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;
/**
* Provides access to Cloud Files via their REST API.
*
* @see <a href="http://docs.rackspace.com/files/api/v1/cf-devguide/content/index.html">Cloud Files</a>
*/
import org.jclouds.cloudfiles.binders.BindIterableToHeadersWithPurgeCDNObjectEmail;
import org.jclouds.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.cloudfiles.functions.ParseCdnUriFromHeaders;
import org.jclouds.cloudfiles.functions.ParseContainerCDNMetadataFromHeaders;
import org.jclouds.cloudfiles.options.ListCdnContainerOptions;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.SwiftClient;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
/** Provides access to Cloud Files via their REST API. */
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface CloudFilesClient extends SwiftClient {
/**
* Retrieve a list of existing CDN-enabled containers.
*/
@Named("ListCDNEnabledContainers")
@GET
@Consumes(APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/")
@Endpoint(CDNManagement.class)
Set<ContainerCDNMetadata> listCDNContainers(ListCdnContainerOptions... options);
/**
@ -45,7 +81,13 @@ public interface CloudFilesClient extends SwiftClient {
* whether the container is currently marked to allow public serving of objects via CDN. The log_retention setting
* specifies whether the CDN access logs should be collected and stored in the Cloud Files storage system.
*/
ContainerCDNMetadata getCDNMetadata(String container);
@Named("ListCDNEnabledContainerMetadata")
@HEAD
@ResponseParser(ParseContainerCDNMetadataFromHeaders.class)
@Fallback(NullOnContainerNotFound.class)
@Path("/{container}")
@Endpoint(CDNManagement.class)
ContainerCDNMetadata getCDNMetadata(@PathParam("container") String container);
/**
* Before a container can be CDN-enabled, it must exist in the storage system. When a container is CDN-enabled, any
@ -62,37 +104,80 @@ public interface CloudFilesClient extends SwiftClient {
* will stay populated on CDN edge servers for the entire period. The most popular objects stay cached based on the
* edge location's logic.
*/
URI enableCDN(String container, long ttl, boolean logRetention);
@Named("CDNEnableContainer")
@PUT
@Path("/{container}")
@Headers(keys = CDN_ENABLED, values = "True")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
URI enableCDN(@PathParam("container") String container,
@HeaderParam(CDN_TTL) long ttl,
@HeaderParam(CDN_LOG_RETENTION) boolean logRetention);
/**
* @see CloudFilesClient#enableCDN(String, long, boolean)
*/
URI enableCDN(String container, long ttl);
@Named("CDNEnableContainer")
@PUT
@Path("/{container}")
@Headers(keys = CDN_ENABLED, values = "True")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
URI enableCDN(@PathParam("container") String container, @HeaderParam(CDN_TTL) long ttl);
/**
* @see CloudFilesClient#enableCDN(String, long, boolean)
*/
URI enableCDN(String container);
@Named("CDNEnableContainer")
@PUT
@Path("/{container}")
@Headers(keys = CDN_ENABLED, values = "True")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
URI enableCDN(@PathParam("container") String container);
/**
* @see CloudFilesClient#enableCDN(String, long, boolean)
*/
URI updateCDN(String container, long ttl, boolean logRetention);
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
URI updateCDN(@PathParam("container") String container,
@HeaderParam(CDN_TTL) long ttl,
@HeaderParam(CDN_LOG_RETENTION) boolean logRetention);
/**
* @see CloudFilesClient#enableCDN(String, long, boolean)
*/
URI updateCDN(String container, boolean logRetention);
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
URI updateCDN(@PathParam("container") String container, @HeaderParam(CDN_LOG_RETENTION) boolean logRetention);
/**
* @see CloudFilesClient#enableCDN(String, long, boolean)
*/
URI updateCDN(String container, long ttl);
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CDNManagement.class)
URI updateCDN(@PathParam("container") String container, @HeaderParam(CDN_TTL) long ttl);
/**
* Remove the container from the CDN. Please note, however, that objects remain public until their TTL expires.
*/
boolean disableCDN(String container);
@Named("DisableCDNEnabledContainer")
@POST
@Path("/{container}")
@Headers(keys = CDN_ENABLED, values = "False")
@Endpoint(CDNManagement.class)
boolean disableCDN(@PathParam("container") String container);
/**
* You can purge a CDN-enabled object when you find it absolutely necessary to remove the object from public access
@ -107,12 +192,23 @@ public interface CloudFilesClient extends SwiftClient {
* (2) by creating a support ticket to purge entire containers. The 25-object limit does not apply when purging an
* entire container via Support.
*/
boolean purgeCDNObject(String container, String object, Iterable<String> emails);
@Named("PurgeCDNEnabledObject")
@DELETE
@Path("/{container}/{object}")
@Headers(keys = CDN_CONTAINER_PURGE_OBJECT_EMAIL, values = "{email}")
@Endpoint(CDNManagement.class)
boolean purgeCDNObject(@PathParam("container") String container, @PathParam("object") String object,
@BinderParam(BindIterableToHeadersWithPurgeCDNObjectEmail.class) Iterable<String> emails);
/**
* @see CloudFilesClient#purgeCDNObject(String, String, Iterable)
*/
boolean purgeCDNObject(String container, String object);
@Named("PurgeCDNEnabledObject")
@DELETE
@Path("/{container}/{object}")
@Endpoint(CDNManagement.class)
boolean purgeCDNObject(@PathParam("container") String container, @PathParam("object") String object);
/**
* You may use your Cloud Files account to create a static website on the World Wide Web. First, you must CDN-enable
@ -130,7 +226,11 @@ public interface CloudFilesClient extends SwiftClient {
* is outside the scope of this documentation. Once you have your CNAME established, map your domain name to your
* Cloud Files CDN URL to get your site up and running on the Web.
*/
boolean setCDNStaticWebsiteIndex(String container, String index);
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@Headers(keys = CDN_WEBSITE_INDEX, values = "{index}")
boolean setCDNStaticWebsiteIndex(@PathParam("container") String container, @PathParam("index") String index);
/**
* You may create and set custom error pages for visitors to your website; currently, only 401 (Unauthorized) and
@ -143,5 +243,9 @@ public interface CloudFilesClient extends SwiftClient {
*
* You need only set the error parameter once for your entire static website.
*/
boolean setCDNStaticWebsiteError(String container, String error);
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@Headers(keys = CDN_WEBSITE_ERROR, values = "{error}")
boolean setCDNStaticWebsiteError(@PathParam("container") String container, @PathParam("error") String error);
}

View File

@ -1,98 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.cloudfiles.blobstore;
import static com.google.common.util.concurrent.Futures.transform;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
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.cloudfiles.CloudFilesAsyncClient;
import org.jclouds.cloudfiles.CloudFilesClient;
import org.jclouds.cloudfiles.blobstore.functions.EnableCDNAndCache;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
import org.jclouds.openstack.swift.blobstore.functions.BlobStoreListContainerOptionsToListContainerOptions;
import org.jclouds.openstack.swift.blobstore.functions.BlobToObject;
import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceList;
import org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceMetadata;
import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlob;
import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata;
import org.jclouds.openstack.swift.blobstore.strategy.internal.AsyncMultipartUploadStrategy;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
/**
*
* @deprecated will be removed in jclouds 1.7, as async interfaces are no longer
* supported. Please use {@link CloudFilesBlobStore}
*/
@Deprecated
@Singleton
public class CloudFilesAsyncBlobStore extends SwiftAsyncBlobStore {
private final EnableCDNAndCache enableCDNAndCache;
@Inject
protected CloudFilesAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, CloudFilesClient sync, CloudFilesAsyncClient async,
ContainerToResourceMetadata container2ResourceMd,
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableCDNAndCache,
Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) {
super(context, blobUtils, userExecutor, defaultLocation, locations, sync, async, container2ResourceMd,
container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd,
blob2ObjectGetOptions, fetchBlobMetadataProvider, multipartUploadStrategy);
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 transform(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;
}
}, userExecutor);
return returnVal;
}
}

View File

@ -22,11 +22,9 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import org.jclouds.cloudfiles.CloudFilesClient;
import org.jclouds.cloudfiles.blobstore.CloudFilesAsyncBlobStore;
import org.jclouds.cloudfiles.blobstore.CloudFilesBlobStore;
import org.jclouds.cloudfiles.blobstore.functions.CloudFilesObjectToBlobMetadata;
import org.jclouds.cloudfiles.domain.ContainerCDNMetadata;
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;
@ -59,7 +57,6 @@ public class CloudFilesBlobStoreContextModule extends SwiftBlobStoreContextModul
protected void configure() {
super.configure();
bind(SwiftBlobStore.class).to(CloudFilesBlobStore.class);
bind(SwiftAsyncBlobStore.class).to(CloudFilesAsyncBlobStore.class);
bind(ObjectToBlobMetadata.class).to(CloudFilesObjectToBlobMetadata.class);
}
}

View File

@ -16,42 +16,35 @@
*/
package org.jclouds.cloudfiles.config;
import static org.jclouds.reflect.Reflection2.typeToken;
import java.net.URI;
import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.cloudfiles.CDNManagement;
import org.jclouds.cloudfiles.CloudFilesAsyncClient;
import org.jclouds.cloudfiles.CloudFilesClient;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
import org.jclouds.openstack.keystone.v1_1.suppliers.V1DefaultRegionIdSupplier;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.config.SwiftRestClientModule;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.openstack.swift.config.SwiftHttpApiModule;
import org.jclouds.rest.ConfiguresHttpApi;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Provides;
import com.google.inject.Scopes;
@ConfiguresRestClient
public class CloudFilesRestClientModule extends SwiftRestClientModule<CloudFilesClient, CloudFilesAsyncClient> {
public CloudFilesRestClientModule() {
super(typeToken(CloudFilesClient.class), typeToken(CloudFilesAsyncClient.class), ImmutableMap
.<Class<?>, Class<?>> of());
@ConfiguresHttpApi
public class CloudFilesHttpApiModule extends SwiftHttpApiModule<CloudFilesClient> {
public CloudFilesHttpApiModule() {
super(CloudFilesClient.class);
}
@Override
protected void bindResolvedClientsToCommonSwift() {
bind(CommonSwiftClient.class).to(CloudFilesClient.class).in(Scopes.SINGLETON);
bind(CommonSwiftAsyncClient.class).to(CloudFilesAsyncClient.class).in(Scopes.SINGLETON);
}
public static class StorageAndCDNManagementEndpointModule extends AuthenticationServiceModule {

View File

@ -45,7 +45,7 @@ public class CloudFilesClientLiveTest extends CommonSwiftClientLiveTest<CloudFil
@Override
public CloudFilesClient getApi() {
return view.unwrap(CloudFilesApiMetadata.CONTEXT_TOKEN).getApi();
return view.unwrapApi(CloudFilesClient.class);
}
@Override

View File

@ -27,8 +27,8 @@ import org.jclouds.blobstore.internal.BaseBlobSignerExpectTest;
import org.jclouds.cloudfiles.CloudFilesApiMetadata;
import org.jclouds.cloudfiles.CloudFilesApiMetadata.CloudFilesTemporaryUrlExtensionModule;
import org.jclouds.cloudfiles.blobstore.config.CloudFilesBlobStoreContextModule;
import org.jclouds.cloudfiles.config.CloudFilesRestClientModule;
import org.jclouds.cloudfiles.config.CloudFilesRestClientModule.StorageAndCDNManagementEndpointModule;
import org.jclouds.cloudfiles.config.CloudFilesHttpApiModule;
import org.jclouds.cloudfiles.config.CloudFilesHttpApiModule.StorageAndCDNManagementEndpointModule;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
@ -142,7 +142,7 @@ public class CloudFilesBlobSignerExpectTest extends BaseBlobSignerExpectTest {
.defaultModules(
ImmutableSet.<Class<? extends Module>> builder()
.add(StorageAndCDNManagementEndpointModule.class)
.add(CloudFilesRestClientModule.class)
.add(CloudFilesHttpApiModule.class)
.add(CloudFilesBlobStoreContextModule.class)
.add(StaticTimeAndTemporaryUrlKeyModule.class).build()).build();
}

View File

@ -31,16 +31,16 @@ public class CloudFilesRestClientModuleTest {
@Test
public void testWithKey() {
assertEquals(
CloudFilesRestClientModule.<String, String> valueForKey(
Suppliers.<Map<String, Supplier<String>>> ofInstance(ImmutableMap.of("foo",
Suppliers.ofInstance("bar"))), Suppliers.ofInstance("foo")).get(), "bar");
CloudFilesHttpApiModule.<String, String> valueForKey(Suppliers
.<Map<String, Supplier<String>>>ofInstance(ImmutableMap.of("foo", Suppliers.ofInstance("bar"))),
Suppliers.ofInstance("foo")).get(), "bar");
}
@Test
public void testWithKeyUnmatchedIsNull() {
assertEquals(
CloudFilesRestClientModule.<String, String> valueForKey(
Suppliers.<Map<String, Supplier<String>>> ofInstance(ImmutableMap.of("boo",
Suppliers.ofInstance("bar"))), Suppliers.ofInstance("foo")).get(), null);
CloudFilesHttpApiModule.<String, String> valueForKey(Suppliers
.<Map<String, Supplier<String>>>ofInstance(ImmutableMap.of("boo", Suppliers.ofInstance("bar"))),
Suppliers.ofInstance("foo")).get(), null);
}
}

View File

@ -18,7 +18,6 @@ package org.jclouds.rackspace.cloudfiles;
import static org.testng.Assert.assertEquals;
import org.jclouds.cloudfiles.CloudFilesApiMetadata;
import org.jclouds.cloudfiles.CloudFilesClient;
import org.jclouds.cloudfiles.CloudFilesClientLiveTest;
import org.jclouds.openstack.swift.domain.SwiftObject;
@ -37,7 +36,7 @@ public class CloudFilesUKClientLiveTest extends CloudFilesClientLiveTest {
@Override
public CloudFilesClient getApi() {
return view.unwrap(CloudFilesApiMetadata.CONTEXT_TOKEN).getApi();
return view.unwrapApi(CloudFilesClient.class);
}
@Override