diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextBuilder.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextBuilder.java index f436fb60c3..cda9120cad 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextBuilder.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesContextBuilder.java @@ -23,26 +23,12 @@ */ package org.jclouds.rackspace.cloudfiles; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_ADDRESS; -import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_REDIRECTS; -import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_RETRIES; -import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_SECURE; -import static org.jclouds.http.HttpConstants.PROPERTY_SAX_DEBUG; -import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_IO_WORKER_THREADS; -import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTIONS; -import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTION_REUSE; -import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_SESSION_FAILURES; -import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_REQUEST_INVOKER_THREADS; -import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_RACKSPACE_KEY; -import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_RACKSPACE_USER; - import java.util.List; import java.util.Properties; -import org.jclouds.cloud.CloudContextBuilder; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.rackspace.RackspaceContextBuilder; import org.jclouds.rackspace.cloudfiles.config.RestCloudFilesConnectionModule; import com.google.inject.Injector; @@ -58,11 +44,11 @@ import com.google.inject.Module; * If no Modules are specified, the default {@link JDKLoggingModule logging} and * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. * - * @author Adrian Cole, Andrew Newdigate + * @author Adrian Cole * @see CloudFilesContext */ public class CloudFilesContextBuilder extends - CloudContextBuilder { + RackspaceContextBuilder { public CloudFilesContextBuilder(Properties props) { super(props); @@ -70,43 +56,30 @@ public class CloudFilesContextBuilder extends public static CloudFilesContextBuilder newBuilder(String id, String secret) { Properties properties = new Properties(); - - properties.setProperty(PROPERTY_HTTP_ADDRESS, "api.mosso.com"); - properties.setProperty(PROPERTY_HTTP_SECURE, "true"); - properties.setProperty(PROPERTY_SAX_DEBUG, "false"); - properties.setProperty(PROPERTY_HTTP_MAX_RETRIES, "5"); - properties.setProperty(PROPERTY_HTTP_MAX_REDIRECTS, "5"); - properties.setProperty(PROPERTY_POOL_MAX_CONNECTION_REUSE, "75"); - properties.setProperty(PROPERTY_POOL_MAX_SESSION_FAILURES, "2"); - properties.setProperty(PROPERTY_POOL_REQUEST_INVOKER_THREADS, "1"); - properties.setProperty(PROPERTY_POOL_IO_WORKER_THREADS, "2"); - properties.setProperty(PROPERTY_POOL_MAX_CONNECTIONS, "12"); - CloudFilesContextBuilder builder = new CloudFilesContextBuilder(properties); builder.authenticate(id, secret); return builder; } - public void authenticate(String id, String secret) { - properties.setProperty(PROPERTY_RACKSPACE_USER, checkNotNull(id, "user")); - properties.setProperty(PROPERTY_RACKSPACE_KEY, checkNotNull(secret, "key")); + + protected void addConnectionModule(List modules) { + super.addConnectionModule(modules); + modules.add(new RestCloudFilesConnectionModule()); } + @Override + protected void addContextModule(List modules) { +//TODO + } + + @Override + protected void addParserModule(List modules) { + //TODO + } + + @Override public CloudFilesContext buildContext() { return buildInjector().getInstance(CloudFilesContext.class); } - protected void addParserModule(List modules) { - // TODO - } - - protected void addContextModule(List modules) { - // TODO - } - - protected void addConnectionModule(List modules) { - modules.add(new RestCloudFilesConnectionModule()); - // TODO - } - } diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/config/RestCloudFilesConnectionModule.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/config/RestCloudFilesConnectionModule.java index 2b4c564b17..d3510b8313 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/config/RestCloudFilesConnectionModule.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/config/RestCloudFilesConnectionModule.java @@ -1,30 +1,21 @@ package org.jclouds.rackspace.cloudfiles.config; -import java.net.MalformedURLException; import java.net.URI; import org.jclouds.cloud.ConfiguresCloudConnection; -import org.jclouds.http.HttpConstants; import org.jclouds.http.RequiresHttp; -import org.jclouds.rackspace.Authentication; -import org.jclouds.rackspace.CDN; -import org.jclouds.rackspace.RackSpaceAuthentication; import org.jclouds.rackspace.Storage; -import org.jclouds.rackspace.RackSpaceAuthentication.AuthenticationResponse; import org.jclouds.rackspace.cloudfiles.CloudFilesConnection; import org.jclouds.rackspace.cloudfiles.CloudFilesContext; import org.jclouds.rackspace.cloudfiles.internal.GuiceCloudFilesContext; -import org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants; import org.jclouds.rest.RestClientFactory; -import org.jclouds.rest.config.JaxrsModule; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.Singleton; -import com.google.inject.name.Named; /** - * Configures the S3 connection, including logging and http transport. + * Configures the Cloud Files connection, including logging and http transport. * * @author Adrian Cole */ @@ -34,66 +25,9 @@ public class RestCloudFilesConnectionModule extends AbstractModule { @Override protected void configure() { - install(new JaxrsModule()); bind(CloudFilesContext.class).to(GuiceCloudFilesContext.class); - bindErrorHandlers(); - bindRetryHandlers(); } - - @Provides - @Singleton - protected AuthenticationResponse provideAuthenticationResponse( - @Authentication URI authenticationUri, RestClientFactory factory, - @Named(CloudFilesConstants.PROPERTY_RACKSPACE_USER) String user, - @Named(CloudFilesConstants.PROPERTY_RACKSPACE_KEY) String key) { - return factory.create(authenticationUri, RackSpaceAuthentication.class).authenticate(user, - key); - } - - @Provides - @Authentication - protected String provideAuthenticationToken(@Authentication URI authenticationUri, - RestClientFactory factory, - @Named(CloudFilesConstants.PROPERTY_RACKSPACE_USER) String user, - @Named(CloudFilesConstants.PROPERTY_RACKSPACE_KEY) String key) { - return factory.create(authenticationUri, RackSpaceAuthentication.class).authenticate(user, - key).getAuthToken(); - } - - @Provides - @Singleton - @Storage - protected URI provideStorageUrl(AuthenticationResponse response) { - return response.getStorageUrl(); - } - - @Provides - @Singleton - @CDN - protected URI provideCDNUrl(AuthenticationResponse response) { - return response.getCDNManagementUrl(); - } - - protected void bindErrorHandlers() { - // TODO - } - - protected void bindRetryHandlers() { - // TODO retry on 401 by AuthenticateRequest.update() - } - - @Singleton - @Provides - @Authentication - protected URI provideAddress(@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address, - @Named(HttpConstants.PROPERTY_HTTP_PORT) int port, - @Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure) - throws MalformedURLException { - - return URI.create(String.format("%1$s://%2$s:%3$s", isSecure ? "https" : "http", address, - port)); - } - + @Provides @Singleton protected CloudFilesConnection provideConnection(@Storage URI authenticationUri, diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/package-info.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/package-info.java index 4519278558..5cc417e800 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/package-info.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/package-info.java @@ -22,7 +22,7 @@ * ==================================================================== */ /** - * This package contains an RackSpace Cloud Files client implemented by {@link org.jclouds.http.HttpCommandExecutorService} commands. + * This package contains an Rackspace Cloud Files client implemented by {@link org.jclouds.http.HttpCommandExecutorService} commands. * * @see * @author Adrian Cole diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/reference/CloudFilesHeaders.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/reference/CloudFilesHeaders.java index 7d0ab9a8d4..7bb42774e5 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/reference/CloudFilesHeaders.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/reference/CloudFilesHeaders.java @@ -25,7 +25,7 @@ package org.jclouds.rackspace.cloudfiles.reference; /** - * Additional headers specified by RackSpace Cloud Files REST API. + * Additional headers specified by Rackspace Cloud Files REST API. * * @see * @author Adrian Cole diff --git a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/reference/package-info.java b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/reference/package-info.java index 22ca57825b..072365d17f 100644 --- a/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/reference/package-info.java +++ b/rackspace/cloudfiles/core/src/main/java/org/jclouds/rackspace/cloudfiles/reference/package-info.java @@ -22,7 +22,7 @@ * ==================================================================== */ /** - * This package contains properties and reference data used in RackSpace Cloud Files. + * This package contains properties and reference data used in Rackspace Cloud Files. * @author Adrian Cole */ package org.jclouds.rackspace.cloudfiles.reference; \ No newline at end of file diff --git a/rackspace/core/src/main/java/org/jclouds/rackspace/Authentication.java b/rackspace/core/src/main/java/org/jclouds/rackspace/Authentication.java index f5193f6b48..bdf82d2c6e 100755 --- a/rackspace/core/src/main/java/org/jclouds/rackspace/Authentication.java +++ b/rackspace/core/src/main/java/org/jclouds/rackspace/Authentication.java @@ -31,7 +31,7 @@ import java.lang.annotation.Target; import com.google.inject.BindingAnnotation; /** - * Represents an authenticated context to RackSpace. + * Represents an authenticated context to Rackspace. * * @see * @author Adrian Cole diff --git a/rackspace/core/src/main/java/org/jclouds/rackspace/CDN.java b/rackspace/core/src/main/java/org/jclouds/rackspace/CDN.java index 84ea7222b0..082a007ae2 100755 --- a/rackspace/core/src/main/java/org/jclouds/rackspace/CDN.java +++ b/rackspace/core/src/main/java/org/jclouds/rackspace/CDN.java @@ -31,7 +31,7 @@ import java.lang.annotation.Target; import com.google.inject.BindingAnnotation; /** - * Represents a component related to RackSpace Cloud Files Content delivery network. + * Represents a component related to Rackspace Cloud Files Content delivery network. * * @see * @author Adrian Cole diff --git a/rackspace/core/src/main/java/org/jclouds/rackspace/RackspaceContextBuilder.java b/rackspace/core/src/main/java/org/jclouds/rackspace/RackspaceContextBuilder.java new file mode 100755 index 0000000000..108f041b7b --- /dev/null +++ b/rackspace/core/src/main/java/org/jclouds/rackspace/RackspaceContextBuilder.java @@ -0,0 +1,92 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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.rackspace; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_ADDRESS; +import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_REDIRECTS; +import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_RETRIES; +import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_SECURE; +import static org.jclouds.http.HttpConstants.PROPERTY_SAX_DEBUG; +import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_IO_WORKER_THREADS; +import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTIONS; +import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTION_REUSE; +import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_SESSION_FAILURES; +import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_REQUEST_INVOKER_THREADS; +import static org.jclouds.rackspace.reference.RackSpaceConstants.PROPERTY_RACKSPACE_KEY; +import static org.jclouds.rackspace.reference.RackSpaceConstants.PROPERTY_RACKSPACE_USER; + +import java.util.List; +import java.util.Properties; + +import org.jclouds.cloud.CloudContext; +import org.jclouds.cloud.CloudContextBuilder; +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.rackspace.config.RackspaceAuthenticationModule; + +import com.google.inject.Injector; +import com.google.inject.Module; + +/** + * Creates {@link RackspaceContext} or {@link Injector} instances based on the most commonly + * requested arguments. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + *

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole + * @see CloudFilesContext + */ +public abstract class RackspaceContextBuilder> extends + CloudContextBuilder { + + public RackspaceContextBuilder(Properties props) { + super(props); + properties.setProperty(PROPERTY_HTTP_ADDRESS, "api.mosso.com"); + properties.setProperty(PROPERTY_HTTP_SECURE, "true"); + properties.setProperty(PROPERTY_SAX_DEBUG, "false"); + properties.setProperty(PROPERTY_HTTP_MAX_RETRIES, "5"); + properties.setProperty(PROPERTY_HTTP_MAX_REDIRECTS, "5"); + properties.setProperty(PROPERTY_POOL_MAX_CONNECTION_REUSE, "75"); + properties.setProperty(PROPERTY_POOL_MAX_SESSION_FAILURES, "2"); + properties.setProperty(PROPERTY_POOL_REQUEST_INVOKER_THREADS, "1"); + properties.setProperty(PROPERTY_POOL_IO_WORKER_THREADS, "2"); + properties.setProperty(PROPERTY_POOL_MAX_CONNECTIONS, "12"); + } + + public void authenticate(String id, String secret) { + properties.setProperty(PROPERTY_RACKSPACE_USER, checkNotNull(id, "user")); + properties.setProperty(PROPERTY_RACKSPACE_KEY, checkNotNull(secret, "key")); + } + + + protected void addConnectionModule(List modules) { + modules.add( new RackspaceAuthenticationModule()); + } + +} diff --git a/rackspace/core/src/main/java/org/jclouds/rackspace/Server.java b/rackspace/core/src/main/java/org/jclouds/rackspace/Server.java index e4918dc571..1824b8f10c 100644 --- a/rackspace/core/src/main/java/org/jclouds/rackspace/Server.java +++ b/rackspace/core/src/main/java/org/jclouds/rackspace/Server.java @@ -31,7 +31,7 @@ import java.lang.annotation.Target; import com.google.inject.BindingAnnotation; /** - * Represents a component related to RackSpace Cloud Servers. + * Represents a component related to Rackspace Cloud Servers. * * @see * @author Adrian Cole diff --git a/rackspace/core/src/main/java/org/jclouds/rackspace/Storage.java b/rackspace/core/src/main/java/org/jclouds/rackspace/Storage.java index 1583b16dd7..bb22041f58 100755 --- a/rackspace/core/src/main/java/org/jclouds/rackspace/Storage.java +++ b/rackspace/core/src/main/java/org/jclouds/rackspace/Storage.java @@ -31,7 +31,7 @@ import java.lang.annotation.Target; import com.google.inject.BindingAnnotation; /** - * Represents a component related to RackSpace Cloud Files. + * Represents a component related to Rackspace Cloud Files. * * @see * @author Adrian Cole diff --git a/rackspace/core/src/main/java/org/jclouds/rackspace/config/RackspaceAuthenticationModule.java b/rackspace/core/src/main/java/org/jclouds/rackspace/config/RackspaceAuthenticationModule.java new file mode 100755 index 0000000000..50c182af5b --- /dev/null +++ b/rackspace/core/src/main/java/org/jclouds/rackspace/config/RackspaceAuthenticationModule.java @@ -0,0 +1,101 @@ +package org.jclouds.rackspace.config; + +import static org.jclouds.rackspace.reference.RackSpaceConstants.PROPERTY_RACKSPACE_KEY; +import static org.jclouds.rackspace.reference.RackSpaceConstants.PROPERTY_RACKSPACE_USER; + +import java.net.MalformedURLException; +import java.net.URI; + +import org.jclouds.http.HttpConstants; +import org.jclouds.http.RequiresHttp; +import org.jclouds.rackspace.Authentication; +import org.jclouds.rackspace.CDN; +import org.jclouds.rackspace.RackSpaceAuthentication; +import org.jclouds.rackspace.Server; +import org.jclouds.rackspace.Storage; +import org.jclouds.rackspace.RackSpaceAuthentication.AuthenticationResponse; +import org.jclouds.rest.RestClientFactory; +import org.jclouds.rest.config.JaxrsModule; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.name.Named; + +/** + * Configures the Rackspace authentication service connection, including logging and http transport. + * + * @author Adrian Cole + */ +@RequiresHttp +public class RackspaceAuthenticationModule extends AbstractModule { + + @Override + protected void configure() { + install(new JaxrsModule()); + bindErrorHandlers(); + bindRetryHandlers(); + } + + @Provides + @Singleton + protected AuthenticationResponse provideAuthenticationResponse( + @Authentication URI authenticationUri, RestClientFactory factory, + @Named(PROPERTY_RACKSPACE_USER) String user, + @Named(PROPERTY_RACKSPACE_KEY) String key) { + return factory.create(authenticationUri, RackSpaceAuthentication.class).authenticate(user, + key); + } + + @Provides + @Authentication + protected String provideAuthenticationToken(@Authentication URI authenticationUri, + RestClientFactory factory, + @Named(PROPERTY_RACKSPACE_USER) String user, + @Named(PROPERTY_RACKSPACE_KEY) String key) { + return factory.create(authenticationUri, RackSpaceAuthentication.class).authenticate(user, + key).getAuthToken(); + } + + @Provides + @Singleton + @Storage + protected URI provideStorageUrl(AuthenticationResponse response) { + return response.getStorageUrl(); + } + + @Provides + @Singleton + @Server + protected URI provideServerUrl(AuthenticationResponse response) { + return response.getServerManagementUrl(); + } + + @Provides + @Singleton + @CDN + protected URI provideCDNUrl(AuthenticationResponse response) { + return response.getCDNManagementUrl(); + } + + protected void bindErrorHandlers() { + // TODO + } + + protected void bindRetryHandlers() { + // TODO retry on 401 by AuthenticateRequest.update() + } + + @Singleton + @Provides + @Authentication + protected URI provideAddress(@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address, + @Named(HttpConstants.PROPERTY_HTTP_PORT) int port, + @Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure) + throws MalformedURLException { + + return URI.create(String.format("%1$s://%2$s:%3$s", isSecure ? "https" : "http", address, + port)); + } + +} \ No newline at end of file diff --git a/rackspace/core/src/main/java/org/jclouds/rackspace/reference/package-info.java b/rackspace/core/src/main/java/org/jclouds/rackspace/reference/package-info.java index 2132f394d1..c2b38cb692 100644 --- a/rackspace/core/src/main/java/org/jclouds/rackspace/reference/package-info.java +++ b/rackspace/core/src/main/java/org/jclouds/rackspace/reference/package-info.java @@ -22,7 +22,7 @@ * ==================================================================== */ /** - * This package contains properties and reference data used in RackSpace. + * This package contains properties and reference data used in Rackspace. * @author Adrian Cole */ package org.jclouds.rackspace.reference; \ No newline at end of file