Last month I attended DroidCon 2012 and did a talked about using Juju and Ubuntu to deliver Android applications with a Web Service background. The guys at Skillmatters were kind enough to record and edit the video, and now it publicly available.
If you thought I had concluded my blog series on demonstrating how Ubuntu is the best environment to write up “connected” or “cloud backend” Android Apps, think again!
So far this is what we covered:
The next step is “How to test that it all works on a production environment”. If you have tested to death both your Android application and your web service locally, it is time to check if they will still work in real life. How do we do this? With few simple commands, we are going to deploy the same web service into the Amazon Cloud, and the application in a mobile phone. All managed from the comfort of my Ubuntu Desktop.
Deploying to Amazon Web Services (AWS)
The only pre-requisite here is that you do have an AWS account. Once you are logged into the AWS website, you can find the credentials that you will need to set up your juju environment. You can find a tutorial on how to set up your Elastic Compute Cloud (ec2) environment –> here.
The required information for Juju is stored in the environment.yaml file in the ~/.juju folder. In the following sample file you can see that two environments have been defined:
default: local environments: aws: type: ec2 access-key: YOUR-ACCESS-KEY-GOES-HERE secret-key: YOUR-SECRET-KEY-GOES-HERE control-bucket: juju-faefb490d69a41f0a3616a4808e0766b admin-secret: 81a1e7429e6847c4941fda7591246594 default-series: precise juju-origin: ppa ssl-hostname-verification: true local: type: local control-bucket: juju-a14dfae3830142d9ac23c499395c2785999 admin-secret: 6608267bbd6b447b8c90934167b2a294999 default-series: precise juju-origin: distro data-dir: /home/victorp/myjuju_data
With my environments now configured, it’s time to deploy my services. This first step is to bootstrap my environment:
juju bootstrap -e aws
With the command completed successfully, I can check the status and I will see that the juju control instance is now up and running in Amazon:
juju status -e aws
2012-09-19 11:43:34,248 INFO Connected to environment.
machines:
0:
agent-state: running
dns-name: ec2-75-101-189-208.compute-1.amazonaws.com
instance-id: i-0e4f7174
instance-state: running
services: {}
2012-09-19 11:43:35,322 INFO 'status' command finished successfully
Lets continue deploying the services. As I am only doing testing, I want to pay the minimum for it, it will ask juju to set a constrain to only use micro instances. Then I will deploy a mysql and a lamp service:
juju set-constraints instance-type=t1.micro -e aws juju deploy mysql -e aws juju deploy --repository ~/mycharm local:lamp -e aws juju set lamp website-database="android_todo" -e aws juju set lamp website-bzr="lp:~vtuson/+junk/mytodo_web" -e aws juju expose lamp -e aws juju add-relation lamp mysql -e aws
With all my services now running I can go to the Amazon EC2 instance console and see how they have been deployed as micro instances. I can now also enter the public address for my lamp service and see the ToDo list table as expected.
Testing the Android App on a real phone
Running Juju status, I can retrieve the public url for the lamp service and I replace the uri vairable in the TodoSourceData class with “ec2-107-22-151-171.compute-1.amazonaws.com/database.php”. The next step is to plug a HTC Desire set up on debug mode into my laptop’s usb port. The rest is taken care by the Android Eclipse plug-ins. When I click the run project button, I am presented with a choice of targets:
I just need to press “OK” and my ToDo app is launched in the handset. Opening the menu options and pressing “Sync” fetches the ToDo data from the Amazon services, as expected:
That is all for today! Let me know if you have any suggestions on what else I should cover on this blog series.
Time for the next chapter of my blog series about demonstrating how Ubuntu is the best environment to write up “connected” or “cloud backend” Android Apps. As you might know, the Android SDK allows you to set up a sandboxed environment to develop Mobile apps in your desktop, using Juju you can do the same for Cloud apps.
To walk you through how to put these great development tools together, I set out to accomplish:
Today I am going to cover the bottom two bullet points in one go! For this post, I am going to assume that you know a bit of Android development. If you want a great source of introductory material check Lars Vogel’s website.
I have created a simple ToDo Android application that can store tasks into a local SQLite db and allows you to “Star” important items. The code for my Simple Todo app is hosted in Launchpad. I have written my application for Android 2.3, but you can use a later version.
Reading remote data from the MySQL server is confined to a small class that retrieves a JSON object and translates it into a TodoItem object. Equally , the server code that prints that content table into a JSON object is extremely simple. Beyond this, you can go crazy and implement a RESTfull API to sync the databases.
At the moment, I am just inserting Server side data into the Local database and making sure I don’t add duplicates.Here is a video that shows how easy is to work and test both environments:
The same environment should then work if you are running the Android application on an external phone. But that is another blog post
It is time to continue with my blog series on demonstrating how Ubuntu is the best environment to write up “connected” or “cloud backend” Android Apps. As you might know, the Android SDK allows you to set up a sandboxed environment to develop Mobile apps in your desktop, using Juju you can do the same for Cloud apps.
To walk you through how to put these great development tools together, I set out to accomplish:
Today is time to set-up our own Cloud environment in a PC. A good starting point for a web application is a LAMP stack. If you hope for you service to get popular, you might want to split out the database service and the web service into their own instances so they can be scaled easily.
When I set out to do this, I wanted to write an extremely simple PHP page that would expose a data table from a Mysql server. I looked up the available charms on the store. I found that you had a lot of charms for existing apps, but none that had the bare bones of a LAMP stack and just allowed you to install your own web pages. However, I did find a charm to deploy Mysql and a very handy tool to manage it (phpmyadmin). Taking this as a starting point I developed a generic LAMP charm.
The first thing the LAMP charm does is to install and configure a new instance with Apache and PHP5 in an LXC container. The new charm will then copy any files under /website inside the charm folder structure, into /var/www. It also allows you to specify a Bazaar branch. It will clone the branch into the webserver and copy the contents to /var/www. I keep my TODO application for this exercise here.
Using juju, you can set up a relationship with a Mysql service. A Mysql database is created by default at this time. You can change the name of the database as a configuration options. If you provide a file called mysql_config either on the /website folder or in the root of you Bazaar branch, this will be used to configure further the Mysql database.
The charm will store the details of the relationship in /var/webconfig. In there you can also find opendb.php, a basic script that will open the connection to the MySQL database for you.
So lets get started! Clone the Lamp branch to a folder of your choice. I have it under “~/Mycharm/precise/lamp”. (If you need to get started with juju check my previous post here)
juju bootstrap
#step1 - deploy Mysql as a service.
juju deploy mysql
#step2 - deploy phpmyadmin tool
juju deploy phpmyadmin
juju set phpmyadmin password="password"
#this makes phpmyadmin public - exposes port 80/tcp
juju expose phpmyadmin
#step3 - link phpmyadmin and mysql so the can talk to each other
juju add-relation phpmyadmin mysql
#step4 deploy lamp from your local folder
juju deploy --repository ~/mycharm local:lamp
#step5 set up your bazaar branch and publish your website
juju set lamp website-bzr="lp:~vtuson/+junk/mytodo_web"
juju expose lamp
#step6 configure your database and link lamp and mysql services
juju set lamp website-database="android_todo"
juju add-relation lamp mysql
Once Juju has completed all the commands, run “juju status”. Now go to the ip address for the LAMP services and visit the databaseweb.php page (e.g. http://192.168.122.174/databaseweb.php) , you get this rather ugly table:
| Id | Todo | Is it starred |
|---|---|---|
| 1 | hello this is a sample | 1 |
| 2 | yes it works! | 0 |
This table is displaying the contents of a Mysql database. You will get the same data if you visit your Myphpadmin service:
So there you are a full and scalable LAMP stack in your PC!
If you want to update the web service by pulling the latest version of the Bazaar branch, just run the following commands:
juju set lamp bzr-update="yes"
juju set lamp bzr-update=
With my web developer “hat” on, I can now hand this charm over to my Android app developer. They will be able to set up exactly the same environment locally to test their app without using expensive server time.
So “Using a few charms from the charm store plus a custom one, set up a MySQL database that can be exposed through a web service with simple commands/steps” – DONE!
Have you ever wondered what is all the fuss about ARM Servers? Yes? good , good.
Have you ever wish you had some crazy Zooming UI presentation that told you all about it? what.. no!? Well though.. because now you have one
If you haven’t heard of Prezi, it is a new way to generate more dynamic presentations. I will give you a few tips:
Without further ado, I give you ARM Server on a Prezi:
url: http://prezi.com/_zwqpnowk8cv/arm-server/
I was aware that data centers around the world were starting to be talked about as an environmental problem, but perhaps the statistic that data centers have the same carbon footprint than the aviation industry (about 2% of the global carbon footprint pie) really put things in perspective for me.
The Open Data Center Alliance ”Carbon Footprint Values” document starts its executive summary with:
According to market research and consulting firm Pike Research, data centers around the world consumed 201.8 terawatt hours (TWh)
in 2010 and energy expenditures reached $23.3 billion. That’s enough electricity to power 19 million average U.S. households. The
good news is that, according to Pike Research, the adoption of cloud computing could lead to a 38% reduction in worldwide data center
energy expenditures by 2020.
The prediction that cloud computing will lead to large savings of energy consumption can be justified by economies of scale. Todays’ enterprise data centers average 20-30% computing power utilisation. The same data center serving Infrastructure As A Service (IaaS) is expected to run at 80-90% occupancy. This plus the opportunity for enterprises to transform a fix cost of ownership into a flexible service subscription will lead to consolidation of data centers.
Economies of scale will also allow large scales data center providers to invest in propose build more sustainable and cheaper to run buildings. A good examples of this is the server and data center specifications shared by Facebook via the Open Compute Project, or Google’s water powered and cooled at-Sea data centers.
As discussions of hefty fines for London by the European Union are currently taking place, sustainability is becoming less a matter of corporate responsibility and more of legal compliance.
However, Cloud computing is bringing applications to individuals that were only available to enterprises a few years ago. This will multiply the need for data centers across the globe beyond the current demand. We need to work beyond finding cheaper ways to cool and power servers and start tackling the real problem, servers themselves need to be exponentially more efficient.
Thankfully both Intel and ARM have quick-started the race for low power servers that will eventually make the Cloud really green.

Latest Official Posts
Featured Blogs
People
You can't take the sky from me
Alex Chiang
allenap
Amit Kucheria
Andres Rodriguez
Andrew Glen-Young
Ara Pulido
Barry Warsaw
Bazaar team
Bitácora de Vuelo
Bjoern Michaelsen
Björn Tillenius
Blogging in the Wind
Bofu Chen
Brad Figg
Brad Marshall
Brian Fromme
Canonical Blog
Canonical Design Blog
Canonical ISD
Canonical Marketing Team Blog
cat /dev/ursula
cat /dev/ursula
Certifiably (Brendan Donegan's Ubuntu Blog)
Chad Miller
Chris Halse Rogers
Chris Johnston
Christian Reis
Code Singer: Gary Poster's blog
Corey Goldberg
Daniel Holbach's blog
Danilo Segan
Darryl Weaver
David Henningsson
David Murphy
David Murphy
David Owen
David Planella
Distributed Teams
Gavin Panella
Graham Binns
Guilherme Salgado
Gustavo Niemeyer
How Bazaar
Iain Lane
Illruminations
Inert Ramblings
James Tait
James Westby
Jamie Strandboge
jedimike's adventures in typing
Jeremy Kerr
Joey Stanford
John Pugh
Jono Bacon
Jorge Castro
Julian Edwards
Julien Funk
JussiP
Ken VanDine
Keng-Yu Lin
kevin gunn
KyleN Ubuntu
KyleN Ubuntu
Landscape Blog
Launchpad Blog
Launchpad Blog
Lee Jones
Louis Bouchard
Manuel de la Pena
Marcin Juszkiewicz
Mark Shuttleworth
Martin Albisetti's blog
Martin Pitt
Matt Fischer
Michael Hall's Blog
Michael Hudson
Michael Terry
Multi-touch on Ubuntu
Not Lucky All The Time, But Smart Everyday…
Olli's random thoughts and impressions
person@CANONICAL-DESK
person@CANONICAL-DESK
Pixoul Photography
Prakash Advani
racarr's blog
racarrs blog!
RedVoodoo.org
Ricardo Salveti
Rick Harding
Robert Ancell
Robert Ayres
Ryan Finnie
S3hh
Scott Sweeny
Sean Feole
Shang Wu
Shuduo
Sidnei da Silva
sil2100//vx web-page
Smackerel of Opinion
Something driven development
Stéphane Graber
Steve George
Steve Langasek
Stuart Bishop
Stuart Metcalfe
Subcritical
Ted Gould
The Dowdberrys
The Orange Notebook
The Quality Hour
The Raving Rick
Timo Jyrinki
tvoss@work
Ubuntu App Developer Blog
Ubuntu Kernel Team Blog
Ubuntu One Blog
Ubuntu Server Team
Ubuntu Server Team
Ubuntu Server Team Blog
utlemming
utlemming's blog
Victor Palau's Blog
Wanderings of a Kernel Engineer
ZhengPeng Hou
~apw
Canonical Voices© 2010 Canonical Ltd. Ubuntu and Canonical are registered trademarks of Canonical Ltd.