JCLOUDS-296 unasync hpcloud storage provider.

This commit is contained in:
Adrian Cole 2014-10-03 19:13:41 -07:00 committed by Adrian Cole
parent e3ada5b726
commit e243fa51a5
12 changed files with 169 additions and 446 deletions

View File

@ -16,27 +16,39 @@
*/
package org.jclouds.hpcloud.objectstorage;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.jclouds.openstack.swift.SwiftFallbacks.TrueOn404FalseOn409;
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.Path;
import javax.ws.rs.PathParam;
import org.jclouds.hpcloud.objectstorage.extensions.CDNContainerApi;
import org.jclouds.location.Region;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.domain.ContainerMetadata;
import org.jclouds.openstack.swift.options.ListContainerOptions;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Provides;
/**
* Provides synchronous access to HP Cloud Object Storage via the REST API.
*
* <p/>
* All commands return a ListenableFuture of the result. Any exceptions incurred during processing
* will be backend in an {@link java.util.concurrent.ExecutionException} as documented in
* {@link ListenableFuture#get()}.
*
* @see HPCloudObjectStorageAsyncApi
* @see <a href="https://manage.hpcloud.com/pages/build/docs/objectstorage-lvs/api">HP Cloud Object
* Storage API</a>
*/
/** Provides synchronous access to HP Cloud Object Storage via the REST API. */
@Deprecated
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface HPCloudObjectStorageApi extends CommonSwiftClient {
/**
*
@ -46,6 +58,20 @@ public interface HPCloudObjectStorageApi extends CommonSwiftClient {
@Region
Set<String> getConfiguredRegions();
@Override
@Named("ListContainers")
@GET
@Consumes(APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/") Set<ContainerMetadata> listContainers(ListContainerOptions... options);
@Override
@Named("DeleteContainer")
@DELETE
@Fallback(TrueOn404FalseOn409.class)
@Path("/{container}")
boolean deleteContainerIfEmpty(@PathParam("container") String container);
/**
* Provides synchronous access to CDN features.
*/

View File

@ -16,46 +16,37 @@
*/
package org.jclouds.hpcloud.objectstorage;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
import com.google.inject.name.Named;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.hpcloud.objectstorage.blobstore.HPCloudObjectStorageBlobRequestSigner;
import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule;
import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageRestClientModule;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.config.MappedAuthenticationApiModule;
import org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToAdminURISupplier;
import org.jclouds.openstack.swift.SwiftKeystoneApiMetadata;
import org.jclouds.openstack.swift.blobstore.config.TemporaryUrlExtensionModule;
import org.jclouds.openstack.swift.extensions.KeystoneTemporaryUrlKeyAsyncApi;
import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyApi;
import org.jclouds.rest.annotations.ApiVersion;
import static org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageHttpApiModule.HPCloudObjectStorageEndpointModule;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
import java.net.URI;
import java.util.Properties;
import static org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageRestClientModule.HPCloudObjectStorageEndpointModule;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
import static org.jclouds.rest.config.BinderUtils.bindSyncToAsyncHttpApi;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.hpcloud.objectstorage.blobstore.HPCloudObjectStorageBlobRequestSigner;
import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule;
import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageHttpApiModule;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.openstack.keystone.v2_0.config.AuthenticationApiModule;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToAdminURISupplier;
import org.jclouds.openstack.swift.SwiftKeystoneApiMetadata;
import org.jclouds.openstack.swift.blobstore.config.TemporaryUrlExtensionModule;
import org.jclouds.openstack.swift.extensions.KeystoneTemporaryUrlKeyApi;
import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyApi;
import org.jclouds.rest.annotations.ApiVersion;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import com.google.inject.name.Named;
/**
* Implementation of {@link org.jclouds.providers.ProviderMetadata} for HP Cloud Services Object Storage
*/
public class HPCloudObjectStorageApiMetadata extends SwiftKeystoneApiMetadata {
/**
* @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(HPCloudObjectStorageApi.class)} as
* {@link HPCloudObjectStorageAsyncApi} interface will be removed in jclouds 1.7.
*/
@Deprecated
public static final TypeToken<org.jclouds.rest.RestContext<HPCloudObjectStorageApi, HPCloudObjectStorageAsyncApi>> CONTEXT_TOKEN = new TypeToken<org.jclouds.rest.RestContext<HPCloudObjectStorageApi, HPCloudObjectStorageAsyncApi>>() {
private static final long serialVersionUID = 1L;
};
@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
@ -75,22 +66,20 @@ public class HPCloudObjectStorageApiMetadata extends SwiftKeystoneApiMetadata {
return properties;
}
public static class Builder extends SwiftKeystoneApiMetadata.Builder<Builder> {
@SuppressWarnings("deprecation")
public static class Builder extends SwiftKeystoneApiMetadata.Builder<HPCloudObjectStorageApi, Builder> {
protected Builder() {
super(HPCloudObjectStorageApi.class, HPCloudObjectStorageAsyncApi.class);
super(HPCloudObjectStorageApi.class);
id("hpcloud-objectstorage")
.endpointName("identity service url ending in /v2.0/")
.defaultEndpoint("https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/")
.name("HP Cloud Services Object Storage API")
.documentation(URI.create("https://build.hpcloud.com/object-storage/api"))
.defaultProperties(HPCloudObjectStorageApiMetadata.defaultProperties())
.context(CONTEXT_TOKEN)
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(MappedAuthenticationApiModule.class)
.add(AuthenticationApiModule.class)
.add(HPCloudObjectStorageEndpointModule.class)
.add(IgnoreRegionVersionsModule.class)
.add(HPCloudObjectStorageRestClientModule.class)
.add(HPCloudObjectStorageHttpApiModule.class)
.add(HPCloudObjectStorageBlobStoreContextModule.class)
.add(HPCloudObjectStorageTemporaryUrlExtensionModule.class).build());
}
@ -110,14 +99,15 @@ public class HPCloudObjectStorageApiMetadata extends SwiftKeystoneApiMetadata {
* Ensures keystone auth is used instead of swift auth
*/
public static class HPCloudObjectStorageTemporaryUrlExtensionModule extends
TemporaryUrlExtensionModule<HPCloudObjectStorageAsyncApi> {
TemporaryUrlExtensionModule<HPCloudObjectStorageApi> {
@Override
protected void bindRequestSigner() {
bind(BlobRequestSigner.class).to(HPCloudObjectStorageBlobRequestSigner.class);
}
@Override
protected void bindTemporaryUrlKeyApi() {
bindSyncToAsyncHttpApi(binder(), TemporaryUrlKeyApi.class, KeystoneTemporaryUrlKeyAsyncApi.class);
bindHttpApi(binder(), KeystoneTemporaryUrlKeyApi.class);
bind(TemporaryUrlKeyApi.class).to(KeystoneTemporaryUrlKeyApi.class);
}
}

View File

@ -1,100 +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.hpcloud.objectstorage;
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.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.hpcloud.objectstorage.extensions.CDNContainerAsyncApi;
import org.jclouds.location.Region;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.SwiftFallbacks.TrueOn404FalseOn409;
import org.jclouds.openstack.swift.domain.ContainerMetadata;
import org.jclouds.openstack.swift.options.ListContainerOptions;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Provides;
/**
* Provides asynchronous access to HP Cloud Object Storage via the REST API.
*
* <p/>
* All commands return a ListenableFuture of the result. Any exceptions incurred
* during processing will be backend in an
* {@link java.util.concurrent.ExecutionException} as documented in
* {@link ListenableFuture#get()}.
*
* @see HPCloudObjectStorageApi
* @see <a
* href="https://api-docs.hpcloud.com/hpcloud-object-storage/1.0/content/ch_object-storage-dev-overview.html">HP
* Cloud Object Storage API</a>
* @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(HPCloudObjectStorageApi.class)} as
* {@link HPCloudObjectStorageAsyncApi} interface will be removed in jclouds 1.7.
*/
@Deprecated
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface HPCloudObjectStorageAsyncApi extends CommonSwiftAsyncClient {
/**
*
* @return the Region codes configured
*/
@Provides
@Region
Set<String> getConfiguredRegions();
/**
* @see org.jclouds.openstack.swift.CommonSwiftClient#listContainers
*/
@Named("ListContainers")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Path("/")
ListenableFuture<? extends Set<ContainerMetadata>> listContainers(ListContainerOptions... options);
/**
* @see org.jclouds.openstack.swift.CommonSwiftClient#deleteContainerIfEmpty
*/
@Named("DeleteContainer")
@DELETE
@Fallback(TrueOn404FalseOn409.class)
@Path("/{container}")
ListenableFuture<Boolean> deleteContainerIfEmpty(@PathParam("container") String container);
/**
* Provides asynchronous access to CDN features.
*/
@Delegate
Optional<CDNContainerAsyncApi> getCDNExtension();
}

View File

@ -1,94 +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.hpcloud.objectstorage.blobstore;
import static com.google.common.util.concurrent.Futures.immediateFuture;
import static com.google.common.util.concurrent.Futures.transform;
import java.net.URI;
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.collect.Memoized;
import org.jclouds.domain.Location;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncApi;
import org.jclouds.hpcloud.objectstorage.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;
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 HPCloudObjectStorageBlobStore}
*/
@Deprecated
@Singleton
public class HPCloudObjectStorageAsyncBlobStore extends SwiftAsyncBlobStore {
private final EnableCDNAndCache enableAndCache;
@Inject
protected HPCloudObjectStorageAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation,
@Memoized Supplier<Set<? extends Location>> locations, HPCloudObjectStorageApi sync, HPCloudObjectStorageAsyncApi async,
ContainerToResourceMetadata container2ResourceMd,
BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions,
ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object,
ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions,
Provider<FetchBlobMetadata> fetchBlobMetadataProvider, EnableCDNAndCache enableAndCache,
Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) {
super(context, blobUtils, userExecutor, defaultLocation, locations, sync, async, container2ResourceMd,
container2ContainerListOptions, container2ResourceList, object2Blob, blob2Object, object2BlobMd,
blob2ObjectGetOptions, fetchBlobMetadataProvider, multipartUploadStrategy);
this.enableAndCache = enableAndCache;
}
@Override
public ListenableFuture<Boolean> createContainerInLocation(Location location, final String container,
CreateContainerOptions options) {
if (options.isPublicRead()) {
return transform(immediateFuture(enableAndCache.apply(container)), new Function<URI, Boolean>() {
public Boolean apply(URI from) {
return from != null;
}
}, userExecutor);
}
return createContainerInLocation(location, container);
}
}

View File

@ -41,7 +41,7 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
import org.jclouds.crypto.Crypto;
import org.jclouds.date.TimeStamp;
import org.jclouds.domain.Credentials;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncApi;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.options.GetOptions;
import org.jclouds.openstack.keystone.v2_0.domain.Access;
@ -94,9 +94,9 @@ public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner
this.blobToObject = checkNotNull(blobToObject, "blobToObject");
this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
this.getMethod = method(HPCloudObjectStorageAsyncApi.class, "getObject", String.class, String.class, GetOptions[].class);
this.deleteMethod = method(HPCloudObjectStorageAsyncApi.class, "removeObject", String.class, String.class);
this.createMethod = method(HPCloudObjectStorageAsyncApi.class, "putObject", String.class, SwiftObject.class);
this.getMethod = method(HPCloudObjectStorageApi.class, "getObject", String.class, String.class, GetOptions[].class);
this.deleteMethod = method(HPCloudObjectStorageApi.class, "removeObject", String.class, String.class);
this.createMethod = method(HPCloudObjectStorageApi.class, "putObject", String.class, SwiftObject.class);
}
@Override

View File

@ -29,8 +29,8 @@ import javax.inject.Singleton;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.internal.SubmissionAsyncBlobStore;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi;
import org.jclouds.hpcloud.objectstorage.blobstore.HPCloudObjectStorageAsyncBlobStore;
import org.jclouds.hpcloud.objectstorage.blobstore.HPCloudObjectStorageBlobStore;
import org.jclouds.hpcloud.objectstorage.blobstore.functions.HPCloudObjectStorageObjectToBlobMetadata;
import org.jclouds.hpcloud.objectstorage.domain.CDNContainer;
@ -46,6 +46,7 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.inject.Provides;
import com.google.inject.Scopes;
public class HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreContextModule {
@ -94,8 +95,8 @@ public class HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreCo
@Override
protected void configure() {
bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL);
bind(AsyncBlobStore.class).to(HPCloudObjectStorageAsyncBlobStore.class);
bind(BlobStore.class).to(HPCloudObjectStorageBlobStore.class);
bind(AsyncBlobStore.class).to(SubmissionAsyncBlobStore.class).in(Scopes.SINGLETON);
bind(ObjectToBlobMetadata.class).to(HPCloudObjectStorageObjectToBlobMetadata.class);
}
}

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.jclouds.hpcloud.objectstorage.config;
import static org.jclouds.reflect.Reflection2.typeToken;
import static org.jclouds.util.Suppliers2.getLastValueInMap;
import static org.jclouds.util.Suppliers2.getValueInMapOrNull;
@ -26,9 +26,6 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageAsyncApi;
import org.jclouds.hpcloud.objectstorage.extensions.CDNContainerApi;
import org.jclouds.hpcloud.objectstorage.extensions.CDNContainerAsyncApi;
import org.jclouds.hpcloud.services.HPExtensionCDN;
import org.jclouds.hpcloud.services.HPExtensionServiceType;
import org.jclouds.javax.annotation.Nullable;
@ -36,32 +33,25 @@ import org.jclouds.location.reference.LocationConstants;
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.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 org.jclouds.rest.annotations.ApiVersion;
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 HPCloudObjectStorageRestClientModule extends
SwiftRestClientModule<HPCloudObjectStorageApi, HPCloudObjectStorageAsyncApi> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder().put(
CDNContainerApi.class, CDNContainerAsyncApi.class).build();
@ConfiguresHttpApi
public class HPCloudObjectStorageHttpApiModule extends SwiftHttpApiModule<HPCloudObjectStorageApi> {
public HPCloudObjectStorageRestClientModule() {
super(typeToken(HPCloudObjectStorageApi.class), typeToken(HPCloudObjectStorageAsyncApi.class),
DELEGATE_MAP);
public HPCloudObjectStorageHttpApiModule() {
super(HPCloudObjectStorageApi.class);
}
protected void bindResolvedClientsToCommonSwift() {
bind(CommonSwiftClient.class).to(HPCloudObjectStorageApi.class).in(Scopes.SINGLETON);
bind(CommonSwiftAsyncClient.class).to(HPCloudObjectStorageAsyncApi.class).in(Scopes.SINGLETON);
}
private static Supplier<URI> getUriSupplier(String serviceType, String apiVersion, RegionIdToURISupplier.Factory factory, String region) {

View File

@ -16,40 +16,98 @@
*/
package org.jclouds.hpcloud.objectstorage.extensions;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.jclouds.Fallbacks.EmptyFluentIterableOnNotFoundOr404;
import static org.jclouds.blobstore.BlobStoreFallbacks.NullOnContainerNotFound;
import static org.jclouds.hpcloud.objectstorage.reference.HPCloudObjectStorageHeaders.CDN_ENABLED;
import static org.jclouds.hpcloud.objectstorage.reference.HPCloudObjectStorageHeaders.CDN_TTL;
import java.net.URI;
import javax.inject.Named;
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 org.jclouds.hpcloud.objectstorage.domain.CDNContainer;
import org.jclouds.hpcloud.objectstorage.functions.ParseCDNContainerFromHeaders;
import org.jclouds.hpcloud.objectstorage.functions.ParseCDNUriFromHeaders;
import org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions;
import org.jclouds.hpcloud.services.HPExtensionCDN;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
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.annotations.Beta;
import com.google.common.collect.FluentIterable;
/**
* Provides synchronous access to HP Cloud Object Storage via the REST API.
*
* <p/>
* All commands return a ListenableFuture of the result. Any exceptions incurred during processing
* will be backend in an {@link java.util.concurrent.ExecutionException} as documented in {@link ListenableFuture#get()}.
*
* @see org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApi
* @see <a href="https://manage.hpcloud.com/pages/build/docs/objectstorage-lvs/api">HP Cloud Object
* Storage API</a>
* @see CDNContainerAsyncApi
*/
@Beta
@RequestFilters(AuthenticateRequest.class)
@Endpoint(HPExtensionCDN.class)
public interface CDNContainerApi {
@Beta
@Named("ListCDNEnabledContainers")
@GET
@Consumes(APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
@Path("/")
FluentIterable<CDNContainer> list();
@Beta
@Named("ListCDNEnabledContainers")
@GET
@Consumes(APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
@Path("/")
FluentIterable<CDNContainer> list(ListCDNContainerOptions options);
CDNContainer get(String container);
@Beta
@Named("ListCDNEnabledContainerMetadata")
@HEAD
@ResponseParser(ParseCDNContainerFromHeaders.class)
@Fallback(NullOnContainerNotFound.class)
@Path("/{container}")
CDNContainer get(@PathParam("container") String container);
URI enable(String container, long ttl);
@Beta
@Named("CDNEnableContainer")
@PUT
@Path("/{container}")
@Headers(keys = CDN_ENABLED, values = "True")
@ResponseParser(ParseCDNUriFromHeaders.class)
URI enable(@PathParam("container") String container, @HeaderParam(CDN_TTL) long ttl);
URI enable(String container);
@Beta
@Named("CDNEnableContainer")
@PUT
@Path("/{container}")
@Headers(keys = CDN_ENABLED, values = "True")
@ResponseParser(ParseCDNUriFromHeaders.class)
URI enable(@PathParam("container") String container);
URI update(String container, long ttl);
boolean disable(String container);
@Beta
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@ResponseParser(ParseCDNUriFromHeaders.class)
URI update(@PathParam("container") String container, @HeaderParam(CDN_TTL) long ttl);
@Beta
@Named("DisableCDNEnabledContainer")
@PUT
@Path("/{container}")
@Headers(keys = CDN_ENABLED, values = "False")
boolean disable(@PathParam("container") String container);
}

View File

@ -1,148 +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.hpcloud.objectstorage.extensions;
import java.net.URI;
import javax.inject.Named;
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.Fallbacks.EmptyFluentIterableOnNotFoundOr404;
import org.jclouds.blobstore.BlobStoreFallbacks.NullOnContainerNotFound;
import org.jclouds.hpcloud.objectstorage.domain.CDNContainer;
import org.jclouds.hpcloud.objectstorage.functions.ParseCDNContainerFromHeaders;
import org.jclouds.hpcloud.objectstorage.functions.ParseCDNUriFromHeaders;
import org.jclouds.hpcloud.objectstorage.options.ListCDNContainerOptions;
import org.jclouds.hpcloud.objectstorage.reference.HPCloudObjectStorageHeaders;
import org.jclouds.hpcloud.services.HPExtensionCDN;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
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.annotations.Beta;
import com.google.common.collect.FluentIterable;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to HP Cloud Object Storage via the REST API.
*
* <p/>
* All commands return a ListenableFuture of the result. Any exceptions incurred
* during processing will be backend in an
* {@link java.util.concurrent.ExecutionException} as documented in
* {@link ListenableFuture#get()}.
*
* @see HPCloudObjectStorageApi
* @see <a
* href="https://api-docs.hpcloud.com/hpcloud-cdn-storage/1.0/content/ch_cdn-dev-overview.html">HP
* Cloud Object Storage API</a>
*/
@RequestFilters(AuthenticateRequest.class)
@Endpoint(HPExtensionCDN.class)
public interface CDNContainerAsyncApi {
/**
* @see HPCloudObjectStorageApi#list()
*/
@Beta
@Named("ListCDNEnabledContainers")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
@Path("/")
ListenableFuture<FluentIterable<CDNContainer>> list();
/**
* @see HPCloudObjectStorageApi#list(ListCDNContainerOptions)
*/
@Beta
@Named("ListCDNEnabledContainers")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "format", values = "json")
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
@Path("/")
ListenableFuture<FluentIterable<CDNContainer>> list(ListCDNContainerOptions options);
/**
* @see HPCloudObjectStorageApi#get(String)
*/
@Beta
@Named("ListCDNEnabledContainerMetadata")
@HEAD
@ResponseParser(ParseCDNContainerFromHeaders.class)
@Fallback(NullOnContainerNotFound.class)
@Path("/{container}")
ListenableFuture<CDNContainer> get(@PathParam("container") String container);
/**
* @see HPCloudObjectStorageApi#enable(String, long)
*/
@Beta
@Named("CDNEnableContainer")
@PUT
@Path("/{container}")
@Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "True")
@ResponseParser(ParseCDNUriFromHeaders.class)
ListenableFuture<URI> enable(@PathParam("container") String container,
@HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl);
/**
* @see HPCloudObjectStorageApi#enable(String)
*/
@Beta
@Named("CDNEnableContainer")
@PUT
@Path("/{container}")
@Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "True")
@ResponseParser(ParseCDNUriFromHeaders.class)
ListenableFuture<URI> enable(@PathParam("container") String container);
/**
* @see HPCloudObjectStorageApi#update(String, long)
*/
@Beta
@Named("UpdateCDNEnabledContainerMetadata")
@POST
@Path("/{container}")
@ResponseParser(ParseCDNUriFromHeaders.class)
ListenableFuture<URI> update(@PathParam("container") String container,
@HeaderParam(HPCloudObjectStorageHeaders.CDN_TTL) long ttl);
/**
* @see HPCloudObjectStorageApi#disable(String)
*/
@Beta
@Named("DisableCDNEnabledContainer")
@PUT
@Path("/{container}")
@Headers(keys = HPCloudObjectStorageHeaders.CDN_ENABLED, values = "False")
ListenableFuture<Boolean> disable(@PathParam("container") String container);
}

View File

@ -39,7 +39,7 @@ public class HPCloudObjectStorageClientLiveTest extends CommonSwiftClientLiveTes
@Override
public HPCloudObjectStorageApi getApi() {
return view.unwrap(HPCloudObjectStorageApiMetadata.CONTEXT_TOKEN).getApi();
return view.unwrapApi(HPCloudObjectStorageApi.class);
}
@Override

View File

@ -25,12 +25,12 @@ import org.jclouds.blobstore.internal.BaseBlobSignerExpectTest;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApiMetadata;
import org.jclouds.hpcloud.objectstorage.HPCloudObjectStorageApiMetadata.HPCloudObjectStorageTemporaryUrlExtensionModule;
import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule;
import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageRestClientModule;
import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageHttpApiModule;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.keystone.v2_0.config.MappedAuthenticationApiModule;
import org.jclouds.openstack.keystone.v2_0.config.AuthenticationApiModule;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule;
import org.jclouds.openstack.swift.config.SwiftRestClientModule.KeystoneStorageEndpointModule;
import org.jclouds.openstack.swift.config.SwiftHttpApiModule.KeystoneStorageEndpointModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -132,10 +132,10 @@ public class HPCloudObjectStorageBlobSignerExpectTest extends BaseBlobSignerExpe
protected ApiMetadata createApiMetadata() {
return new HPCloudObjectStorageApiMetadata().toBuilder()
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(MappedAuthenticationApiModule.class)
.add(AuthenticationApiModule.class)
.add(KeystoneStorageEndpointModule.class)
.add(RegionModule.class)
.add(HPCloudObjectStorageRestClientModule.class)
.add(HPCloudObjectStorageHttpApiModule.class)
.add(HPCloudObjectStorageBlobStoreContextModule.class)
.add(StaticTimeAndTemporaryUrlKeyModule.class).build()).build();
}

View File

@ -78,7 +78,7 @@ public class HPCloudObjectStorageEndpointModuleTest {
@Test
public void testObjectStorageRegion() {
final HPCloudObjectStorageRestClientModule.HPCloudObjectStorageEndpointModule moduleToTest = new HPCloudObjectStorageRestClientModule.HPCloudObjectStorageEndpointModule();
final HPCloudObjectStorageHttpApiModule.HPCloudObjectStorageEndpointModule moduleToTest = new HPCloudObjectStorageHttpApiModule.HPCloudObjectStorageEndpointModule();
for (int i = 1; i <= 3; i++) {
Supplier<URI> resultingSupplier = moduleToTest.provideStorageUrl(mockFactory, apiVersion, String.format("region%1$s", i));
@ -93,7 +93,7 @@ public class HPCloudObjectStorageEndpointModuleTest {
@Test
public void testCDNRegion() {
final HPCloudObjectStorageRestClientModule moduleToTest = new HPCloudObjectStorageRestClientModule();
final HPCloudObjectStorageHttpApiModule moduleToTest = new HPCloudObjectStorageHttpApiModule();
for (int i = 1; i <= 3; i++) {
Supplier<URI> resultingSupplier = moduleToTest.provideCDNUrl(mockCDNFactory, apiVersion, String.format("region%1$s", i));
@ -111,7 +111,7 @@ public class HPCloudObjectStorageEndpointModuleTest {
*/
@Test
public void testObjectStorageUndefinedRegion() {
final HPCloudObjectStorageRestClientModule.HPCloudObjectStorageEndpointModule moduleToTest = new HPCloudObjectStorageRestClientModule.HPCloudObjectStorageEndpointModule();
final HPCloudObjectStorageHttpApiModule.HPCloudObjectStorageEndpointModule moduleToTest = new HPCloudObjectStorageHttpApiModule.HPCloudObjectStorageEndpointModule();
Supplier<URI> resultingSupplier = moduleToTest.provideStorageUrl(mockFactory, apiVersion, "region-that-dne");
assertNotNull(resultingSupplier);
@ -121,7 +121,7 @@ public class HPCloudObjectStorageEndpointModuleTest {
@Test
public void testCDNUndefinedRegion() {
final HPCloudObjectStorageRestClientModule moduleToTest = new HPCloudObjectStorageRestClientModule();
final HPCloudObjectStorageHttpApiModule moduleToTest = new HPCloudObjectStorageHttpApiModule();
Supplier<URI> resultingSupplier = moduleToTest.provideCDNUrl(mockCDNFactory, apiVersion, "region-that-dne");
assertNotNull(resultingSupplier);