OSGi in the Cloud
Running an OSGi container in a public cloud service, such as GoGrid.com, is the ultimate proof of the Scale Invariance promised in our Beyond Software Architecture presentation. Reason enough for Marcel Offermans and myself to give it a try and deploy our software on EC2.
Our goal is to us a standard EC2 image and run Java and an OSGi framework on it, through the use of PAXRunner. We will install software bundles onto the instance later, by a provisioning mechanism.
Subscribing
Go through the standard subscription process at aws.amazon.com and create an EC2 account. When completed, do three things.
- Add SSH port 22 to the default security group;
- Create a Private/Public Keypair;
- Download your Private Key, as you’ll need it to connect to your images
Choosing an AMI
At this stage, we are using a standard Ubuntu 9.04 AMI, provided by alestic.com (AMI ID: ami-ccf615a5).
Launch an instance and connect to it using SSH:
local> ssh -i EC2.pem root@ec2-a-b-c-d.amazonaws.com |
Enable multiverse repositories by editing /etc/apt/sources.list. Add these four lines at the end (for EC2′s US-EAST cloud).
deb http://us.ec2.archive.ubuntu.com/ubuntu/ jaunty main multiverse deb-src http://us.ec2.archive.ubuntu.com/ubuntu/ jaunty main multiverse deb http://us.ec2.archive.ubuntu.com/ubuntu/ jaunty-updates main multiverse deb-src http://us.ec2.archive.ubuntu.com/ubuntu/ jaunty-updates main multiverse |
Update the APT database:
ec2> sudo apt-get update |
Install java
Install Sun’s Java 6 JDK using APT:
ec2> sudo apt-get install sun-java6-jdk |
Run an OSGi Framework using Pax Runner
A great way of installing and running an OSGi framework is using PAX Runner. PAX Runner transparently downloads and runs for you all major OSGi implementations.
Download and unarchive PAX Runner.
ec2> curl http://repo1.maven.org/maven2/org/ops4j/pax/runner/pax-runner-assembly/1.3.0/pax-runner-assembly-1.3.0-jdk15.tar.gz > pax-runner-assembly-1.3.0-jdk15.tar.gz ec2> tar xzf pax-runner-assembly-1.3.0-jdk15.tar.gz |
Installing and starting an OSGi Framework can be done by running PAX Runners shell script. By adding the URL of a bundle as a parameter, this bundle will be downloaded and started.
ec2> ./pax-runner-1.3.0/bin/pax-run.sh http://www.vangrondelle.com/code/hellocloud_1.0.0.jar __________ __________ \______ \_____ ___ ___ \______ \__ __ ____ ____ ___________ | ___/\__ \ \ \/ / | _/ | \/ \ / \_/ __ \_ __ \ | | / __ \_> < | | \ | / | \ | \ ___/| | \/ |____| (____ /__/\_ \ |____|_ /____/|___| /___| /\___ >__| \/ \/ \/ \/ \/ \/ Pax Runner (1.3.0) from OPS4J - http://www.ops4j.org ---------------------------------------------------- -> Using config [classpath:META-INF/runner.properties] -> Using only arguments from command line -> Scan bundles from [http://www.vangrondelle.com/code/hellocloud_1.0.0.jar] -> Scan bundles from [scan-bundle:http://www.vangrondelle.com/code/hellocloud_1.0.0.jar] -> Provision bundle [http://www.vangrondelle.com/code/hellocloud_1.0.0.jar, at default start level, bundle will be started, bundle will be loaded from the cache] -> Preparing framework [Felix 2.0.1] -> Downloading bundles... -> http://www.vangrondelle.com/code/hellocloud_1.0.0.jar : 1078 bytes @ [ 359kBps ] -> Using execution environment [J2SE-1.6] -> Runner has successfully finished his job! Welcome to Felix ================ Hello Cloud! -> |
As you see, Felix is installed by default. Different OSGi implementations can be run by adding the --platform equinox|knopflerfish flag. Even the version to be installed can be specified.
Turning all this into a bootstrap script
For easy launching, you could add all this into a bootstrap script that turns a default Ubuntu image into an OSGi server with a single command.
Turning the Java installation into a silent install requires some additional scripting.
You can now install and run a bundle using the following command.
ec2> curl www.vangrondelle.com/code/bootstrap.sh | sh |
This script needs some enhancements: Multiverse repositories are added everytime its run for now. Script might detect EC2 Zone and add appropriate repositories.
This entry was posted on Thursday, December 3rd, 2009 at 10:20 am and is filed under How to. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
December 3rd, 2009 at 11:16 am
Tweets that mention OSGi in de Cloud -- Topsy.com says:[...] This post was mentioned on Twitter by adreghiciu, Marcel Offermans. Marcel Offermans said: Experimenting with OSGi in the cloud, Jeroen and I sat down yesterday: http://tr.im/Gwlj #osgi #cloud #felix #pax #runner #ec2 [...]
December 3rd, 2009 at 3:05 pm
Pax Runner is in da cloud « pax my framework says:[...] } Checkout the excellent post of Jeroen van Grondelle about running OSGi in a public cloud service via Pax Runner. Leave a [...]