When Written: Sept 2012
To many the Cloud is somewhere to store data so that you can share information between users and devices. However for the developers amongst us the Cloud can represent an opportunity to provide new or better solutions to our customers. Whilst for some web based applications a simple Cloud based web hosting solution will be sufficient, for many developers this will not be enough. Should you want to do something a little more complex the ability to be able to write code out on the Cloud and then to access it from there could be the answer to many a developer’s prayers. As you can imagine, with the growth of the Cloud and its products there are a multitude of options available. In this brief look we are going to examine the offerings from OpenShift by Red Hat (https://openshift.redhat.com/app/ ) and Cloud Foundry (http://www.cloudfoundry.com/ ).
With both these offerings you can write your code in a variety of languages and have it run out on the Cloud. This code is usually your own or it can be an open source package like a CMS for example. Developing on the Cloud takes a little getting used to as you don’t normally have a local copy of your application and the environment that it runs under on your development box. This means that you really need to set up a testing area in the Cloud for your code as well as a ‘live’ area that will become the public area for your final version. A variation on this technique is offered by Cloud Foundry where if you prefer you can run a virtual machine locally using VMware and develop on that before deploying your code live.
When developing for the Cloud you always have to keep in mind that such things as local disk storage does not persist if the application is restarted or upgraded. This is obviously not an issue with temporary files that are created as your application runs but should you need the information in these files to survive a restart then you need to store the information in one of the Cloud Data stores that are available, this normally being a database like MySql or MongoDB. You also need to consider the access that is available to users of your application. Because of security, the ports available publically are limited and so, whilst your app itself can use a variety of ports to communicate within the Cloud environment, only one or two ports are available to any external application be it a browser or an App used to access your code.
To start to use either of these services you first need to create an account after which you can set up one or more application areas. Into these areas you put and test your code. The only item that we had a bit of a struggle with was the registering of correct Public and private SSH keys because without these you cannot upload your code. But once this was done developing on either of these services was as easy as it ever is with code. The whole process of writing an application to work on the Cloud rather than a physical box takes a little getting used to. The virtual nature of the environment does mean that you may have to think your way round the way your code works and accesses data and stores variables, but many of these problems are similar to the way any web application works with sessions that expire and variables that may expire with them. The techniques needed to work around these problems are well known and both the systems that we have looked at have lots of on-line documentation to help you avoid the known issues with coding in these environments.
The difference between them? Assuming that they both support your preferred coding language then there is not a lot of difference. OpenShift has a great range of languages along with some ready rolled Open Source products than can be installed with a simple click. To get started you need to create an account and then choose a public url format for your application. This will be in the format http://xxxx-cloudpro.rhcloud.com. However,if you are not using one of their ‘instant applications’ like Drupal then you will be using a ‘web cartridge’ which uses the popular Open Source Git version control system to manage your code. The idea is to push your changed code to the Git repository and then the system will automatically deploy your code and, if necessary, restart your application. Before you can do this however you will need to create and register a public / private key for security purposes to prevent unauthorised users uploading code. If you need to add extra capabilities to your application you can add further ‘web cartridges’ like databases or cron services. To manage most of the capabilities of OpenShift it is suggested that you use a command line tool provided called RHC, but if you want something a bit more user-friendly then there is a plug-in to the JBoss Developer Studio IDE which gives you a full development environment with code colouring.
With Cloud Foundry you can either use VMC to deploy your code to the Cloud service but this is just a command line tool, or there is a plug-in to STS or Eclipse if you want to use a graphical IDE. Running the supplied virtual machine helps in the testing process although again configuring the security settings was little confusing; however, it is a once only process and the supplied on-line documentation certainly clarified the process. The various different steps involved depending on whether your application requires none, single or multiple services are also well documented on the web site (http://docs.cloudfoundry.com/tools/deploying-apps.html ). Apart from the issues we mentioned about storage of data, writing for the Cloud is not that much more different to normal web based development, it is the initial setting up of the application areas and the security that can take a little work, but that is often the case with conventional web based code. Once your application is deployed on the Cloud, you can sit back and not worry about such dull things as hard discs failing or server availability, that has just become someone else’s problem!
Article by: Mark Newton
Published in: Mark Newton