You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by je...@apache.org on 2010/07/15 05:44:25 UTC

svn commit: r964295 - in /incubator/libcloud/java: ./ trunk/ trunk/lib/ trunk/src/ trunk/src/base/ trunk/src/base/beans/ trunk/src/base/exceptions/ trunk/src/base/interfaces/ trunk/src/drivers/ trunk/src/drivers/ibm/ trunk/src/drivers/rackspace/

Author: jerry
Date: Thu Jul 15 03:44:23 2010
New Revision: 964295

URL: http://svn.apache.org/viewvc?rev=964295&view=rev
Log:
Separate directory for libcloud-java

Added:
    incubator/libcloud/java/
    incubator/libcloud/java/trunk/
    incubator/libcloud/java/trunk/.classpath   (with props)
    incubator/libcloud/java/trunk/.project   (with props)
    incubator/libcloud/java/trunk/lib/
    incubator/libcloud/java/trunk/lib/apache-mime4j-0.6.jar   (with props)
    incubator/libcloud/java/trunk/lib/commons-codec-1.3.jar   (with props)
    incubator/libcloud/java/trunk/lib/commons-logging-1.1.1.jar   (with props)
    incubator/libcloud/java/trunk/lib/httpclient-4.0.1.jar   (with props)
    incubator/libcloud/java/trunk/lib/httpcore-4.0.1.jar   (with props)
    incubator/libcloud/java/trunk/lib/httpmime-4.0.1.jar   (with props)
    incubator/libcloud/java/trunk/lib/resolver.jar   (with props)
    incubator/libcloud/java/trunk/lib/serializer.jar   (with props)
    incubator/libcloud/java/trunk/lib/xercesImpl.jar   (with props)
    incubator/libcloud/java/trunk/lib/xercesSamples.jar   (with props)
    incubator/libcloud/java/trunk/lib/xml-apis.jar   (with props)
    incubator/libcloud/java/trunk/src/
    incubator/libcloud/java/trunk/src/base/
    incubator/libcloud/java/trunk/src/base/ConnectionKey.java   (with props)
    incubator/libcloud/java/trunk/src/base/ConnectionUserAndKey.java   (with props)
    incubator/libcloud/java/trunk/src/base/DefaultHandler.java   (with props)
    incubator/libcloud/java/trunk/src/base/LoggingConnection.java   (with props)
    incubator/libcloud/java/trunk/src/base/LoggingConnectionUserAndKey.java   (with props)
    incubator/libcloud/java/trunk/src/base/Node.java   (with props)
    incubator/libcloud/java/trunk/src/base/NodeDriver.java   (with props)
    incubator/libcloud/java/trunk/src/base/NodeState.java   (with props)
    incubator/libcloud/java/trunk/src/base/Providers.java   (with props)
    incubator/libcloud/java/trunk/src/base/Response.java   (with props)
    incubator/libcloud/java/trunk/src/base/beans/
    incubator/libcloud/java/trunk/src/base/beans/NodeAuth.java   (with props)
    incubator/libcloud/java/trunk/src/base/beans/NodeImage.java   (with props)
    incubator/libcloud/java/trunk/src/base/beans/NodeLocation.java   (with props)
    incubator/libcloud/java/trunk/src/base/beans/NodeSize.java   (with props)
    incubator/libcloud/java/trunk/src/base/exceptions/
    incubator/libcloud/java/trunk/src/base/exceptions/InvalidCredsException.java   (with props)
    incubator/libcloud/java/trunk/src/base/interfaces/
    incubator/libcloud/java/trunk/src/base/interfaces/IConnection.java   (with props)
    incubator/libcloud/java/trunk/src/base/interfaces/INode.java   (with props)
    incubator/libcloud/java/trunk/src/base/interfaces/INodeDriver.java   (with props)
    incubator/libcloud/java/trunk/src/base/interfaces/IResponse.java   (with props)
    incubator/libcloud/java/trunk/src/base/interfaces/IResponseHandler.java   (with props)
    incubator/libcloud/java/trunk/src/drivers/
    incubator/libcloud/java/trunk/src/drivers/ibm/
    incubator/libcloud/java/trunk/src/drivers/ibm/IBMConnection.java   (with props)
    incubator/libcloud/java/trunk/src/drivers/ibm/IBMDriver.java   (with props)
    incubator/libcloud/java/trunk/src/drivers/ibm/IBMHandler.java   (with props)
    incubator/libcloud/java/trunk/src/drivers/ibm/Main.java   (with props)
    incubator/libcloud/java/trunk/src/drivers/rackspace/
    incubator/libcloud/java/trunk/src/drivers/rackspace/Main.java   (with props)
    incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceConnection.java   (with props)
    incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceDriver.java   (with props)
    incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceHandler.java   (with props)

