27.5. Creating Ant Bundles
- An Ant recipe file named
deploy.xml
- Any associated application files. These application files can be anything; commonly, they fall into two categories:
- Archive files (JAR or ZIP files)
- Raw text configuration files, which can include tokens where users define the values when the bundle is deployed
27.5.1. Supported Ant Versions
Software | Version |
---|---|
Ant | 1.8.0 |
Ant-Contrib | 1.0b3 |
27.5.2. Additional Ant References
Ant Information Resources
- Apache Ant Documentation Main Page
- Ant Build File Documentation
- Liquibase Database Schema Tasks
- Ant-Contrib Documentation
27.5.3. Breakdown of an Ant Recipe
deploy.xml
.
Example 27.1. Simple Ant Recipe
deploy.xml
file simply identifies the file as an an script and references the provisioning Ant elements.
<project name="test-bundle" default="main" xmlns:rhq="antlib:org.rhq.bundle">
<rhq:bundle name="Example App" version="2.4" description="an example bundle">
port
token defined in Section 27.5.5, “Using Templatized Configuration Files”, the <rhq:input-property> element identifies it in the recipe. The name
argument is the input_field value in the token, the description
argument gives the field description used in the UI and the other arguments set whether the value is required, what its allowed syntax is, and any default values to supply. (This doesn't list the files which use tokens, only the tokens themselves.)
<rhq:input-property name="listener.port" description="This is where the product will listen for incoming messages" required="true" defaultValue="8080" type="integer"/>
<rhq:deployment-unit name="appserver" preinstallTarget="preinstall" postinstallTarget="postinstall" compliance="filesAndDirectories">
/home/.rhqdeployments/
resourceID/backup
.
name
is the name of the configuration file within the bundle, while the destinationFile is the relative (to the deployment directory) path and filename of the file after it is deployed.
<rhq:file name="test-v2.properties" destinationFile="conf/test.properties" replace="true"/>
- Identify the archive file by name.
- Define how to handle the archive. Simply put, it sets whether to copy the archive over to the destination and then leave it as-is, still as an archive, or whether to extract the archive once it is deployed. This is called exploding the archive. If an archive is exploded, then a postinstall task can be called to move or edit files, as necessary.
- Identify any files within the archive which contain tokens that need to be realized. This is a child element, <rhq:fileset>. This can use wildcards to include types of files or files within subdirectories or it can explicitly state which files to process.
<rhq:archive name="MyApp.zip" exploded="true"> <rhq:replace> <rhq:fileset> <include name="**/*.properties"/> </rhq:fileset> </rhq:replace> </rhq:archive>
*.log
files within the logs/
directory are saved.
<rhq:ignore> <rhq:fileset> <include name="logs/*.log"/> </rhq:fileset> </rhq:ignore> </rhq:deployment-unit> </rhq:bundle>
<target name="main" /> <target name="preinstall"> <echo>Deploying Test Bundle v2.4 to ${rhq.deploy.dir}...</echo> <property name="preinstallTargetExecuted" value="true"/> <rhq:audit status="SUCCESS" action="Preinstall Notice" info="Preinstalling to ${rhq.deploy.dir}" message="Another optional message"> Some additional, optional details regarding the deployment of ${rhq.deploy.dir} </rhq:audit> </target> <target name="postinstall"> <echo>Done deploying Test Bundle v2.4 to ${rhq.deploy.dir}.</echo> <property name="postinstallTargetExecuted" value="true"/> </target> </project>
27.5.4. Using Ant Tasks
deploy.xml
file with some JBoss ON-specific elements. An Ant bundle distribution file supports more complex Ant configuration, including Ant tasks and targets.
27.5.4.1. Supported Ant Tasks
deploy.xml
file, which loops back to the file, which calls the <antcall> task again, which calls the deploy.xml
file again. This creates an infinite loop.
- See Section 27.5.2, “Additional Ant References” for links to comprehensive Ant-Contrib resources.
27.5.4.2. Using Default, Pre-Install, and Post-Install Targets
<target name="main" />
27.5.4.3. Calling Ant Targets
- In
deploy.xml
for the Ant recipe, add a <rhq:deployment-unit> element which identifies the Ant target.<rhq:deployment-unit name="jar" postinstallTarget="myExampleCall">
- Then, define the target.
<target name="myExampleCall"> <ant antfile="another.xml" target="doSomething"> <property name="param1" value="111"></property> </ant> </target>
- Create a separate
another.xml
file in the same directory as thedeploy.xml
file. This file contains the Ant task.<project name="another" default="main"> <target name="doSomething"> <echo>inside doSomething. param1=${param1}</echo> </target> </project>
27.5.5. Using Templatized Configuration Files
input_field=@@property@@
port=@@listener.port@@
<rhq:input-property name="listener.port" ... />
Figure 27.3. Port Token During Provisioning
Token | Description |
---|---|
rhq.deploy.dir | The directory location where the bundle will be installed. |
rhq.deploy.id | A unique ID assigned to the specific bundle deployment. |
rhq.deploy.name | The name of the bundle deployment. |
@@rhq.system.hostname@@
Token Name | Taken From... | Java API |
---|---|---|
rhq.system.hostname | Java API | SystemInfo.getHostname() |
rhq.system.os.name | Java API | SystemInfo.getOperatingSystemName() |
rhq.system.os.version | Java API | SystemInfo.getOperatingSystemVersion() |
rhq.system.os.type | Java API | SystemInfo.getOperatingSystemType().toString() |
rhq.system.architecture | Java API | SystemInfo.getSystemArchitecture() |
rhq.system.cpu.count | Java API | SystemInfo.getNumberOfCpus() |
rhq.system.interfaces.java.address | Java API | InetAddress.getByName(SystemInfo.getHostname()).getHostAddress() |
rhq.system.interfaces.network_adapter_name.mac | Java API | NetworkAdapterInfo.getMacAddress() |
rhq.system.interfaces.network_adapter_name.type | Java API | NetworkAdapterInfo.getType() |
rhq.system.interfaces.network_adapter_name.flags | Java API | NetworkAdapterInfo.getAllFlags() |
rhq.system.interfaces.network_adapter_name.address | Java API | NetworkAdapterInfo.getUnicastAddresses().get(0).getHostAddress() |
rhq.system.interfaces.network_adapter_name.multicast.address | Java API | NetworkAdapterInfo.getMulticastAddresses().get(0).getHostAddress() |
rhq.system.sysprop.java.io.tmpdir | Java system property | |
rhq.system.sysprop.file.separator | Java system property | |
rhq.system.sysprop.line.separator | Java system property | |
rhq.system.sysprop.path.separator | Java system property | |
rhq.system.sysprop.java.home | Java system property | |
rhq.system.sysprop.java.version | Java system property | |
rhq.system.sysprop.user.timezone | Java system property | |
rhq.system.sysprop.user.region | Java system property | |
rhq.system.sysprop.user.country | Java system property | |
rhq.system.sysprop.user.language | Java system property |
27.5.6. Processing JBoss ON Properties and Ant Properties
27.5.7. Limits and Considerations for Ant Recipes
27.5.7.1. Unsupported Ant Tasks
- <antcall> (instead, use <ant> to reference a separate XML file in the bundle which contains the Ant targets)
- <macrodef> and macro definitions
27.5.7.2. Symlinks
<untar src="abc.tar.gz" compression="gzip" dest="somedirectory"/>
27.5.7.3. WARNING: The Managed (Target) Directory and Overwriting or Saving Files
- The file in the current directory is also in the bundle. In this case, the bundle file always overwrites the current file. (There is one exception to this. If the file in the bundle has not been updated and is the same version as the local file, but the local file has modifications. In that case, the local file is preserved.)
- The file in the current directory does not exist in the bundle. In that case, the bundle deletes the file in the current directory.
compliance
All of the information about the application being deployed is defined in the <rhq:deployment-unit> element in a bundle recipe. The compliance attribute on the <rhq:deployment-unit> element sets how the provisioning process should handle existing files in the deployment directory.
/home/.rhqdeployments/
resourceID/backup
.
<rhq:ignore>
There can be files that are used or created by an application, apart from the bundle, which need to be preserved after a bundle deployment. This can include things like log files, instance-specific configuration files, or user-supplied content like images. These files can be ignored during the provisioning process, which preserves the files instead of removing them.
<rhq:ignore> <rhq:fileset> <include name="logs/*.log"/> </rhq:fileset> </rhq:ignore>
Clean Deployment
Both compliance and <rhq:ignore> are set in the recipe. At the time that the bundle is actually provisioned, there is an option to run a clean deployment. The clean deployment option deletes everything in the deployment directory and provisions the bundle in a clean directory, regardless of the compliance and <rhq:ignore> settings in the recipe.
27.5.8. A Reference of JBoss ON Ant Recipe Elements
27.5.8.1. rhq:bundle
Attribute | Description | Optional or Required |
---|---|---|
name | The name given to the bundle. | Required |
version | The version string for this specific bundle. Bundles can have the same name, but each bundle of that name must have a unique version string. These version strings normally conform to an OSGi style of versioning, such as 1.0 or 1.2.FINAL. | Required |
description | A readable description of this specific bundle version. | Optional |
Example 27.2. rhq:bundle
<rhq:bundle name="example" version="1.0" description="an example bundle">
27.5.8.2. rhq:input-property
Attribute | Description | Optional or Required |
---|---|---|
name | The name of the user-defined property. Within the recipe, this property can be referred to by this name, in the format ${property_name}. | Required |
description | A readable description of the property. This is the text string displayed in the JBoss ON bundle UI when the bundle is deployed. | Required |
type |
Sets the syntax accepted for the user-defined value. There are several different options:
| Required |
required | Sets whether the property is required or optional for configuration. The default value is false, which means the property is optional. If this argument isn't given, then it is assumed that the property is optional. | Optional |
defaultValue | Gives a value for the property to use if the user does not define a value when the bundle is deployed. | Optional |
Example 27.3. rhq:input-property
<rhq:input-property name="listener.port" description="This is where the product will listen for incoming messages" required="true" defaultValue="8080" type="integer"/>
27.5.8.3. rhq:deployment-unit
Attribute | Description | Optional or Required |
---|---|---|
name | The name of the application. | Required |
compliance |
Sets whether JBoss ON should manage all files in the top root directory (deployment directory) where the bundle is deployed. If filesAndDirectories, any unrelated files found in the top deployment directory (files not included in the bundle) are ignored and will not be overwritten or removed when future bundle updates are deployed. The default is full, which means that the provisioning process manages all files and directories and removes or overwrites anything not in the bundle.
Any existing content in the root directory is backed up before it is deleted, so it can be restored later. The backup directory is
/home/.rhqdeployments/ resourceID/backup .
| Optional |
preinstallTarget | An Ant target that is invoked before the deployment unit is installed. | Optional |
postinstallTarget | An Ant target that is invoked after the deployment unit is installed. | Optional |
Example 27.4. rhq:deployment-unit
<rhq:deployment-unit name="appserver" preinstallTarget="preinstall" postinstallTarget="postinstall">
27.5.8.4. rhq:archive
Attribute | Description | Optional or Required |
---|---|---|
name |
The filename of the archive file to include in the bundle.
Important
If the archive file is packaged with the Ant recipe file inside the bundle distribution ZIP file, then the name must contain the relative path to the location of the archive file in the ZIP file.
| Required |
exploded | Sets whether the archive's contents will be extracted and stored into the bundle destination directory (true) or whether to store the files in the same relative directory as is given in the name attribute (false). If the files are exploded, they are extracted starting in the deployment directory. Post-install targets can be used to move files after they have been extracted. | Optional |
destinationDir | The directory where this archive or its exploded results are to be copied. If this is a relative path, it is relative to the deployment directory given by the user when the bundle is deployed. If this is an absolute path, that is the location on the filesystem where the file will be copied. This attribute sets the directory for the file to be copied to. The actual file name is set in the name attribute. | Optional |
Example 27.5. rhq:archive
<rhq:archive name="file.zip"> <rhq:replace> <rhq:fileset> <include name="**/*.properties"/> </rhq:fileset> </rhq:replace> </rhq:archive>
See Also
27.5.8.5. rhq:url-archive
rhq:archive
except that the server accesses the archive over the network rather than including the archive directly in the bundle distribution file.
Attribute | Description | Optional or Required |
---|---|---|
url |
Gives the URL to the location of the archive file. The archive is downloaded and installed in the deployment directory.
Note
For the bundle to be successfully deployed, the URL must be accessible to all agent machines where this bundle is to be deployed. If an agent cannot access the URL, it cannot pull down the archive and thus cannot deploy it on the machine.
| Required |
exploded | If true, the archive's contents will be extracted and stored into the bundle destination directory; if false, the zip file will be compressed and stored in the top level destination directory.
Note
If the files are exploded, they are extracted starting in the deployment directory. Post-install targets can be used to move files after they have been extracted.
| Optional |
destinationDir | The directory where this archive or its exploded results are to be copied. If this is a relative path, it is relative to the deployment directory given by the user when the bundle is deployed. If this is an absolute path, that is the location on the filesystem where the file will be copied. This attribute sets the directory for the file to be copied to. The actual file name is set in the name attribute. | Optional |
Example 27.6. rhq:url-archive
<rhq:url-archive url="http://server.example.com/apps/files/archive.zip"> <rhq:replace> <rhq:fileset> <include name="**/*.properties"/> </rhq:fileset> </rhq:replace> </rhq:url-archive>
See Also
27.5.8.6. rhq:file
Attribute | Description | Optional or Required |
---|---|---|
name |
The name of the raw configuration file.
Important
If the configuration file is packaged with the Ant recipe file inside the bundle distribution ZIP file, then the name must contain the relative path to the location of the file within the ZIP file.
| Required |
destinationFile |
The full path and filename for the file on the destination resource. Relative paths must be relative to the final deployment directory (defined in the
rhq.deploy.dir parameter when the bundle is deployed). It is also possible to use absolute paths, as long as both the directory and the filename are specified.
Note
If the destinationDir attribute is used, the destinationFile attribute cannot be used.
| Required, unless destinationDir is used |
destinationDir |
The directory where this file is to be copied. If this is a relative path, it is relative to the deployment directory given by the user when the bundle is deployed. If this is an absolute path, that is the location on the filesystem where the file will be copied.
This attribute sets the directory for the file to be copied to. The actual file name is set in the
name attribute.
If the
destinationFile attribute is used, the destinationDir attribute cannot be used.
| Required, unless destinationFile is used |
replace | Indicates whether the file is templatized and requires additional processing to realize the token values. | Required |
Example 27.7. rhq:file
<rhq:file name="test-v2.properties" destinationFile="subdir/test.properties" replace="true"/>
destinationDir
nor the destinationFile
attribute is used, then the raw file is placed in the same location under the deployment directory as its location in the bundle distribution.
27.5.8.7. rhq:url-file
rhq:file
, contains the information to identify and process configuration files for the application which have token values that must be realized. This option specifies a remote file which is downloaded from the given URL, rather than being included in the bundle archive.
Attribute | Description | Optional or Required |
---|---|---|
url |
Gives the URL to the templatized file. The file is downloaded and installed in the deployment directory.
Note
For the bundle to be successfully deployed, the URL must be accessible to all agent machines where this bundle is to be deployed. If an agent cannot access the URL, it cannot pull down the archive and thus cannot deploy it on the machine.
| Required |
destinationFile |
The full path and filename for the file on the destination resource. Relative paths must be relative to the final deployment directory (defined in the
rhq.deploy.dir parameter when the bundle is deployed). It is also possible to use absolute paths, as long as both the directory and the filename are specified.
Note
If the destinationDir attribute is used, the destinationFile attribute cannot be used.
This attribute must give both the path name and the file name.
| Required, unless destinationDir is used |
destinationDir |
The directory where this file is to be copied. If this is a relative path, it is relative to the deployment directory given by the user when the bundle is deployed. If this is an absolute path, that is the location on the filesystem where the file will be copied.
This attribute sets the directory for the file to be copied to. The actual file name is set in the
name attribute.
If the
destinationFile attribute is used, the destinationDir attribute cannot be used.
| Required, unless destinationFile is used |
replace | Indicates whether the file is templatized and requires additional processing to realize the token values. | Required |
Example 27.8. rhq:url-file
<rhq:url-file url="http://server.example.com/apps/files/test.conf" destinationFile="subdir/test.properties" replace="true"/>
destinationDir
nor the destinationFile
attribute is used, then the raw file is placed in the same location under the deployment directory as its location in the bundle distribution.
27.5.8.8. rhq:property
Attribute | Description | Optional or Required |
---|---|---|
relativeToDeployDir
|
Only applicable if the file attribute is also used and is a relative path.
Defaults to false.
If true, the file is resolved against the deploy directory of the bundle instead of the working directory from which the bundle deployment is executed.
|
Optional
|
27.5.8.9. rhq:audit
rhq:audit
configuration sends information to the server about the additional processing steps and their results.
Attribute | Description | Optional or Required |
---|---|---|
status | The status of the processing. The possible values are SUCCESS, WARN, and FAILURE. The default is SUCCESS. | Optional |
action | The name of the processing step. | Required |
info | A short summary of what the action is doing, such as the name of the target of the action or an affected filename. | Optional |
message | A brief text string which provides additional information about the action. | Optional |
Example 27.9. rhq:audit
<rhq:audit status="SUCCESS" action="Preinstall Notice" info="Preinstalling to ${rhq.deploy.dir}" message="Another optional message"> Some additional, optional details regarding the deployment of ${rhq.deploy.dir} </rhq:audit>
27.5.8.10. rhq:replace
Example 27.10. Example
<rhq:archive name="file.zip"> <rhq:replace> <rhq:fileset> <include name="**/*.properties"/> </rhq:fileset> </rhq:replace> </rhq:archive>
27.5.8.11. rhq:ignore
/opt/myapp
and Bundle B to /opt/myapp/webapp1
).
Example 27.11. rhq:ignore
<rhq:ignore> <rhq:fileset> <include name="logs/*.log"/> </rhq:fileset> </rhq:ignore>
27.5.8.12. rhq:fileset
Child Element | Description |
---|---|
<include name=filename /> | The filename of the file. For <rhq:replace>, this is a file within the archive (JAR or ZIP) file which is templatized and must have its token values realized. For <rhq:ignore>, this is a file in the application's deployment directory which should be ignored and preserved when the bundle is upgraded. |
Example 27.12. rhq:fileset
<rhq:replace> <rhq:fileset> <include name="**/*.properties"/> </rhq:fileset> </rhq:replace>
27.5.8.13. rhq:system-service
Attribute | Description | Optional or Required |
---|---|---|
name | The name of the script. | Required |
scriptFile | The filename of the script. If the script file is packaged with the Ant recipe file inside the bundle distribution ZIP file, then the scriptFile must contain the relative path to the location of the file in the ZIP file. | Required |
configFile | The name of any configuration or properties file used by the script. If the configuration file is packaged with the Ant recipe file inside the bundle distribution ZIP file, then the configFile must contain the relative path to the location of the file in the ZIP file. | Optional |
overwriteScript | Sets whether to overwrite any existing init file to configure the application as a system service. | Optional |
startLevels | Sets the run level for the application service. | Optional |
startPriority | Sets the start order or priority for the application service. | Optional |
stopPriority | Sets the stop order or priority for the application service. | Optional |
Example 27.13. rhq:system-service
<rhq:system-service name="example-bundle-init" scriptFile="example-init-script" configFile="example-init-config" overwriteScript="true" startLevels="3,4,5" startPriority="80" stopPriority="20"/>
27.5.8.14. rhq:handover
Attribute | Description | Optional or Required |
---|---|---|
action | The name of the action the target resource component should execute. | Required |
failonerror | Whether the ANT recipe build should fail if the target resource component reports a failure. true or false. Defaults to true. | Optional |
- <rhq:file>
- <rhq:url-file>
- <rhq:archive>
- <rhq:url-archive>
Example 27.14. rhq:handover
<rhq:file name="prepareDatasource.cli" replace="true"> <rhq:handover action="execute-script" failonerror="false"/> </rhq:file> <rhq:archive name="website.war"> <rhq:handover action="deployment"> <rhq:handover-param name="runtimeName" value="${myapp.runtime.name}"/> <rhq:handover-param name="serverGroup" value="${server.group}"/> </rhq:handover> </rhq:archive>
prepareDatasource.cli
file content will always be handed over to the target resource component before the website.war
archive content.
See Also
27.5.8.15. rhq:handover-param
Attribute | Description | Optional or Required |
---|---|---|
name | The name of the parameter | Required |
value | The name of the value. | Required |
rhq:handover-param
child tags.
Example 27.15. rhq:handover-param
<rhq:file name="prepareDatasource.cli" replace="true"> <rhq:handover action="execute-script" failonerror="false"/> </rhq:file> <rhq:archive name="website.war"> <rhq:handover action="deployment"> <rhq:handover-param name="runtimeName" value="${myapp.runtime.name}"/> <rhq:handover-param name="serverGroup" value="${server.group}"/> </rhq:handover> </rhq:archive>