Wednesday, July 14, 2010

Simple Bundle generator for RHQ provisioning feature

So in RHQ 3 we've added this cool new provisioning feature.
This allows you to deploy a bundle to a group of platforms or other resources like e..g JBossAS servers.

So what is a bundle? Basically it is some piece of software to be deployed and a matching recipe file. There are two kinds of recipe files: FileTemplateBundle and AntBundle - I'll only talk about the ant-style recipes here.

When I started looking at the bundle UI, I remembered Mazz' great video, but being on the train, I had no access to it. So how do I deploy?
First thing you need to have is either a valid bundle distribution file or at least a valid recipe file.

A bundle distribution file is (by default) a zip file where all entries lie directly in the root directory like this (actually other is possible):

$ unzip -l
Length Date Time Name
-------- ---- ---- ----
1150 07-12-10 16:27 demo.war
948 07-12-10 16:38 deploy.xml
-------- -------
2098 2 files

In the bundle I have demo.war to provision and the deploy.xml file as recipe. Lets have a look at the recipe file:

<?xml version="1.0"?>
<project name="demo" default="main"
<rhq:bundle name="demo" version="1.0"
description="Just some bundle">
description="Who do we greet?"
<rhq:deployment-unit name="war">
<rhq:archive name="demo.war">
<include name="*.jsp"/>
<target name="main"/>

Some of you will see that this is an ant file with some extra tags in the rhq namespace. Lets go through the sections.

First is the boilerplate code that defines an ant project and then
within that we see one bundle denoted by the <rhq:bundle> tag. The bundle has a name of demo and is at version 1.0.

Next there is an <rhq:input-property> tag which defines that the deploy UI should ask for a property which may be used to replace tokens by the users input. This input-property is optional and can show up multiple times.

The most important part is the <rhq:deployment-unit> tag, which defines the content to deploy in its embedded <archive> tag - demo.war in our case. And then we have a <rhq:replace> element embedded in this which defines a standard ant fileset that defines files in which token replacements can occur, like .jsp files in our example.

While this recipe file is not complicated, it still needs some typing, so I started writing a bundle generator, which is in RHQ 4 master in modules/helpers/bundleGen/ (actually you can use that to define bundles for RHQ 3)

Using the bundle generator

$ java -jar bundleGen-4.0.0-SNAPSHOT-jar-with-dependencies.jar
Please give the project name[myProject]:
Please give the bundle name: demoBundle
Please specify the bundle version[1.0]:
Please describe your bundle: Just testing
Please give the name (only) of your bundle content file: demo.war
Please give the directory (only) of your bundle content file: /tmp/
Please give a patten of files to replace templates: *.jsp
Jul 14, 2010 9:24:31 AM org.rhq.helpers.bundleGen.BundleGen createFile
INFO: Trying to generate /var/folders/m9/m9pXAK2WHoyq22G2P9J8L++++TI/-Tmp-//bundleGen/deploy.xml
Jul 14, 2010 9:24:31 AM org.rhq.helpers.bundleGen.BundleGen run
INFO: Your bundle is now ready in [/tmp/]

So this is asking some questions - those with [text] have this text as default, so you can just press return to accept it.

When the generator has finished it prints where you can obtain the created bundle from - /tmp/ in our case.

The generator is far from finished; for example there is no way to specify <rhq:input-property> tags so far.


One interesting detail is the XmlQuestionsReader which takes input from an XML file about the questions to ask. It partially supports internationalization in the form that you can have basename_lang.xml variants of the input, as you can see here. I am not yet exactly happy with this, as there is no fallback to the default version if a question is not defined.

Also there is no way yet to tell that a certain <question> can be repeated to form a List/Set (as it would be needed for the <rhq:input-property> tags).

So please give me feedback and if you want to help improving the generator, you are free to do so.


Anonymous said...

To what problem is this the answer?

Heiko W. Rupp said...

this is a good question.

The issue is that to use the new provisioning feature, you need to wrap the stuff to deploy in a so called bundle. This is the file to deploy plus a file that gives metadata to the deployment.

Creating this bundle by hand is somewhat tedious, so I've started writing that generator to help creating bundles. In future versions of RHQ, this might even be integrated in the UI, but for the start it is standalone.

Maciej Swiderski said...

are there any plans to provide maven plugin to generate bundle while building a project? or shall maven assembly be used for such scenario?