Tag Archives: featured

Cloud Computing is not…?

Cloud computing is not deploying a new database server in moments.

Cloud computing is about delivering a fast, reliable, consistent database service to your applications, wherever and whenever the need occurs, without the application owner having to

If you find someone trying to sell you on the first of these situations, tell them thanks but while self-service provisioning, virtualisation and high levels of automation are all great, they’re steps along the journey to utility computing, not where the journey ends.

Using CloudFoundry with Node.JS and MongoDB

This isn’t so much a question, just a bit of extra documentation for people. There’s not a lot of clear examples on how to make a simple connection from CloudFoundry to Mongo DB when you’re using NodeJS, so I thought I’d stick up this example using the simple to use MongoDB mongoskin wrapper. The MongoDB native driver for Node is a bit awkward when you’re using authentication, so I skipped to the mongoskin layer, which is almost identical.

In your application directory, you need to a file called app.js containing the following code:

var mongodb = require(‘mongoskin’);
var env = JSON.parse(process.env.VCAP_SERVICES);
var mongo = env[‘mongodb-1.8’][0][‘credentials’];
var mongourl = “mongo://” + mongo.username + “:” + mongo.password + “@” + mongo.hostname + “:” + mongo.port + “/” + mongo.db + “?auto_reconnect=true”;
console.log(mongourl);
var db = new mongodb.db( mongourl ); //This is the connection

var http = require(‘http’)
port = Number(process.env.VCAP_APP_PORT || 3000),
host = process.env.VCAP_APP_HOST || ‘localhost’;

http.createServer(function (req, res) {
res.writeHead(200, {‘Content-Type’: ‘text/plain’});
var currentdate = new Date();

db.test.insert({ daterecord:  currentdate }, {}); //This is the insert

res.end(‘Welcome to Cloud Foundry!\n’ +
host + ‘:’ + port + ‘\n’ +
require(‘util’).inspect(process.env, false, null) + ‘\n’ + fullresult + ‘\n’);
}).listen(port, host);
console.log(‘Server running at http://’ + host + ‘:’ + port + ‘/’);
You also need a subdirectory called node_modules containing the mongoskin module. Using the latest version (1.0.3 of npm) to do this, run:
mkdir node_modules
npm install mongoskin
then run
vmc push appname
When asked if you want to bind a service, say Yes, then pick MongoDB.
The username, password, etc, are picked up automatically in the app.js file.
All the script actually does is insert a new record each time you visit the page, containing the current date, then dumps out all the environment variables to screen, so you can see where the database details are gathered from.
Hope this helps some people, if you have any problems with the code please leave me a comment on here!

Try CloudFoundry on an AWS Micro instance

Update: Unfortunately the snapshot behind this AMI was affected by the AWS data deletion bug recently, so is no longer available. VMware haven’t yet released their own official AMI, but Rightscale’s build is excellent.

There’s lots of excitement and interest around VMware’s new open source platform as a service (PaaS) offering, but at the moment the only way to try it is either to sign up to the cloudfoundry.com service and wait for an invite, or use an image the RightScale have developed for AWS.

However, there’s no real reason the image had to be used via RightScale, so I’ve created an AWS Micro image based on the regular AWS Ubuntu 10.04 image, and following the instructions from github.

It took around 3 hours to do the full build, all the compiles, etc, so I figured it was worth making the AMI image available to everyone, so other people don’t have to do the same thing. I’ve added a 512MB swap file, as the management tools need more memory than a normal Micro image can cope with, but other than that it’s pretty much the stock image.

You can launch the public AMI instance now, from the “eu-west-1” region with the public AMI ID “ami-17dee963”. You can’t launch it from the other regions, sorry. It’ll launch as a Micro image, so it could even be free if it’s your first AWS instance.

The various build tests all pass, but sometimes it is a little slow to run (due to the lack of memory).

Login as “ubuntu”, then run:

cd ~/cloudfoundry/vcap
bin/vcap start
bin/vcap tail

And you should see everything working. If you need to do any debugging, the place to start is the github CloudFoundry VCAP section.

This image is provided as a test version, please don’t rely on it for anything, and I’ll remove the AMI image when the VMware guys launch their own CloudFoundry “Micro” package in a few weeks.

Update: Unfortunately the snapshot behind this AMI was affected by the AWS data deletion bug recently, so is no longer available. VMware haven’t yet released their own official AMI, but Rightscale’s build is excellent.