From 7cf11db4080ae49ff4d9e12b67fa15cd09ba1626 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 3 Oct 2014 19:12:19 -0700 Subject: [PATCH] JCLOUDS-296 unasync legacy swift provider. --- .../swift/CommonSwiftAsyncClient.java | 276 ------------------ .../openstack/swift/CommonSwiftClient.java | 225 +++++++++++--- .../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 +- ...entModule.java => SwiftHttpApiModule.java} | 26 +- ...e.java => SwiftKeystoneHttpApiModule.java} | 17 +- ...i.java => KeystoneTemporaryUrlKeyApi.java} | 4 +- .../swift/extensions/TemporaryUrlKeyApi.java | 39 ++- .../extensions/TemporaryUrlKeyAsyncApi.java | 62 ---- .../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 -------------- 25 files changed, 326 insertions(+), 1079 deletions(-) delete mode 100644 apis/swift/src/main/java/org/jclouds/openstack/swift/CommonSwiftAsyncClient.java delete mode 100644 apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftAsyncClient.java delete mode 100644 apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneAsyncClient.java delete mode 100644 apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftAsyncBlobStore.java rename apis/swift/src/main/java/org/jclouds/openstack/swift/config/{SwiftRestClientModule.java => SwiftHttpApiModule.java} (81%) rename apis/swift/src/main/java/org/jclouds/openstack/swift/config/{SwiftKeystoneRestClientModule.java => SwiftKeystoneHttpApiModule.java} (61%) rename apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/{KeystoneTemporaryUrlKeyAsyncApi.java => KeystoneTemporaryUrlKeyApi.java} (91%) delete mode 100644 apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyAsyncApi.java delete mode 100644 apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.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 f977b089f2..0000000000 --- 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 getAccountStatistics(); - - /** - * @see CommonSwiftClient#listContainers - */ - @Named("ListContainers") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @QueryParams(keys = "format", values = "json") - @Path("/") - ListenableFuture> listContainers(ListContainerOptions... options); - - /** - * @see CommonSwiftClient#getContainerMetadata - */ - @Named("GetContainerMetadata") - @Beta - @HEAD - @Path("/{container}") - @Consumes(MediaType.WILDCARD) - @ResponseParser(ParseContainerMetadataFromHeaders.class) - @Fallback(NullOnContainerNotFound.class) - ListenableFuture getContainerMetadata(@PathParam("container") String container); - - /** - * @see CommonSwiftClient#setContainerMetadata - */ - @Named("UpdateContainerMetadata") - @POST - @Path("/{container}") - @Fallback(FalseOnContainerNotFound.class) - ListenableFuture setContainerMetadata(@PathParam("container") String container, - @BinderParam(BindMapToHeadersWithContainerMetadataPrefix.class) Map containerMetadata); - - /** - * @see CommonSwiftClient#deleteContainerMetadata - */ - @Named("UpdateContainerMetadata") - @POST - @Path("/{container}") - @Fallback(FalseOnContainerNotFound.class) - ListenableFuture deleteContainerMetadata(@PathParam("container") String container, - @BinderParam(BindIterableToHeadersWithContainerDeleteMetadataPrefix.class) Iterable metadataKeys); - - /** - * @see CommonSwiftClient#createContainer - */ - @Named("CreateContainer") - @PUT - @ResponseParser(ReturnTrueIf201.class) - @Path("/{container}") - ListenableFuture createContainer(@PathParam("container") String container, - CreateContainerOptions... options); - - /** - * @see CommonSwiftClient#setObjectInfo - */ - @Named("UpdateObjectMetadata") - @POST - @Path("/{container}/{name}") - ListenableFuture setObjectInfo(@PathParam("container") String container, - @PathParam("name") String name, - @BinderParam(BindMapToHeadersWithPrefix.class) Map userMetadata); - - /** - * @see CommonSwiftClient#createContainer - */ - @Named("CreateContainer") - @PUT - @ResponseParser(ReturnTrueIf201.class) - @Path("/{container}") - ListenableFuture createContainer(@PathParam("container") String container); - - /** - * @see CommonSwiftClient#deleteContainerIfEmpty - */ - @Named("DeleteContainer") - @DELETE - @Fallback(TrueOn404FalseOn409.class) - @Path("/{container}") - ListenableFuture deleteContainerIfEmpty(@PathParam("container") String container); - - /** - * @see CommonSwiftClient#listObjects - */ - @Named("ListObjects") - @GET - @QueryParams(keys = "format", values = "json") - @ResponseParser(ParseObjectInfoListFromJsonResponse.class) - @Path("/{container}") - ListenableFuture> listObjects(@PathParam("container") String container, - ListContainerOptions... options); - - /** - * @see CommonSwiftClient#containerExists - */ - @Named("GetContainerMetadata") - @HEAD - @Path("/{container}") - @Consumes(MediaType.WILDCARD) - @Fallback(FalseOnContainerNotFound.class) - ListenableFuture containerExists(@PathParam("container") String container); - - /** - * @see CommonSwiftClient#putObject - */ - @Named("PutObject") - @PUT - @Path("/{container}/{name}") - @Headers(keys = EXPECT, values = "100-continue") - @ResponseParser(ParseETagHeader.class) - ListenableFuture 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 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 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 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 objectExists(@PathParam("container") String container, - @PathParam("name") String name); - - /** - * @see CommonSwiftClient#removeObject - */ - @Named("RemoveObject") - @DELETE - @Fallback(VoidOnNotFoundOr404.class) - @Path("/{container}/{name}") - ListenableFuture 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 putObjectManifest(@PathParam("container") String container, - @PathParam("name") String name); -} 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 c5e4f5d640..a367e5a4bd 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()} */ @Provides SwiftObject newSwiftObject(); @@ -61,8 +98,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(); /** @@ -94,9 +137,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 listContainers(ListContainerOptions... options); /** @@ -106,9 +155,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()} */ - ContainerMetadata getContainerMetadata(String container); + @Deprecated + @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. @@ -120,10 +176,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()} */ - boolean setContainerMetadata(String container, Map containerMetadata); - + @Deprecated + @Named("UpdateContainerMetadata") + @POST + @Path("/{container}") + @Fallback(FalseOnContainerNotFound.class) + boolean setContainerMetadata(@PathParam("container") String container, + @BinderParam(BindMapToHeadersWithContainerMetadataPrefix.class) Map containerMetadata); + /** * Delete the metadata on the given container. * @@ -134,9 +196,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()} */ - boolean deleteContainerMetadata(String container, Iterable metadataKeys); + @Deprecated + @Named("UpdateContainerMetadata") + @POST + @Path("/{container}") + @Fallback(FalseOnContainerNotFound.class) + boolean deleteContainerMetadata(@PathParam("container") String container, + @BinderParam(BindIterableToHeadersWithContainerDeleteMetadataPrefix.class) Iterable metadataKeys); /** * Create a container. @@ -146,84 +214,161 @@ 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()} */ - boolean createContainer(String container); + @Deprecated + @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()} */ 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()} */ - boolean deleteContainerIfEmpty(String container); + @Deprecated + @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()} */ - boolean containerExists(String container); + @Deprecated + @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)} */ - PageSet listObjects(String container, ListContainerOptions... options); + @Deprecated + @Named("ListObjects") + @GET + @QueryParams(keys = "format", values = "json") + @ResponseParser(ParseObjectInfoListFromJsonResponse.class) + @Path("/{container}") + PageSet 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()} */ - SwiftObject getObject(String container, String name, GetOptions... options); + @Deprecated + @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()} */ - boolean setObjectInfo(String container, String name, Map userMetadata); + @Deprecated + @Named("UpdateObjectMetadata") + @POST + @Path("/{container}/{name}") + boolean setObjectInfo(@PathParam("container") String container, + @PathParam("name") String name, + @BinderParam(BindMapToHeadersWithPrefix.class) Map 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()} */ - MutableObjectInfoWithMetadata getObjectInfo(String container, String name); + @Deprecated + @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()} */ - String putObject(String container, SwiftObject object); + @Deprecated + @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()} */ - boolean copyObject(String sourceContainer, String sourceObject, String destinationContainer, String destinationObject); - + @Deprecated + @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()} */ - void removeObject(String container, String name); + @Deprecated + @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()} */ - boolean objectExists(String container, String name); + @Deprecated + @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()} */ - String putObjectManifest(String container, String name); + @Deprecated + @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); } 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 7be8b965ea..ddafc79b80 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> CONTEXT_TOKEN = new TypeToken>() { - 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> extends BaseRestApiMetadata.Builder { - @SuppressWarnings("deprecation") + public abstract static class Builder> extends + BaseHttpApiMetadata.Builder { + 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 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.>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 { + private static class ConcreteBuilder extends Builder { @Override protected ConcreteBuilder self() { return this; 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 4616b463e5..0000000000 --- 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 { -} 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 6250ff18c9..4e5e1c6ddb 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 { } 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 300061aeb6..35049df182 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> CONTEXT_TOKEN = new TypeToken>() { - 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> extends SwiftApiMetadata.Builder { + public abstract static class Builder> + extends SwiftApiMetadata.Builder { + 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 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.>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 { + private static class ConcreteBuilder extends Builder { @Override protected ConcreteBuilder self() { return this; 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 58feeef229..0000000000 --- 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 { - -} 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 5679db5d3b..9cd38a4183 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 { } 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 0fedf685e1..0000000000 --- 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 fetchBlobMetadataProvider; - private final Provider multipartUploadStrategy; - - @Inject - protected SwiftAsyncBlobStore(BlobStoreContext context, BlobUtils blobUtils, - @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, Supplier defaultLocation, - @Memoized Supplier> locations, CommonSwiftClient sync, - CommonSwiftAsyncClient async, ContainerToResourceMetadata container2ResourceMd, - BlobStoreListContainerOptionsToListContainerOptions container2ContainerListOptions, - ContainerToResourceList container2ResourceList, ObjectToBlob object2Blob, BlobToObject blob2Object, - ObjectToBlobMetadata object2BlobMd, BlobToHttpGetOptions blob2ObjectGetOptions, - Provider fetchBlobMetadataProvider, - Provider 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> list() { - return transform(async.listContainers(), - new Function, org.jclouds.blobstore.domain.PageSet>() { - public org.jclouds.blobstore.domain.PageSet apply( - Set from) { - return new PageSetImpl(Iterables.transform(from, container2ResourceMd), null); - } - }, userExecutor); - } - - /** - * This implementation invokes {@link CommonSwiftAsyncClient#containerExists} - * - * @param container - * container name - */ - @Override - public ListenableFuture containerExists(String container) { - return async.containerExists(container); - } - - /** - * Note that location is currently ignored. - */ - @Override - public ListenableFuture createContainerInLocation(Location location, String container) { - return async.createContainer(container); - } - - /** - * This implementation invokes {@link CommonSwiftAsyncClient#listBucket} - * - * @param container - * container name - */ - @Override - public ListenableFuture> list(String container, ListContainerOptions options) { - org.jclouds.openstack.swift.options.ListContainerOptions httpOptions = container2ContainerListOptions - .apply(options); - ListenableFuture> returnVal = async.listObjects(container, httpOptions); - ListenableFuture> 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 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(String container, String key) { - return transform(async.getObjectInfo(container, key), - new Function() { - - @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 getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) { - GetOptions httpOptions = blob2ObjectGetOptions.apply(options); - ListenableFuture 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 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 removeBlob(String container, String key) { - return async.removeObject(container, key); - } - - @Override - protected boolean deleteAndVerifyContainerGone(String container) { - return sync.deleteContainerIfEmpty(container); - } - - @Override - public ListenableFuture 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 createContainerInLocation(Location location, String container, - CreateContainerOptions options) { - if (options.isPublicRead()) - throw new UnsupportedOperationException("publicRead"); - return createContainerInLocation(location, container); - } -} 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 21340d8105..f68b8f2d93 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 implements BlobRequestSigner { +public class SwiftBlobSigner implements BlobRequestSigner { private final Function processor; private final Crypto crypto; @@ -75,7 +75,7 @@ public class SwiftBlobSigner 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, 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 33f8e27202..5387b8ab12 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); } } 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 ede8761bf3..b514f326e7 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 extends AbstractModule { +public abstract class TemporaryUrlExtensionModule extends AbstractModule { - public static class SwiftTemporaryUrlExtensionModule extends TemporaryUrlExtensionModule { + public static class SwiftTemporaryUrlExtensionModule extends TemporaryUrlExtensionModule { @Override protected void bindRequestSigner() { - bind(BlobRequestSigner.class).to(new TypeLiteral>() { + bind(BlobRequestSigner.class).to(new TypeLiteral>() { }); } @@ -62,15 +62,16 @@ public abstract class TemporaryUrlExtensionModule { + TemporaryUrlExtensionModule { 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>() { + bind(BlobRequestSigner.class).to(new TypeLiteral>() { }); } @@ -110,7 +111,6 @@ public abstract class TemporaryUrlExtensionModule> futureParts, final AtomicInteger errors, final int maxRetries, final Map errorMap, final Queue 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 futureETag = client.putObject(container, blob2Object.apply(blobPart)); + final ListenableFuture futureETag = ioExecutor.submit(new Callable() { + @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> futureParts = new ConcurrentHashMap>(); final Map errorMap = Maps.newHashMap(); @@ -246,7 +248,11 @@ public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStra throw rtex; } } else { - ListenableFuture futureETag = ablobstore.putBlob(container, blob, options); + ListenableFuture futureETag = ioExecutor.submit(new Callable() { + @Override public String call() throws Exception { + return blobstore.putBlob(container, blob, options); + } + }); return maxTime != null ? futureETag.get(maxTime, TimeUnit.SECONDS) : futureETag.get(); } 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/SwiftHttpApiModule.java similarity index 81% rename from apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftRestClientModule.java rename to apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftHttpApiModule.java index 1a6a9a11f7..3a673be865 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftRestClientModule.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/config/SwiftHttpApiModule.java @@ -15,7 +15,7 @@ * 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; @@ -38,35 +38,28 @@ 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.ConfiguresHttpApi; import org.jclouds.rest.annotations.ApiVersion; -import org.jclouds.rest.config.RestClientModule; +import org.jclouds.rest.config.HttpApiModule; 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 extends - RestClientModule { +@ConfiguresHttpApi +public class SwiftHttpApiModule extends HttpApiModule { @SuppressWarnings("unchecked") - public SwiftRestClientModule() { - this(TypeToken.class.cast(typeToken(SwiftClient.class)), TypeToken.class.cast(typeToken(SwiftAsyncClient.class)), - ImmutableMap., Class> of()); + public SwiftHttpApiModule() { + this(Class.class.cast(SwiftClient.class)); } - protected SwiftRestClientModule(TypeToken syncClientType, TypeToken asyncClientType, - Map, Class> sync2Async) { - super(syncClientType, asyncClientType, sync2Async); + protected SwiftHttpApiModule(Class syncClientType) { + super(syncClientType); } public static class StorageEndpointModule extends OpenStackAuthenticationModule { @@ -110,7 +103,6 @@ public class SwiftRestClientModule { +@ConfiguresHttpApi +public class SwiftKeystoneHttpApiModule extends SwiftHttpApiModule { - public SwiftKeystoneRestClientModule() { - super(typeToken(SwiftKeystoneClient.class), typeToken(SwiftKeystoneAsyncClient.class), ImmutableMap - ., Class> of()); + public SwiftKeystoneHttpApiModule() { + super(SwiftKeystoneClient.class); } protected void bindResolvedClientsToCommonSwift() { bind(CommonSwiftClient.class).to(SwiftKeystoneClient.class).in(Scopes.SINGLETON); - bind(CommonSwiftAsyncClient.class).to(SwiftKeystoneAsyncClient.class).in(Scopes.SINGLETON); } } diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/KeystoneTemporaryUrlKeyAsyncApi.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/KeystoneTemporaryUrlKeyApi.java similarity index 91% rename from apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/KeystoneTemporaryUrlKeyAsyncApi.java rename to apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/KeystoneTemporaryUrlKeyApi.java index 57c69f3c7f..6c71dfe125 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/KeystoneTemporaryUrlKeyAsyncApi.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/KeystoneTemporaryUrlKeyApi.java @@ -23,11 +23,9 @@ import org.jclouds.rest.annotations.RequestFilters; /** * Only purpose is to override the auth filter with one that works in keystone - * - * @see TemporaryUrlKeyApi */ @RequestFilters(AuthenticateRequest.class) @Endpoint(Storage.class) -public interface KeystoneTemporaryUrlKeyAsyncApi extends TemporaryUrlKeyAsyncApi { +public interface KeystoneTemporaryUrlKeyApi extends TemporaryUrlKeyApi { } diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyApi.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyApi.java index ca20531e8f..0a96960a57 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyApi.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyApi.java @@ -16,17 +16,38 @@ */ package org.jclouds.openstack.swift.extensions; +import static org.jclouds.openstack.swift.reference.SwiftHeaders.ACCOUNT_TEMPORARY_URL_KEY; + +import java.io.Closeable; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.HEAD; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; + +import org.jclouds.openstack.filters.AuthenticateRequest; +import org.jclouds.openstack.swift.Storage; +import org.jclouds.openstack.swift.functions.ParseTemporaryUrlKeyFromHeaders; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; + +@RequestFilters(AuthenticateRequest.class) +@Endpoint(Storage.class) +public interface TemporaryUrlKeyApi extends Closeable { -/** - * @see - */ -public interface TemporaryUrlKeyApi { /** * Retrieve the key used to generate Temporary object access URLs * * @return shared secret key or null - * @see */ + @Named("GetAccountMetadata") + @HEAD + @Path("/") + @Consumes + @ResponseParser(ParseTemporaryUrlKeyFromHeaders.class) String getTemporaryUrlKey(); /** @@ -36,9 +57,9 @@ public interface TemporaryUrlKeyApi { * able to access your temporary URL. If you change it, the TempURL becomes invalid * (within 60 seconds, which is the cache time for a key) and others will not be allowed * to access it. - * - * @param temporaryUrlKey - * @see */ - void setTemporaryUrlKey(String temporaryUrlKey); + @Named("UpdateAccountMetadata") + @POST + @Path("/") + void setTemporaryUrlKey(@HeaderParam(ACCOUNT_TEMPORARY_URL_KEY) String key); } diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyAsyncApi.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyAsyncApi.java deleted file mode 100644 index ca92c123f3..0000000000 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/extensions/TemporaryUrlKeyAsyncApi.java +++ /dev/null @@ -1,62 +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.extensions; - -import com.google.common.util.concurrent.ListenableFuture; -import org.jclouds.openstack.filters.AuthenticateRequest; -import org.jclouds.openstack.swift.Storage; -import org.jclouds.openstack.swift.functions.ParseTemporaryUrlKeyFromHeaders; -import org.jclouds.openstack.swift.reference.SwiftHeaders; -import org.jclouds.rest.annotations.Endpoint; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.HEAD; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.core.MediaType; - -/** - * @see TemporaryUrlKeyApi - * @see docs - */ -@RequestFilters(AuthenticateRequest.class) -@Endpoint(Storage.class) -public interface TemporaryUrlKeyAsyncApi { - - /** - * @see TemporaryUrlKeyApi#getTemporaryUrlKey - */ - @Named("GetAccountMetadata") - @HEAD - @Path("/") - @Consumes(MediaType.WILDCARD) - @ResponseParser(ParseTemporaryUrlKeyFromHeaders.class) - ListenableFuture getTemporaryUrlKey(); - - /** - * @see TemporaryUrlKeyApi#setTemporaryUrlKey - */ - @Named("UpdateAccountMetadata") - @POST - @Path("/") - ListenableFuture setTemporaryUrlKey(@HeaderParam(SwiftHeaders.ACCOUNT_TEMPORARY_URL_KEY) String key); - -} diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java index 796eb48ea3..d021eb5be1 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/CommonSwiftClientTest.java @@ -34,7 +34,7 @@ import org.jclouds.openstack.reference.AuthHeaders; import org.jclouds.openstack.swift.blobstore.SwiftBlobSigner; import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule; import org.jclouds.openstack.swift.blobstore.config.TemporaryUrlExtensionModule; -import org.jclouds.openstack.swift.config.SwiftRestClientModule; +import org.jclouds.openstack.swift.config.SwiftHttpApiModule; import org.jclouds.rest.internal.BaseAsyncClientTest; import org.testng.annotations.Test; @@ -50,7 +50,7 @@ import com.google.inject.TypeLiteral; */ // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire @Test(groups = "unit", testName = "CommonSwiftClientTest") -public abstract class CommonSwiftClientTest extends BaseAsyncClientTest { +public abstract class CommonSwiftClientTest extends BaseAsyncClientTest { public static final long UNIX_EPOCH_TIMESTAMP = 123456789L; public static final String TEMPORARY_URL_KEY = "get-or-set-X-Account-Meta-Temp-Url-Key"; @@ -70,7 +70,7 @@ public abstract class CommonSwiftClientTest extends BaseAsyncClientTest { + public static class StaticTimeAndTemporaryUrlKeyModule extends TemporaryUrlExtensionModule { @Override protected Long unixEpochTimestampProvider() { return UNIX_EPOCH_TIMESTAMP; @@ -85,7 +85,7 @@ public abstract class CommonSwiftClientTest extends BaseAsyncClientTest>() { + bind(BlobRequestSigner.class).to(new TypeLiteral>() { }); } } @@ -95,7 +95,7 @@ public abstract class CommonSwiftClientTest extends BaseAsyncClientTest>builder() .add(StorageEndpointModule.class) - .add(SwiftRestClientModule.class) + .add(SwiftHttpApiModule.class) .add(SwiftBlobStoreContextModule.class) .add(StaticTimeAndTemporaryUrlKeyModule.class).build()).build(); } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientLiveTest.java index bed08595d9..ef4bafc28e 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientLiveTest.java @@ -27,7 +27,6 @@ public class SwiftClientLiveTest extends CommonSwiftClientLiveTest> builder() .add(StorageEndpointModule.class) - .add(SwiftRestClientModule.class) + .add(SwiftHttpApiModule.class) .add(SwiftBlobStoreContextModule.class) .add(StaticTimeAndTemporaryUrlKeyModule.class).build()).build(); } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftKeystoneBlobSignerExpectTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftKeystoneBlobSignerExpectTest.java index 0f9cedd498..b97a8dbd30 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftKeystoneBlobSignerExpectTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/SwiftKeystoneBlobSignerExpectTest.java @@ -26,13 +26,13 @@ import org.jclouds.apis.ApiMetadata; import org.jclouds.blobstore.internal.BaseBlobSignerExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.keystone.v2_0.config.AuthenticationApiModule; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; -import org.jclouds.openstack.keystone.v2_0.config.MappedAuthenticationApiModule; import org.jclouds.openstack.swift.SwiftKeystoneApiMetadata; 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.SwiftHttpApiModule.KeystoneStorageEndpointModule; +import org.jclouds.openstack.swift.config.SwiftKeystoneHttpApiModule; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -139,10 +139,10 @@ public class SwiftKeystoneBlobSignerExpectTest extends BaseBlobSignerExpectTest protected ApiMetadata createApiMetadata() { return new SwiftKeystoneApiMetadata().toBuilder() .defaultModules(ImmutableSet.>builder() - .add(MappedAuthenticationApiModule.class) + .add(AuthenticationApiModule.class) .add(KeystoneStorageEndpointModule.class) .add(KeystoneAuthenticationModule.RegionModule.class) - .add(SwiftKeystoneRestClientModule.class) + .add(SwiftKeystoneHttpApiModule.class) .add(SwiftBlobStoreContextModule.class) .add(StaticTimeAndTemporaryUrlKeyModule.class).build()).build(); } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/config/KeystoneStorageEndpointModuleTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/config/KeystoneStorageEndpointModuleTest.java index 24e2aa8c24..3ca670f81d 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/config/KeystoneStorageEndpointModuleTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/config/KeystoneStorageEndpointModuleTest.java @@ -32,7 +32,7 @@ import java.util.Map; import org.jclouds.location.suppliers.RegionIdToURISupplier; import org.jclouds.openstack.services.ServiceType; -import org.jclouds.openstack.swift.config.SwiftRestClientModule.KeystoneStorageEndpointModule; +import org.jclouds.openstack.swift.config.SwiftHttpApiModule.KeystoneStorageEndpointModule; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java deleted file mode 100644 index 4c30b84af2..0000000000 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/StubSwiftAsyncClient.java +++ /dev/null @@ -1,224 +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.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.util.concurrent.Futures.immediateFuture; -import static com.google.common.util.concurrent.Futures.transform; - -import java.io.IOException; -import java.net.URI; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutionException; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -import org.jclouds.blobstore.LocalAsyncBlobStore; -import org.jclouds.blobstore.domain.BlobMetadata; -import org.jclouds.blobstore.domain.PageSet; -import org.jclouds.blobstore.domain.StorageMetadata; -import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions; -import org.jclouds.blobstore.options.ListContainerOptions; -import org.jclouds.http.options.GetOptions; -import org.jclouds.lifecycle.Closer; -import org.jclouds.openstack.swift.CommonSwiftAsyncClient; -import org.jclouds.openstack.swift.blobstore.functions.BlobToObject; -import org.jclouds.openstack.swift.blobstore.functions.ListContainerOptionsToBlobStoreListContainerOptions; -import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlob; -import org.jclouds.openstack.swift.blobstore.functions.ResourceToObjectInfo; -import org.jclouds.openstack.swift.blobstore.functions.ResourceToObjectList; -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.options.CreateContainerOptions; - -import com.google.common.base.Function; -import com.google.common.base.Throwables; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; - -/** - * Implementation of {@link SwiftAsyncClient} which keeps all data in a local Map object. - */ -@Singleton -public class StubSwiftAsyncClient implements CommonSwiftAsyncClient { - private final HttpGetOptionsListToGetOptions httpGetOptionsConverter; - private final LocalAsyncBlobStore blobStore; - private final SwiftObject.Factory objectProvider; - private final ObjectToBlob object2Blob; - private final BlobToObject blob2Object; - private final ResourceToObjectInfo blob2ObjectInfo; - private final ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions; - private final ResourceToObjectList resource2ObjectList; - private final ListeningExecutorService userExecutor; - private final Closer closer; - - @Inject - private StubSwiftAsyncClient(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, - LocalAsyncBlobStore blobStore, - SwiftObject.Factory objectProvider, HttpGetOptionsListToGetOptions httpGetOptionsConverter, - ObjectToBlob object2Blob, BlobToObject blob2Object, ResourceToObjectInfo blob2ObjectInfo, - ListContainerOptionsToBlobStoreListContainerOptions container2ContainerListOptions, - ResourceToObjectList resource2ContainerList, Closer closer) { - this.userExecutor = userExecutor; - this.blobStore = blobStore; - this.objectProvider = objectProvider; - this.httpGetOptionsConverter = httpGetOptionsConverter; - this.object2Blob = checkNotNull(object2Blob, "object2Blob"); - this.blob2Object = checkNotNull(blob2Object, "blob2Object"); - this.blob2ObjectInfo = checkNotNull(blob2ObjectInfo, "blob2ObjectInfo"); - this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions, - "container2ContainerListOptions"); - this.resource2ObjectList = checkNotNull(resource2ContainerList, "resource2ContainerList"); - this.closer = checkNotNull(closer, "closer"); - } - - public ListenableFuture containerExists(final String container) { - return blobStore.containerExists(container); - } - - public ListenableFuture createContainer(String container) { - return blobStore.createContainerInLocation(null, container); - } - - public ListenableFuture deleteContainerIfEmpty(String container) { - return blobStore.deleteContainerIfEmpty(container); - } - - public ListenableFuture disableCDN(String container) { - throw new UnsupportedOperationException(); - } - - public ListenableFuture enableCDN(String container, long ttl) { - throw new UnsupportedOperationException(); - } - - public ListenableFuture enableCDN(String container) { - throw new UnsupportedOperationException(); - } - - public ListenableFuture getAccountStatistics() { - throw new UnsupportedOperationException(); - } - - public ListenableFuture getObject(String container, String key, GetOptions... options) { - org.jclouds.blobstore.options.GetOptions getOptions = httpGetOptionsConverter.apply(options); - return transform(blobStore.getBlob(container, key, getOptions), blob2Object, userExecutor); - } - - public ListenableFuture getObjectInfo(String container, String key) { - return transform(blobStore.blobMetadata(container, key), - new Function() { - - @Override - public MutableObjectInfoWithMetadata apply(BlobMetadata from) { - - return blob2ObjectInfo.apply(from); - } - - }, userExecutor); - } - - public ListenableFuture> listContainers( - org.jclouds.openstack.swift.options.ListContainerOptions... options) { - PageSet listing; - try { - listing = blobStore.list().get(); - } catch (ExecutionException ee) { - throw Throwables.propagate(ee); - } catch (InterruptedException ie) { - throw Throwables.propagate(ie); - } - return immediateFuture(Sets.newHashSet(Iterables.transform(listing, - new Function() { - public ContainerMetadata apply(StorageMetadata md) { - return ContainerMetadata.builder().name(md.getName()).count(-1).bytes(-1).metadata(new HashMap()).build(); - } - }))); - } - - @Override - public ListenableFuture getContainerMetadata(String container) { - throw new UnsupportedOperationException(); - } - - public ListenableFuture setContainerMetadata(String container, Map containerMetadata) { - throw new UnsupportedOperationException(); - } - - public ListenableFuture deleteContainerMetadata(String container, Iterable metadataKeys) { - throw new UnsupportedOperationException(); - } - - public ListenableFuture createContainer(String container, CreateContainerOptions... options) { - throw new UnsupportedOperationException(); - } - - public ListenableFuture> listObjects(String container, - org.jclouds.openstack.swift.options.ListContainerOptions... optionsList) { - ListContainerOptions options = container2ContainerListOptions.apply(optionsList); - return transform(blobStore.list(container, options), resource2ObjectList, userExecutor); - } - - public ListenableFuture copyObject(String sourceContainer, String sourceObject, String destinationContainer, String destinationObject) { - throw new UnsupportedOperationException(); - } - - public ListenableFuture putObject(String container, SwiftObject object) { - return blobStore.putBlob(container, object2Blob.apply(object)); - } - - public ListenableFuture removeObject(String container, String key) { - return blobStore.removeBlob(container, key); - } - - @Override - public ListenableFuture putObjectManifest(String container, String name) { - return null; - } - - public ListenableFuture setObjectInfo(String container, String key, Map userMetadata) { - throw new UnsupportedOperationException(); - } - - public ListenableFuture updateCDN(String container, long ttl) { - throw new UnsupportedOperationException(); - } - - public SwiftObject newSwiftObject() { - return objectProvider.create(null); - } - - @Override - public ListenableFuture objectExists(String bucketName, String key) { - return blobStore.blobExists(bucketName, key); - } - - @Override - public void close() throws IOException { - closer.close(); - } -}