Chapter 15. Example: Scripting Resource Deployments (JBoss EAP 5)

A common use case for management tools is to automate deployments of new or existing applications. This example creates an easy script for basic management tasks:
  1. Find all JBoss EAP instances for a specified JBoss ON group.
  2. Shut down each EAP instance.
  3. Update binaries for existing deployed applications or create new deployments.
  4. Restart the EAP instance.
  5. End the loop.

15.1. Declaring Custom Functions

This script will use two custom functions to deploy the packages to create new resources.
function usage() {
	println("Usage: deployToGroup <fileName> <groupName>");
	throw "Illegal arguments";
}

function PackageParser(fullPathName) {
	var file = new java.io.File(fullPathName);
		
	var fileName = file.getName();
	var packageType = fileName.substring(fileName.lastIndexOf('.')+1);
	var tmp = fileName.substring(0, fileName.lastIndexOf('.'));
	var realName = tmp.substring(0, tmp.lastIndexOf('-'));
	var version = tmp.substring(tmp.lastIndexOf('-') + 1);			
	var packageName = realName + "." + packageType;
	
	this.packageType = packageType.toLowerCase();
	this.packageName = packageName;
	this.version     = version;
	this.realName    = realName;
}