Example code that uses jclouds to perform common tasks on the Rackspace Cloud. The class names are self explanatory and the code is well commented for you to follow along.
- Username and API key for the Rackspace Cloud - See the Getting Started guide.
- Java Development Kit (JDK) version 6 or later - Download.
- Apache Maven - Maven in 5 Minutes.
- Git - Download.
To setup an environment to compile and run the examples use these commands:
$ git clone https://github.com/jclouds/jclouds-examples.git $ cd jclouds-examples/rackspace/ $ pwd /Users/username/jclouds-examples/rackspace $ ls pom.xml README.md images/ src/
Start with the rackspace package. There you will find general purpose examples of things that are useful across all services.
- Logging.java - How to enable and configure logging.
- Authentication.java - How you can use your credentials to authenticate with the Rackspace Cloud.
The cloudfiles package demonstrates how to accomplish common tasks for putting files in and getting files from the cloud.
- CloudFilesPublish.java - An end to end example of publishing a file on the internet with Cloud Files.
- Other examples of creating, updating, listing, and deleting containers/objects.
The cloudservers package demonstrates how to accomplish common tasks for working with servers in the cloud.
- CloudServersPublish.java - An end to end example of publishing a web page on the internet with Cloud Servers.
- Other examples of creating, manipulating, listing, and deleting servers.
The cloudblockstorage package demonstrates how to accomplish common tasks for working with block storage (aka volumes) in the cloud.
- CreateVolumeAndAttach.java - An end to end example of creating a volume, attaching it to a server, putting a filesystem on it, and mounting it for use to store persistent data.
- Other examples of creating, manipulating, listing, and deleting volumes and snapshots.
The cloudloadbalancers package demonstrates how to accomplish common tasks for working with load balancers in the cloud.
- CreateLoadBalancerWithExistingServers.java - An end to end example of creating a load balancer and adding existing servers (nodes) to it.
- CreateLoadBalancerWithNewServers.java - An end to end example of creating a load balancer and adding new servers (nodes) to it.
- Other examples of creating, manipulating, listing, and deleting load balancers and nodes.
The clouddns package demonstrates how to accomplish common tasks for working with DNS in the cloud.
- CreateDomains.java - An example of creating domains with subdomains and records.
- CreateRecords.java - An example of creating records and adding them to a domain.
- CRUDReverseDNSRecords.java - An example of creating a Cloud Server and a reverse DNS record (PTR) to go along with it.
- Other examples of creating, manipulating, listing, and deleting domains and records.
The clouddatabases package demonstrates how to accomplish common tasks for working with databases in the cloud.
- CreateInstance.java - An example of creating a database instance.
- CreateDatabase.java - An example of creating a database on the database instance.
- CreateUser.java - An example of creating a database user.
- TestDatabase.java - An example of connecting to the database from the public Internet and making a simple request.
- Other examples include deleting instances, databases, and users, and granting root access.
The cloudqueues package demonstrates how to accomplish common tasks for working with queues in the cloud.
- ProducerConsumer.java - An example of the Producer/Consumer pattern.
- PublishSubscribe.java - An example of the Publish/Subscribe pattern.
- StreamMessages.java - An example of streaming messages off of a queue.
To download all dependencies, run:
$ mvn dependency:copy-dependencies "-DoutputDirectory=./lib"
If you also want to download the source jars, run:
$ mvn dependency:copy-dependencies "-DoutputDirectory=./lib" "-Dclassifier=sources"
To run individual examples from the command line use these commands:
Note: If you're on Windows, the only change you need to make is to use a ';' instead of a ':' in the paths.
$ javac -classpath "lib/*:src/main/java/:src/main/resources/" src/main/java/org/jclouds/examples/rackspace/*.java
Every example class has a main method that takes your username as the first argument and your API key as the second argument. The one exception to this is the Authentication example that can take an optional third argument if you want to use your password for authentication.
Try out an example.
$ java -classpath "lib/*:src/main/java/:src/main/resources/" org.jclouds.examples.rackspace.cloudservers.CreateServer myUsername myApiKey
Watch the terminal for output!
To run these examples from Eclipse follow these instructions.
Create a new Java Project and choose jclouds-examples/rackspace/ as the Location.
This should create a project with the following Java Settings. Eclipse will have detected the lib directory and filled in all of the Libraries for you.
Try out an example.
- Double click CreateContainer example file to open it.
- Choose the Run > Run Configurations... menu item.
- Press the plus icon to create a new launch configuration.
- This will automatically create a launch configuration for CreateContainer.
- Switch to the Arguments tab and enter your username and API key in the Program arguments field.
Click Run and watch the Console for the output!
Here are some suggestions on how to continue working with jclouds:
- 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 JavaDocs.
- Return to the Installation Guide and have a look at the different ways to integrate jclouds with your project.
- Join the user mailing list or developer mailing list.
Welcome to the jclouds community!
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: