Virtuality
It's like reality, but not as substantial

20040610 Thursday June 10, 2004

Transforming a Resource Pools Configuration XML Document using XSL

Isn't XML wonderful? No! Well maybe it isn't, but it certainly is useful.

Solaris Resource Pools utilities, pooladm(1M) poolcfg(1M), can be used to examine a Resource Pools configuration. Of course, like most text oriented utilities, the output of these commands is designed to be read by a human working with a shell. I thought it would be nice to be able to examine the Resource Pools configuration using a web browser.

In order to do this you need a few things:

  • A tool to transform your XML document into HTML
  • A web server that can perform XSLT transformations
  • An XSL stylesheet which describes the transformation

In Solaris 10, the xsltproc(1) utility can be used to transform XML documents using XSL stylesheets. If you don't have Solaris 10, think about joining the Solaris Express program and getting early access to Solaris 10. Alternatively, you can download xsltproc as part of the libxslt package for Solaris 9 here.

I've written a cgi-bin script which can be used to invoke xsltproc to perform transformations on input XML documents. Of course, you don't have to use xsltproc, many web servers have extensions that can perform XSLT transformations based on the document type. The virtue of this approach is that it is a "lowest common denominator" which doesn't require any web server configuration or addition module installation. This script relies on a utility program called pooldump which is basically the program from my earlier post about dumping a pools configuration as an XML document. The script, xslt_proc, needs a little customization. Instructions are included at the top of the file.

Finally, you need a stylesheet, pool_html.xsl, which will perform the transformation. I don't claim to be an XSLT expert, so please be gentle with any suggestions for improvements that you might want to make. It's good enough for my needs and I hope that you might find it useful.I keep this in my cgi-bin directory so that I don't need to set an explicit path to it in the xslt_proc script, but you can put it anywhere you like as long as it can be accessed when your cgi-bin script runs.

You can download the cgi-bin script and stylesheet from here.

If you want to see what the HTML output looks like before spending any time on this, here is a sample page that I generated on my workstation.

(2004-06-10 02:16:26.0) Permalink

Generating an XML Document from a Resource Pools Configuration

XML is a convenient representation format for small quantities of data. There are many tools for manipulating XML documents and a lot of people are now familiar enough with the structure of XML to feel comfortable with this type of representation. Especially in preference to yet another problem domain specific data representation format (YAPDSDRF?).

libpool(3LIB) provides an API for manipulating Resource Pools configurations. In particular, the pool_conf_export(3POOL) function may be used to create a file containing the XML representation of a configuration.

pool_conf_export(3POOL) takes three arguments:

 conf - A valid pools configuration pointer
 location - The pathname you wish to write the configuration into
 format - This must be POX_NATIVE which is the native pools representation format 

It's not immediately obvious (and I say this with some shame since I defined this function) that POX_NATIVE == XML. Once you know that, it's fairly obvious how a program to dump a resource pools configuration in XML format can be written.

One further tip, you can pass "-" as the location and the output will be directed to stdout.

I'm sure that I don't need to say that the following program is completely unsupported and used at your peril, but I thought I would say it just to make it clear.


#include <pool.h>

/* ARGSUSED */
int
main(int argc, char **argv)
{
        pool_conf_t *conf;

        if ((conf = pool_conf_alloc()) == NULL) {
                return (2);
        }
        if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY) !=
            PO_SUCCESS) {
                pool_conf_free(conf);
                return (2);
        }

        if (pool_conf_export(conf, "-", POX_NATIVE) != PO_SUCCESS) {
                (void) pool_conf_close(conf);
                pool_conf_free(conf);
                return (2);
        }
        (void) pool_conf_close(conf);
        pool_conf_free(conf);
        return (0);
}

Once you have your configuration as an XML document you can manipulate it easily using a wide range of tools. In a later post, I'll show how you can use an XSL stylesheet to transform the XML document into an HTML document using the xsltproc(1) utility. (2004-06-10 01:00:48.0) Permalink Comments [1]


archives
Playlist
weekly chart
links
referers
News