A view from the clouds: Cloud computing for developers

I'll admit I may be a bit biased, but I am a huge fan of WebSphere sMash. WebSphere sMash is a lightweight application runtime for Web 2.0 style applications, and it provides unprecedented ease of use capabilities. In particular, I think the Zero Resource Model (ZRM) framework in WebSphere sMash offers an extremely easy mechanism for defining a set of data, or resources, and then providing HTTP REST access to those resources. If you aren't familiar with WebSphere sMash or the ZRM, I suggest you visit http://www.projectzero.org. The site offers both documentation and illustrative samples that help every one from beginning to advanced users. In addition, you can download the free developer's editionversion of the WebSphere sMash platform.

So, why am I talking about a web application platform on a cloud computing blog? Well, recently I decided to put the ZRM to work with an element of the cloud. As I said above, the ZRM is designed to allow users to define and access data. Part of accessing that data is an API that supports interacting with data supported in relational stores like DB2, Derby, MySQL, and more. This got me to thinking though about what it would take to devise an API similar to the ZRM's that interacted with Amazon's SimpleDB as a data store.

To that end, I wrote what I think is a pretty easy to use helper class that provides APIs that can be used by WebSphere sMash resource handlers (this is the code on the back-end of the HTTP REST calls) to interact with data in a SimpleDB store. WebSphere sMash users can define their resources just as they would when utilizing the ZRM, but instead of using the ZRM framework to access the data, they can use this API to interact with the data in a SimpleDB store. The API provides a simple delegation method in order to perform CRUD operations on the different resources that have been defined by the user, and it also provides a query API to perform more complex data interactions.

Just to give an idea as to how the API works, suppose a WebSphere sMash user defined a car resource. Using the ZRM, they would also define a resource handler called car implemented in either PHP or Groovy. Inside this resource handler there are methods that the WebSphere sMash runtime will automatically map to HTTP REST requests. For instance, a GET request with the resources/car URL would map to the onList() method in the car resource handler. If a user wanted to use the API for SimpleDB, instead of using the ZRM API, the onList() method would look like the following:

onList() { SDBMapper.delegate("car") render() }

That's all it would take to retrieve and display all the car resources from the SimpleDB store. The same delegate call could also be used to retrieve, create, update, or delete a specific car resource. The SDBMapper is the helper class with the APIs that do all the work to integrate the resource handler with SimpleDB. The SDBMapper class uses an open source Java library called typica. The typica library consists of several different JAR files, and they can be found here http://code.google.com/p/typica/downloads/list. The SDBMapper class only utilizes the sdbShell1.1.jar.

The SDBMapper class also provides users with a query API that provides the ability to perform more detailed queries on the SimpleDB store. Suppose a user wanted to query the SimpleDB store for a list of all cars made by Ford:

On top of the ability to do simple CRUD type operations and more complex queries, the SDBMapper API also provides both a replicate() and restore() API. This comes in handy if the ZRM is being used to handle the data, but a user wanted to back the data up to a SimpleDB store. If that is the case, users can simply issue the SDBMapper.replicate(null) call and all the resources defined via the ZRM will automatically be backed up to a SimpleDB store (optionally, a list of resource names can be provided to the call to back up a subset of all the resources defined via the ZRM). When a user wants to recover the data, they can call SDBMapper.recover() and a list of all the backed up data will be returned.

Having given what I hope is a good background on the SDBMapper API, I would invite you to have a look at the code by going to our WIKI and downloading the sMashSDBSamples.zip in the Samples & Tutorials section. I have two WebSphere sMash samples that show how to use both the data handling and data backup facets of this API. In addition, the SDBMapper.groovy file and sdbShell1.1.jar can be used inside any WebSphere sMash application. Feel free to make any changes to the SDBMapper API that are necessary, but I hope it provides a good start. Remember, this sample is provided "as-is", so use it as you see fit. If you have any questions about the sample, feel free to send me an email at wscloud@us.ibm.com.