Wednesday, November 17, 2010

is it alive?

Watched Mel Brook's Young Frankenstein with my kiddo over the weekend: "It's ALIVE!" is now our catchphrase for, well, you know whenever a 12 year old boy wants to yell something.

How do I know that my Sakai3 has come up and is ready for being poked with a sharp stick? In IRC I chatted for a moment with stuartf about this, and eventually wrote up KERN-1868 to put that sharp stick in the sand.

With the Sakai deployments at Stanford I cooked up a mess of lightweight web tests which could be resolved from the command line. These exercised various points of the service stack culminating in heartbeat test: IT'S ALIVE! (Stanford's Julian Morley has taken these tests and greatly improved them, weaving them through the load balancer's tests.)

Personally being a blunt instrument I'm going to get the JSON used in the Sling Web Console console/bundles report, parse it for Sakai related bundles ( somehow ) status things, and provide a FAIL of some sort if all the Sakai bundles are not up. I think it's clear that this is rather blunt - it will undoubtedly come to pass that some Sakai categorized bundles are in development, or are being A/B'ed and so won't be active, but this is an OK place to start. I'll presume that the Categorization is sufficient for now.

Speaking of starting I am a lazy programmer so I'm going to not get all mightly curly as I explore this approach, but start off by using resty to make my requests.

Resty is a curl wrapper which exposes a set of commands into your shell, allowing you to REST at ease. Here's an example:

 $ . resty
 $ resty http://3akai.sakaiproject.org
 $ GET /system/console/bundles/.json --basic -u"admin:admin"
{"status":"Bundle information: 127 bundles in total - all 127 bundles active.","s":[127,126,1,0,0],"data":[{"id":0,"name":"System Bundle","fragment":false,"stateRaw":32,"state":"Active","version":"2.0.4","symbolicName":"org.apache.felix.framework","category":""},{"id":81,"name":"Apache Aries JMX API","fragment":false,"stateRaw":32,"state":"Active","version":"0.1.0.incubating","symbolicName":"org.apache.aries.jmx.api","category":""},{"id":85,"name":"Apache Aries JMX Core","fragment":false,"stateRaw":32,"state":"Active","version":"0.1.0.incubating","symbolicName":"org.apache.aries.jmx.core","category":""},{"id":68,"name":"Apache Commons IO Bundle","fragment":false,"stateRaw":32,"state":"Active","version":"1.4","symbolicName":"org.apache.commons.io","category":""},{"id":18,"name":"Apache Derby 10.5","fragment":false,"stateRaw":32,"state":"Active","version":"10.5.3000000.802917","symbolicName":"derby","category":""},{"id":111,"name":"Apache Felix Bundle Repository","fragment":false,"stateRaw":32,"state":"Active","version":"1.6.4","symbolicName":"org.apache.felix.bundlerepository","category":""},{"id":45,"name":"Apache Felix Configuration Admin Service","fragment":false,"stateRaw":32,"state":"Active","version":"1.2.4","symbolicName":"org.apache.felix.configadmin","category":"osgi"},{"id":47,"name":"Apache Felix Declarative Services","fragment":false,"stateRaw":32,"state":"Active","version":"1.6.0","symbolicName":"org.apache.felix.scr","category":""},
it has a buddy, pp, which is a perl pretty-printer one liner.

$ curl https://github.com/micha/resty/raw/master/pp > /usr/local/bin/pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0    88    0    88    0     0     83      0 --:--:--  0:00:01 --:--:--   423
$ more /usr/local/bin/pp
perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"'
$ chmod +x /usr/local/bin/pp
which makes things a bit easier for me to read:
Octo:~ casey$ GET /system/console/bundles/.json --basic -u"admin:admin" | pp
{
   "status" : "Bundle information: 127 bundles in total - all 127 bundles active.",
   "data" : [
      {
         "stateRaw" : 32,
         "version" : "2.0.4",
         "fragment" : false,
         "name" : "System Bundle",
         "symbolicName" : "org.apache.felix.framework",
         "state" : "Active",
         "id" : 0,
         "category" : ""
      },
      {
         "stateRaw" : 32,
         "version" : "0.1.0.incubating",
         "fragment" : false,
         "name" : "Apache Aries JMX API",
         "symbolicName" : "org.apache.aries.jmx.api",
         "state" : "Active",
         "id" : 81,
         "category" : ""
      },
What I can now do is GET and PUTS from my command line, with the shell preserving connection info and mongling up the real curl call.

This means I'm ready to rapidly poke at the Console's Bundles page and see what's happily loaded. I'll have to do a lifecycle test to see just how the states change as Sling comes up, and probably have to break something to see what a broken Sakai 3 looks like. Perhaps a stubbly broken bundle. hmm.

Onward! From what I've seen most of the Sakai test framework is harnessed up in Ruby, so to make this quickly useful I'll learn Ruby's JSON parsing next. (I've also been looking into jsawk, which is pretty neat.)

Then back to the 3elenium Grid track.

Resources:

https://github.com/micha/resty#readme and be sure to watch the movie!

No comments: