Issue 963:add transitional api for keystone-authenticated swift

This commit is contained in:
Adrian Cole 2012-06-07 22:06:18 -07:00
parent f3950d6ae7
commit 46b4a6c8da
29 changed files with 527 additions and 293 deletions

View File

@ -18,18 +18,15 @@
*/
package org.jclouds.cloudfiles;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.cloudfiles.blobstore.config.CloudFilesBlobStoreContextModule;
import org.jclouds.cloudfiles.config.CloudFilesRestClientModule;
import org.jclouds.cloudfiles.config.CloudFilesRestClientModule.StorageAndCDNManagementEndpointModule;
import org.jclouds.openstack.swift.SwiftApiMetadata;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.BaseRestApiMetadata;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
@ -40,9 +37,10 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class CloudFilesApiMetadata extends BaseRestApiMetadata {
public class CloudFilesApiMetadata extends SwiftApiMetadata {
/** The serialVersionUID */
private static final long serialVersionUID = 820062881469203616L;
private static final long serialVersionUID = -1572520638079261710L;
public static final TypeToken<RestContext<CloudFilesClient, CloudFilesAsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<CloudFilesClient, CloudFilesAsyncClient>>() {
private static final long serialVersionUID = -5070937833892503232L;
@ -64,28 +62,25 @@ public class CloudFilesApiMetadata extends BaseRestApiMetadata {
protected CloudFilesApiMetadata(Builder builder) {
super(builder);
}
public static Properties defaultProperties() {
Properties properties = BaseRestApiMetadata.defaultProperties();
properties.setProperty(PROPERTY_REGIONS, "DEFAULT");
properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-");
Properties properties = SwiftApiMetadata.defaultProperties();
return properties;
}
public static class Builder extends BaseRestApiMetadata.Builder {
protected Builder() {
public static class Builder extends SwiftApiMetadata.Builder {
protected Builder(){
super(CloudFilesClient.class, CloudFilesAsyncClient.class);
id("cloudfiles")
.name("Rackspace Cloud Files API")
.identityName("Username")
.credentialName("API Key")
.documentation(URI.create("http://docs.rackspacecloud.com/files/api/v1/cfdevguide_d5/content/ch01.html"))
.version("1.0")
.defaultProperties(CloudFilesApiMetadata.defaultProperties())
.view(TypeToken.of(BlobStoreContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(CloudFilesRestClientModule.class, CloudFilesBlobStoreContextModule.class));
.context(CONTEXT_TOKEN)
.defaultModules(ImmutableSet.<Class<? extends Module>>of(StorageAndCDNManagementEndpointModule.class, CloudFilesRestClientModule.class, CloudFilesBlobStoreContextModule.class));
}
@Override
public CloudFilesApiMetadata build() {
return new CloudFilesApiMetadata(this);
@ -97,4 +92,5 @@ public class CloudFilesApiMetadata extends BaseRestApiMetadata {
return this;
}
}
}

View File

@ -27,77 +27,51 @@ import javax.inject.Singleton;
import org.jclouds.cloudfiles.CDNManagement;
import org.jclouds.cloudfiles.CloudFilesAsyncClient;
import org.jclouds.cloudfiles.CloudFilesClient;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.config.SwiftObjectModule;
import org.jclouds.openstack.swift.handlers.ParseSwiftErrorFromHttpResponse;
import org.jclouds.openstack.swift.config.SwiftRestClientModule;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken;
import com.google.inject.Provides;
import com.google.inject.Scopes;
/**
*
* @author Adrian Cole
*/
@ConfiguresRestClient
public class CloudFilesRestClientModule extends RestClientModule<CloudFilesClient, CloudFilesAsyncClient> {
@Provides
@Singleton
CommonSwiftClient provideCommonSwiftClient(CloudFilesClient in) {
return in;
public class CloudFilesRestClientModule extends SwiftRestClientModule<CloudFilesClient, CloudFilesAsyncClient> {
public CloudFilesRestClientModule() {
super(TypeToken.of(CloudFilesClient.class), TypeToken.of(CloudFilesAsyncClient.class), ImmutableMap
.<Class<?>, Class<?>> of());
}
@Provides
@Singleton
CommonSwiftAsyncClient provideCommonSwiftClient(CloudFilesAsyncClient in) {
return in;
protected void bindResolvedClientsToCommonSwift() {
bind(CommonSwiftClient.class).to(CloudFilesClient.class).in(Scopes.SINGLETON);
bind(CommonSwiftAsyncClient.class).to(CloudFilesAsyncClient.class).in(Scopes.SINGLETON);
}
@Override
protected void configure() {
install(new SwiftObjectModule());
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
public static class StorageAndCDNManagementEndpointModule extends AuthenticationServiceModule {
@Provides
@Singleton
@CDNManagement
protected Supplier<URI> provideCDNUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
return getLastValueInMap(factory.createForApiTypeAndVersion("cloudFilesCDN", apiVersion));
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSwiftErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseSwiftErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseSwiftErrorFromHttpResponse.class);
}
@Override
protected void installLocations() {
super.installLocations();
install(new AuthenticationServiceModule());
}
@Provides
@Singleton
@CDNManagement
protected Supplier<URI> provideCDNUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
return getLastValueInMap(factory.createForApiTypeAndVersion("cloudFilesCDN", apiVersion));
}
@Provides
@Singleton
@Storage
protected Supplier<URI> provideStorageUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
return getLastValueInMap(factory.createForApiTypeAndVersion("cloudFiles", apiVersion));
@Provides
@Singleton
@Storage
protected Supplier<URI> provideStorageUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
return getLastValueInMap(factory.createForApiTypeAndVersion("cloudFiles", apiVersion));
}
}
}

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.openstack.keystone.v2_0.config;
import static org.jclouds.util.Suppliers2.getLastValueInMap;
import java.net.URI;
import java.util.Map;
@ -48,11 +50,8 @@ import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.functions.ImplicitOptionalConverter;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.reflect.TypeToken;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
@ -111,14 +110,7 @@ public class KeystoneRestClientModule<S extends KeystoneClient, A extends Keysto
@Identity
protected Supplier<URI> provideStorageUrl(RegionIdToAdminURISupplier.Factory factory,
@Named(KeystoneProperties.VERSION) String version) {
return Suppliers.compose(new Function<Map<String, Supplier<URI>>, URI>() {
//TODO: throw a nice error when there's nothing here
@Override
public URI apply(Map<String, Supplier<URI>> input) {
return Iterables.getLast(input.values()).get();
}
}, factory.createForApiTypeAndVersion(ServiceType.IDENTITY, version));
return getLastValueInMap(factory.createForApiTypeAndVersion(ServiceType.IDENTITY, version));
}
}

View File

@ -34,17 +34,33 @@
<packaging>bundle</packaging>
<properties>
<!-- swift or swift-keystone -->
<test.swift.provider>swift</test.swift.provider>
<test.swift.endpoint>http://localhost:11000</test.swift.endpoint>
<test.swift.api-version>1.0</test.swift.api-version>
<test.swift.build-version></test.swift.build-version>
<test.swift.identity>test:tester</test.swift.identity>
<test.swift.credential>testing</test.swift.credential>
<!-- keystone endpoint -->
<test.swift-keystone.endpoint>http://localhost:5000</test.swift-keystone.endpoint>
<test.swift-keystone.api-version>1.0</test.swift-keystone.api-version>
<test.swift-keystone.build-version></test.swift-keystone.build-version>
<test.swift-keystone.identity>FIXME_IDENTITY</test.swift-keystone.identity>
<test.swift-keystone.credential>FIXME_CREDENTIALS</test.swift-keystone.credential>
<test.jclouds.keystone.credential-type>passwordCredentials</test.jclouds.keystone.credential-type>
<jclouds.osgi.export>org.jclouds.openstack.swift*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>openstack-keystone</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>openstack-common</artifactId>
@ -69,6 +85,13 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>openstack-keystone</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
@ -109,11 +132,18 @@
<systemPropertyVariables>
<jclouds.blobstore.httpstream.url>${jclouds.blobstore.httpstream.url}</jclouds.blobstore.httpstream.url>
<jclouds.blobstore.httpstream.md5>${jclouds.blobstore.httpstream.md5}</jclouds.blobstore.httpstream.md5>
<test.swift.provider>${test.swift.provider}</test.swift.provider>
<test.swift.endpoint>${test.swift.endpoint}</test.swift.endpoint>
<test.swift.api-version>${test.swift.api-version}</test.swift.api-version>
<test.swift.build-version>${test.swift.build-version}</test.swift.build-version>
<test.swift.identity>${test.swift.identity}</test.swift.identity>
<test.swift.credential>${test.swift.credential}</test.swift.credential>
<test.swift-keystone.endpoint>${test.swift-keystone.endpoint}</test.swift-keystone.endpoint>
<test.swift-keystone.api-version>${test.swift-keystone.api-version}</test.swift-keystone.api-version>
<test.swift-keystone.build-version>${test.swift-keystone.build-version}</test.swift-keystone.build-version>
<test.swift-keystone.identity>${test.swift-keystone.identity}</test.swift-keystone.identity>
<test.swift-keystone.credential>${test.swift-keystone.credential}</test.swift-keystone.credential>
<test.jclouds.keystone.credential-type>${test.jclouds.keystone.credential-type}</test.jclouds.keystone.credential-type>
</systemPropertyVariables>
</configuration>
</execution>

View File

@ -20,14 +20,20 @@ package org.jclouds.openstack.swift;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
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.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule;
import org.jclouds.openstack.swift.config.SwiftRestClientModule;
import org.jclouds.openstack.swift.config.SwiftRestClientModule.StorageEndpointModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.BaseRestApiMetadata;
@ -36,29 +42,25 @@ import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
/**
* Implementation of {@link ApiMetadata} for Rackspace Cloud Files API
* Implementation of {@link ApiMetadata} for OpenStack Swift
*
* @author Adrian Cole
*/
public class SwiftApiMetadata extends BaseRestApiMetadata {
/** The serialVersionUID */
private static final long serialVersionUID = 6725672099385580694L;
public static final TypeToken<RestContext<SwiftClient, SwiftAsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<SwiftClient, SwiftAsyncClient>>() {
private static final long serialVersionUID = -5070937833892503232L;
};
private static Builder builder() {
return new Builder();
}
@Override
public Builder toBuilder() {
return builder().fromApiMetadata(this);
return (Builder) new Builder(getApi(), getAsyncApi()).fromApiMetadata(this);
}
public SwiftApiMetadata() {
this(builder());
this(new Builder(SwiftClient.class, SwiftAsyncClient.class));
}
protected SwiftApiMetadata(Builder builder) {
@ -67,14 +69,18 @@ public class SwiftApiMetadata extends BaseRestApiMetadata {
public static Properties defaultProperties() {
Properties properties = BaseRestApiMetadata.defaultProperties();
properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE);
// TODO: this doesn't actually do anything yet.
properties.setProperty(KeystoneProperties.VERSION, "2.0");
properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.API_ACCESS_KEY_CREDENTIALS);
properties.setProperty(PROPERTY_REGIONS, "DEFAULT");
properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-");
return properties;
}
public static class Builder extends BaseRestApiMetadata.Builder {
protected Builder() {
super(SwiftClient.class, SwiftAsyncClient.class);
protected Builder(Class<?> syncClient, Class<?> asyncClient){
super(syncClient, asyncClient);
id("swift")
.name("OpenStack Swift Pre-Diablo API")
.identityName("tenantId:user")
@ -83,7 +89,8 @@ public class SwiftApiMetadata extends BaseRestApiMetadata {
.version("1.0")
.defaultProperties(SwiftApiMetadata.defaultProperties())
.view(TypeToken.of(BlobStoreContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(SwiftRestClientModule.class, SwiftBlobStoreContextModule.class));
.context(CONTEXT_TOKEN)
.defaultModules(ImmutableSet.<Class<? extends Module>>of(StorageEndpointModule.class, SwiftRestClientModule.class, SwiftBlobStoreContextModule.class));
}
@Override

View File

@ -0,0 +1,90 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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 org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule;
import org.jclouds.openstack.swift.config.SwiftKeystoneRestClientModule;
import org.jclouds.openstack.swift.config.SwiftRestClientModule.KeystoneStorageEndpointModule;
import org.jclouds.rest.RestContext;
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
*
* @author Adrian Cole
*/
public class SwiftKeystoneApiMetadata extends SwiftApiMetadata {
/** The serialVersionUID */
private static final long serialVersionUID = 820062881469203616L;
public static final TypeToken<RestContext<SwiftKeystoneClient, SwiftKeystoneAsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<SwiftKeystoneClient, SwiftKeystoneAsyncClient>>() {
private static final long serialVersionUID = -5070937833892503232L;
};
private static Builder builder() {
return new Builder();
}
@Override
public Builder toBuilder() {
return builder().fromApiMetadata(this);
}
public SwiftKeystoneApiMetadata() {
this(builder());
}
protected SwiftKeystoneApiMetadata(Builder builder) {
super(builder);
}
public static Properties defaultProperties() {
Properties properties = SwiftApiMetadata.defaultProperties();
properties.remove(PROPERTY_REGIONS);
return properties;
}
public static class Builder extends SwiftApiMetadata.Builder {
protected Builder(){
super(SwiftKeystoneClient.class, SwiftKeystoneAsyncClient.class);
id("swift-keystone")
.context(CONTEXT_TOKEN)
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneStorageEndpointModule.class, SwiftKeystoneRestClientModule.class, SwiftBlobStoreContextModule.class));
}
@Override
public SwiftKeystoneApiMetadata build() {
return new SwiftKeystoneApiMetadata(this);
}
@Override
public Builder fromApiMetadata(ApiMetadata in) {
super.fromApiMetadata(in);
return this;
}
}
}

View File

@ -0,0 +1,36 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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;
import org.jclouds.rest.annotations.SkipEncoding;
/**
* Functionality that's in Swift, and not in CloudFiles.
*
* @author Adrian Cole
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface SwiftKeystoneAsyncClient extends CommonSwiftAsyncClient {
}

View File

@ -0,0 +1,33 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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 java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
/**
* Functionality that's in Swift, and not in CloudFiles.
*
* @author Adrian Cole
*/
@Timeout(duration = 120, timeUnit = TimeUnit.SECONDS)
public interface SwiftKeystoneClient extends CommonSwiftClient {
}

View File

@ -1,82 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.swift.config;
import java.net.URI;
import javax.inject.Singleton;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService;
import org.jclouds.openstack.reference.AuthHeaders;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.handlers.ParseSwiftErrorFromHttpResponse;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Supplier;
import com.google.inject.Provides;
/**
*
* @author Adrian Cole
*/
@ConfiguresRestClient
public class BaseSwiftRestClientModule<S extends CommonSwiftClient, A extends CommonSwiftAsyncClient> extends
RestClientModule<S, A> {
private final OpenStackAuthenticationModule module;
public BaseSwiftRestClientModule() {
this(new OpenStackAuthenticationModule());
}
public BaseSwiftRestClientModule(OpenStackAuthenticationModule module) {
this.module = module;
}
@Override
protected void configure() {
install(module);
install(new SwiftObjectModule());
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSwiftErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseSwiftErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseSwiftErrorFromHttpResponse.class);
}
@Provides
@Singleton
@Storage
protected Supplier<URI> provideStorageUrl(URIFromAuthenticationResponseForService.Factory factory) {
return factory.create(AuthHeaders.STORAGE_URL);
}
}

View File

@ -0,0 +1,29 @@
package org.jclouds.openstack.swift.config;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.SwiftKeystoneAsyncClient;
import org.jclouds.openstack.swift.SwiftKeystoneClient;
import org.jclouds.rest.ConfiguresRestClient;
import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken;
import com.google.inject.Scopes;
/**
*
* @author Adrian Cole
*/
@ConfiguresRestClient
public class SwiftKeystoneRestClientModule extends SwiftRestClientModule<SwiftKeystoneClient, SwiftKeystoneAsyncClient> {
public SwiftKeystoneRestClientModule() {
super(TypeToken.of(SwiftKeystoneClient.class), TypeToken.of(SwiftKeystoneAsyncClient.class), ImmutableMap
.<Class<?>, Class<?>> of());
}
protected void bindResolvedClientsToCommonSwift() {
bind(CommonSwiftClient.class).to(SwiftKeystoneClient.class).in(Scopes.SINGLETON);
bind(CommonSwiftAsyncClient.class).to(SwiftKeystoneAsyncClient.class).in(Scopes.SINGLETON);
}
}

View File

@ -18,33 +18,97 @@
*/
package org.jclouds.openstack.swift.config;
import static org.jclouds.util.Suppliers2.getLastValueInMap;
import java.net.URI;
import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.openstack.config.OpenStackAuthenticationModule;
import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForRegions;
import org.jclouds.openstack.reference.AuthHeaders;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.SwiftAsyncClient;
import org.jclouds.openstack.swift.SwiftClient;
import org.jclouds.openstack.swift.handlers.ParseSwiftErrorFromHttpResponse;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken;
import com.google.inject.Provides;
import com.google.inject.Scopes;
/**
*
* @author Adrian Cole
*/
@ConfiguresRestClient
public class SwiftRestClientModule extends BaseSwiftRestClientModule<SwiftClient, SwiftAsyncClient> {
public class SwiftRestClientModule<S extends CommonSwiftClient, A extends CommonSwiftAsyncClient> extends RestClientModule<S, A> {
@Provides
@Singleton
CommonSwiftClient provideCommonSwiftClient(SwiftClient in) {
return in;
@SuppressWarnings("unchecked")
public SwiftRestClientModule() {
this((TypeToken) TypeToken.of(SwiftClient.class), (TypeToken) TypeToken.of(SwiftAsyncClient.class), ImmutableMap
.<Class<?>, Class<?>> of());
}
@Provides
@Singleton
CommonSwiftAsyncClient provideCommonSwiftClient(SwiftAsyncClient in) {
return in;
protected SwiftRestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType,
Map<Class<?>, Class<?>> sync2Async) {
super(syncClientType, asyncClientType, sync2Async);
}
public static class StorageEndpointModule extends OpenStackAuthenticationModule {
@Provides
@Singleton
@Storage
protected Supplier<URI> provideStorageUrl(URIFromAuthenticationResponseForService.Factory factory) {
return factory.create(AuthHeaders.STORAGE_URL);
}
}
public static class KeystoneStorageEndpointModule extends KeystoneAuthenticationModuleForRegions {
@Provides
@Singleton
@Storage
protected Supplier<URI> provideStorageUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
return getLastValueInMap(factory.createForApiTypeAndVersion(ServiceType.OBJECT_STORE, apiVersion));
}
}
@Override
protected void configure() {
install(new SwiftObjectModule());
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
bindResolvedClientsToCommonSwift();
}
protected void bindResolvedClientsToCommonSwift() {
bind(CommonSwiftClient.class).to(SwiftClient.class).in(Scopes.SINGLETON);
bind(CommonSwiftAsyncClient.class).to(SwiftAsyncClient.class).in(Scopes.SINGLETON);
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSwiftErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseSwiftErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseSwiftErrorFromHttpResponse.class);
}
}

View File

@ -1 +1,2 @@
org.jclouds.openstack.swift.SwiftApiMetadata
org.jclouds.openstack.swift.SwiftApiMetadata
org.jclouds.openstack.swift.SwiftKeystoneApiMetadata

View File

@ -26,6 +26,7 @@ import static org.testng.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
@ -36,6 +37,7 @@ import org.jclouds.crypto.CryptoStreams;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.options.GetOptions;
import org.jclouds.io.Payloads;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.swift.domain.AccountMetadata;
import org.jclouds.openstack.swift.domain.ContainerMetadata;
import org.jclouds.openstack.swift.domain.MutableObjectInfoWithMetadata;
@ -286,5 +288,12 @@ public abstract class CommonSwiftClientLiveTest<C extends CommonSwiftClient> ext
object.getInfo().getMetadata().put("Metadata", "metadata-value");
return object;
}
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
return props;
}
}

View File

@ -22,19 +22,24 @@ import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.net.URI;
import java.util.Properties;
import javax.inject.Singleton;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.functions.URIFromAuthenticationResponseForService;
import org.jclouds.openstack.internal.TestOpenStackAuthenticationModule;
import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.openstack.reference.AuthHeaders;
import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule;
import org.jclouds.openstack.swift.config.SwiftRestClientModule;
import org.jclouds.rest.internal.BaseAsyncClientTest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
@ -47,47 +52,34 @@ import com.google.inject.TypeLiteral;
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "SwiftClientTest")
public abstract class CommonSwiftClientTest extends BaseAsyncClientTest<SwiftAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<SwiftAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<SwiftAsyncClient>>() {
};
}
@Override
protected void checkFilters(HttpRequest request) {
}
@Override
protected Module createModule() {
return new TestSwiftRestClientModule();
}
@ConfiguresRestClient
protected static class TestSwiftRestClientModule extends
BaseSwiftRestClientModule<SwiftClient, SwiftAsyncClient> {
private TestSwiftRestClientModule() {
super(new TestOpenStackAuthenticationModule());
}
@Provides
@Singleton
CommonSwiftClient provideCommonSwiftClient(SwiftClient in) {
return in;
}
@Provides
@Singleton
CommonSwiftAsyncClient provideCommonSwiftClient(SwiftAsyncClient in) {
return in;
}
}
protected String provider = "swift";
protected ApiMetadata createApiMetadata() {
return new SwiftApiMetadata();
public static class StorageEndpointModule extends TestOpenStackAuthenticationModule {
@Provides
@Singleton
@Storage
protected Supplier<URI> provideStorageUrl(URIFromAuthenticationResponseForService.Factory factory) {
return factory.create(AuthHeaders.STORAGE_URL);
}
}
protected ApiMetadata createApiMetadata() {
return new SwiftApiMetadata().toBuilder().defaultModules(
ImmutableSet.<Class<? extends Module>> of(StorageEndpointModule.class, SwiftRestClientModule.class,
SwiftBlobStoreContextModule.class)).build();
}
@Override
protected Properties setupProperties() {
Properties properties = new Properties();

View File

@ -24,15 +24,15 @@ import org.testng.annotations.Test;
*
* @author Adrian Cole
*/
@Test(groups = "live")
public class SwiftClientLiveTest extends CommonSwiftClientLiveTest<SwiftClient> {
@Test(groups = "live", testName = "SwiftClientLiveTest")
public class SwiftClientLiveTest extends CommonSwiftClientLiveTest<CommonSwiftClient> {
public SwiftClientLiveTest(){
provider = "swift";
provider = System.getProperty("test.swift.provider", "swift");
}
@Override
public SwiftClient getApi() {
public CommonSwiftClient getApi() {
return view.unwrap(SwiftApiMetadata.CONTEXT_TOKEN).getApi();
}

View File

@ -0,0 +1,34 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.blobstore.internal.BaseBlobStoreApiMetadataTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "SwiftKeystoneApiMetadataTest")
public class SwiftKeystoneApiMetadataTest extends BaseBlobStoreApiMetadataTest {
public SwiftKeystoneApiMetadataTest() {
super(new SwiftKeystoneApiMetadata());
}
}

View File

@ -25,12 +25,14 @@ import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest;
import org.jclouds.blobstore.options.PutOptions;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.testng.ITestContext;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.*;
import java.util.Properties;
/**
*
@ -39,12 +41,20 @@ import java.io.*;
*/
@Test(groups = "live")
public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
return props;
}
private InputSupplier<InputStream> oneHundredOneConstitutions;
private byte[] oneHundredOneConstitutionsMD5;
public SwiftBlobIntegrationLiveTest() {
provider = "swift";
provider = System.getProperty("test.swift.provider", "swift");
}
@Override
@Test(enabled = false)
public void testGetTwoRanges() {

View File

@ -18,7 +18,10 @@
*/
package org.jclouds.openstack.swift.blobstore.integration;
import java.util.Properties;
import org.jclouds.blobstore.integration.internal.BaseBlobLiveTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.testng.annotations.Test;
/**
@ -28,7 +31,14 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "live" })
public class SwiftBlobLiveTest extends BaseBlobLiveTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
return props;
}
public SwiftBlobLiveTest() {
provider = "swift";
provider = System.getProperty("test.swift.provider", "swift");
}
}

View File

@ -18,7 +18,10 @@
*/
package org.jclouds.openstack.swift.blobstore.integration;
import java.util.Properties;
import org.jclouds.blobstore.integration.internal.BaseBlobMapIntegrationTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.testng.annotations.Test;
/**
@ -26,7 +29,14 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live")
public class SwiftBlobMapIntegrationLiveTest extends BaseBlobMapIntegrationTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
return props;
}
public SwiftBlobMapIntegrationLiveTest() {
provider = "swift";
provider = System.getProperty("test.swift.provider", "swift");
}
}

View File

@ -18,7 +18,10 @@
*/
package org.jclouds.openstack.swift.blobstore.integration;
import java.util.Properties;
import org.jclouds.blobstore.integration.internal.BaseBlobSignerLiveTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.testng.annotations.Test;
/**
@ -27,7 +30,14 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "live" })
public class SwiftBlobSignerLiveTest extends BaseBlobSignerLiveTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
return props;
}
public SwiftBlobSignerLiveTest() {
provider = "swift";
provider = System.getProperty("test.swift.provider", "swift");
}
}

View File

@ -18,7 +18,10 @@
*/
package org.jclouds.openstack.swift.blobstore.integration;
import java.util.Properties;
import org.jclouds.blobstore.integration.internal.BaseContainerIntegrationTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.testng.annotations.Test;
/**
@ -27,7 +30,14 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live")
public class SwiftContainerIntegrationLiveTest extends BaseContainerIntegrationTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
return props;
}
public SwiftContainerIntegrationLiveTest() {
provider = "swift";
provider = System.getProperty("test.swift.provider", "swift");
}
}

View File

@ -20,8 +20,10 @@ package org.jclouds.openstack.swift.blobstore.integration;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Properties;
import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.testng.annotations.Test;
/**
@ -29,8 +31,15 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live", testName = "SwiftContainerLiveTest" )
public class SwiftContainerLiveTest extends BaseContainerLiveTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
return props;
}
public SwiftContainerLiveTest() {
provider = "swift";
provider = System.getProperty("test.swift.provider", "swift");
}
@Test(expectedExceptions = UnsupportedOperationException.class)

View File

@ -18,7 +18,10 @@
*/
package org.jclouds.openstack.swift.blobstore.integration;
import java.util.Properties;
import org.jclouds.blobstore.integration.internal.BaseInputStreamMapIntegrationTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.testng.annotations.Test;
/**
@ -26,7 +29,14 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live")
public class SwiftInputStreamMapIntegrationLiveTest extends BaseInputStreamMapIntegrationTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
return props;
}
public SwiftInputStreamMapIntegrationLiveTest() {
provider = "swift";
provider = System.getProperty("test.swift.provider", "swift");
}
}

View File

@ -18,7 +18,10 @@
*/
package org.jclouds.openstack.swift.blobstore.integration;
import java.util.Properties;
import org.jclouds.blobstore.integration.internal.BaseServiceIntegrationTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.testng.annotations.Test;
/**
@ -26,7 +29,14 @@ import org.testng.annotations.Test;
*/
@Test(groups = "live")
public class SwiftServiceIntegrationLiveTest extends BaseServiceIntegrationTest {
@Override
protected Properties setupProperties() {
Properties props = super.setupProperties();
setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE);
return props;
}
public SwiftServiceIntegrationLiveTest() {
provider = "swift";
provider = System.getProperty("test.swift.provider", "swift");
}
}

View File

@ -25,7 +25,6 @@ import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@ -35,7 +34,6 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.blobstore.TransientAsyncBlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;

View File

@ -36,7 +36,6 @@
<properties>
<!-- keystone endpoint -->
<test.openstack-swift.endpoint>http://localhost:5000</test.openstack-swift.endpoint>
<!-- keystone version -->
<test.openstack-swift.api-version>1.0</test.openstack-swift.api-version>
<test.openstack-swift.build-version></test.openstack-swift.build-version>
<test.openstack-swift.identity>FIXME_IDENTITY</test.openstack-swift.identity>

View File

@ -18,23 +18,17 @@
*/
package org.jclouds.hpcloud.objectstorage;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule;
import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageRestClientModule;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.KeystoneAuthenticationModuleForRegions;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.openstack.swift.SwiftApiMetadata;
import org.jclouds.openstack.swift.config.SwiftRestClientModule.KeystoneStorageEndpointModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.BaseRestApiMetadata;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
@ -44,7 +38,7 @@ import com.google.inject.Module;
*
* @author Jeremy Daggett
*/
public class HPCloudObjectStorageApiMetadata extends BaseRestApiMetadata {
public class HPCloudObjectStorageApiMetadata extends SwiftApiMetadata {
/** The serialVersionUID */
private static final long serialVersionUID = 820062881469203616L;
@ -72,26 +66,21 @@ public class HPCloudObjectStorageApiMetadata extends BaseRestApiMetadata {
public static Properties defaultProperties() {
Properties properties = SwiftApiMetadata.defaultProperties();
properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE);
// TODO: this doesn't actually do anything yet.
properties.setProperty(KeystoneProperties.VERSION, "2.0");
properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.API_ACCESS_KEY_CREDENTIALS);
properties.remove(PROPERTY_REGIONS);
return properties;
}
public static class Builder extends BaseRestApiMetadata.Builder {
protected Builder() {
public static class Builder extends SwiftApiMetadata.Builder {
protected Builder(){
super(HPCloudObjectStorageClient.class, HPCloudObjectStorageAsyncClient.class);
id("hpcloud-objectstorage")
.name("HP Cloud Services Object Storage API")
.identityName("tenantName:accessKey")
.credentialName("secretKey")
.version("1.0")
.documentation(URI.create("https://build.hpcloud.com/object-storage/api"))
.defaultProperties(HPCloudObjectStorageApiMetadata.defaultProperties())
.view(TypeToken.of(BlobStoreContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneAuthenticationModuleForRegions.class, HPCloudObjectStorageRestClientModule.class, HPCloudObjectStorageBlobStoreContextModule.class));
.context(CONTEXT_TOKEN)
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneStorageEndpointModule.class, HPCloudObjectStorageRestClientModule.class, HPCloudObjectStorageBlobStoreContextModule.class));
}
@Override

View File

@ -31,26 +31,18 @@ import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNAsyncClient;
import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNClient;
import org.jclouds.hpcloud.services.HPExtensionCDN;
import org.jclouds.hpcloud.services.HPExtensionServiceType;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.CommonSwiftClient;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.config.SwiftObjectModule;
import org.jclouds.openstack.swift.handlers.ParseSwiftErrorFromHttpResponse;
import org.jclouds.openstack.swift.config.SwiftRestClientModule;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.rest.config.RestClientModule;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken;
import com.google.inject.Provides;
import com.google.inject.Scopes;
/**
*
@ -58,37 +50,18 @@ import com.google.inject.Provides;
*/
@ConfiguresRestClient
public class HPCloudObjectStorageRestClientModule extends
RestClientModule<HPCloudObjectStorageClient, HPCloudObjectStorageAsyncClient> {
SwiftRestClientModule<HPCloudObjectStorageClient, HPCloudObjectStorageAsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder().put(
HPCloudCDNClient.class, HPCloudCDNAsyncClient.class).build();
public HPCloudObjectStorageRestClientModule() {
super(DELEGATE_MAP);
super(TypeToken.of(HPCloudObjectStorageClient.class), TypeToken.of(HPCloudObjectStorageAsyncClient.class),
DELEGATE_MAP);
}
protected void configure() {
install(new SwiftObjectModule());
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseSwiftErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseSwiftErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseSwiftErrorFromHttpResponse.class);
}
@Provides
@Singleton
CommonSwiftClient provideCommonSwiftClient(HPCloudObjectStorageClient in) {
return in;
}
@Provides
@Singleton
CommonSwiftAsyncClient provideCommonSwiftClient(HPCloudObjectStorageAsyncClient in) {
return in;
protected void bindResolvedClientsToCommonSwift() {
bind(CommonSwiftClient.class).to(HPCloudObjectStorageClient.class).in(Scopes.SINGLETON);
bind(CommonSwiftAsyncClient.class).to(HPCloudObjectStorageAsyncClient.class).in(Scopes.SINGLETON);
}
@Provides
@ -97,12 +70,4 @@ public class HPCloudObjectStorageRestClientModule extends
protected Supplier<URI> provideCDNUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
return getLastValueInMap(factory.createForApiTypeAndVersion(HPExtensionServiceType.CDN, apiVersion));
}
@Provides
@Singleton
@Storage
protected Supplier<URI> provideStorageUrl(RegionIdToURISupplier.Factory factory, @ApiVersion String apiVersion) {
return getLastValueInMap(factory.createForApiTypeAndVersion(ServiceType.OBJECT_STORE, apiVersion));
}
}

View File

@ -46,7 +46,6 @@ public class HPCloudObjectStorageBlobStoreExpectTest extends BaseHPCloudObjectSt
Set<? extends Location> locations = clientWhenLocationsExist.listAssignableLocations();
assertNotNull(locations);
assertEquals(locations.size(), 1);
// TODO: does this location make sense?
assertEquals(locations.iterator().next().getId(), "hpcloud-objectstorage");
assertEquals(locations.iterator().next().getId(), "region-a.geo-1");
}
}