RSS

Monthly Archives: August 2012

Logging in jclouds

TL;DR For basic header and wire logging in jclouds:

  1. Download logback
  2. Put the JARs on your classpath
  3. Put this logback.xml on your classpath
  4. Use the SLF4JLoggingModule()
  5. Run

I’m still learning jclouds and one thing that helps me out a lot is if I can get some insight into what’s going on under the hood. Specifically, since what we’re really doing is talking to an HTTP API, I like to be able to see what’s going over the wire. Fortunately jclouds allows for some pretty fine grained logging out-of-the-box and it’s relatively easy to configure too…once you know where everything goes. ;)

jclouds itself uses SLF4J Logging in its examples so let’s try that. I’m building off of my previous post Getting started with jclouds so the directory structure is the same as that. Here’s the Java app I’m using to try this out. You can see the use of SLF4J Logging from line 43 where I add the SLF4JLoggingModule to a list of modules to be injected into the ComputeServiceContext.

Now we compile and run it.

Clearly I’m missing something. Googling the error quickly reveals that “Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.”

I’ve noticed that the jclouds source code contains logback.xml a bunch of times (for example this one) so I’ll use logback too. From the logback download page I grab the latest tar.gz. Once unzipped I copy the logback-core-x.x.x.jar and the logback-classic-x.x.x.jar into my lib directory. I also realize that I’ll need to configure the logback for myself as well. Working from the example I trim it down to the absolute minimum of what I need.

Then I place the logback.xml file in my top level directory and give it another go.

Success! Let’s see what we’ve got.

Lines starting with “>>” are requests.

Lines starting with “<<” are responses.

The JSON at the beginning of a request or the end of a response is the body of the request/response.

Here’s basically what jclouds does when listing servers (aka “Nodes” in jclouds terminology).

  1. Authenticate to get a token
  2. List all servers in detail in the “ORD” zone
  3. List all servers in detail in the “DFW” zone
  4. List all images in detail in the “ORD” zone
  5. List all images in detail in the “DFW” zone
  6. List all flavors in detail in the “ORD” zone
  7. List all flavors in detail in the “DFW” zone
  8. Mash all of the relevant details together into ComputeMetadata objects and return the results

That’s a lot of requests just to list servers. I think I understand the tradeoff from jclouds perspective though. Either you can return a really useful list of servers with all the possible info you might need or you can force the user to fetch that detail as they need it. From a usability perspective it’s better just to grab it all at once.

One thing I see missing from the request headers is the User-Agent header. Unfortunately it doesn’t get logged as this header is added to the request in JavaUrlHttpCommandExecutorService.java after the headers have been logged. Oh well, we can see everything else we need to.

This post was written on Mac OS X 10.8, Java 1.6.0, jclouds 1.5.0-beta.10. If you’re on a different OS and run into problems, please feel free to comment.

 
Leave a comment

Posted by on August 18, 2012 in java, jclouds, openstack

 

How I get a Token from the Rackspace Open Cloud from the Command Line

On Mac OS X

 
Leave a comment

Posted by on August 17, 2012 in curl, openstack, python, rackspace

 

Getting started with jclouds

cumulusklein

Update: Using jclouds 1.5.1

I’m just starting to get familiar with the open source jclouds cross-cloud toolkit. Whenever I get started with something new like this I like to start out with the most simple application possible that still does something sort of useful. And when starting out, I prefer to work from the command line so I can get a feel for how something is really put together. After that, when I move to using a build tool like Maven or Ant or putting everything into Eclipse or another IDE, I have a better understanding of its dependecies and config.

With that in mind I headed over to the jclouds installation page to download the JARs for it. Okay…what is lein???

Looks lein is part of leiningen. One of the tools that jclouds can use to manage dependencies. Downloading the lein script is no problem but I also need the project.clj file. No problem…but what version to put in the dependencies list?

After sifting through the jclouds group and jclouds-dev groups I find a post that points to beta.10 being the latest and greatest. I find a blog that points to 1.5.1 being the latest and greatest. I’ll try putting that in the project.clj file and give it a shot.

That’s a lot of JARs.

Now all I want to do is list all of my servers on the Rackspace open cloud. After some trial and error I came up with the following app.

Follow the instructions below to compile and run the app. Thankfully Java 1.6 allows for wildcard expansion on the command line, otherwise it would be a serious pain including all of those JARs.

There you have it. If anyone is more familiar with lein and/or leiningen and can show me how to limit it to downloading just the JARs I need, let me know in the comments.

This post was written on Mac OS X 10.8, Java 1.6.0, jclouds 1.5.1 1.5.0-beta.10. If you’re on a different OS and run into problems, please feel free to comment.

 
5 Comments

Posted by on August 15, 2012 in jclouds, openstack, rackspace

 
 
Follow

Get every new post delivered to your Inbox.