4. Creating the Script

Our script should have two command line parameters. The first should be the path of the new application which should be installed on the group. The second one is the name of the group itself. Now we should find a way to parse those parameters in our script:

As you can see, we need a group with only JBossAS Server resource types as top level resources. Now "server" contains the JBossAS instance. But why are we re-reading the server? Because we need it fully populated. Internally, the CLI is using simple JPA persistence. And as you can imagine, it is necessary to not always fetch all dependant objects.

Next step is to traverse all the children of the server instance and find the resource name of our application:

You may wonder why I am surrounding the actual operation with a try / catch statement. This is currently due to a NullPointerException caused by the underlying API. But the server does what we want so it is save to ignore the exception.

5. Creating a new resource

So now we are able to update an existing application. But what happens if the server is new and does not already have the application deployed? This means, we need to use the CLI to create a new resource which will then be deployed to the JBoss Server.

Unfortunately, it is not that easy to create a new resource. The discussed approach does also only work for JBossAS Server instances and not for Tomcat servers. But changing this is should be easy.

We first need to get the resource type for the application. This depends on several paramters:

The type of the application (i.e. WAR or EAR)

The type of the container the app needs to be deployed on (Tomcat, JBoss AS etc.)

As you know, each resource in JON has some configuration parameters. The same is true for WARs or EARs deployed on a JBoss AS. In order to be able to create a new resource, we need to fill some parameters.

Please make sure that the given JBoss AS server instance is still running and that JON knows that it's running. Otherwise you'll get an Exception saying that the JON agent is not able to upload the binary content to the server.

That's it. Congratulations!

If you would like to have some more in deep knowledge of using the CLI, here's a link to a test script of the RHQ 1.3.GA release:

6. Conclusion

As you can see it is fairly easy to use the new scripting engine to automate many tasks of daily administration just by typing a few lines of JavaScript code into an editor.

The attached script can be used for own scripts. It was developed during a simple Proof Of Concept for a customer. The purpose was to show how the scripting engine JON 2.3 can be used and that it is possible to update 20 nodes of JBoss EAP in one go.