Added: incubator/libcloud/java/trunk/.classpath
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/.classpath?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/.classpath (added)
+++ incubator/libcloud/java/trunk/.classpath Thu Jul 15 03:44:23 2010
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="lib" path="lib/apache-mime4j-0.6.jar"/>
+	<classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/>
+	<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
+	<classpathentry kind="lib" path="lib/httpclient-4.0.1.jar"/>
+	<classpathentry kind="lib" path="lib/httpcore-4.0.1.jar"/>
+	<classpathentry kind="lib" path="lib/httpmime-4.0.1.jar"/>
+	<classpathentry kind="lib" path="lib/resolver.jar"/>
+	<classpathentry kind="lib" path="lib/serializer.jar"/>
+	<classpathentry kind="lib" path="lib/xercesImpl.jar"/>
+	<classpathentry kind="lib" path="lib/xercesSamples.jar"/>
+	<classpathentry kind="lib" path="lib/xml-apis.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Propchange: incubator/libcloud/java/trunk/.classpath
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/.project
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/.project?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/.project (added)
+++ incubator/libcloud/java/trunk/.project Thu Jul 15 03:44:23 2010
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>libcloud-java</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Propchange: incubator/libcloud/java/trunk/.project
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/lib/apache-mime4j-0.6.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/apache-mime4j-0.6.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/apache-mime4j-0.6.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/apache-mime4j-0.6.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/lib/commons-codec-1.3.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/commons-codec-1.3.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/commons-codec-1.3.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/commons-codec-1.3.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/lib/commons-logging-1.1.1.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/commons-logging-1.1.1.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/commons-logging-1.1.1.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/commons-logging-1.1.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/lib/httpclient-4.0.1.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/httpclient-4.0.1.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/httpclient-4.0.1.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/httpclient-4.0.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/lib/httpcore-4.0.1.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/httpcore-4.0.1.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/httpcore-4.0.1.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/httpcore-4.0.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/lib/httpmime-4.0.1.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/httpmime-4.0.1.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/httpmime-4.0.1.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/httpmime-4.0.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/lib/resolver.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/resolver.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/resolver.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/resolver.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/lib/serializer.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/serializer.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/serializer.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/serializer.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/lib/xercesImpl.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/xercesImpl.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/xercesImpl.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/xercesImpl.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/lib/xercesSamples.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/xercesSamples.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/xercesSamples.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/xercesSamples.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/lib/xml-apis.jar
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/lib/xml-apis.jar?rev=964295&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/libcloud/java/trunk/lib/xml-apis.jar
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/libcloud/java/trunk/lib/xml-apis.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/libcloud/java/trunk/src/base/ConnectionKey.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/ConnectionKey.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/ConnectionKey.java (added)
+++ incubator/libcloud/java/trunk/src/base/ConnectionKey.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,208 @@
+package base;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpHost;
+import org.apache.http.NameValuePair;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.utils.URIUtils;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
+
+import base.interfaces.IConnection;
+import base.interfaces.INodeDriver;
+
+public class ConnectionKey implements IConnection {
+
+	protected String host;
+
+	protected int port;
+
+	protected String userId;
+
+	protected String key;
+
+	protected boolean secure;
+
+	protected INodeDriver driver;
+
+	protected DefaultHttpClient httpClient;
+
+	protected HttpHost httpHost;
+	
+	public ConnectionKey(String key, boolean secure, String host, INodeDriver driver) {
+		this.key = key;
+		this.secure = secure;
+		this.host = host;
+		this.driver = driver;
+		this.userId = null;	// subclass my initialize
+		this.port = -1;		// default port used by HTTPComponents
+	}
+
+	public ConnectionKey(String key, boolean secure, String host, int port,
+			INodeDriver driver) {
+		this.key = key;
+		this.secure = secure;
+		this.host = host;
+		this.port = port;
+		this.driver = driver;
+		this.httpClient = null;
+		this.httpHost = null;
+		this.userId = null;	// subclass my initialize
+	}
+
+	public void connect() {
+		connect(host, port);
+	}
+
+	public void connect(String host, int port) {
+		this.host = host;
+		this.port = port;
+
+		httpClient = new DefaultHttpClient();
+		if (userId != null) {
+			httpClient.getCredentialsProvider().setCredentials(
+					new AuthScope(host, port),
+					new UsernamePasswordCredentials(userId, key));
+		}
+	}
+
+	public Response request(String method, String action,
+			Map<String, String> headers, Map<String, String> params, String data) {
+		// Connect if not already connected
+		if (httpClient == null) {
+			connect();
+		}
+		
+		// Compose request headers with priority
+		Map<String, String> reqHeaders = new HashMap<String, String>();
+		reqHeaders.put("User-Agent", getUserAgent());	// 3: libcloud headers
+		reqHeaders.put("Host", host);
+		reqHeaders = addDefaultHeaders(reqHeaders); 	// 2: provider headers
+		if (headers != null) {
+			reqHeaders.putAll(headers); 				// 1: argument headers
+		}
+
+		// Compose request parameters with priority
+		Map<String, String> reqParams = new HashMap<String, String>();
+		reqParams = addDefaultParams(reqParams); 		// 2: provider parameters
+		if (params != null) {
+			reqParams.putAll(params); 					// 1: argument parameters
+		}
+
+		// Convert parameters to list for URLEncodedUtils
+		List<NameValuePair> paramsNVP = new ArrayList<NameValuePair>();
+		for (String name : reqParams.keySet()) {
+			paramsNVP.add(new BasicNameValuePair(name, reqParams.get(name)));
+		}
+
+		// Create URI endpoint
+		URI uri = null;
+		try {
+			String protocol = secure ? "https" : "http";
+			uri = URIUtils.createURI(protocol, host, port, action,
+					URLEncodedUtils.format(paramsNVP, "UTF-8"), null);
+		} catch (URISyntaxException e) {
+			e.printStackTrace();
+			return null;
+		}
+
+		// Create request to send
+		HttpUriRequest request = null;
+		if (method.equalsIgnoreCase("GET")) {
+			request = new HttpGet(uri);
+		} else if (method.equalsIgnoreCase("DELETE")) {
+			request = new HttpDelete(uri);
+		} else if (method.equalsIgnoreCase("PUT")) {
+			request = new HttpPut(uri);
+		} else if (method.equalsIgnoreCase("POST")) {
+			request = new HttpPost(uri);
+		} else {
+			throw new IllegalArgumentException("Illegal HTTP method: " + method);
+		}
+
+		// Encode and add the payload data
+		String encoded = encodeData(data);
+		if (encoded != null && !encoded.equals("")) {
+			try {
+				((HttpEntityEnclosingRequest) request).setEntity(new StringEntity(encoded));
+			} catch (UnsupportedEncodingException e) {
+				e.printStackTrace();
+				return null;
+			}
+		}
+
+		// Add headers to the request
+		for (String header : reqHeaders.keySet()) {
+			request.addHeader(header, reqHeaders.get(header));
+		}
+
+		// Execute the request!
+		try {
+			return new Response(httpClient.execute(request));
+		} catch (ClientProtocolException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		return null; // Error
+	}
+
+	public Map<String, String> addDefaultHeaders(Map<String, String> headers) {
+		return headers;
+	}
+
+	public Map<String, String> addDefaultParams(Map<String, String> params) {
+		return params;
+	}
+
+	public String encodeData(String data) {
+		return data;
+	}
+	
+	/*
+	 * Utility that performs UTF-8 encoding of a map of Strings. Returns a
+	 * String that is suitable for use as an application/x-www-form-urlencoded
+	 * list of parameters in an HTTP PUT or HTTP POST.
+	 * 
+	 * @param dataMap is the map of String values to format as a UTF-8 String
+	 * 
+	 * @return String is the UTF-8 encoding of the map of String values
+	 */
+	public String encodeDataMap(Map<String, String> dataMap) {
+		// Convert map to List<NameValuePair> for URLEncodedUtils
+		List<BasicNameValuePair> nvp = new ArrayList<BasicNameValuePair>();
+		for (String key : dataMap.keySet()) {
+			nvp.add(new BasicNameValuePair(key, dataMap.get(key)));
+		}
+		
+		return URLEncodedUtils.format(nvp, "UTF-8");
+	}
+
+	/*
+	 * Defines the user agent used when making requests.
+	 * 
+	 * @return String is the user agent for making requests
+	 */
+	private String getUserAgent() {
+		return "libcloud-java";	// TODO: generate version like python?
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/ConnectionKey.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/ConnectionUserAndKey.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/ConnectionUserAndKey.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/ConnectionUserAndKey.java (added)
+++ incubator/libcloud/java/trunk/src/base/ConnectionUserAndKey.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,18 @@
+package base;
+
+import base.interfaces.INodeDriver;
+
+public class ConnectionUserAndKey extends ConnectionKey {
+
+	public ConnectionUserAndKey(String userId, String key, boolean secure,
+			String host, int port, INodeDriver driver) {
+		super(key, secure, host, port, driver);
+		this.userId = userId;
+	}
+
+	public ConnectionUserAndKey(String userId, String key, boolean secure,
+			String host, INodeDriver driver) {
+		super(key, secure, host, driver);
+		this.userId = userId;
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/ConnectionUserAndKey.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/DefaultHandler.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/DefaultHandler.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/DefaultHandler.java (added)
+++ incubator/libcloud/java/trunk/src/base/DefaultHandler.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,41 @@
+package base;
+
+import base.interfaces.IResponse;
+import base.interfaces.IResponseHandler;
+
+public class DefaultHandler implements IResponseHandler {
+	
+	protected IResponse response;
+	
+	protected Object object;
+
+	public DefaultHandler(IResponse response) {
+		this.response = response;
+		
+		if (success()) {
+			parseBody();
+		} else {
+			throw new RuntimeException(parseError());
+		}
+	}
+	
+	public Object getParsedObject() {
+		return object;
+	}
+	
+	public IResponse getResponse() {
+		return response;
+	}
+	
+	protected boolean success() {
+		return response.getStatus() == 200;
+	}
+	
+	protected void parseBody() {
+		object = response.getBody();
+	}
+	
+	protected String parseError() {
+		return response.getStatus() + " " + response.getPhrase();
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/DefaultHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/LoggingConnection.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/LoggingConnection.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/LoggingConnection.java (added)
+++ incubator/libcloud/java/trunk/src/base/LoggingConnection.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,60 @@
+package base;
+
+import java.util.Map;
+
+import base.interfaces.INodeDriver;
+
+public class LoggingConnection extends ConnectionKey {
+
+	protected StringBuffer log;
+		
+	public LoggingConnection(String key, boolean secure, String host, int port,
+			INodeDriver driver) {
+		super(key, secure, host, port, driver);
+		log = new StringBuffer();
+	}
+
+	public Response request(String method, String action,
+			Map<String, String> headers, Map<String, String> params, String data) {
+		log.append(logCurl(method, action, data, headers));
+		Response response = super.request(method, action, headers, params, data);
+		log.append(logResponse(response));
+		return response;
+	}
+	
+	protected String logResponse(Response response) {
+		String logEntry = "# -------- begin response ----------\n";
+		logEntry += response.version.getProtocol() + "/" 
+				 + response.version.getMajor() + "." + response.version.getMinor();		
+		logEntry += " " + response.status + " " + response.phrase + "\r\n";
+		
+		if (response.headers != null) {
+			for (Map.Entry<String, String> header : response.headers.entrySet()) {
+			    logEntry += header.getKey() + ": " + header.getValue() + "\r\n";
+			}
+		}
+
+		logEntry += "\r\n" + response.body + "\r\n";
+		logEntry += "\n# -------- end response ------------\n";
+		
+		return logEntry;
+	}
+	
+	protected String logCurl(String method, String url, String body, Map<String, String> headers) {
+		String curl = "curl -X " + method + " ";
+		
+		if (headers != null) {
+			for (Map.Entry<String, String> header : headers.entrySet()) {
+			    curl += "-H \"" + header.getKey() + ": " + header.getValue() + "\" ";
+			}
+		}
+		
+		if (body != null && !"".equals(body)) {
+			curl += "-d \"" + body + "\" ";
+		}
+		
+		curl += url;		
+		return curl;
+	}
+	
+}

Propchange: incubator/libcloud/java/trunk/src/base/LoggingConnection.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/LoggingConnectionUserAndKey.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/LoggingConnectionUserAndKey.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/LoggingConnectionUserAndKey.java (added)
+++ incubator/libcloud/java/trunk/src/base/LoggingConnectionUserAndKey.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,13 @@
+package base;
+
+import base.interfaces.INodeDriver;
+
+public class LoggingConnectionUserAndKey extends LoggingConnection {
+
+	public LoggingConnectionUserAndKey(String userId, String key, boolean secure,
+			String host, int port, INodeDriver driver) {
+		super(key, secure, host, port, driver);
+		this.userId = userId;
+	}
+	
+}

Propchange: incubator/libcloud/java/trunk/src/base/LoggingConnectionUserAndKey.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/Node.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/Node.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/Node.java (added)
+++ incubator/libcloud/java/trunk/src/base/Node.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,87 @@
+package base;
+
+import java.util.Map;
+import java.util.UUID;
+
+import base.interfaces.INode;
+import base.interfaces.INodeDriver;
+
+public class Node implements INode {
+	
+	private String uuid;
+	
+	private String id;
+	
+	private String name;
+	
+	private NodeState state;
+	
+	private String publicIp;
+	
+	private String privateIp;
+	
+	private Map<String, String> extra;
+	
+	private INodeDriver driver;
+	
+	public Node(String id, String name, NodeState state, String publicIp, String privateIp, Map<String, String> extra, INodeDriver driver) {
+		this.id = id;
+		this.name = name;
+		this.state = state;
+		this.publicIp = publicIp;
+		this.privateIp = privateIp;
+		this.extra = extra;
+		this.driver = driver;
+	}
+
+	public boolean destroy() {
+		return driver.destroyNode(this);
+	}
+
+	public boolean reboot() {
+		return driver.rebootNode(this);
+	}
+
+	public INodeDriver getDriver() {
+		return driver;
+	}
+
+	public Map<String, String> getExtra() {
+		return extra;
+	}
+
+	public String getId() {
+		return id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public String getPrivateIp() {
+		return privateIp;
+	}
+
+	public String getPublicIp() {
+		return publicIp;
+	}
+
+	public NodeState getState() {
+		return state;
+	}
+
+	public String getUuid() {
+		return UUID.randomUUID().toString();
+	}
+	
+	public String toString() {
+		return "<Node" +
+		": uuid=" + getUuid() +
+		", id=" + id + 
+		", name=" + name +
+		", state=" + state + 
+		", publicIp=" + publicIp +
+		", driver=" + driver.getName() + 
+		" ...>";
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/Node.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/NodeDriver.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/NodeDriver.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/NodeDriver.java (added)
+++ incubator/libcloud/java/trunk/src/base/NodeDriver.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,13 @@
+package base;
+
+import base.interfaces.IConnection;
+import base.interfaces.INodeDriver;
+
+public abstract class NodeDriver implements INodeDriver {
+	
+	protected IConnection connection;
+	
+	public IConnection getConnection() {
+		return connection;
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/NodeDriver.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/NodeState.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/NodeState.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/NodeState.java (added)
+++ incubator/libcloud/java/trunk/src/base/NodeState.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,9 @@
+package base;
+
+public enum NodeState {
+	RUNNING,
+	REBOOTING,
+	TERMINATED,
+	PENDING,
+	UNKNOWN;
+}

Propchange: incubator/libcloud/java/trunk/src/base/NodeState.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/Providers.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/Providers.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/Providers.java (added)
+++ incubator/libcloud/java/trunk/src/base/Providers.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,98 @@
+package base;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.EnumMap;
+
+public class Providers {
+	public static enum Provider {
+		DUMMY,
+	    EC2_US_EAST,
+	    EC2_EU_WEST,
+	    EC2_US_WEST,
+	    ECP,
+	    GOGRID,
+	    RACKSPACE,
+	    SLICEHOST,
+	    VPSNET,
+	    LINODE,
+	    RIMUHOSTING,
+	    VOXEL,
+	    SOFTLAYER,
+	    EUCALYPTUS,
+	    IBM,
+	    OPENNEBULA,
+	    DREAMHOST;
+	}
+	
+	private static EnumMap<Provider, String> providerMap;
+	
+	private static void initProviderMap()
+	{
+		providerMap = new EnumMap<Provider, String>(Provider.class);
+		
+		//First parameter to the map is the Provider name from the enum, the
+		//second parameter is the package name of the driver.  When adding a new
+		//provider, simply add it to the "Provider" enum and add a providerMap.put
+		//below with the appropriate parameters.
+		providerMap.put(Provider.IBM, "drivers.ibm.IBMDriver");
+		providerMap.put(Provider.RACKSPACE, "drivers.rackspace.XXX");
+		providerMap.put(Provider.SLICEHOST, "drivers.slicehost.XXX");
+		providerMap.put(Provider.EC2_US_EAST, "");
+		providerMap.put(Provider.EC2_EU_WEST, "");
+		providerMap.put(Provider.EC2_US_WEST, "");
+		providerMap.put(Provider.ECP, "");
+		providerMap.put(Provider.GOGRID, "");
+		providerMap.put(Provider.VPSNET, "");
+		providerMap.put(Provider.LINODE, "");
+		providerMap.put(Provider.RIMUHOSTING, "");
+		providerMap.put(Provider.VOXEL, "");
+		providerMap.put(Provider.SOFTLAYER, "");
+		providerMap.put(Provider.EUCALYPTUS, "");
+		providerMap.put(Provider.OPENNEBULA, "");
+		providerMap.put(Provider.DREAMHOST, "");
+	}
+	
+	public static Class get_driver(Provider p)
+	{
+		if (providerMap == null)
+			initProviderMap();
+		
+		Class driverClass = null;
+		try {
+			String classname = providerMap.get(p);
+			driverClass = Class.forName(classname);
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+		}
+		return driverClass;
+	}
+	
+	public static NodeDriver constructDriver(Class<? extends NodeDriver> myClass, Object ... args) {
+		// Convert arguments to class array
+		Class<?>[] classArgs = new Class[args.length];
+		for (int i = 0; i < args.length; i++) {
+			classArgs[i] = args[i].getClass();
+		}
+		
+		try {
+			// Get constructor and create instance
+			Constructor<?> constructor = myClass.getConstructor(classArgs);
+			return (NodeDriver)constructor.newInstance(args);
+		} catch (SecurityException e) {
+			e.printStackTrace();
+		} catch (NoSuchMethodException e) {
+			e.printStackTrace();
+		} catch (IllegalArgumentException e) {
+			e.printStackTrace();
+		} catch (InstantiationException e) {
+			e.printStackTrace();
+		} catch (IllegalAccessException e) {
+			e.printStackTrace();
+		} catch (InvocationTargetException e) {
+			e.printStackTrace();
+		}
+		
+		return null;
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/Providers.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/Response.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/Response.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/Response.java (added)
+++ incubator/libcloud/java/trunk/src/base/Response.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,96 @@
+package base;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolVersion;
+
+import base.interfaces.IResponse;
+
+
+public class Response implements IResponse {
+	
+	protected int status;
+	
+	protected String phrase;
+	
+	protected String body;
+	
+	protected ProtocolVersion version;
+	
+	protected Map<String, String> headers;
+	
+	public Response(HttpResponse response) {
+		
+		// Retrieve HTTP version from response
+		version = response.getStatusLine().getProtocolVersion();
+		
+		// Retrieve status code from response
+		status = response.getStatusLine().getStatusCode();
+		
+		// Retrieve reason from response
+		phrase = response.getStatusLine().getReasonPhrase();
+		
+		// Retrieve body from response
+		body = null;
+		HttpEntity entity = response.getEntity();
+		if (entity != null) {
+			try {
+				String line = null;
+				StringBuffer bodySb = new StringBuffer();
+				BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
+				while ((line = reader.readLine()) != null) {
+					bodySb.append(line);
+				}
+				body = bodySb.toString();
+				entity.consumeContent();
+			} catch (IOException ioe) {
+				ioe.printStackTrace();
+			}
+		}
+		
+		// Retrieve headers from response
+		headers = new HashMap<String, String>();
+		for (Header header : response.getAllHeaders()) {
+			this.headers.put(header.getName(), header.getValue());
+		}
+	}
+
+	public String getBody() {
+		return body;
+	}
+
+	public ProtocolVersion getVersion() {
+		return version;
+	}
+	
+	public String getPhrase() {
+		return phrase;
+	}
+
+	public Map<String, String> getHeaders() {
+		return headers;
+	}
+
+	public int getStatus() {
+		return status;
+	}
+	
+	public String toString() {
+		StringBuilder sb = new StringBuilder();
+		sb.append(status + " " + phrase + '\n');
+		sb.append("Headers:\n");
+		for (String key : headers.keySet()) {
+			sb.append('\t' + key + ": " + headers.get(key) + '\n');
+		}
+		sb.append("Body: ");
+		sb.append(body);
+		return sb.toString();
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/Response.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/beans/NodeAuth.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/beans/NodeAuth.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/beans/NodeAuth.java (added)
+++ incubator/libcloud/java/trunk/src/base/beans/NodeAuth.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,10 @@
+package base.beans;
+
+public class NodeAuth {
+
+	public String secret;
+	
+	public NodeAuth(String secret) {
+		this.secret = secret;
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/beans/NodeAuth.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/beans/NodeImage.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/beans/NodeImage.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/beans/NodeImage.java (added)
+++ incubator/libcloud/java/trunk/src/base/beans/NodeImage.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,31 @@
+package base.beans;
+
+import java.util.Map;
+
+import base.interfaces.INodeDriver;
+
+public class NodeImage {
+	
+	public String id;
+	
+	public String name;
+	
+	public Map<String, String> extra;
+	
+	public INodeDriver driver;
+	
+	public NodeImage(String id, String name, Map<String, String> extra, INodeDriver driver) {
+		this.id = id;
+		this.name = name;
+		this.extra = extra;
+		this.driver = driver;
+	}
+	
+	public String toString() {
+		return "<NodeImage" +
+		": id=" + id +
+		", name=" + name +
+		", driver=" + driver.getName() + 
+		" ...>";
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/beans/NodeImage.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/beans/NodeLocation.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/beans/NodeLocation.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/beans/NodeLocation.java (added)
+++ incubator/libcloud/java/trunk/src/base/beans/NodeLocation.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,30 @@
+package base.beans;
+
+import base.interfaces.INodeDriver;
+
+public class NodeLocation {
+	
+	public String id;
+	
+	public String name;
+	
+	public String country;
+	
+	public INodeDriver driver;
+	
+	public NodeLocation(String id, String name, String country, INodeDriver driver) {
+		this.id = id;
+		this.name = name;
+		this.country = country;
+		this.driver = driver;
+	}
+
+	public String toString() {
+		return "<NodeLocation" +
+			": id=" + id +
+			", name=" + name +
+			", country=" + country + 
+			", driver=" + driver.getName() + 
+			" ...>";
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/beans/NodeLocation.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/beans/NodeSize.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/beans/NodeSize.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/beans/NodeSize.java (added)
+++ incubator/libcloud/java/trunk/src/base/beans/NodeSize.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,43 @@
+package base.beans;
+
+import base.interfaces.INodeDriver;
+
+public class NodeSize {
+
+	public String id;
+	
+	public String name;
+	
+	public int ram;
+	
+	public int disk;
+	
+	public int bandwidth;
+	
+	public float price;
+	
+	public INodeDriver driver;
+	
+	public NodeSize(String id, String name, int ram, int disk, int bandwidth,
+			float price, INodeDriver driver) {
+		this.id = id;
+		this.name = name;
+		this.ram = ram;
+		this.disk = disk;
+		this.bandwidth = bandwidth;
+		this.price = price;
+		this.driver = driver;
+	}
+	
+	public String toString() {
+		return "<NodeSize" +
+			": id=" + id +
+			", name=" + name +
+			", ram=" + ram + 
+			", disk=" + disk +
+			", bandwidth=" + bandwidth + 
+			", price=" + price +
+			", driver=" + driver.getName() + 
+			" ...>";
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/beans/NodeSize.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/exceptions/InvalidCredsException.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/exceptions/InvalidCredsException.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/exceptions/InvalidCredsException.java (added)
+++ incubator/libcloud/java/trunk/src/base/exceptions/InvalidCredsException.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,14 @@
+package base.exceptions;
+
+public class InvalidCredsException extends RuntimeException {
+	
+	private static final long serialVersionUID = 1L;
+
+	public InvalidCredsException() {
+		super();
+	}
+	
+	public InvalidCredsException(String msg) {
+		super(msg);
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/base/exceptions/InvalidCredsException.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/interfaces/IConnection.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/interfaces/IConnection.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/interfaces/IConnection.java (added)
+++ incubator/libcloud/java/trunk/src/base/interfaces/IConnection.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,24 @@
+package base.interfaces;
+
+import java.util.Map;
+
+import base.Response;
+
+public interface IConnection {
+
+	public void connect();
+
+	public void connect(String host, int port);
+
+	public Response request(String method, String action,
+			Map<String, String> headers, Map<String, String> params, String data);
+
+	public Map<String, String> addDefaultHeaders(Map<String, String> headers);
+
+	public Map<String, String> addDefaultParams(Map<String, String> params);
+
+	public String encodeData(String data);
+	
+	// TODO: better way to handle URL encoding maps?
+	public String encodeDataMap(Map<String, String> dataMap);
+}

Propchange: incubator/libcloud/java/trunk/src/base/interfaces/IConnection.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/interfaces/INode.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/interfaces/INode.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/interfaces/INode.java (added)
+++ incubator/libcloud/java/trunk/src/base/interfaces/INode.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,28 @@
+package base.interfaces;
+
+import java.util.Map;
+
+import base.NodeState;
+
+public interface INode {
+
+	public boolean reboot();
+	
+	public boolean destroy();
+	
+	public String getUuid();
+	
+	public String getId();
+	
+	public String getName();
+	
+	public NodeState getState();
+	
+	public String getPublicIp();
+	
+	public String getPrivateIp();
+	
+	public INodeDriver getDriver();
+	
+	public Map<String, String> getExtra();
+}

Propchange: incubator/libcloud/java/trunk/src/base/interfaces/INode.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/interfaces/INodeDriver.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/interfaces/INodeDriver.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/interfaces/INodeDriver.java (added)
+++ incubator/libcloud/java/trunk/src/base/interfaces/INodeDriver.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,32 @@
+package base.interfaces;
+
+import java.util.List;
+import java.util.Map;
+
+import base.beans.NodeAuth;
+import base.beans.NodeImage;
+import base.beans.NodeLocation;
+import base.beans.NodeSize;
+
+public interface INodeDriver {
+	
+	public INode createNode(String name, NodeSize size,
+			NodeImage image, NodeLocation location, NodeAuth auth,
+			Map<String, String> extra);
+
+	public boolean destroyNode(INode node);
+
+	public boolean rebootNode(INode node);
+
+	public List<INode> listNodes();
+
+	public List<NodeImage> listImages();
+
+	public List<NodeSize> listSizes();
+
+	public List<NodeLocation> listLocations();
+	
+	public String getName();
+	
+	public IConnection getConnection();
+}

Propchange: incubator/libcloud/java/trunk/src/base/interfaces/INodeDriver.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/interfaces/IResponse.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/interfaces/IResponse.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/interfaces/IResponse.java (added)
+++ incubator/libcloud/java/trunk/src/base/interfaces/IResponse.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,14 @@
+package base.interfaces;
+
+import java.util.Map;
+
+public interface IResponse {
+	
+	public int getStatus();
+	
+	public String getBody();
+	
+	public String getPhrase();
+	
+	public Map<String, String> getHeaders();
+}

Propchange: incubator/libcloud/java/trunk/src/base/interfaces/IResponse.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/base/interfaces/IResponseHandler.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/base/interfaces/IResponseHandler.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/base/interfaces/IResponseHandler.java (added)
+++ incubator/libcloud/java/trunk/src/base/interfaces/IResponseHandler.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,8 @@
+package base.interfaces;
+
+public interface IResponseHandler {
+
+	public Object getParsedObject();
+	
+	public IResponse getResponse();
+}

Propchange: incubator/libcloud/java/trunk/src/base/interfaces/IResponseHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/drivers/ibm/IBMConnection.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/drivers/ibm/IBMConnection.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/drivers/ibm/IBMConnection.java (added)
+++ incubator/libcloud/java/trunk/src/drivers/ibm/IBMConnection.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,31 @@
+package drivers.ibm;
+
+import java.util.Map;
+
+import org.apache.commons.codec.binary.Base64;
+
+import base.ConnectionUserAndKey;
+import base.interfaces.INodeDriver;
+
+public class IBMConnection extends ConnectionUserAndKey {
+	
+	private static final String DEFAULT_HOST = "www-180.ibm.com";
+	private static final boolean DEFAULT_SECURE = true;
+	
+	public IBMConnection(String userId, String key, INodeDriver driver) {
+		super(userId, key, DEFAULT_SECURE, DEFAULT_HOST, driver);
+	}
+
+	public IBMConnection(String userId, String key, boolean secure,
+			String host, int port, INodeDriver driver) {
+		super(userId, key, secure, host, port, driver);
+	}
+	
+	public Map<String, String> addDefaultHeaders(Map<String, String> headers) {
+		headers.put("Accept", "text/xml");
+		String authorization = "Basic " + new String(Base64.encodeBase64((userId + ":" + key).getBytes()));
+		headers.put("Authorization", authorization);
+		headers.put("Content-Type", "text/xml");
+		return headers;
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/drivers/ibm/IBMConnection.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/drivers/ibm/IBMDriver.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/drivers/ibm/IBMDriver.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/drivers/ibm/IBMDriver.java (added)
+++ incubator/libcloud/java/trunk/src/drivers/ibm/IBMDriver.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,217 @@
+package drivers.ibm;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import base.Node;
+import base.NodeDriver;
+import base.NodeState;
+import base.beans.NodeAuth;
+import base.beans.NodeImage;
+import base.beans.NodeLocation;
+import base.beans.NodeSize;
+import base.interfaces.INode;
+import base.interfaces.IResponse;
+
+/*
+ * TODO: comment all classes
+ * TODO: overload constructor with userId, key, host, and port
+ * TODO: listImages(NodeLocation)
+ * TODO: listSizes(NodeLocation)
+ */
+public class IBMDriver extends NodeDriver {
+
+	private static final String NAME = "IBM Developer Cloud";
+
+	private static final String REST_BASE = "/cloud/enterprise/beta/api/rest/20090403/";
+
+	private static final Map<Integer, NodeState> NODE_STATE_MAP = new HashMap<Integer, NodeState>();
+
+	public IBMDriver(String userId, String key) {
+		connection = new IBMConnection(userId, key, this);
+
+		// Map IBM instance states to libcloud
+		NODE_STATE_MAP.put(0, NodeState.PENDING);
+		NODE_STATE_MAP.put(1, NodeState.PENDING);
+		NODE_STATE_MAP.put(2, NodeState.TERMINATED);
+		NODE_STATE_MAP.put(3, NodeState.TERMINATED);
+		NODE_STATE_MAP.put(4, NodeState.TERMINATED);
+		NODE_STATE_MAP.put(5, NodeState.RUNNING);
+		NODE_STATE_MAP.put(6, NodeState.UNKNOWN);
+		NODE_STATE_MAP.put(7, NodeState.PENDING);
+		NODE_STATE_MAP.put(8, NodeState.REBOOTING);
+		NODE_STATE_MAP.put(9, NodeState.PENDING);
+		NODE_STATE_MAP.put(10, NodeState.PENDING);
+		NODE_STATE_MAP.put(11, NodeState.TERMINATED);
+	}
+
+	public String getName() {
+		return NAME;
+	}
+
+	public INode createNode(String name, NodeSize size, NodeImage image,
+			NodeLocation location, NodeAuth auth, Map<String, String> extra) {
+		// Compose headers for message body
+		Map<String, String> data = new HashMap<String, String>();
+		data.put("name", name);
+		data.put("imageID", image.id);
+		data.put("instanceType", size.id);
+		if (location != null) {
+			data.put("location", location.id);
+		}
+		if (auth != null) {
+			data.put("publicKey", auth.secret);
+		}
+		if (extra != null) {
+			for (String key : extra.keySet()) {
+				data.put(key, extra.get(key));
+			}
+		}
+		
+		String encoded = connection.encodeDataMap(data);
+		Map<String, String> headers = new HashMap<String, String>();
+		headers.put("Content-Type", "application/x-www-form-urlencoded");
+		IResponse response = connection.request("POST", REST_BASE + "instances", headers, null, encoded);
+		IBMHandler handler = new IBMHandler(response);
+		return parseNodes((Document)handler.getParsedObject()).get(0);
+	}
+
+	public boolean rebootNode(INode node) {
+		Map<String, String> headers = new HashMap<String, String>();
+		headers.put("Content-Type", "application/x-www-form-urlencoded");
+		Map<String, String> data = new HashMap<String, String>();
+		data.put("state", "restart");
+		IResponse response = connection.request("PUT", REST_BASE + "instances/"
+				+ node.getId(), headers, null, connection.encodeDataMap(data));
+		new IBMHandler(response);
+		return response.getStatus() == 200;
+	}
+
+	public boolean destroyNode(INode node) {
+		IResponse response = connection.request("DELETE", REST_BASE
+				+ "instances/" + node.getId(), null, null, "");
+		new IBMHandler(response);
+		return response.getStatus() == 200;
+	}
+
+	public List<NodeImage> listImages() {
+		IResponse response = connection.request("GET", REST_BASE + "images",
+				null, null, "");
+		IBMHandler rh = new IBMHandler(response);
+		return parseImages((Document) rh.getParsedObject());
+	}
+
+	public List<NodeLocation> listLocations() {
+		IResponse response = connection.request("GET", REST_BASE + "locations",
+				null, null, "");
+		IBMHandler rh = new IBMHandler(response);
+		return parseLocations((Document) rh.getParsedObject());
+	}
+
+	public List<INode> listNodes() {
+		IResponse response = connection.request("GET", REST_BASE + "instances",
+				null, null, "");
+		IBMHandler rh = new IBMHandler(response);
+		return parseNodes((Document) rh.getParsedObject());
+	}
+
+	public List<NodeSize> listSizes() {
+		List<NodeSize> sizes = new ArrayList<NodeSize>();
+		sizes.add(new NodeSize("SMALL", "SMALL", -1, -1, -1, -1, this));
+		sizes.add(new NodeSize("MEDIUM", "MEDIUM", -1, -1, -1, -1, this));
+		sizes.add(new NodeSize("LARGE", "LARGE", -1, -1, -1, -1, this));
+		return sizes;
+	}
+
+	// ----------------------------- PRIVATE HELPERS ---------------------------
+
+	private List<NodeImage> parseImages(Document doc) {
+		List<NodeImage> images = new ArrayList<NodeImage>();
+		List<Element> elems = getFirstElementsByTagName(doc
+				.getDocumentElement(), "Image");
+		for (Element elem : elems) {
+			images.add(parseImage(elem));
+		}
+		return images;
+	}
+
+	private NodeImage parseImage(Element elem) {
+		return new NodeImage(getTextValue(elem, "ID"), getTextValue(elem,
+				"Name"), null, // TODO: include parametersUrl in extra
+				this);
+	}
+
+	private List<INode> parseNodes(Document doc) {
+		List<INode> nodes = new ArrayList<INode>();
+		List<Element> elems = getFirstElementsByTagName(doc.getDocumentElement(), "Instance");
+		for (Element elem : elems) {
+			nodes.add(parseNode(elem));
+		}
+		return nodes;
+	}
+
+	private INode parseNode(Element elem) {
+		return new Node(getTextValue(elem, "ID"),
+				getTextValue(elem, "Name"),
+				NODE_STATE_MAP.get(new Integer(getTextValue(elem, "Status"))),
+				getTextValue(elem, "IP"),
+				null,
+				null,
+				this);
+	}
+
+	private List<NodeLocation> parseLocations(Document doc) {
+		List<NodeLocation> locations = new ArrayList<NodeLocation>();
+		List<Element> elems = getFirstElementsByTagName(doc
+				.getDocumentElement(), "Location");
+		for (Element elem : elems) {
+			locations.add(parseLocation(elem));
+		}
+		return locations;
+	}
+
+	private NodeLocation parseLocation(Element elem) {
+		return new NodeLocation(getTextValue(elem, "ID"), getTextValue(elem,
+				"Name"), "US", this);
+	}
+
+	private String getTextValue(Element elem, String tagName) {
+		NodeList nl = elem.getElementsByTagName(tagName);
+		if (nl.getLength() > 0) {
+			if (nl.item(0).getFirstChild() == null) {
+				return "";
+			} else {
+				return nl.item(0).getFirstChild().getNodeValue();
+			}
+		} else {
+			return null;
+		}
+	}
+
+	private List<Element> getFirstElementsByTagName(Element elem, String tagName) {
+		List<Element> elements = new ArrayList<Element>();
+		NodeList children = elem.getChildNodes();
+		for (int i = 0; i < children.getLength(); i++) {
+			Element child = (Element) children.item(i);
+			if (child.getTagName().equals(tagName)) {
+				elements.add(child);
+			}
+		}
+		return elements;
+	}
+	//	
+	// private List<String> getTextValues(Element elem, String tagName) {
+	// List<String> values = new ArrayList<String>();
+	// NodeList nl = elem.getElementsByTagName(tagName);
+	// for (int i = 0; i < nl.getLength(); i++) {
+	// values.add(nl.item(i).getFirstChild().getNodeValue());
+	// }
+	// return values;
+	// }
+}

Propchange: incubator/libcloud/java/trunk/src/drivers/ibm/IBMDriver.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/drivers/ibm/IBMHandler.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/drivers/ibm/IBMHandler.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/drivers/ibm/IBMHandler.java (added)
+++ incubator/libcloud/java/trunk/src/drivers/ibm/IBMHandler.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,51 @@
+package drivers.ibm;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import base.DefaultHandler;
+import base.exceptions.InvalidCredsException;
+import base.interfaces.IResponse;
+
+public class IBMHandler extends DefaultHandler {
+
+	public IBMHandler(IResponse response) {
+		super(response);
+	}
+
+	protected void parseBody() {
+		object = null;
+		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+		try {
+			DocumentBuilder db = dbf.newDocumentBuilder();
+			object = db.parse(new InputSource(new StringReader(response
+					.getBody())));
+		} catch (ParserConfigurationException e) {
+			e.printStackTrace();
+		} catch (SAXException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	protected String parseError() {
+		if (response.getStatus() == 401) {
+			if (response.getBody().equals("")) {
+				throw new InvalidCredsException(response.getStatus() + ": "
+						+ response.getPhrase());
+			} else {
+				throw new InvalidCredsException(response.getBody());
+			}
+		} else {
+			return response.getBody();
+		}
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/drivers/ibm/IBMHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/drivers/ibm/Main.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/drivers/ibm/Main.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/drivers/ibm/Main.java (added)
+++ incubator/libcloud/java/trunk/src/drivers/ibm/Main.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,47 @@
+package drivers.ibm;
+
+import java.util.List;
+
+import base.Providers;
+import base.Providers.Provider;
+import base.beans.NodeSize;
+import base.interfaces.INode;
+
+
+public class Main {
+	public static void main(String[] args) {
+		Class driverClass = Providers.get_driver(Provider.IBM);
+		IBMDriver driver = (IBMDriver)Providers.constructDriver(driverClass, "woodser@us.ibm.com", "d3vpassword");
+		List<INode> nodes = driver.listNodes();
+		List<NodeSize> sizes = driver.listSizes();
+//		List<NodeImage> images = driver.listImages();
+//		List<NodeLocation> locations = driver.listLocations();
+		for (INode node : nodes) {
+			System.out.println(node.toString());
+		}
+//		for (NodeLocation location : locations) {
+//			System.out.println(location.toString());
+//		}
+//		for (NodeImage image : images) {
+//			System.out.println(image.toString());
+//		}
+		for (NodeSize size : sizes) {
+			System.out.println(size.toString());
+		}
+//		System.out.println(driver.rebootNode(nodes.get(0)));
+//		System.out.println(driver.destroyNode(nodes.get(0))); WARNING: ACTUALLY DELETES THE NODE!
+		
+		// Create a node
+		/*
+		NodeSize size = new NodeSize("LARGE", "LARGE", -1, -1, -1, -1, driver);
+		NodeImage image = new NodeImage("11", "Rational Insight", null, driver);
+		NodeLocation location = new NodeLocation("1", "POK", "US", driver);
+		NodeAuth auth = new NodeAuth("MyPublicKey");
+		Map<String, String> extra = new HashMap<String, String>();
+		extra.put("insight_admin_password", "myPassword1");
+		extra.put("db2_admin_password", "myPassword2");
+		extra.put("report_user_password", "myPassword3");
+		driver.createNode("Eric Test 5", size, image, location, auth, extra);
+		*/
+	}
+}

Propchange: incubator/libcloud/java/trunk/src/drivers/ibm/Main.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/drivers/rackspace/Main.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/drivers/rackspace/Main.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/drivers/rackspace/Main.java (added)
+++ incubator/libcloud/java/trunk/src/drivers/rackspace/Main.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,5 @@
+package drivers.rackspace;
+
+public class Main {
+
+}

Propchange: incubator/libcloud/java/trunk/src/drivers/rackspace/Main.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceConnection.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceConnection.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceConnection.java (added)
+++ incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceConnection.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,5 @@
+package drivers.rackspace;
+
+public class RackspaceConnection {
+
+}

Propchange: incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceConnection.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceDriver.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceDriver.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceDriver.java (added)
+++ incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceDriver.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,5 @@
+package drivers.rackspace;
+
+public class RackspaceDriver {
+
+}

Propchange: incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceDriver.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceHandler.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceHandler.java?rev=964295&view=auto
==============================================================================
--- incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceHandler.java (added)
+++ incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceHandler.java Thu Jul 15 03:44:23 2010
@@ -0,0 +1,5 @@
+package drivers.rackspace;
+
+public class RackspaceHandler {
+
+}

Propchange: incubator/libcloud/java/trunk/src/drivers/rackspace/RackspaceHandler.java
------------------------------------------------------------------------------
    svn:executable = *