mirror of https://github.com/apache/jclouds.git
Issue 75: pushed more code up to rackspace level
git-svn-id: http://jclouds.googlecode.com/svn/trunk@1628 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
3877b69c76
commit
bdd0cf3b22
|
@ -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 <code>Module</code>s 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<CloudFilesConnection, CloudFilesContext> {
|
||||
RackspaceContextBuilder<CloudFilesConnection, CloudFilesContext> {
|
||||
|
||||
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<Module> modules) {
|
||||
super.addConnectionModule(modules);
|
||||
modules.add(new RestCloudFilesConnectionModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addContextModule(List<Module> modules) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addParserModule(List<Module> modules) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudFilesContext buildContext() {
|
||||
return buildInjector().getInstance(CloudFilesContext.class);
|
||||
}
|
||||
|
||||
protected void addParserModule(List<Module> modules) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
protected void addContextModule(List<Module> modules) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
protected void addConnectionModule(List<Module> modules) {
|
||||
modules.add(new RestCloudFilesConnectionModule());
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
||||
* @author Adrian Cole
|
||||
|
|
|
@ -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 <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
||||
* @author Adrian Cole
|
||||
|
|
|
@ -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;
|
|
@ -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 <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
|
||||
* @author Adrian Cole
|
||||
|
|
|
@ -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 <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
||||
* @author Adrian Cole
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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.
|
||||
* <p/>
|
||||
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
|
||||
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see CloudFilesContext
|
||||
*/
|
||||
public abstract class RackspaceContextBuilder<C, X extends CloudContext<C>> extends
|
||||
CloudContextBuilder<C,X> {
|
||||
|
||||
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<Module> modules) {
|
||||
modules.add( new RackspaceAuthenticationModule());
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
|
||||
* @author Adrian Cole
|
||||
|
|
|
@ -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 <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
|
||||
* @author Adrian Cole
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
Loading…
Reference in New Issue