Microcontainer Tools - Grapher

Posted by    |      

Last few weeks, apart from doing real work ;-), I've been hacking away a simple tool to display MC's components. I named the project Grapher, as that's what the project/app does - it creates a plain graph.

This is a plain graph of current JBoss5.1.0.GA's MC components. As we could already learn in DZone and MC component models, the component types (currently) span from POJOs, MBeans, Aliases, Deployments, Core services to any extension (KernelRegistryPlugin). And you can see there is a lot of them and it's not easy to put them all on the plain.

[AllGraphCreator] Vertices: 830, Edges: 1563

I'm using JGraph to do the rendering, while using its layout component only for personal usage (license requirement).

The project source code lives here, and any UI or core contribution is as always welcome. Specially UI part could do some work as I pretty much suck at it - currently all input/output is done via single servlet and broswer's address line. :-)

The code itself is nicely structured, split into functional pieces

  • graph creation
  • layout
  • request mapping
  • rendering
  • routing
  • analysis (TODO)

Graph creation has the following impl:

  • All - show all components
  • Bean - show component and its first level dependencies
  • Tree - show component and all transitive dependencies
  • Deployment - show deployment's components; recursion/transitivity is optional

Some examples

  • http://localhost:8080/grapher/
  • http://localhost:8080/grapher/?bean=MainDeployer
  • http://localhost:8080/grapher/?tree=MainDeployer
  • http://localhost:8080/grapher/?deployment=vfs-jboss-beans.xml
  • http://localhost:8080/grapher/?deployment=vfs-jboss-beans.xml&recurse=true
  • http://localhost:8080/grapher/?deployment=metadata-deployer-jboss-beans.xml&folder=deployers

Layout is hacked in via reflection due to license issues, but for personal usage you can use any of the following JGraphLayout impls

      // a ctor hack
      map.put("simple0", "com.jgraph.layout.graph.JGraphSimpleLayout");
      map.put("simple1", "com.jgraph.layout.graph.JGraphSimpleLayout");
      map.put("simple2", "com.jgraph.layout.graph.JGraphSimpleLayout");

      map.put("tree", "com.jgraph.layout.tree.JGraphTreeLayout");
      map.put("spring", "com.jgraph.layout.graph.JGraphSpringLayout");
      map.put("hierarchical", "com.jgraph.layout.hierarchical.JGrapHierarchicalhLayout");
      map.put("compound", "com.jgraph.layout.JGraphCompoundLayout");
      map.put("compact", "com.jgraph.layout.tree.JGraphCompactTreeLayout");
      map.put("moen", "com.jgraph.layout.tree.JGraphMoenLayout");
      map.put("radial", "com.jgraph.layout.graph.JGraphRadialTreeLayout");
      map.put("annealing", "com.jgraph.layout.graph.JGraphAnnealingLayout");
      map.put("fr", "com.jgraph.layout.graph.JGraphFRLayout");
      map.put("organic", "com.jgraph.layout.organic.JGraphOrganicLayout");
      map.put("self", "com.jgraph.layout.organic.JGraphSelfOrganizingOrganicLayout");
      map.put("isom", "com.jgraph.layout.graph.JGraphISOMLayout");
      map.put("org", "com.jgraph.layout.tree.OrganizationalChart");
      map.put("grid", "com.jgraph.layout.simpl.SimpleGridLayout");

where the default used is SimpleGridLayout.

  • http://localhost:8080/grapher/?tree=MainDeployer&layout=isom

Note: I still need to check how to handle layout better, as I see too much of overlaps.

Each of the pieces can be changed at config or runtime.

public interface GraphComponentMapper<T>
{
   /**
    * Initialize.
    *
    * @param config the config map
    */
   void init(Map<String, String> config);

   /**
    * Map component from request.
    *
    * @param request the request
    * @return mapped component
    */
   T mapComponent(HttpServletRequest request);

   /**
    * Map component to the key.
    *
    * @param key the key
    * @param value the value
    * @return mapped component
    */
   T mapComponent(String key, String value);
}

Where I have such component mappers for graph creator, layout and renderer. The defaults are used at servlet initialization, but you can provide your own.

Currenly I support these renderers

  • PNG (default)
  • JPG
  • GIF
  • SVG
  • Html ul/li

Renderer example

  • http://localhost:8080/grapher/?tree=MainDeployer&renderer=svg

Any request can use any combination of these, plus some additional filtering.

You can list the component type excludes

      mapControllerContextClass("pojo", AbstractKernelControllerContext.class, Color.BLUE);
      mapControllerContextClass("alias", AliasControllerContext.class, Color.GRAY);
      mapControllerContextClass("core", BeanKernelRegistryEntry.class, Color.RED);
      mapControllerContextClass("ext", AbstractKernelRegistryEntry.class, Color.ORANGE);
      mapControllerContextClass("mbean", "org.jboss.system.microcontainer.ServiceControllerContext", Color.MAGENTA);
      mapControllerContextClass("dep", "org.jboss.deployers.plugins.deployers.DeploymentControllerContext", Color.GREEN);

Here you can also see the colors that are mapped against certain component type.

Exclude POJOs example

  • http://localhost:8080/grapher/?exclude=pojo

Exclude multiple types

  • http://localhost:8080/grapher/?exclude=mbean,ext,alias

Also availabe option is to define which dependecy type you wanna use to find dependencies

  • IDepenOn (default)
  • DependsOnMe
  • Unresolved

  • http://localhost:8080/grapher/?tree=MainDeployer&dependency=DependsOnMe

This leaves us with analysis piece, which is still WIP. The whole graph is backed by JBoss Common Core Graph code, hence we already have some of the theoretical algorithms present, but I would still like to do a bit more.

The current idea that I have is to somehow join rules/scripts with graph theory.

  • give me all sub-graphs whose number of vertices is less than 20
  • give me all sub-graphs with depth less than 5

This way we could do some proper analysis and easily determine how to place On-Demand mode and define lazy beans. But like I said, this is still very non-defined, so any help welcome. Wink wink our Drools committers. ;-)

Also good thing about the project is that most of if not all of the code is properly tested, with each functional piece having its matching test. So, when you contribute, you know when you broke something. ;-)

ps: Simple mvn package creates the grapher.war, for any useful layout check pom.xml ;-)


Back to top