JCLOUDS-296 unasync legacy swift provider.
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/bbad831c Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/bbad831c Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/bbad831c Branch: refs/heads/use-agentproxy-008 Commit: bbad831c004734f3cee79d748bb99719ba394e2c Parents: dda43df Author: Adrian Cole <[email protected]> Authored: Fri Oct 3 19:12:19 2014 -0700 Committer: Adrian Cole <[email protected]> Committed: Fri Oct 3 23:14:03 2014 -0700 ---------------------------------------------------------------------- .../openstack/swift/CommonSwiftAsyncClient.java | 276 ------------------- .../openstack/swift/CommonSwiftClient.java | 213 +++++++++++--- .../openstack/swift/SwiftApiMetadata.java | 45 ++- .../openstack/swift/SwiftAsyncClient.java | 34 --- .../jclouds/openstack/swift/SwiftClient.java | 6 + .../swift/SwiftKeystoneApiMetadata.java | 42 +-- .../swift/SwiftKeystoneAsyncClient.java | 35 --- .../openstack/swift/SwiftKeystoneClient.java | 6 + .../swift/blobstore/SwiftAsyncBlobStore.java | 258 ----------------- .../swift/blobstore/SwiftBlobSigner.java | 6 +- .../config/SwiftBlobStoreContextModule.java | 9 +- .../config/TemporaryUrlExtensionModule.java | 30 +- .../ParallelMultipartUploadStrategy.java | 30 +- .../swift/config/SwiftHttpApiModule.java | 115 ++++++++ .../config/SwiftKeystoneHttpApiModule.java | 35 +++ .../config/SwiftKeystoneRestClientModule.java | 42 --- .../swift/config/SwiftRestClientModule.java | 123 --------- .../extensions/KeystoneTemporaryUrlKeyApi.java | 31 +++ .../KeystoneTemporaryUrlKeyAsyncApi.java | 33 --- .../swift/extensions/TemporaryUrlKeyApi.java | 39 ++- .../extensions/TemporaryUrlKeyAsyncApi.java | 62 ----- .../openstack/swift/CommonSwiftClientTest.java | 10 +- .../openstack/swift/SwiftClientLiveTest.java | 3 +- .../swift/SwiftKeystoneClientLiveTest.java | 2 +- .../blobstore/SwiftBlobSignerExpectTest.java | 4 +- .../SwiftKeystoneBlobSignerExpectTest.java | 10 +- .../KeystoneStorageEndpointModuleTest.java | 2 +- .../swift/internal/StubSwiftAsyncClient.java | 224 --------------- 28 files changed, 479 insertions(+), 1246 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java deleted file mode 100644 index f977b08..0000000 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java +++ /dev/null @@ -1,276 +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.openstack.swift; - -import static com.google.common.net.HttpHeaders.EXPECT; - -import java.io.Closeable; -import java.util.Map; -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.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.VoidOnNotFoundOr404; -import org.jclouds.blobstore.BlobStoreFallbacks.FalseOnContainerNotFound; -import org.jclouds.blobstore.BlobStoreFallbacks.FalseOnKeyNotFound; -import org.jclouds.blobstore.BlobStoreFallbacks.NullOnContainerNotFound; -import org.jclouds.blobstore.BlobStoreFallbacks.NullOnKeyNotFound; -import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix; -import org.jclouds.blobstore.domain.PageSet; -import org.jclouds.http.functions.ParseETagHeader; -import org.jclouds.http.functions.ReturnTrueIf201; -import org.jclouds.http.options.GetOptions; -import org.jclouds.openstack.swift.SwiftFallbacks.TrueOn404FalseOn409; -import org.jclouds.openstack.swift.binders.BindIterableToHeadersWithContainerDeleteMetadataPrefix; -import org.jclouds.openstack.swift.binders.BindMapToHeadersWithContainerMetadataPrefix; -import org.jclouds.openstack.swift.binders.BindSwiftObjectMetadataToRequest; -import org.jclouds.openstack.swift.domain.AccountMetadata; -import org.jclouds.openstack.swift.domain.ContainerMetadata; -import org.jclouds.openstack.swift.domain.MutableObjectInfoWithMetadata; -import org.jclouds.openstack.swift.domain.ObjectInfo; -import org.jclouds.openstack.swift.domain.SwiftObject; -import org.jclouds.openstack.swift.functions.ObjectName; -import org.jclouds.openstack.swift.functions.ParseAccountMetadataResponseFromHeaders; -import org.jclouds.openstack.swift.functions.ParseContainerMetadataFromHeaders; -import org.jclouds.openstack.swift.functions.ParseObjectFromHeadersAndHttpContent; -import org.jclouds.openstack.swift.functions.ParseObjectInfoFromHeaders; -import org.jclouds.openstack.swift.functions.ParseObjectInfoListFromJsonResponse; -import org.jclouds.openstack.swift.options.CreateContainerOptions; -import org.jclouds.openstack.swift.options.ListContainerOptions; -import org.jclouds.openstack.swift.reference.SwiftHeaders; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.annotations.ParamParser; -import org.jclouds.rest.annotations.QueryParams; -import org.jclouds.rest.annotations.ResponseParser; - -import com.google.common.annotations.Beta; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.inject.Provides; - -/** - * Common features in OpenStack Swift. - * - * @see CommonSwiftClient - * - * - * @deprecated Please use {@code org.jclouds.ContextBuilder#buildApi(CommonSwiftClient.class)} as - * {@link CommonSwiftAsyncClient} will be removed in jclouds 2.0. - */ -@Deprecated -public interface CommonSwiftAsyncClient extends Closeable { - @Provides - SwiftObject newSwiftObject(); - - /** - * @see CommonSwiftClient#getAccountStatistics - */ - @Named("GetAccountMetadata") - @HEAD - @Path("/") - @Consumes(MediaType.WILDCARD) - @ResponseParser(ParseAccountMetadataResponseFromHeaders.class) - ListenableFuture<AccountMetadata> getAccountStatistics(); - - /** - * @see CommonSwiftClient#listContainers - */ - @Named("ListContainers") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "format", values = "json") - @Path("/") - ListenableFuture<? extends Set<ContainerMetadata>> listContainers(ListContainerOptions... options); - - /** - * @see CommonSwiftClient#getContainerMetadata - */ - @Named("GetContainerMetadata") - @Beta - @HEAD - @Path("/{container}") - @Consumes(MediaType.WILDCARD) - @ResponseParser(ParseContainerMetadataFromHeaders.class) - @Fallback(NullOnContainerNotFound.class) - ListenableFuture<ContainerMetadata> getContainerMetadata(@PathParam("container") String container); - - /** - * @see CommonSwiftClient#setContainerMetadata - */ - @Named("UpdateContainerMetadata") - @POST - @Path("/{container}") - @Fallback(FalseOnContainerNotFound.class) - ListenableFuture<Boolean> setContainerMetadata(@PathParam("container") String container, - @BinderParam(BindMapToHeadersWithContainerMetadataPrefix.class) Map<String, String> containerMetadata); - - /** - * @see CommonSwiftClient#deleteContainerMetadata - */ - @Named("UpdateContainerMetadata") - @POST - @Path("/{container}") - @Fallback(FalseOnContainerNotFound.class) - ListenableFuture<Boolean> deleteContainerMetadata(@PathParam("container") String container, - @BinderParam(BindIterableToHeadersWithContainerDeleteMetadataPrefix.class) Iterable<String> metadataKeys); - - /** - * @see CommonSwiftClient#createContainer - */ - @Named("CreateContainer") - @PUT - @ResponseParser(ReturnTrueIf201.class) - @Path("/{container}") - ListenableFuture<Boolean> createContainer(@PathParam("container") String container, - CreateContainerOptions... options); - - /** - * @see CommonSwiftClient#setObjectInfo - */ - @Named("UpdateObjectMetadata") - @POST - @Path("/{container}/{name}") - ListenableFuture<Boolean> setObjectInfo(@PathParam("container") String container, - @PathParam("name") String name, - @BinderParam(BindMapToHeadersWithPrefix.class) Map<String, String> userMetadata); - - /** - * @see CommonSwiftClient#createContainer - */ - @Named("CreateContainer") - @PUT - @ResponseParser(ReturnTrueIf201.class) - @Path("/{container}") - ListenableFuture<Boolean> createContainer(@PathParam("container") String container); - - /** - * @see CommonSwiftClient#deleteContainerIfEmpty - */ - @Named("DeleteContainer") - @DELETE - @Fallback(TrueOn404FalseOn409.class) - @Path("/{container}") - ListenableFuture<Boolean> deleteContainerIfEmpty(@PathParam("container") String container); - - /** - * @see CommonSwiftClient#listObjects - */ - @Named("ListObjects") - @GET - @QueryParams(keys = "format", values = "json") - @ResponseParser(ParseObjectInfoListFromJsonResponse.class) - @Path("/{container}") - ListenableFuture<PageSet<ObjectInfo>> listObjects(@PathParam("container") String container, - ListContainerOptions... options); - - /** - * @see CommonSwiftClient#containerExists - */ - @Named("GetContainerMetadata") - @HEAD - @Path("/{container}") - @Consumes(MediaType.WILDCARD) - @Fallback(FalseOnContainerNotFound.class) - ListenableFuture<Boolean> containerExists(@PathParam("container") String container); - - /** - * @see CommonSwiftClient#putObject - */ - @Named("PutObject") - @PUT - @Path("/{container}/{name}") - @Headers(keys = EXPECT, values = "100-continue") - @ResponseParser(ParseETagHeader.class) - ListenableFuture<String> putObject(@PathParam("container") String container, - @PathParam("name") @ParamParser(ObjectName.class) @BinderParam(BindSwiftObjectMetadataToRequest.class) SwiftObject object); - - /** - * @see CommonSwiftClient#copyObject - */ - @Named("CopyObject") - @PUT - @Path("/{destinationContainer}/{destinationObject}") - @Headers(keys = SwiftHeaders.OBJECT_COPY_FROM, values = "/{sourceContainer}/{sourceObject}") - @Fallback(FalseOnContainerNotFound.class) - ListenableFuture<Boolean> copyObject(@PathParam("sourceContainer") String sourceContainer, - @PathParam("sourceObject") String sourceObject, - @PathParam("destinationContainer") String destinationContainer, - @PathParam("destinationObject") String destinationObject); - - /** - * @see CommonSwiftClient#getObject - */ - @Named("GetObject") - @GET - @ResponseParser(ParseObjectFromHeadersAndHttpContent.class) - @Fallback(NullOnKeyNotFound.class) - @Path("/{container}/{name}") - ListenableFuture<SwiftObject> getObject(@PathParam("container") String container, - @PathParam("name") String name, - GetOptions... options); - - /** - * @see CommonSwiftClient#getObjectInfo - */ - @Named("GetObjectMetadata") - @HEAD - @ResponseParser(ParseObjectInfoFromHeaders.class) - @Fallback(NullOnKeyNotFound.class) - @Path("/{container}/{name}") - @Consumes(MediaType.WILDCARD) - ListenableFuture<MutableObjectInfoWithMetadata> getObjectInfo(@PathParam("container") String container, - @PathParam("name") String name); - - /** - * @see CommonSwiftClient#objectExists - */ - @Named("GetObjectMetadata") - @HEAD - @Fallback(FalseOnKeyNotFound.class) - @Path("/{container}/{name}") - @Consumes(MediaType.WILDCARD) - ListenableFuture<Boolean> objectExists(@PathParam("container") String container, - @PathParam("name") String name); - - /** - * @see CommonSwiftClient#removeObject - */ - @Named("RemoveObject") - @DELETE - @Fallback(VoidOnNotFoundOr404.class) - @Path("/{container}/{name}") - ListenableFuture<Void> removeObject(@PathParam("container") String container, - @PathParam("name") String name); - - @Named("PutObjectManifest") - @PUT - @Path("/{container}/{name}") - @ResponseParser(ParseETagHeader.class) - @Headers(keys = "X-Object-Manifest", values = "{container}/{name}/") - ListenableFuture<String> putObjectManifest(@PathParam("container") String container, - @PathParam("name") String name); -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftClient.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftClient.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftClient.java index c995e65..dc7dfdc 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftClient.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftClient.java @@ -16,19 +16,56 @@ */ package org.jclouds.openstack.swift; +import static com.google.common.net.HttpHeaders.EXPECT; +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; +import static org.jclouds.Fallbacks.VoidOnNotFoundOr404; +import static org.jclouds.blobstore.BlobStoreFallbacks.FalseOnContainerNotFound; +import static org.jclouds.blobstore.BlobStoreFallbacks.FalseOnKeyNotFound; +import static org.jclouds.blobstore.BlobStoreFallbacks.NullOnContainerNotFound; +import static org.jclouds.blobstore.BlobStoreFallbacks.NullOnKeyNotFound; +import static org.jclouds.openstack.swift.reference.SwiftHeaders.OBJECT_COPY_FROM; + import java.io.Closeable; import java.util.Map; 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.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.jclouds.blobstore.binders.BindMapToHeadersWithPrefix; import org.jclouds.blobstore.domain.PageSet; +import org.jclouds.http.functions.ParseETagHeader; +import org.jclouds.http.functions.ReturnTrueIf201; import org.jclouds.http.options.GetOptions; +import org.jclouds.openstack.swift.binders.BindIterableToHeadersWithContainerDeleteMetadataPrefix; +import org.jclouds.openstack.swift.binders.BindMapToHeadersWithContainerMetadataPrefix; +import org.jclouds.openstack.swift.binders.BindSwiftObjectMetadataToRequest; import org.jclouds.openstack.swift.domain.AccountMetadata; import org.jclouds.openstack.swift.domain.ContainerMetadata; import org.jclouds.openstack.swift.domain.MutableObjectInfoWithMetadata; import org.jclouds.openstack.swift.domain.ObjectInfo; import org.jclouds.openstack.swift.domain.SwiftObject; +import org.jclouds.openstack.swift.functions.ObjectName; +import org.jclouds.openstack.swift.functions.ParseAccountMetadataResponseFromHeaders; +import org.jclouds.openstack.swift.functions.ParseContainerMetadataFromHeaders; +import org.jclouds.openstack.swift.functions.ParseObjectFromHeadersAndHttpContent; +import org.jclouds.openstack.swift.functions.ParseObjectInfoFromHeaders; +import org.jclouds.openstack.swift.functions.ParseObjectInfoListFromJsonResponse; import org.jclouds.openstack.swift.options.CreateContainerOptions; import org.jclouds.openstack.swift.options.ListContainerOptions; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.ResponseParser; import com.google.inject.Provides; @@ -36,8 +73,8 @@ import com.google.inject.Provides; * Common features in OpenStack Swift. * * - * @deprecated Please use {@code com.jclouds.openstack.swift.v1.SwiftApi} and related - * feature APIs in {@code com.jclouds.openstack.swift.v1.features.*} as noted in + * @deprecated Please use {@code org.jclouds.openstack.swift.v1.SwiftApi} and related + * feature APIs in {@code org.jclouds.openstack.swift.v1.features.*} as noted in * each method. This interface will be removed in jclouds 2.0. */ @Deprecated @@ -45,7 +82,7 @@ public interface CommonSwiftClient extends Closeable { /** * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.domain.SwiftObject#builder()} + * {@link org.jclouds.openstack.swift.v1.domain.SwiftObject#builder()} */ @Deprecated @Provides @@ -62,9 +99,14 @@ public interface CommonSwiftClient extends Closeable { * * @return the {@link AccountMetadata} * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.AccountApi#get()} + * {@link org.jclouds.openstack.swift.v1.features.AccountApi#get()} */ @Deprecated + @Named("GetAccountMetadata") + @HEAD + @Path("/") + @Consumes() + @ResponseParser(ParseAccountMetadataResponseFromHeaders.class) AccountMetadata getAccountStatistics(); /** @@ -96,10 +138,15 @@ public interface CommonSwiftClient extends Closeable { * list is exactly divisible by the limit, the last request will simply have no content. * * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ContainerApi#list()} and - * {@link com.jclouds.openstack.swift.v1.features.ContainerApi#list(ListContainerOptions)} + * {@link org.jclouds.openstack.swift.v1.features.ContainerApi#list()} and + * {@link org.jclouds.openstack.swift.v1.features.ContainerApi#list(ListContainerOptions)} */ @Deprecated + @Named("ListContainers") + @GET + @Consumes(APPLICATION_JSON) + @QueryParams(keys = "format", values = "json") + @Path("/") Set<ContainerMetadata> listContainers(ListContainerOptions... options); /** @@ -109,10 +156,16 @@ public interface CommonSwiftClient extends Closeable { * the container to get the metadata from * @return the {@link ContainerMetadata} * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ContainerApi#get()} + * {@link org.jclouds.openstack.swift.v1.features.ContainerApi#get()} */ @Deprecated - ContainerMetadata getContainerMetadata(String container); + @Named("GetContainerMetadata") + @HEAD + @Path("/{container}") + @Consumes() + @ResponseParser(ParseContainerMetadataFromHeaders.class) + @Fallback(NullOnContainerNotFound.class) + ContainerMetadata getContainerMetadata(@PathParam("container") String container); /** * Set the {@link ContainerMetadata} on the given container. @@ -124,10 +177,16 @@ public interface CommonSwiftClient extends Closeable { * @return {@code true} * if the Container Metadata was successfully created or updated, false if not. * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ContainerApi#updateMetadata()} + * {@link org.jclouds.openstack.swift.v1.features.ContainerApi#updateMetadata()} */ @Deprecated - boolean setContainerMetadata(String container, Map<String, String> containerMetadata); + @Named("UpdateContainerMetadata") + @POST + @Path("/{container}") + @Fallback(FalseOnContainerNotFound.class) + boolean setContainerMetadata(@PathParam("container") String container, + @BinderParam(BindMapToHeadersWithContainerMetadataPrefix.class) Map<String, String> containerMetadata); + /** * Delete the metadata on the given container. @@ -139,10 +198,15 @@ public interface CommonSwiftClient extends Closeable { * @return {@code true} * if the Container was successfully deleted, false if not. * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ContainerApi#deleteMetadata()} + * {@link org.jclouds.openstack.swift.v1.features.ContainerApi#deleteMetadata()} */ @Deprecated - boolean deleteContainerMetadata(String container, Iterable<String> metadataKeys); + @Named("UpdateContainerMetadata") + @POST + @Path("/{container}") + @Fallback(FalseOnContainerNotFound.class) + boolean deleteContainerMetadata(@PathParam("container") String container, + @BinderParam(BindIterableToHeadersWithContainerDeleteMetadataPrefix.class) Iterable<String> metadataKeys); /** * Create a container. @@ -152,97 +216,164 @@ public interface CommonSwiftClient extends Closeable { * @return {@code true} * if the Container was successfully created, false if not. * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ContainerApi#createIfAbsent()} + * {@link org.jclouds.openstack.swift.v1.features.ContainerApi#createIfAbsent()} */ @Deprecated - boolean createContainer(String container); + @Named("CreateContainer") + @PUT + @ResponseParser(ReturnTrueIf201.class) + @Path("/{container}") + boolean createContainer(@PathParam("container") String container); /** * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ContainerApi#createIfAbsent()} + * {@link org.jclouds.openstack.swift.v1.features.ContainerApi#createIfAbsent()} */ @Deprecated boolean createContainer(String container, CreateContainerOptions... options); /** * @deprecated This method will be replaced by - * (@link com.jclouds.openstack.swift.v1.features.ContainerApi#deleteIfEmpty()} + * (@link org.jclouds.openstack.swift.v1.features.ContainerApi#deleteIfEmpty()} */ @Deprecated - boolean deleteContainerIfEmpty(String container); - + @Named("DeleteContainer") + @DELETE + @Fallback(SwiftFallbacks.TrueOn404FalseOn409.class) + @Path("/{container}") + boolean deleteContainerIfEmpty(@PathParam("container") String container); /** * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ContainerApi#head()} + * {@link org.jclouds.openstack.swift.v1.features.ContainerApi#head()} */ @Deprecated - boolean containerExists(String container); + @Named("GetContainerMetadata") + @HEAD + @Path("/{container}") + @Consumes + @Fallback(FalseOnContainerNotFound.class) + boolean containerExists(@PathParam("container") String container); /** * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ObjectApi#list()} and - * {@link com.jclouds.openstack.swift.v1.features.ObjectApi#list(ListContainerOptions)} + * {@link org.jclouds.openstack.swift.v1.features.ObjectApi#list()} and + * {@link org.jclouds.openstack.swift.v1.features.ObjectApi#list(ListContainerOptions)} */ @Deprecated - PageSet<ObjectInfo> listObjects(String container, ListContainerOptions... options); + @Named("ListObjects") + @GET + @QueryParams(keys = "format", values = "json") + @ResponseParser(ParseObjectInfoListFromJsonResponse.class) + @Path("/{container}") + PageSet<ObjectInfo> listObjects(@PathParam("container") String container, + ListContainerOptions... options); /** * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ObjectApi#get()} + * {@link org.jclouds.openstack.swift.v1.features.ObjectApi#get()} */ @Deprecated - SwiftObject getObject(String container, String name, GetOptions... options); + @Named("GetObject") + @GET + @ResponseParser(ParseObjectFromHeadersAndHttpContent.class) + @Fallback(NullOnKeyNotFound.class) + @Path("/{container}/{name}") + SwiftObject getObject(@PathParam("container") String container, @PathParam("name") String name, + GetOptions... options); /** * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ObjectApi@updateMetadata()} + * {@link org.jclouds.openstack.swift.v1.features.ObjectApi@updateMetadata()} */ @Deprecated - boolean setObjectInfo(String container, String name, Map<String, String> userMetadata); + @Named("UpdateObjectMetadata") + @POST + @Path("/{container}/{name}") + boolean setObjectInfo(@PathParam("container") String container, + @PathParam("name") String name, + @BinderParam(BindMapToHeadersWithPrefix.class) Map<String, String> userMetadata); /** * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ObjectApi#head()} + * {@link org.jclouds.openstack.swift.v1.features.ObjectApi#head()} */ @Deprecated - MutableObjectInfoWithMetadata getObjectInfo(String container, String name); + @Named("GetObjectMetadata") + @HEAD + @ResponseParser(ParseObjectInfoFromHeaders.class) + @Fallback(NullOnKeyNotFound.class) + @Path("/{container}/{name}") + @Consumes + MutableObjectInfoWithMetadata getObjectInfo(@PathParam("container") String container, + @PathParam("name") String name); /** * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ObjectApi#replace()} + * {@link org.jclouds.openstack.swift.v1.features.ObjectApi#replace()} */ @Deprecated - String putObject(String container, SwiftObject object); + @Named("PutObject") + @PUT + @Path("/{container}/{name}") + @Headers(keys = EXPECT, values = "100-continue") + @ResponseParser(ParseETagHeader.class) + String putObject(@PathParam("container") String container, @PathParam("name") @ParamParser(ObjectName.class) + @BinderParam(BindSwiftObjectMetadataToRequest.class) SwiftObject object); + /** * @return True If the object was copied * @throws CopyObjectException If the object was not copied * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ObjectApi#copy()} + * {@link org.jclouds.openstack.swift.v1.features.ObjectApi#copy()} */ @Deprecated - boolean copyObject(String sourceContainer, String sourceObject, String destinationContainer, String destinationObject); - + @Named("CopyObject") + @PUT + @Path("/{destinationContainer}/{destinationObject}") + @Headers(keys = OBJECT_COPY_FROM, values = "/{sourceContainer}/{sourceObject}") + @Fallback(FalseOnContainerNotFound.class) + boolean copyObject(@PathParam("sourceContainer") String sourceContainer, + @PathParam("sourceObject") String sourceObject, + @PathParam("destinationContainer") String destinationContainer, + @PathParam("destinationObject") String destinationObject); + /** * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ObjectApi#delete()} + * {@link org.jclouds.openstack.swift.v1.features.ObjectApi#delete()} */ @Deprecated - void removeObject(String container, String name); + @Named("RemoveObject") + @DELETE + @Fallback(VoidOnNotFoundOr404.class) + @Path("/{container}/{name}") + void removeObject(@PathParam("container") String container, @PathParam("name") String name); + /** * @throws org.jclouds.blobstore.ContainerNotFoundException * if the container is not present * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ObjectApi#head()} + * {@link org.jclouds.openstack.swift.v1.features.ObjectApi#head()} */ @Deprecated - boolean objectExists(String container, String name); + @Named("GetObjectMetadata") + @HEAD + @Fallback(FalseOnKeyNotFound.class) + @Path("/{container}/{name}") + @Consumes + boolean objectExists(@PathParam("container") String container, @PathParam("name") String name); /** * @deprecated This method will be replaced by - * {@link com.jclouds.openstack.swift.v1.features.ObjectApi#replaceManifest()} + * {@link org.jclouds.openstack.swift.v1.features.ObjectApi#replaceManifest()} */ @Deprecated - String putObjectManifest(String container, String name); -} + + @Named("PutObjectManifest") + @PUT + @Path("/{container}/{name}") + @ResponseParser(ParseETagHeader.class) + @Headers(keys = "X-Object-Manifest", values = "{container}/{name}/") + String putObjectManifest(@PathParam("container") String container, @PathParam("name") String name); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java index 7be8b96..ddafc79 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java @@ -27,30 +27,17 @@ import java.util.Properties; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; import org.jclouds.openstack.swift.blobstore.config.TemporaryUrlExtensionModule.SwiftTemporaryUrlExtensionModule; -import org.jclouds.openstack.swift.config.SwiftRestClientModule; -import org.jclouds.openstack.swift.config.SwiftRestClientModule.StorageEndpointModule; -import org.jclouds.rest.internal.BaseRestApiMetadata; +import org.jclouds.openstack.swift.config.SwiftHttpApiModule; +import org.jclouds.openstack.swift.config.SwiftHttpApiModule.StorageEndpointModule; +import org.jclouds.rest.internal.BaseHttpApiMetadata; import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; import com.google.inject.Module; -/** - * Implementation of {@link ApiMetadata} for OpenStack Swift - */ -public class SwiftApiMetadata extends BaseRestApiMetadata { - - /** - * @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(SwiftClient.class)} as - * {@link SwiftAsyncClient} interface will be removed in jclouds 2.0. - */ - @Deprecated - public static final TypeToken<org.jclouds.rest.RestContext<? extends SwiftClient, ? extends SwiftAsyncClient>> CONTEXT_TOKEN = new TypeToken<org.jclouds.rest.RestContext<? extends SwiftClient, ? extends SwiftAsyncClient>>() { - private static final long serialVersionUID = 1L; - }; +public class SwiftApiMetadata extends BaseHttpApiMetadata { @Override - public Builder<?> toBuilder() { + public Builder<?, ?> toBuilder() { return new ConcreteBuilder().fromApiMetadata(this); } @@ -58,12 +45,12 @@ public class SwiftApiMetadata extends BaseRestApiMetadata { this(new ConcreteBuilder()); } - protected SwiftApiMetadata(Builder<?> builder) { + protected SwiftApiMetadata(Builder<?, ?> builder) { super(builder); } public static Properties defaultProperties() { - Properties properties = BaseRestApiMetadata.defaultProperties(); + Properties properties = BaseHttpApiMetadata.defaultProperties(); properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-"); properties.setProperty(PROPERTY_REGIONS, "DEFAULT"); // Keystone 1.1 expires tokens after 24 hours and allows renewal 1 hour @@ -73,14 +60,15 @@ public class SwiftApiMetadata extends BaseRestApiMetadata { return properties; } - public abstract static class Builder<T extends Builder<T>> extends BaseRestApiMetadata.Builder<T> { - @SuppressWarnings("deprecation") + public abstract static class Builder<A extends CommonSwiftClient, T extends Builder<A, T>> extends + BaseHttpApiMetadata.Builder<A, T> { + protected Builder() { - this(SwiftClient.class, SwiftAsyncClient.class); + this(Class.class.cast(SwiftClient.class)); } - - protected Builder(Class<?> syncClient, Class<?> asyncClient) { - super(syncClient, asyncClient); + + protected Builder(Class<A> syncClient) { + super(syncClient); id("swift") .name("OpenStack Swift with SwiftAuth") .identityName("tenantId:user") @@ -89,10 +77,9 @@ public class SwiftApiMetadata extends BaseRestApiMetadata { .version("1.0") .defaultProperties(SwiftApiMetadata.defaultProperties()) .view(typeToken(BlobStoreContext.class)) - .context(CONTEXT_TOKEN) .defaultModules(ImmutableSet.<Class<? extends Module>>builder() .add(StorageEndpointModule.class) - .add(SwiftRestClientModule.class) + .add(SwiftHttpApiModule.class) .add(SwiftBlobStoreContextModule.class) .add(SwiftTemporaryUrlExtensionModule.class).build()); } @@ -103,7 +90,7 @@ public class SwiftApiMetadata extends BaseRestApiMetadata { } } - private static class ConcreteBuilder extends Builder<ConcreteBuilder> { + private static class ConcreteBuilder extends Builder<SwiftClient, ConcreteBuilder> { @Override protected ConcreteBuilder self() { return this; http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftAsyncClient.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftAsyncClient.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftAsyncClient.java deleted file mode 100644 index 4616b46..0000000 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftAsyncClient.java +++ /dev/null @@ -1,34 +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.openstack.swift; - -import org.jclouds.openstack.filters.AuthenticateRequest; -import org.jclouds.rest.annotations.Endpoint; -import org.jclouds.rest.annotations.RequestFilters; - -/** - * Functionality that's in Swift, and not in CloudFiles. - * - * - * @deprecated Please use {@code org.jclouds.ContextBuilder#buildApi(SwiftClient.class)}, as - * {@link SwiftAsyncClient} will be removed in jclouds 2.0. - */ -@Deprecated -@RequestFilters(AuthenticateRequest.class) -@Endpoint(Storage.class) -public interface SwiftAsyncClient extends CommonSwiftAsyncClient { -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftClient.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftClient.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftClient.java index 6250ff1..4e5e1c6 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftClient.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftClient.java @@ -16,6 +16,10 @@ */ package org.jclouds.openstack.swift; +import org.jclouds.openstack.filters.AuthenticateRequest; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.RequestFilters; + /** * Functionality that's in Swift, and not in CloudFiles. * @@ -25,5 +29,7 @@ package org.jclouds.openstack.swift; * will be removed in jclouds 2.0. */ @Deprecated +@RequestFilters(AuthenticateRequest.class) +@Endpoint(Storage.class) public interface SwiftClient extends CommonSwiftClient { } http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java index 300061a..35049df 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java @@ -16,42 +16,29 @@ */ package org.jclouds.openstack.swift; -import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; 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 java.util.Properties; +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.config.KeystoneAuthenticationModule; -import org.jclouds.openstack.keystone.v2_0.config.MappedAuthenticationApiModule; import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; import org.jclouds.openstack.swift.blobstore.config.TemporaryUrlExtensionModule.SwiftKeystoneTemporaryUrlExtensionModule; -import org.jclouds.openstack.swift.config.SwiftKeystoneRestClientModule; -import org.jclouds.openstack.swift.config.SwiftRestClientModule.KeystoneStorageEndpointModule; +import org.jclouds.openstack.swift.config.SwiftKeystoneHttpApiModule; +import org.jclouds.openstack.swift.config.SwiftHttpApiModule.KeystoneStorageEndpointModule; import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; import com.google.inject.Module; -/** - * Implementation of {@link ApiMetadata} for OpenStack Swift authenticated with KeyStone - */ public class SwiftKeystoneApiMetadata extends SwiftApiMetadata { - /** - * @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(SwiftKeystoneClient.class)} as - * {@link SwiftKeystoneAsyncClient} interface will be removed in jclouds 2.0. - */ - @Deprecated - public static final TypeToken<org.jclouds.rest.RestContext<SwiftKeystoneClient, SwiftKeystoneAsyncClient>> CONTEXT_TOKEN = new TypeToken<org.jclouds.rest.RestContext<SwiftKeystoneClient, SwiftKeystoneAsyncClient>>() { - private static final long serialVersionUID = 1L; - }; - @Override - public Builder<?> toBuilder() { + public Builder<?, ?> toBuilder() { return new ConcreteBuilder().fromApiMetadata(this); } @@ -59,7 +46,7 @@ public class SwiftKeystoneApiMetadata extends SwiftApiMetadata { this(new ConcreteBuilder()); } - protected SwiftKeystoneApiMetadata(Builder<?> builder) { + protected SwiftKeystoneApiMetadata(Builder<?, ?> builder) { super(builder); } @@ -72,26 +59,27 @@ public class SwiftKeystoneApiMetadata extends SwiftApiMetadata { return properties; } - public abstract static class Builder<T extends Builder<T>> extends SwiftApiMetadata.Builder<T> { + public abstract static class Builder<A extends CommonSwiftClient, T extends Builder<A, T>> + extends SwiftApiMetadata.Builder<A, T> { + protected Builder() { - this(SwiftKeystoneClient.class, SwiftKeystoneAsyncClient.class); + this(Class.class.cast(SwiftKeystoneClient.class)); } - protected Builder(Class<?> syncClient, Class<?> asyncClient) { - super(syncClient, asyncClient); + protected Builder(Class<A> syncClient) { + super(syncClient); id("swift-keystone") .name("OpenStack Swift with Keystone authentication") .identityName("${tenantName}:${userName} or ${userName}, if your keystone supports a default tenant") .credentialName("${password}") .endpointName("KeyStone base url ending in /v2.0/") .defaultEndpoint("http://localhost:5000/v2.0/") - .context(CONTEXT_TOKEN) .defaultProperties(SwiftKeystoneApiMetadata.defaultProperties()) .defaultModules(ImmutableSet.<Class<? extends Module>>builder() - .add(MappedAuthenticationApiModule.class) + .add(AuthenticationApiModule.class) .add(KeystoneStorageEndpointModule.class) .add(KeystoneAuthenticationModule.RegionModule.class) - .add(SwiftKeystoneRestClientModule.class) + .add(SwiftKeystoneHttpApiModule.class) .add(SwiftBlobStoreContextModule.class) .add(SwiftKeystoneTemporaryUrlExtensionModule.class).build()); } @@ -102,7 +90,7 @@ public class SwiftKeystoneApiMetadata extends SwiftApiMetadata { } } - private static class ConcreteBuilder extends Builder<ConcreteBuilder> { + private static class ConcreteBuilder extends Builder<SwiftKeystoneClient, ConcreteBuilder> { @Override protected ConcreteBuilder self() { return this; http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneAsyncClient.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneAsyncClient.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneAsyncClient.java deleted file mode 100644 index 58feeef..0000000 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneAsyncClient.java +++ /dev/null @@ -1,35 +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.openstack.swift; - -import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; -import org.jclouds.rest.annotations.Endpoint; -import org.jclouds.rest.annotations.RequestFilters; - -/** - * Functionality that's in Swift, and not in CloudFiles. - * - * - * @deprecated Please use {@code org.jclouds.ContextBuilder#buildApi(SwiftKeystoneClient.class)}, as - * {@link SwiftKeystoneAsyncClient} will be removed in jclouds 2.0. - */ -@Deprecated -@RequestFilters(AuthenticateRequest.class) -@Endpoint(Storage.class) -public interface SwiftKeystoneAsyncClient extends SwiftAsyncClient { - -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneClient.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneClient.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneClient.java index 5679db5..9cd38a4 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneClient.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneClient.java @@ -16,11 +16,17 @@ */ package org.jclouds.openstack.swift; +import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.RequestFilters; + /** * Functionality that's in Swift, and not in CloudFiles. * * @deprecated This interface will be removed in jclouds 2.0. */ @Deprecated +@RequestFilters(AuthenticateRequest.class) +@Endpoint(Storage.class) public interface SwiftKeystoneClient extends SwiftClient { } http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftAsyncBlobStore.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftAsyncBlobStore.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftAsyncBlobStore.java deleted file mode 100644 index 0fedf68..0000000 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftAsyncBlobStore.java +++ /dev/null @@ -1,258 +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.openstack.swift.blobstore; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.util.concurrent.Futures.transform; -import static org.jclouds.blobstore.util.BlobStoreUtils.createParentIfNeededAsync; - -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.domain.Blob; -import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.PageSet; -import org.jclouds.blobstore.domain.StorageMetadata; -import org.jclouds.blobstore.domain.internal.PageSetImpl; -import org.jclouds.blobstore.functions.BlobToHttpGetOptions; -import org.jclouds.blobstore.internal.BaseAsyncBlobStore; -import org.jclouds.blobstore.options.CreateContainerOptions; -import org.jclouds.blobstore.options.ListContainerOptions; -import org.jclouds.blobstore.options.PutOptions; -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.http.options.GetOptions; -import org.jclouds.openstack.swift.CommonSwiftAsyncClient; -import org.jclouds.openstack.swift.CommonSwiftClient; -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 org.jclouds.openstack.swift.domain.ContainerMetadata; -import org.jclouds.openstack.swift.domain.MutableObjectInfoWithMetadata; -import org.jclouds.openstack.swift.domain.ObjectInfo; -import org.jclouds.openstack.swift.domain.SwiftObject; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.collect.Iterables; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; - -/** - * - * @deprecated This class will be removed in jclouds 2.0, as async interfaces are no longer - * supported. Please use {@link SwiftBlobStore}. - */ -@Deprecated -@Singleton -public class SwiftAsyncBlobStore extends BaseAsyncBlobStore { - private final CommonSwiftClient sync; - private final CommonSwiftAsyncClient async; - private final ContainerToResourceMetadata container2ResourceMd; - private final BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions; - private final ContainerToResourceList container2ResourceList; - private final ObjectToBlob object2Blob; - private final BlobToObject blob2Object; - private final ObjectToBlobMetadata object2BlobMd; - private final BlobToHttpGetOptions blob2ObjectGetOptions; - private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider; - private final Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy; - - @Inject - protected SwiftAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, - @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier<Location> defaultLocation, - @Memoized Supplier<Set<? extends Location>> locations, CommonSwiftClient sync, - CommonSwiftAsyncClient async, ContainerToResourceMetadata container2ResourceMd, - BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, - ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, - ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, - Provider<FetchBlobMetadata> fetchBlobMetadataProvider, - Provider<AsyncMultipartUploadStrategy> multipartUploadStrategy) { - super(context, blobUtils, userExecutor, defaultLocation, locations); - this.sync = sync; - this.async = async; - this.container2ResourceMd = container2ResourceMd; - this.container2ContainerListOptions = container2ContainerListOptions; - this.container2ResourceList = container2ResourceList; - this.object2Blob = object2Blob; - this.blob2Object = blob2Object; - this.object2BlobMd = object2BlobMd; - this.blob2ObjectGetOptions = blob2ObjectGetOptions; - this.fetchBlobMetadataProvider = checkNotNull(fetchBlobMetadataProvider, "fetchBlobMetadataProvider"); - this.multipartUploadStrategy = multipartUploadStrategy; - } - - /** - * This implementation invokes {@link CommonSwiftAsyncClient#listContainers} - */ - @Override - public ListenableFuture<PageSet<? extends StorageMetadata>> list() { - return transform(async.listContainers(), - new Function<Set<ContainerMetadata>, org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata>>() { - public org.jclouds.blobstore.domain.PageSet<? extends StorageMetadata> apply( - Set<ContainerMetadata> from) { - return new PageSetImpl<StorageMetadata>(Iterables.transform(from, container2ResourceMd), null); - } - }, userExecutor); - } - - /** - * This implementation invokes {@link CommonSwiftAsyncClient#containerExists} - * - * @param container - * container name - */ - @Override - public ListenableFuture<Boolean> containerExists(String container) { - return async.containerExists(container); - } - - /** - * Note that location is currently ignored. - */ - @Override - public ListenableFuture<Boolean> createContainerInLocation(Location location, String container) { - return async.createContainer(container); - } - - /** - * This implementation invokes {@link CommonSwiftAsyncClient#listBucket} - * - * @param container - * container name - */ - @Override - public ListenableFuture<PageSet<? extends StorageMetadata>> list(String container, ListContainerOptions options) { - org.jclouds.openstack.swift.options.ListContainerOptions httpOptions = container2ContainerListOptions - .apply(options); - ListenableFuture<PageSet<ObjectInfo>> returnVal = async.listObjects(container, httpOptions); - ListenableFuture<PageSet<? extends StorageMetadata>> list = transform(returnVal, container2ResourceList, - userExecutor); - return options.isDetailed() ? transform(list, fetchBlobMetadataProvider.get().setContainerName(container), - userExecutor) : list; - } - - /** - * This implementation invokes {@link CommonSwiftAsyncClient#objectExists} - * - * @param container - * container name - * @param key - * object key - */ - @Override - public ListenableFuture<Boolean> blobExists(String container, String key) { - return async.objectExists(container, key); - } - - /** - * This implementation invokes {@link CommonSwiftAsyncClient#headObject} - * - * @param container - * container name - * @param key - * object key - */ - @Override - public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) { - return transform(async.getObjectInfo(container, key), - new Function<MutableObjectInfoWithMetadata, BlobMetadata>() { - - @Override - public BlobMetadata apply(MutableObjectInfoWithMetadata from) { - return object2BlobMd.apply(from); - } - - }, userExecutor); - } - - /** - * This implementation invokes {@link CommonSwiftAsyncClient#getObject} - * - * @param container - * container name - * @param key - * object key - */ - @Override - public ListenableFuture<Blob> getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) { - GetOptions httpOptions = blob2ObjectGetOptions.apply(options); - ListenableFuture<SwiftObject> returnVal = async.getObject(container, key, httpOptions); - return transform(returnVal, object2Blob, userExecutor); - } - - /** - * This implementation invokes {@link CommonSwiftAsyncClient#putObject} - * - * @param container - * container name - * @param blob - * object - */ - @Override - public ListenableFuture<String> putBlob(String container, Blob blob) { - createParentIfNeededAsync(this, container, blob); - return async.putObject(container, blob2Object.apply(blob)); - } - - /** - * This implementation invokes {@link CommonSwiftAsyncClient#removeObject} - * - * @param container - * container name - * @param key - * object key - */ - @Override - public ListenableFuture<Void> removeBlob(String container, String key) { - return async.removeObject(container, key); - } - - @Override - protected boolean deleteAndVerifyContainerGone(String container) { - return sync.deleteContainerIfEmpty(container); - } - - @Override - public ListenableFuture<String> putBlob(String container, Blob blob, PutOptions options) { - if (options.isMultipart()) { - return multipartUploadStrategy.get().execute(container, blob, options, blob2Object); - } else { - return putBlob(container, blob); - } - } - - @Override - public ListenableFuture<Boolean> createContainerInLocation(Location location, String container, - CreateContainerOptions options) { - if (options.isPublicRead()) - throw new UnsupportedOperationException("publicRead"); - return createContainerInLocation(location, container); - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobSigner.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobSigner.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobSigner.java index 21340d8..f68b8f2 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobSigner.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobSigner.java @@ -40,7 +40,7 @@ import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.options.GetOptions; -import org.jclouds.openstack.swift.CommonSwiftAsyncClient; +import org.jclouds.openstack.swift.CommonSwiftClient; import org.jclouds.openstack.swift.TemporaryUrlKey; import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; import org.jclouds.openstack.swift.domain.SwiftObject; @@ -56,7 +56,7 @@ import com.google.common.reflect.Invokable; import com.google.inject.Provider; @Singleton -public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRequestSigner { +public class SwiftBlobSigner<T extends CommonSwiftClient> implements BlobRequestSigner { private final Function<Invocation, HttpRequest> processor; private final Crypto crypto; @@ -75,7 +75,7 @@ public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRe * create a signer for this subtype of swift * * @param processor - * bound to the current subclass of {@link CommonSwiftAsyncClient} + * bound to the current subclass of {@link CommonSwiftClient} */ @Inject protected SwiftBlobSigner(BlobToObject blobToObject, BlobToHttpGetOptions blob2HttpGetOptions, Crypto crypto, http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java index 33f8e27..5387b8a 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/SwiftBlobStoreContextModule.java @@ -16,26 +16,21 @@ */ package org.jclouds.openstack.swift.blobstore.config; - import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.attr.ConsistencyModel; -import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; +import org.jclouds.blobstore.internal.SubmissionAsyncBlobStore; import org.jclouds.openstack.swift.blobstore.SwiftBlobStore; import com.google.inject.AbstractModule; import com.google.inject.Scopes; -/** - * Configures the {@link CloudFilesBlobStoreContext}; requires - * {@link SwiftAsyncBlobStore} bound. - */ public class SwiftBlobStoreContextModule extends AbstractModule { @Override protected void configure() { bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL); - bind(AsyncBlobStore.class).to(SwiftAsyncBlobStore.class).in(Scopes.SINGLETON); + bind(AsyncBlobStore.class).to(SubmissionAsyncBlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(SwiftBlobStore.class).in(Scopes.SINGLETON); } } http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/TemporaryUrlExtensionModule.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/TemporaryUrlExtensionModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/TemporaryUrlExtensionModule.java index ede8761..b514f32 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/TemporaryUrlExtensionModule.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/TemporaryUrlExtensionModule.java @@ -16,42 +16,42 @@ */ package org.jclouds.openstack.swift.blobstore.config; -import static org.jclouds.rest.config.BinderUtils.bindSyncToAsyncHttpApi; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; +import static org.jclouds.rest.config.BinderUtils.bindHttpApi; import java.util.concurrent.TimeUnit; + import javax.inject.Singleton; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.date.TimeStamp; -import org.jclouds.openstack.swift.CommonSwiftAsyncClient; -import org.jclouds.openstack.swift.SwiftAsyncClient; -import org.jclouds.openstack.swift.SwiftKeystoneAsyncClient; +import org.jclouds.openstack.swift.CommonSwiftClient; +import org.jclouds.openstack.swift.SwiftClient; +import org.jclouds.openstack.swift.SwiftKeystoneClient; import org.jclouds.openstack.swift.TemporaryUrlKey; import org.jclouds.openstack.swift.blobstore.SwiftBlobSigner; -import org.jclouds.openstack.swift.extensions.KeystoneTemporaryUrlKeyAsyncApi; +import org.jclouds.openstack.swift.extensions.KeystoneTemporaryUrlKeyApi; import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyApi; -import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyAsyncApi; import org.jclouds.openstack.swift.suppliers.ReturnOrFetchTemporaryUrlKey; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.inject.AbstractModule; import com.google.inject.Inject; -import com.google.inject.name.Named; import com.google.inject.Provides; import com.google.inject.TypeLiteral; +import com.google.inject.name.Named; /** * Isolates dependencies needed for {@link SwiftBlobSigner} */ -public abstract class TemporaryUrlExtensionModule<A extends CommonSwiftAsyncClient> extends AbstractModule { +public abstract class TemporaryUrlExtensionModule<A extends CommonSwiftClient> extends AbstractModule { - public static class SwiftTemporaryUrlExtensionModule extends TemporaryUrlExtensionModule<SwiftAsyncClient> { + public static class SwiftTemporaryUrlExtensionModule extends TemporaryUrlExtensionModule<SwiftClient> { @Override protected void bindRequestSigner() { - bind(BlobRequestSigner.class).to(new TypeLiteral<SwiftBlobSigner<SwiftAsyncClient>>() { + bind(BlobRequestSigner.class).to(new TypeLiteral<SwiftBlobSigner<SwiftClient>>() { }); } @@ -62,15 +62,16 @@ public abstract class TemporaryUrlExtensionModule<A extends CommonSwiftAsyncClie * */ public static class SwiftKeystoneTemporaryUrlExtensionModule extends - TemporaryUrlExtensionModule<SwiftKeystoneAsyncClient> { + TemporaryUrlExtensionModule<SwiftKeystoneClient> { protected void bindTemporaryUrlKeyApi() { - bindSyncToAsyncHttpApi(binder(), TemporaryUrlKeyApi.class, KeystoneTemporaryUrlKeyAsyncApi.class); + bindHttpApi(binder(), KeystoneTemporaryUrlKeyApi.class); + bind(TemporaryUrlKeyApi.class).to(KeystoneTemporaryUrlKeyApi.class); } @Override protected void bindRequestSigner() { - bind(BlobRequestSigner.class).to(new TypeLiteral<SwiftBlobSigner<SwiftKeystoneAsyncClient>>() { + bind(BlobRequestSigner.class).to(new TypeLiteral<SwiftBlobSigner<SwiftKeystoneClient>>() { }); } @@ -110,7 +111,6 @@ public abstract class TemporaryUrlExtensionModule<A extends CommonSwiftAsyncClie protected abstract void bindRequestSigner(); protected void bindTemporaryUrlKeyApi() { - bindSyncToAsyncHttpApi(binder(), TemporaryUrlKeyApi.class, TemporaryUrlKeyAsyncApi.class); + bindHttpApi(binder(), TemporaryUrlKeyApi.class); } - } http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/strategy/internal/ParallelMultipartUploadStrategy.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/strategy/internal/ParallelMultipartUploadStrategy.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/strategy/internal/ParallelMultipartUploadStrategy.java index bf11489..6257799 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/strategy/internal/ParallelMultipartUploadStrategy.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/strategy/internal/ParallelMultipartUploadStrategy.java @@ -43,10 +43,8 @@ import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.io.Payload; import org.jclouds.io.PayloadSlicer; import org.jclouds.logging.Logger; -import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.CommonSwiftClient; -import org.jclouds.openstack.swift.SwiftApiMetadata; -import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore; +import org.jclouds.openstack.swift.blobstore.SwiftBlobStore; import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; import org.jclouds.util.Throwables2; @@ -93,13 +91,13 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra private final ListeningExecutorService ioExecutor; - protected final SwiftAsyncBlobStore ablobstore; + protected final SwiftBlobStore blobstore; protected final PayloadSlicer slicer; @Inject - public ParallelMultipartUploadStrategy(SwiftAsyncBlobStore ablobstore, PayloadSlicer slicer, + public ParallelMultipartUploadStrategy(SwiftBlobStore blobstore, PayloadSlicer slicer, @Named(Constants.PROPERTY_IO_WORKER_THREADS) ListeningExecutorService ioExecutor) { - this.ablobstore = checkNotNull(ablobstore, "ablobstore"); + this.blobstore = checkNotNull(blobstore, "blobstore"); this.slicer = checkNotNull(slicer, "slicer"); this.ioExecutor = checkNotNull(ioExecutor, "ioExecutor"); } @@ -112,22 +110,26 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra final Map<Integer, ListenableFuture<String>> futureParts, final AtomicInteger errors, final int maxRetries, final Map<Integer, Exception> errorMap, final Queue<Part> toRetry, final CountDownLatch latch, - BlobToObject blob2Object) { + final BlobToObject blob2Object) { if (errors.get() > maxRetries) { activeParts.remove(part); // remove part from the bounded-queue without blocking latch.countDown(); return; } - final CommonSwiftAsyncClient client = ablobstore.getContext().unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getAsyncApi(); + final CommonSwiftClient client = blobstore.getContext().unwrapApi(CommonSwiftClient.class); Payload chunkedPart = slicer.slice(payload, offset, size); logger.debug(String.format("async uploading part %s of %s to container %s", part, key, container)); final long start = System.currentTimeMillis(); String blobPartName = blob.getMetadata().getName() + PART_SEPARATOR + String.valueOf(part); - Blob blobPart = ablobstore.blobBuilder(blobPartName).payload(chunkedPart). + final Blob blobPart = blobstore.blobBuilder(blobPartName).payload(chunkedPart). contentDisposition(blobPartName).build(); - final ListenableFuture<String> futureETag = client.putObject(container, blob2Object.apply(blobPart)); + final ListenableFuture<String> futureETag = ioExecutor.submit(new Callable<String>() { + @Override public String call() throws Exception { + return client.putObject(container, blob2Object.apply(blobPart)); + } + }); futureETag.addListener(new Runnable() { @Override public void run() { @@ -171,7 +173,7 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra long chunkSize = algorithm.getChunkSize(); long remaining = algorithm.getRemaining(); if (parts > 0) { - CommonSwiftClient client = ablobstore.getContext().unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getApi(); + final CommonSwiftClient client = blobstore.getContext().unwrapApi(CommonSwiftClient.class); final Map<Integer, ListenableFuture<String>> futureParts = new ConcurrentHashMap<Integer, ListenableFuture<String>>(); final Map<Integer, Exception> errorMap = Maps.newHashMap(); @@ -246,7 +248,11 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra throw rtex; } } else { - ListenableFuture<String> futureETag = ablobstore.putBlob(container, blob, options); + ListenableFuture<String> futureETag = ioExecutor.submit(new Callable<String>() { + @Override public String call() throws Exception { + return blobstore.putBlob(container, blob, options); + } + }); return maxTime != null ? futureETag.get(maxTime, TimeUnit.SECONDS) : futureETag.get(); } http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftHttpApiModule.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftHttpApiModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftHttpApiModule.java new file mode 100644 index 0000000..3a673be --- /dev/null +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftHttpApiModule.java @@ -0,0 +1,115 @@ +/* + * 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.openstack.swift.config; + +import static org.jclouds.util.Suppliers2.getLastValueInMap; +import static org.jclouds.util.Suppliers2.getValueInMapOrNull; + +import java.net.URI; +import java.util.Map; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; +import org.jclouds.json.config.GsonModule.DateAdapter; +import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import org.jclouds.location.reference.LocationConstants; +import org.jclouds.location.suppliers.RegionIdToURISupplier; +import org.jclouds.openstack.config.OpenStackAuthenticationModule; +import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; +import org.jclouds.openstack.reference.AuthHeaders; +import org.jclouds.openstack.services.ServiceType; +import org.jclouds.openstack.swift.CommonSwiftClient; +import org.jclouds.openstack.swift.Storage; +import org.jclouds.openstack.swift.SwiftClient; +import org.jclouds.openstack.swift.handlers.ParseSwiftErrorFromHttpResponse; +import org.jclouds.rest.ConfiguresHttpApi; +import org.jclouds.rest.annotations.ApiVersion; +import org.jclouds.rest.config.HttpApiModule; + +import com.google.common.base.Supplier; +import com.google.inject.Provides; +import com.google.inject.Scopes; + +@ConfiguresHttpApi +public class SwiftHttpApiModule<S extends CommonSwiftClient> extends HttpApiModule<S> { + + @SuppressWarnings("unchecked") + public SwiftHttpApiModule() { + this(Class.class.cast(SwiftClient.class)); + } + + protected SwiftHttpApiModule(Class<S> syncClientType) { + super(syncClientType); + } + + public static class StorageEndpointModule extends OpenStackAuthenticationModule { + @Provides + @Singleton + @Storage + protected Supplier<URI> provideStorageUrl(URIFromAuthenticationResponseForService.Factory factory) { + return factory.create(AuthHeaders.STORAGE_URL); + } + } + + public static class KeystoneStorageEndpointModule extends KeystoneAuthenticationModule { + @Provides + @Singleton + @Storage + protected Supplier<URI> provideStorageUrl(RegionIdToURISupplier.Factory factory, + @ApiVersion String apiVersion, + @Named(LocationConstants.PROPERTY_REGION) String region) { + + //Get the URI's keyed by their region name + Supplier<Map<String, Supplier<URI>>> endpointsSupplier = factory.createForApiTypeAndVersion(ServiceType.OBJECT_STORE, apiVersion); + + //Pick the matching region name (if any) otherwise just return an arbitrary URL if no region name is set + //NOTE: The region string should never be null (it can be empty) if this object was instantiated via guice + // as it pulls these named strings from a Properties object. + if (region.isEmpty()) { + return getLastValueInMap(endpointsSupplier); + } else { + return getValueInMapOrNull(endpointsSupplier, region); + } + } + } + + @Override + protected void configure() { + install(new SwiftObjectModule()); + bind(DateAdapter.class).to(Iso8601DateAdapter.class); + super.configure(); + bindResolvedClientsToCommonSwift(); + } + + protected void bindResolvedClientsToCommonSwift() { + bind(CommonSwiftClient.class).to(SwiftClient.class).in(Scopes.SINGLETON); + } + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSwiftErrorFromHttpResponse.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseSwiftErrorFromHttpResponse.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseSwiftErrorFromHttpResponse.class); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftKeystoneHttpApiModule.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftKeystoneHttpApiModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftKeystoneHttpApiModule.java new file mode 100644 index 0000000..dd5f4d0 --- /dev/null +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftKeystoneHttpApiModule.java @@ -0,0 +1,35 @@ +/* + * 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.openstack.swift.config; + +import org.jclouds.openstack.swift.CommonSwiftClient; +import org.jclouds.openstack.swift.SwiftKeystoneClient; +import org.jclouds.rest.ConfiguresHttpApi; + +import com.google.inject.Scopes; + +@ConfiguresHttpApi +public class SwiftKeystoneHttpApiModule extends SwiftHttpApiModule<SwiftKeystoneClient> { + + public SwiftKeystoneHttpApiModule() { + super(SwiftKeystoneClient.class); + } + + protected void bindResolvedClientsToCommonSwift() { + bind(CommonSwiftClient.class).to(SwiftKeystoneClient.class).in(Scopes.SINGLETON); + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftKeystoneRestClientModule.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftKeystoneRestClientModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftKeystoneRestClientModule.java deleted file mode 100644 index bac1de6..0000000 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftKeystoneRestClientModule.java +++ /dev/null @@ -1,42 +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.openstack.swift.config; - -import static org.jclouds.reflect.Reflection2.typeToken; - -import org.jclouds.openstack.swift.CommonSwiftAsyncClient; -import org.jclouds.openstack.swift.CommonSwiftClient; -import org.jclouds.openstack.swift.SwiftKeystoneAsyncClient; -import org.jclouds.openstack.swift.SwiftKeystoneClient; -import org.jclouds.rest.ConfiguresRestClient; - -import com.google.common.collect.ImmutableMap; -import com.google.inject.Scopes; - -@ConfiguresRestClient -public class SwiftKeystoneRestClientModule extends SwiftRestClientModule<SwiftKeystoneClient, SwiftKeystoneAsyncClient> { - - public SwiftKeystoneRestClientModule() { - super(typeToken(SwiftKeystoneClient.class), typeToken(SwiftKeystoneAsyncClient.class), ImmutableMap - .<Class<?>, Class<?>> of()); - } - - protected void bindResolvedClientsToCommonSwift() { - bind(CommonSwiftClient.class).to(SwiftKeystoneClient.class).in(Scopes.SINGLETON); - bind(CommonSwiftAsyncClient.class).to(SwiftKeystoneAsyncClient.class).in(Scopes.SINGLETON); - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/bbad831c/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftRestClientModule.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftRestClientModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftRestClientModule.java deleted file mode 100644 index 1a6a9a1..0000000 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftRestClientModule.java +++ /dev/null @@ -1,123 +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.openstack.swift.config; -import static org.jclouds.reflect.Reflection2.typeToken; -import static org.jclouds.util.Suppliers2.getLastValueInMap; -import static org.jclouds.util.Suppliers2.getValueInMapOrNull; - -import java.net.URI; -import java.util.Map; - -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.http.HttpErrorHandler; -import org.jclouds.http.annotation.ClientError; -import org.jclouds.http.annotation.Redirection; -import org.jclouds.http.annotation.ServerError; -import org.jclouds.json.config.GsonModule.DateAdapter; -import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; -import org.jclouds.location.reference.LocationConstants; -import org.jclouds.location.suppliers.RegionIdToURISupplier; -import org.jclouds.openstack.config.OpenStackAuthenticationModule; -import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService; -import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; -import org.jclouds.openstack.reference.AuthHeaders; -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.SwiftAsyncClient; -import org.jclouds.openstack.swift.SwiftClient; -import org.jclouds.openstack.swift.handlers.ParseSwiftErrorFromHttpResponse; -import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.annotations.ApiVersion; -import org.jclouds.rest.config.RestClientModule; - -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; -import com.google.common.reflect.TypeToken; -import com.google.inject.Provides; -import com.google.inject.Scopes; - -@ConfiguresRestClient -public class SwiftRestClientModule<S extends CommonSwiftClient, A extends CommonSwiftAsyncClient> extends - RestClientModule<S, A> { - - @SuppressWarnings("unchecked") - public SwiftRestClientModule() { - this(TypeToken.class.cast(typeToken(SwiftClient.class)), TypeToken.class.cast(typeToken(SwiftAsyncClient.class)), - ImmutableMap.<Class<?>, Class<?>> of()); - } - - protected SwiftRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType, - Map<Class<?>, Class<?>> sync2Async) { - super(syncClientType, asyncClientType, sync2Async); - } - - public static class StorageEndpointModule extends OpenStackAuthenticationModule { - @Provides - @Singleton - @Storage - protected Supplier<URI> provideStorageUrl(URIFromAuthenticationResponseForService.Factory factory) { - return factory.create(AuthHeaders.STORAGE_URL); - } - } - - public static class KeystoneStorageEndpointModule extends KeystoneAuthenticationModule { - @Provides - @Singleton - @Storage - protected Supplier<URI> provideStorageUrl(RegionIdToURISupplier.Factory factory, - @ApiVersion String apiVersion, - @Named(LocationConstants.PROPERTY_REGION) String region) { - - //Get the URI's keyed by their region name - Supplier<Map<String, Supplier<URI>>> endpointsSupplier = factory.createForApiTypeAndVersion(ServiceType.OBJECT_STORE, apiVersion); - - //Pick the matching region name (if any) otherwise just return an arbitrary URL if no region name is set - //NOTE: The region string should never be null (it can be empty) if this object was instantiated via guice - // as it pulls these named strings from a Properties object. - if (region.isEmpty()) { - return getLastValueInMap(endpointsSupplier); - } else { - return getValueInMapOrNull(endpointsSupplier, region); - } - } - } - - @Override - protected void configure() { - install(new SwiftObjectModule()); - bind(DateAdapter.class).to(Iso8601DateAdapter.class); - super.configure(); - bindResolvedClientsToCommonSwift(); - } - - protected void bindResolvedClientsToCommonSwift() { - bind(CommonSwiftClient.class).to(SwiftClient.class).in(Scopes.SINGLETON); - bind(CommonSwiftAsyncClient.class).to(SwiftAsyncClient.class).in(Scopes.SINGLETON); - } - - @Override - protected void bindErrorHandlers() { - bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSwiftErrorFromHttpResponse.class); - bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseSwiftErrorFromHttpResponse.class); - bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseSwiftErrorFromHttpResponse.class); - } - -}
