Adding Rules To XL-Deploy
XL-Deploy uses it's object model to determine it's deployment plan. For most applications this works fine. Sometimes we might want to take some extra steps during a deployment. Custom deployment steps can be created by defining these rules in the XL-Rules file. Sometimes we may want to dynamically create deployment steps depending on other information in the environment. As an example of this I will demonstrate how to dynamically create deployment steps with XL-Rules and a small Jython script.
For this example lets say we need to run a script at the beginning and end of our deployment. We only need to run this script if the infrastructure host has the "pretest" or "posttest" tags set. Furthermore, we only need to run the script once on each host. The first step is to define a rule in xl-rules.xmlThe <planning-script-path> tag defines the location of a Jython script that will dynamically create the deployment steps that should be added to the deployment plan. The path the script starts from is the <XLDeploy_HOME>/ext folder. Once this file is changed it is necessary to restart the XL-Deploy server for this change to take effect.
Out next step is do define the logic that determines when to add steps to the deployment plan.
I have defined the functions to help build our additional deployment steps. So our script defines the methods then calls update_hosts(). We pass a call to the getContainerListFromDeployedApplicaiton() method to get the unique list of containers we are deploying to. Then we can go through all of the containers checking for our tags. If we find the tag set we will add either the pretest step or the posttest step. For this example our script is the same for both. The script in this example is a Free Marker Template script. The result of this script adds some pre deploy steps as well as some post install steps as follows:
It is convenient to use this method for specialized load balancers or kicking off scripted testing from XL Deploy. You might even find other uses for this.
The code in this example can be found in my blog github repository as follows: