Getting Started: The Rackspace Cloud
- Introduction
- Get a Username and API Key
- Get jclouds
- Terminology
- Your First Cloud Files App
- Your First Cloud Servers App
- Working with Cloud Block Storage
- Working with Cloud Load Balancers
- Next Steps
- Rackspace Cloud Providers
- Support and Feedback
Introduction
The Rackspace Cloud platform includes everything you need to build websites and applications that scale servers, storage, networking, APIs, and more. The Rackspace Cloud is based on OpenStack, which is a global collaboration of developers and cloud computing technologists producing the ubiquitous open source cloud computing platform for public and private clouds.
This guide assumes you're familiar with Java and its technologies. To get started you'll need access to the Rackspace cloud and jclouds.
Get a Username and API Key
- Sign up for free for the Rackspace Cloud (US).
- Login to the Cloud Control Panel (US).
- In the top right corner click on your username and then API Keys.
Likewise you can go to the Rackspace Cloud (UK) and login to the Cloud Control Panel (UK).
Get jclouds
- Ensure you are using the Java Development Kit (JDK) version 6 or later.
javac -version
- Ensure you are using Maven version 3 or later.
mvn -version
- Create a directory to try out jclouds.
mkdir jcloudscd jclouds
- Make a local copy of this pom.xml file in the jclouds directory.
- mvn dependency:copy-dependencies "-DoutputDirectory=./lib"
- You should now have a directory with the following structure:
jclouds/pom.xmllib/*.jar
Terminology
There are some differences in terminology between jclouds and Rackspace/OpenStack that should be made clear.
| jclouds | Rackspace/OpenStack | |
|---|---|---|
| Compute | Cloud Servers (Nova) | |
| Node | Server | |
| Location/Zone | Region | |
| Hardware | Flavor | |
| NodeMetadata | Server details | |
| UserMetadata | Metadata | |
| BlobStore | Cloud Files (Swift) | |
| Blob | File (Object) |
Your First Cloud Files App
Introduction
Cloud Files is an easy to use online storage for files and media which can be delivered globally over Akamai's content delivery network (CDN).
APIs
Cloud Files works with a portable layer in jclouds that is used to access features common to all cloud object storage systems. Cloud Files also works with the OpenStack layer in jclouds that is used to access features common to all OpenStack Swift object storage systems. Finally, Cloud Files works with the Rackspace layer in jclouds that is used to access features specific to the Rackspace object storage system.
- The portable API for Cloud Files is org.jclouds.blobstore.BlobStore.
- The OpenStack API for Cloud Files is org.jclouds.openstack.swift.CommonSwiftClient.
- The Rackspace API for Cloud Files is org.jclouds.cloudfiles.CloudFilesClient.
- You can find these APIs in the latest Javadoc.
The Source Code
- Create the directory hierarchy org/jclouds/examples/rackspace/cloudfiles/ in your jclouds directory.
- Create Java source files called CreateContainer.java and Constants.java in the directory above.
- You should now have a directory with the following structure:
jclouds/pom.xmllib/*.jar
org/jclouds/examples/rackspace/cloudfiles/CreateContainer.javaConstants.java
- Open CreateContainer.java for editing.
- Go to the example code CreateContainer.java, read it over, and copy the code into your file.
- Open Constants.java for editing.
- Go to the example code Constants.java, read it over, and copy the code into your file.
Compile and Run
javac -classpath ".:lib/*" org/jclouds/examples/rackspace/cloudfiles/CreateContainer.java
java -classpath ".:lib/*" org.jclouds.examples.rackspace.cloudfiles.CreateContainer myUsername myApiKey
Create Container
jclouds-example
Your First Cloud Servers App
Introduction
Cloud Servers is an easy to use service that provides on-demand servers that you can use to to build dynamic websites, deliver mobile apps, or crunch big data.
APIs
Cloud Servers works with a portable layer in jclouds that is used to access features common to all cloud compute systems. Cloud Servers also works with the OpenStack layer in jclouds that is used to access features common to all OpenStack Nova compute systems.
- The portable API for Cloud Servers is org.jclouds.compute.ComputeService.
- The OpenStack API for Cloud Servers is the org.jclouds.openstack.nova.v2_0.features.ServerApi. It's accessible via the org.jclouds.openstack.nova.v2_0.NovaApi.
- You can find these APIs in the latest Javadoc.
The Source Code
- Create the directory hierarchy org/jclouds/examples/rackspace/cloudservers/ in your jclouds directory.
- Create Java source files called CreateServer.java and Constants.java in the directory above.
- You should now have a directory with the following structure:
jclouds/pom.xmllib/*.jar
org/jclouds/examples/rackspace/cloudservers/CreateServer.javaConstants.java
- Open CreateServer.java for editing.
- Go to the example code CreateServer.java, read it over, and copy the code into your file.
- Open Constants.java for editing.
- Go to the example code Constants.java, read it over, and copy the code into your file.
Compile and Run
javac -classpath ".:lib/*" org/jclouds/examples/rackspace/cloudservers/CreateServer.java
java -classpath ".:lib/*" org.jclouds.examples.rackspace.cloudservers.CreateServer myUsername myApiKey
Images
Image{id=9eb71a23-2c7e-...}
...
Flavors
Flavor{id=2,...}
...
Create Server
.....................................................
ServerCreated{id=b037b1a1-...}
Login IP: 123.123.123.123 Username: root Password: a1b2c3d4
Working with Cloud Block Storage
Introduction
Cloud Block Storage allows you to create volumes on which to persistently store your data from your servers, even when those servers have been deleted. It delivers consistent performance for your I/O-intensive applications.
APIs
Cloud Block Storage works with the OpenStack layer in jclouds that is used to access features common to all OpenStack Cinder block storage systems.
- The OpenStack API for Cloud Block Storage is the org.jclouds.openstack.cinder.v1.CinderApi. All other APIs for working with block storage are accessible via the CinderApi.
- You can find these APIs in the latest Javadoc.
The Source Code
- Create the directory hierarchy org/jclouds/examples/rackspace/cloudblockstorage/ in your jclouds directory.
- Create Java source files called CreateVolumeAndAttach.java and Constants.java in the directory above.
- You should now have a directory with the following structure:
jclouds/pom.xmllib/*.jar
org/jclouds/examples/rackspace/cloudblockstorage/CreateVolumeAndAttach.javaConstants.java
- Open CreateVolumeAndAttach.java for editing.
- Go to the example code CreateVolumeAndAttach.java, read it over, and copy the code into your file.
- Open Constants.java for editing.
- Go to the example code Constants.java, read it over, and copy the code into your file.
Compile and Run
javac -classpath ".:lib/*" org/jclouds/examples/rackspace/cloudblockstorage/CreateVolumeAndAttach.java
java -classpath ".:lib/*" org.jclouds.examples.rackspace.cloudblockstorage.CreateVolumeAndAttach myUsername myApiKey
Create Server
{id=DFW/8814...}
Login: ssh root@123.123.123.123
Password: a1b2c3d4
Create Volume
Volume{id=53d9...}
Create Volume Attachment
VolumeAttachment{id=53d9...}
Mount Volume and Create Filesystem
Exit Status: 0
List Volumes
...
Working with Cloud Load Balancers
Introduction
Cloud Load Balancers distributes workloads across two or more servers, network links, and other resources to maximize throughput, minimize response time, and avoid overload. Rackspace Cloud Load Balancers allow you to quickly load balance multiple Cloud Servers for optimal resource utilization.
APIs
Cloud Load Balancers works with the Rackspace layer in jclouds that is used to access features specific to the Rackspace load balancer system.
- The Rackspace API for Cloud Load Balancers is org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi. All other APIs for working with load balancers are accessible via the CloudLoadBalancersApi.
- You can find these APIs in the latest Javadoc.
The Source Code
- Create the directory hierarchy org/jclouds/examples/rackspace/cloudloadbalancers/ in your jclouds directory.
- Create Java source files called CreateLoadBalancerWithExistingServers.java and Constants.java in the directory above.
- You should now have a directory with the following structure:
jclouds/pom.xmllib/*.jar
org/jclouds/examples/rackspace/cloudloadbalancers/CreateLoadBalancerWithExistingServers.javaConstants.java
- Open CreateLoadBalancerWithExistingServers.java for editing.
- Go to the example code CreateLoadBalancerWithExistingServers.java, read it over, and copy the code into your file.
- Open Constants.java for editing.
- Go to the example code Constants.java, read it over, and copy the code into your file.
Compile and Run
javac -classpath ".:lib/*" org/jclouds/examples/rackspace/cloudloadbalancers/CreateLoadBalancerWithExistingServers.java
java -classpath ".:lib/*" org.jclouds.examples.rackspace.cloudloadbalancers.CreateLoadBalancerWithExistingServers myUsername myApiKey
Create Cloud Load Balancer
LoadBalancer{id=85901...}
Go to http://166.78.34.87
jclouds in a Managed Container
Setting up jclouds to work in a managed container is easy. You simply need to ensure that jclouds won't spawn any of its own threads. You can do this by using the ExecutorServiceModule when building your Context.
An example code snippet.
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.concurrent.config.ExecutorServiceModule;
public class MyJEEClass {
...
private void init() {
Iterable<Module> modules = ImmutableSet.<Module> of(
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()));
ComputeServiceContext context = ContextBuilder.newBuilder("rackspace-cloudservers-us")
.credentials("myUsername", "myApiKey")
.modules(modules)
.buildView(ComputeServiceContext.class);
ComputeService compute = context.getComputeService();
}
...
}
Next Steps
- Try the rest of the examples and the Logging example.
- When you're ready to publish some web pages on the internet, try the CloudFilesPublish.java, CloudServersPublish.java, or CreateLoadBalancerWithNewServers.java examples.
- Change the examples to do different things that you want to do.
- After running some examples, compare the output with what you see in the Cloud Control Panel.
- Browse the documentation and have a look at the latest Javadoc.
- Return to the Installation Guide and have a look at the different ways to integrate jclouds with your project.
- Join the jclouds mailing list or maybe even the jclouds developer mailing list.
Rackspace Cloud Providers
This is a list of providers that work with the Rackspace Cloud that you can use to build your Context.
"cloudfiles-us""cloudfiles-uk""rackspace-cloudservers-us""rackspace-cloudservers-uk""rackspace-cloudblockstorage-us""rackspace-cloudblockstorage-uk""rackspace-cloudloadbalancers-us""rackspace-cloudloadbalancers-uk"
Support and Feedback
Your feedback is appreciated! If you have specific issues with Rackspace support in jclouds, we'd prefer that you file an issue via JIRA.
For general feedback and support requests, send an email to: