Canonical Voices

Posts tagged with 'mobile'

Victor Palau

Oh my, seems that the Canonical team has been busy ;)

link to youtube video -  Here


Read more
Victor Palau

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:

  • Proof that you can access a Juju local environment from the Android Emulator  done!
  • 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!
  • Develop a TODO list android app and connect it to the web service, so they talk to each other. – done!

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:

  • “local” is the environment that I have been using in my PC to test my web service using LXC containers.
  • “aws” gives Juju the information required to deploy services using my Amazon account.
  • “local” is set as default. This means that if I just run “juju bootstrap” this command applies to the local environment. To bootstrap the AWS environment, I would do “juju bootstrap -e aws”.
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.


Read more
Victor Palau

Droidcon – London

Just a brief post to say that I will be talking at DroidCon on 26th October in London. This is what I will be covering:

Most Android apps nowadays are a front or local client for online services, from backing up data to the cloud to providing a cross platform service. This requires developers to have access to not just an Android environment, but also to a staging server that they can mess with. This requires the app developer to either gain knowledge of how to set up this complex web, or wait for someone to do it for them.

Juju is a service orchestration tool that allows you to deploy cloud applications like WordPress or Mysql to live clouds such as Amazon Web Services (AWS). Juju Charms package the wisdom of experience Dev Ops so anyone can deploy a complex apps with few simple commands. This can first be done to a local environment running in your laptop, and once you are confident on the service, deploy it to a live cloud. Ubuntu ,the leading linux desktop distribution, brings together the best support for Android app development (used by the Google Android team) with an easy to use cloud deployment toolset.

This talk will explore the simplicity of developing an android app that needs to talk to a cloud service. The talk will be framed around an example of a “TODO list” android app that locally stores information into a SQLite database, and then backs-up user data to the cloud. The talk will show how a android developer can deploy, in his or her laptop, a complex web service with just a handful of commands, and then get the application talking to the service form within the android emulator. Join us to grasp how Ubuntu can provide android developers a full test environment in a box.

My Droidcon talk profile


Read more
Victor Palau

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:

  • Proof that you can access a Juju local environment from the Android Emulator  done!
  • 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!
  • Develop a TODO list android app
  • Connect the android app and the webservice, so they talk to each other.

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:

Or Click Here for the video.

The same environment should then work if you are running the Android application on an external phone. But that is another blog post ;)


Read more
Victor Palau

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:

  • Proof that you can access a Juju local environment from the Android Emulator  done!
  • 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
  • Develop a TODO list android app
  • Connect the android app and the webservice, so they talk to each other.

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!


Read more