OMF on Android

  1. Setup device

In order to run OMF Resource Controller on an Android device, we need a Ruby interpreter.

We will use Scripting Layer for Android (SL4A). Go to Downloads and download the latest revision of sl4a.apk.

You can install this app via adb:

adb install sl4a.apk

or you can copy the file onto your device's SD card and navigate to it with a file manager such as Astro.

Note: You will need to have enabled installation of non-Market apps via Setting > Applications > Unknown Sources.

SL4A only includes the Shell interpreter, but we need Ruby functionality. Fortunately, SL4A supports a JRuby interpreter. JRuby is an implementation of Ruby on the Java Virtual Machine. The majority of your code and gems will run properly, with the exception of native gems written in C, such as the built in Yaml parser.

To install the JRuby interpreter, press Menu and then View > Interpreters. From here you can see all installed interpreters. To add a new one, press Menu and then Add > JRuby. The .apk should automatically download. Install and open it. Press install, and it will download the necessary libraries to start the JRuby interpreter from SL4A.

  1. Get OMF source code

Now we need the OMF source code to run.

git clone git:// -b release-5.3

We will only work with omf-common and omf-resctl.

Copy the root directory that holds omf-common and omf-resctl to sl4a/scripts on the device's SD card. You should now be able to view the OMF files in SL4A.

  1. Bootstrap OMF

If you just try to start the resource controller by running omf-resctl/ruby/omf-resctl/nodeAgent.rb, you will run into errors regarding the load path. This is because the resource controller is supposed to be started via omf-resctl/sbin/omf-resctl:


export LANG=c

if [ -e /usr/share/omf-resctl-$VER/$APP ]; then
   echo "Cannot find the ruby module location ($APP)."
   exit 1;
exec ruby1.8 -I$PDIR -I/usr/share/omf-common-$VER $PDIR/$APP $*

So nodeAgent.rb is run with ruby1.8 with the 2 -I flags. These -I flags load the dependencies into Ruby before nodeAgent.rb is run. Since we are working with an app that does not support command line arguments, we will have to implement a workaround.

In the root directory of the OMF source code, create a file called bootstrap.rb and copy this in:

APP_DIR = File.expand_path File.dirname(__FILE__)
#GEM_DIR = File.join(APP_DIR, 'vendor', 'gems')
RESCTL_DIR = File.join(APP_DIR, 'omf-resctl', 'ruby')
COMMON_DIR = File.join(APP_DIR, 'omf-common', 'ruby')
NODE_PATH = File.join(RESCTL_DIR,'omf-resctl', 'nodeAgent.rb')

#Dir.entries(GEM_DIR).each do |dir| 
#  $LOAD_PATH << File.join(GEM_DIR, dir, 'lib')



require NODE_PATH

This script is in essence a Ruby translation of the shell script above that loads all Ruby dependencies (RESCTL_DIR and COMMON_DIR) to the LOAD_PATH variable before running nodeAgent.rb (NODE_PATH).

  1. Load networking drivers

In order to properly retreve data from the device, you need to use the corresponding driver for the wireless chipsets. nodeAgent does this by running lspci, which does not work on Android.

Comment out the call to lspci from line 412-425 and 428-447 in omf-resctl\ruby\omf-resctl\omf_agent\nodeAgent.rb, leaving the Intel card portion uncommented

require 'omf-resctl/omf_driver/intel' "Have Intel cards"
AgentCommands::DEV_MAPPINGS['net/w0'] ='net/w0', 'eth2')
AgentCommands::DEV_MAPPINGS['net/w1'] ='net/w1', 'eth3')

The Intel driver is not completely compatible with the wireless chipsets on the device, but it works.

  1. Vendorize Gems

OMF relies on several gems that we do not have on the SD card.

In order to continue, we need the log4r, xmpp4r, and RbYAML gems. On a computer with Ruby and RubyGems installed, type

gem install log4r
gem install xmpp4r
gem install RbYAML

to install the gems. SL4A doesnt support RubyGems, so we will have to vendorize them.

mkdir vendor/gems
gem unpack log4r --target=vendor/gems
gem unpack xmpp4r --target=vendor/gems
gem unpack RbYAML --target=vendor/gems

and then place the /vendor directory in the root directory of OMF on the device's SD card.

Uncomment the 4 lines in bootstrap.rb - They check the vendor/gems folder and manually load the gems.

OMF uses .yaml configuration files, but the default Yaml parser in Ruby is written in C, and therefore will not work on JRuby. We will use RbYAML instead. Replace line 358-359 of omf-resctl\ruby\omf-resctl\omf_agent\nodeAgent.rb:

require 'yaml'
h = YAML::load_file(@configFile)

with RbYAML:

require 'rbyaml'
temp_h = RbYAML::load_file(@configFile)
h = symbolize(temp_h)

and add the symbolize private method after line 386:

def symbolize (hash)
  if hash.class == Hash
    newHash = {}
      hash.each do |k, v|
        newHash[k.gsub(":", "").to_sym] = symbolize(v)
    return newHash
    return hash

This is necessary because the native Yaml parser returns a hash with symbols for keys, and RbYAML returns a hash with strings as keys. We recursively copy the data into a new hash and convert the key from a string to symbol.

  1. Configure node

Resource Controller should be running now, you need to configure it accordingly.

Last modified 11 years ago Last modified on Oct 18, 2013, 10:22:07 PM
Note: See TracWiki for help on using the wiki.