Thursday, May 26, 2011

CloudFoundry - Simplicity Matters

'Simplicity Matters' - is the mantra of SpringSource.

Its just amazing to witness how fast SpringSource simplifying the access to huge number of heterogeneous service providers based on the ideas of AOP and DI.

Spring Roo revolutionized the concept of 'Rapid Application Development' by on-demand resource allocation and service provisioning through load-time-weaving of aspects !
Couple of lines of commands and the complete gwt-spring-mvc application launched into Google App Engine !
At the same time, MongoDB came up with a 'ridiculously simple' json-based api to provide super-fast asynchronous highly-scalable, available, partitioned data-storage with simple ways to crud, map-reduce, search, index ! It challenged the 'conventional wisdom' of building 'ultra-pathetic', 'super-complex' enterprise OLTP and BI solutions ! Redis garnered much excitement by providing a brilliant 'data-structure key-value storage' !

Its no wonder that Spring quickly provided a wrapper to access MongoDB, Redis, Riak, Node.js. 

'Spring Data promotes the classic Spring values, enhancing developer productivity by removing the API noise, boiler-plate code and resource management and offering a consistent programming model.'
Birds of same feather flock together :-)

Soon.. SpringSource reached the point of culmination by offering ... CloudFoundry ! 
Its motto 'Every Programmer is a Hero' !
Just by hiding gory details of IaaS, PaaS (which hitherto seemed like sole properties of large enterprise companies) ...

It provides the much-awaited magic-touch to launch an user application directly onto cloud, making it always available, fail-safe, scalable, manageable
User can simply specify/change/manage what sorts of service it requires (mongodb, redis, grails, node.js etc..) and specify the target (amazon cloud, vmware, cloud foundry , azure, etc..) .. all dynamically !

Well ! the only change you need to make is -(1) inside spring-beans xml, specify a with the name of dataSource that (2) you need to add as a service to your deployed app - on the fly (through STS / CLI) ! Thats it ! WoW !

When Spring Integration is supported in Cloud Foundry, its going to join another long-time friend of developers - Mule ... which has already provided industry's first iPaas (Integration Platform as Service) !

Enough theory ! Its time to get our hands dirty !

Build Cloud-ready App using Ruby :
The CLI Tool - VMC (vmware cloud-controller) can be installed by ruby gem.
VMC simply make various rest requests (push / update / target / start / stop ..). Accordingly cloud-controller delegates the requests to droplet execution engine which routes the requests to service providers (allocated by cloud-controllers).

Here goes the simple steps to push a ruby 'Say hello' app to Cloud !

require 'sinatra' 
get '/' do  
    "Welcome !  You are now in Cloud Foundry! "

Launch a Spring-MySql App into Cloud :

Nothing gets more exciting to be able to deploy our very own sample app on cloud !

1. This sample code 'To-Do List Manager' just works and need no tweaking !
** Login Credentials specified in security-context.xml
2. Just need to remember that we should create a 'tododb' service and link it to the application !
Upon starting the app if it does not work on first chance, we just need to restart it once or twice !
3. Inspect logs
# look at the main logs that contain crash information
vmc crashlogs my-app
# to inspect other logs (migration.log, staging.log, etc.)
vmc files my-app logs/migration.log


Launch a Spring-MongoDB App on the Cloud :
1. Download hello-spring-mongodb from cloudfoundry samples.
2. Import the project in STS.
3. Rename the application to some unique name like -mongoapp
4. Remember to add the mongodb namespace - in root-context.xml
xmlns:mongo="" and specify the schema location

5. Now few Command Line tasks..
6. Package the app : mvn package
7. Test that vmc target is
8. Next attach a mongoDB service and start the service as shown below...

9. The service name should match with the one specified in 'mongoTemplate' e.g. 'mongodb-hello-mongo'

10. Finally we should expect the output as specified in -
A ready-to-go powerful web-flow sample :
See Live :

We can easily tweak any of the above apps in STS to make it a real-life robust app and take full advantage of free cloud !

For more complicated examples involving Social Search, Events and Caching - we can consult the following articles :  this is a SUPER SHOT ...  .....
and another ACTION-PACKED sample ...

A very complex streaming-events sample where external source sends events to redis store. Events are sent to browser using ajax-long-polling (instant update) and also pushed into Mongo for future lookup and  analysis (BI) . Cloudfoundry makes it look so simple and easy to learn the concepts !

Here I show the steps ...  (assumption : ticker-analysis mongo service and ticker-stream redis service are already created) :

See it live :
More food for thoughts :

References :  
Comprehensive List :
Command Line Reference :

Architecture :

Ruby on CloudFoundry :

MongoDB on CLoudFoundry :

Redis on CloudFoundry in Ubuntu :

No comments: