Running a Java Application To Demo The Cluster

So it’s all well and good having a nice MySQL cluster running on some tiny hardware, but what can you do with it?

Well in order to demo the software at some upcoming techtours my colleague put together a little Java application to showcase what can be done.

I want to run my raspberry pi’s headless so in order to get this to work I needed to install a vncserver

sudo apt-get install tightvncserver

Once this is installed make a note of the display you set up and check you can connect to it via a vnc client.

Install the java application

configure the config file for the MySQL credentials

Run the java application in a shell window on the remote VNC session making sure the screen variable has been set accordingly

export DISPLAY=1:4

When you have it all working it should look like the following

Screen Shot 2013-09-05 at 10.06.10


Monitoring The Cluster Using the LCD Panel

I thought it would be nice to have a display on pi1 (the primary node) so found an LCD kit that hopefully I could write a little script to hack around to display the status of each data node.

So I purchased the Adafruit Char 16×2 LCD Plate from:×2-LCD-kit

Then set about soldering it all up

20130715_135813_Macaulay Ave


20130715_143836_Macaulay Ave

I followed the guide here:×2-character-lcd-plus-keypad-for-raspberry-pi/assembly

Once the kit was all soldered up you have to enable the linux kernel to recognise it

I followed the guide here×2-character-lcd-plus-keypad-for-raspberry-pi/usage

I then modified the sample code to get the output from the cluster node status. The code I used is below

from time import sleep
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
from subprocess import *
from time import sleep, strftime
from datetime import datetime

# Initialize the LCD plate. Should auto-detect correct I2C bus. If not,
# pass '0' for early 256 MB Model B boards or '1' for all later versions
lcd = Adafruit_CharLCDPlate()
# Clear display and show greeting, pause 1 sec
lcd.message("MySQL Cluster\n Running On Pi")
cmd = "ndb_mgm -e show |grep ^id=[3,4]|awk {'print $1 $2 $3}'|sed s/=//g|sed 's/[(]/ /g'"

def run_cmd(cmd):
 p = Popen(cmd, shell=True, stdout=PIPE)
 output = p.communicate()[0]
 return output
while 1:
 clusterstatus = run_cmd(cmd)
 lcd.message('%b %d %H:%M:%S\n'))
 lcd.message(( clusterstatus ))

# Poll buttons, display message & set backlight accordingly
btn = ((lcd.LEFT , 'left'),
 (lcd.UP , 'up'),
 (lcd.DOWN , 'down'),
 (lcd.RIGHT , 'right'),
 (lcd.SELECT, ''))
prev = -1
while True:
 for b in btn:
 if lcd.buttonPressed(b[0]):
 if b is not prev:
 prev = b

The final result