JCLOUDS-296 unasync legacy swift provider.

This commit is contained in:
Adrian Cole 2014-10-03 19:12:19 -07:00 committed by Adrian Cole
parent 76bd3bea9d
commit 7cf11db408
25 changed files with 326 additions and 1079 deletions

View File

@ -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);
}

View File

@ -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<ContainerMetadata> 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<String, String> containerMetadata);
@Deprecated
@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.
*
@ -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<String> metadataKeys);
@Deprecated
@Named("UpdateContainerMetadata")
@POST
@Path("/{container}")
@Fallback(FalseOnContainerNotFound.class)
boolean deleteContainerMetadata(@PathParam("container") String container,
@BinderParam(BindIterableToHeadersWithContainerDeleteMetadataPrefix.class) Iterable<String> 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<ObjectInfo> listObjects(String container, ListContainerOptions... options);
@Deprecated
@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()}
*/
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<String, String> userMetadata);
@Deprecated
@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()}
*/
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);
}

View File

@ -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;

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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;

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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);
}
}

View File

@ -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,

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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();
}

View File

@ -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<S extends CommonSwiftClient, A extends CommonSwiftAsyncClient> extends
RestClientModule<S, A> {
@ConfiguresHttpApi
public class SwiftHttpApiModule<S extends CommonSwiftClient> extends HttpApiModule<S> {
@SuppressWarnings("unchecked")
public SwiftRestClientModule() {
this(TypeToken.class.cast(typeToken(SwiftClient.class)), TypeToken.class.cast(typeToken(SwiftAsyncClient.class)),
ImmutableMap.<Class<?>, Class<?>> of());
public SwiftHttpApiModule() {
this(Class.class.cast(SwiftClient.class));
}
protected SwiftRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType,
Map<Class<?>, Class<?>> sync2Async) {
super(syncClientType, asyncClientType, sync2Async);
protected SwiftHttpApiModule(Class<S> syncClientType) {
super(syncClientType);
}
public static class StorageEndpointModule extends OpenStackAuthenticationModule {
@ -110,7 +103,6 @@ public class SwiftRestClientModule<S extends CommonSwiftClient, A extends Common
protected void bindResolvedClientsToCommonSwift() {
bind(CommonSwiftClient.class).to(SwiftClient.class).in(Scopes.SINGLETON);
bind(CommonSwiftAsyncClient.class).to(SwiftAsyncClient.class).in(Scopes.SINGLETON);
}
@Override

View File

@ -16,27 +16,20 @@
*/
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 org.jclouds.rest.ConfiguresHttpApi;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Scopes;
@ConfiguresRestClient
public class SwiftKeystoneRestClientModule extends SwiftRestClientModule<SwiftKeystoneClient, SwiftKeystoneAsyncClient> {
@ConfiguresHttpApi
public class SwiftKeystoneHttpApiModule extends SwiftHttpApiModule<SwiftKeystoneClient> {
public SwiftKeystoneRestClientModule() {
super(typeToken(SwiftKeystoneClient.class), typeToken(SwiftKeystoneAsyncClient.class), ImmutableMap
.<Class<?>, 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);
}
}

View File

@ -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 {
}

View File

@ -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 <a href="http://docs.rackspace.com/files/api/v1/cf-devguide/content/Public_Access_to_Account-d1a4440.html" />
*/
public interface TemporaryUrlKeyApi {
/**
* Retrieve the key used to generate Temporary object access URLs
*
* @return shared secret key or null
* @see <a href="http://docs.rackspace.com/files/api/v1/cf-devguide/content/Set_Account_Metadata-d1a4460.html" />
*/
@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 <a href="http://docs.rackspace.com/files/api/v1/cf-devguide/content/Set_Account_Metadata-d1a4460.html" />
*/
void setTemporaryUrlKey(String temporaryUrlKey);
@Named("UpdateAccountMetadata")
@POST
@Path("/")
void setTemporaryUrlKey(@HeaderParam(ACCOUNT_TEMPORARY_URL_KEY) String key);
}

View File

@ -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 <a href="http://docs.openstack.org/trunk/openstack-object-storage/admin/content/swift-tempurl.html">docs</a>
*/
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface TemporaryUrlKeyAsyncApi {
/**
* @see TemporaryUrlKeyApi#getTemporaryUrlKey
*/
@Named("GetAccountMetadata")
@HEAD
@Path("/")
@Consumes(MediaType.WILDCARD)
@ResponseParser(ParseTemporaryUrlKeyFromHeaders.class)
ListenableFuture<String> getTemporaryUrlKey();
/**
* @see TemporaryUrlKeyApi#setTemporaryUrlKey
*/
@Named("UpdateAccountMetadata")
@POST
@Path("/")
ListenableFuture<Void> setTemporaryUrlKey(@HeaderParam(SwiftHeaders.ACCOUNT_TEMPORARY_URL_KEY) String key);
}

View File

@ -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<SwiftAsyncClient> {
public abstract class CommonSwiftClientTest extends BaseAsyncClientTest<SwiftClient> {
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<SwiftAsy
}
}
public static class StaticTimeAndTemporaryUrlKeyModule extends TemporaryUrlExtensionModule<SwiftAsyncClient> {
public static class StaticTimeAndTemporaryUrlKeyModule extends TemporaryUrlExtensionModule<SwiftClient> {
@Override
protected Long unixEpochTimestampProvider() {
return UNIX_EPOCH_TIMESTAMP;
@ -85,7 +85,7 @@ public abstract class CommonSwiftClientTest extends BaseAsyncClientTest<SwiftAsy
@Override
protected void bindRequestSigner() {
bind(BlobRequestSigner.class).to(new TypeLiteral<SwiftBlobSigner<SwiftAsyncClient>>() {
bind(BlobRequestSigner.class).to(new TypeLiteral<SwiftBlobSigner<SwiftClient>>() {
});
}
}
@ -95,7 +95,7 @@ public abstract class CommonSwiftClientTest extends BaseAsyncClientTest<SwiftAsy
return new SwiftApiMetadata().toBuilder()
.defaultModules(ImmutableSet.<Class<? extends Module>>builder()
.add(StorageEndpointModule.class)
.add(SwiftRestClientModule.class)
.add(SwiftHttpApiModule.class)
.add(SwiftBlobStoreContextModule.class)
.add(StaticTimeAndTemporaryUrlKeyModule.class).build()).build();
}

View File

@ -27,7 +27,6 @@ public class SwiftClientLiveTest extends CommonSwiftClientLiveTest<CommonSwiftCl
@Override
public CommonSwiftClient getApi() {
return view.unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getApi();
return view.unwrapApi(CommonSwiftClient.class);
}
}

View File

@ -27,6 +27,6 @@ public class SwiftKeystoneClientLiveTest extends CommonSwiftClientLiveTest<Commo
@Override
public CommonSwiftClient getApi() {
return view.unwrap(SwiftKeystoneApiMetadata.CONTEXT_TOKEN).getApi();
return view.unwrapApi(CommonSwiftClient.class);
}
}

View File

@ -30,7 +30,7 @@ import org.jclouds.openstack.swift.CommonSwiftClientTest.StorageEndpointModule;
import org.jclouds.openstack.swift.SwiftApiMetadata;
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.SwiftHttpApiModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -139,7 +139,7 @@ public class SwiftBlobSignerExpectTest extends BaseBlobSignerExpectTest {
.defaultModules(
ImmutableSet.<Class<? extends Module>> builder()
.add(StorageEndpointModule.class)
.add(SwiftRestClientModule.class)
.add(SwiftHttpApiModule.class)
.add(SwiftBlobStoreContextModule.class)
.add(StaticTimeAndTemporaryUrlKeyModule.class).build()).build();
}

View File

@ -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.<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(StaticTimeAndTemporaryUrlKeyModule.class).build()).build();
}

View File

@ -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;

View File

@ -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<Boolean> containerExists(final String container) {
return blobStore.containerExists(container);
}
public ListenableFuture<Boolean> createContainer(String container) {
return blobStore.createContainerInLocation(null, container);
}
public ListenableFuture<Boolean> deleteContainerIfEmpty(String container) {
return blobStore.deleteContainerIfEmpty(container);
}
public ListenableFuture<Boolean> disableCDN(String container) {
throw new UnsupportedOperationException();
}
public ListenableFuture<URI> enableCDN(String container, long ttl) {
throw new UnsupportedOperationException();
}
public ListenableFuture<URI> enableCDN(String container) {
throw new UnsupportedOperationException();
}
public ListenableFuture<AccountMetadata> getAccountStatistics() {
throw new UnsupportedOperationException();
}
public ListenableFuture<SwiftObject> 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<MutableObjectInfoWithMetadata> getObjectInfo(String container, String key) {
return transform(blobStore.blobMetadata(container, key),
new Function<BlobMetadata, MutableObjectInfoWithMetadata>() {
@Override
public MutableObjectInfoWithMetadata apply(BlobMetadata from) {
return blob2ObjectInfo.apply(from);
}
}, userExecutor);
}
public ListenableFuture<? extends Set<ContainerMetadata>> listContainers(
org.jclouds.openstack.swift.options.ListContainerOptions... options) {
PageSet<? extends StorageMetadata> 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<StorageMetadata, ContainerMetadata>() {
public ContainerMetadata apply(StorageMetadata md) {
return ContainerMetadata.builder().name(md.getName()).count(-1).bytes(-1).metadata(new HashMap<String, String>()).build();
}
})));
}
@Override
public ListenableFuture<ContainerMetadata> getContainerMetadata(String container) {
throw new UnsupportedOperationException();
}
public ListenableFuture<Boolean> setContainerMetadata(String container, Map<String, String> containerMetadata) {
throw new UnsupportedOperationException();
}
public ListenableFuture<Boolean> deleteContainerMetadata(String container, Iterable<String> metadataKeys) {
throw new UnsupportedOperationException();
}
public ListenableFuture<Boolean> createContainer(String container, CreateContainerOptions... options) {
throw new UnsupportedOperationException();
}
public ListenableFuture<PageSet<ObjectInfo>> 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<Boolean> copyObject(String sourceContainer, String sourceObject, String destinationContainer, String destinationObject) {
throw new UnsupportedOperationException();
}
public ListenableFuture<String> putObject(String container, SwiftObject object) {
return blobStore.putBlob(container, object2Blob.apply(object));
}
public ListenableFuture<Void> removeObject(String container, String key) {
return blobStore.removeBlob(container, key);
}
@Override
public ListenableFuture<String> putObjectManifest(String container, String name) {
return null;
}
public ListenableFuture<Boolean> setObjectInfo(String container, String key, Map<String, String> userMetadata) {
throw new UnsupportedOperationException();
}
public ListenableFuture<URI> updateCDN(String container, long ttl) {
throw new UnsupportedOperationException();
}
public SwiftObject newSwiftObject() {
return objectProvider.create(null);
}
@Override
public ListenableFuture<Boolean> objectExists(String bucketName, String key) {
return blobStore.blobExists(bucketName, key);
}
@Override
public void close() throws IOException {
closer.close();
}
}