Friday, 17 April 2009

Simple OSGi Bundle Visualisation with Flare

Last night I knocked together a simple OSGi Bundle Visualisation using Flare, a visualisation framework for ActionScript/Flex released under BSD license. You can see the fruits of my labour by following the instructions below. My work here is released under no specific license, so you're free to copy, modify, redistribute, whatever, as you see fit.

You can see a demo of some static data generated from my container by clicking here.

1) A running HttpService

1) Download the bundle from here. Source is available here.
2) Install it in your OSGi container
3) Start it
4) Access http://localhost/ where http://localhost is the root of your container's HttpService (e.g. http://localhost:8080 in a lot of cases)

The visualisation currently shows a list of the installed bundles displayed in a radial layout. Mouse over a bundle to see where it imports packages from (red) and where other bundles import packages from it (green). Click once on a bundle to show the import connections, click again to show the export connections, click again to hide connections. Click anywhere not on a bundle to reset the vis.

Note that you can also tab through the bundles and use enter to 'activate' them.

Firstly I register a servlet which exports all the bundle information as JSON at the following URL:

This was frustratingly more complex than I had anticipated. I had hoped the OSGi APIs would expose which packages are imported/exported but I actually had to go through each Bundle's headers in order to work it out and this becomes a parsing nightmare. In the end I took and modified some code from an other OSGi project (namely QuotedTokenizer from Felix) to handle the parsing of the header values.

The visualisation itself is based on the DependencyGraph example that comes with Flare. I modified it for my Flex environment and then copied it to a class called OSGiGraph. This class simply adds each bundle to the dependency tree (as a child of the root) and then creates edges between bundles by looping through each imported package and finding an export package. Apart from changing a few other minor variables the result is as you can see.

Limitations and future enhancements:

- Does not consider package versions
- Does not consider 'uses'
- Does not consider 'Require-Bundle'
- Does not display imported and exported packages
- Does not display bundle states
- Restricted to a single layout (CircleLayout)
- No high level grouping (e.g. vendor/category)
- Does not display services registered or used

I've tested the visualisation with a container that has 19 bundles in it and it looks OK. However, I can imagine that as that number increases it would be increasingly more difficult to see. For instance, if LinkedIn's 400+ bundles were to be displayed it would quickly become a lot of static noise. To address this I will probably create a more complicated bundle hierarchy based on another property from the bundle's manifest, for instance Bundle-Category (which appears to be widely under-used, IMHO) and/or Bundle-Vendor. A text input filter could also help here.

I also plan on allowing the visualisation layout to be changeable on the fly. The radial view looks OK, but there's nothing to say it has to look like that. Representations of the bundles floating around randomly is just as representative, IMHO, though perhaps sorted by name rather than truly random. Alternative layouts might allow extra useful information to be displayed, such as the packages imported/exported and services registered/used.


While this is a simplistic visualisation of OSGi bundles it demonstrates Flare's capabilities, though somewhat crudely, and is also a starting point for a more advanced drop-in visualisation of an OSGi container's state.

No comments: