It’s cloudy, today. But I’m not speaking about the weather in northern hemisphere autumn. Cloud Computing, two words that cannot be explained with just a sentence, is now a reality, born to change our (digital) lives.
Cloud Computing may mean different things to different people. For some, it would be having their personal documents, photos and music synchronized “in the cloud” and accessible through their PC or mobile device. For others, it would be being able to run their favorite games and to do their favorite stuff anywhere, anytime. It may be a cost-effective, agile hosting solution, an elastic production environment for databases and application servers, and many, many other things. Google Docs, Picasa, iCloud, Facebook, Twitter, Foursquare, Amazon EC2…
In this article, though, we will be discussing about Cloud Computing as a platform where developers can deploy their highly scalable, highly available solutions. We call this Platform-as-a-Service, or PaaS for short. PaaS also means a lot of things but for us is forgetting about dealing with the OS, the application server, the disc or the memory in the server. You just have your “application space”, where you can upload your solutions, execute them, monitor how they behave and control the amount of resources available to them.
You don’t know where your application physically is, the type of host server, operating system configuration or even how the application server is configured at all. You may certainly know about some or all of this, but it is really not needed to achieve your targets: develop your idea and make it available to your clients (no matter how much or where they are) in a hassle.
VMware Cloud Foundry is one of such platforms.
2 VMware Cloud Foundry
Cloud Foundry, www.cloudfoundry.com, is an open platform sponsored by VMware, born to support multiple frameworks, application servers and even multiple cloud providers. You may think on it as a core product that may be used as a foundation for more advanced cloud services.
Cloud Foundry is open source. This means that you can get and contribute to the platform, build it and run it in your own host. As an open source project it lives at www.cloudfoundry.org.
From Cloud Foundry site you may download a virtual machine with the live platform (the Micro Cloud Foundry) for your own use or request an account in the public, Internet-wide Cloud Foundry platform. Either one or the other, you will get the ability to run Java with Spring, Ruby on Rails and Sinatra, Groovy, Grails or Scala applications and leverage MySQL, Redis or MongoDB data services.
For the rest of this article we will show how to start working with Cloud Foundry, prepare an existing Java with Spring application and deploy it to the cloud. We will be using Eclipse IDE Java EE bundle with Spring IDE installed on it and the public Cloud Foundry instance, so really no special setup is needed to start working on it.
3 Get Ready! Eclipse the Cloud!
The first step is to request an account in Cloud Foundry site. Currently Cloud Foundry is in beta status and in theory access is granted as soon as VMware grows the existing public premises, thus the ‘request an invite’ label. In practice, access is granted quickly and you will receive an initial password by mail.
3.1 Changing the Initial Password with Cloud Foundry Ruby gems
My recommendation is to change that password. Cloud Foundry can be controlled through Ruby gems or through Eclipse plug-ins. Although the Eclipse plug-ins are the easiest way to work on the code, deploy and test applications, some tasks needs the Ruby scripts, so let’s start by installing them.
As I use Windows, I downloaded the Zipped distribution from http://www.rubyinstaller.org/ and place it in a folder that I will refer as %RUBY_HOME%. From a command prompt, move to %RUBY_HOME%/bin directory (yes, it’s Windows, but you can use forward slashes as well) and issue the following commands:
Needed if you are behind a proxy, use the right one for your network or skip this command
>gem install vmc
Install the VMware Cloud Foundry gem
>vmc target api.cloudfoundry.com
This is the public Cloud Foundry instance
Enter the credentials received by mail
Enter the new password twice and it’s done!
3.2 Install the Cloud Foundry support into Eclipse IDE
Next step is to install the Cloud Foundry plug-ins to control our application space from Eclipse IDE. To do that, the easiest way is, inside the IDE, go to Eclipse Marketplace (Help -> Eclipse Marketplace menu), search for “Cloud Foundry” and install the feature appropriate for the Eclipse version (Helios or Indigo are supported):
Once installed, create a new server inside Eclipse. You will now have a new server type available:
Enter your credentials (don’t forget the new password) and keep selected the public Cloud Foundry instance:
You can at this moment select the applications to be deployed into your application space, but for now we will not add anything there. Click the Finish button to save the server and return to the workbench.
4 Deployment to the Cloud
Now that our environment is ready to support Cloud Foundry, let’s discuss about what changes need to be done on an existing Java with Spring application to be deployed there.
The reference application is a very simple one: web interface using JSP and JSTL, plus Spring MVC and Hibernate. It is currently configured to use an embedded HSQLDB database for data persistent storage.
4.1 Adding Support for MySQL
The first adaptation that we are going to do is to add support for MySQL to our application. Open the server configuration page in Eclipse (double-click on server name, this is the server created before in 3.2) and move to the Applications tab:
To add the application, click the button on the Application header, select the application from the available list and click Finish. In the next dialog, you will need to assign a name to the application. This name should not be in use in the public instance. You may as well select the memory assigned to the application. In our case the default 512 MB are Ok:
Now we have the application ready to be deployed, but still not services are associated to it:
Now click the button on the Services header. Give a name to the service and select “MySQL database service” in the drop-down list:
Finally, drag the service from the Services header to the Application Services header to bind it to the application:
4.2 Updating Spring configuration
Our next step is to update the Spring configuration thus the application can make use of the MySQL database. This is a very simple step, as actually the platform is able to inject the data source at runtime. To do that, replace the data source bean definition for the following:
And add this schema to the XML:
xmlns:cloud="http://schema.cloudfoundry.org/spring" xsi:schemaLocation="…<your existing schemas>…http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.6.xsd”
4.3 Running the Application
Surprisingly, that’s all. We are ready to deploy the application into Cloud Foundry. Just run the application as you would do with any regular server and after a few seconds you will see your application living in the cloud!
4.4 Basic Monitoring
The deployed application can be monitored, at least up to some extent, from the server page in Eclipse. The page will get updated with some basic metrics as instances in use, CPU usage, memory usage, disk usage and live time:
It is very easy to start working with Cloud Foundry platform. Your existing code would run there with little or no changes at all. Configuration is also very straightforward.
Although in their current beta status, Cloud Foundry is a very interesting platform, powerful and flexible. It is difficult to say how much time will be needed until it is ready for enterprise-wide deployments with thousands of users and wide geographical dispersion, but surely we will see commercial offerings based on the platform in the following months.
Jump into the cloud! Are you ready?