Red Hat Training
A Red Hat training course is available for Red Hat JBoss Operations Network
Writing Custom Plug-ins
Guidelines for Writing Custom Server and Agent Resource Plug-ins
Abstract
Chapter 1. An Overview of JBoss ON Plug-ins
1.1. Extending JBoss ON: Plug-ins Defined
Figure 1.1. JBoss ON Architecture

- Every plug-in is packaged as a JAR file.
- Every plug-in has a required XML file, the plug-in descriptor, which defines all of the plug-in capabilities.
- Every plug-in contains compiled Java files which contain the code necessary to perform all of the actions defined in the descriptor.
- Plug-ins run inside a plug-in container, which is the entity that directly interacts with the plug-ins and starts and stops all plug-ins.
- All custom plug-ins are deployed to the JBoss ON server. Server-side plug-ins are propagated across the high availability cloud to all of the other servers, while agent plug-ins are made available through the server for the agents to download.
1.2. Basic Components of Plug-ins in JBoss ON
1.2.1. Plug-in Containers
1.2.2. Plug-in Descriptor
META-INF/
directory in the JAR file of the plug-in. For server-side plug-ins, this file must be named rhq-serverplugin.xml
, and for agent plug-ins, rhq-plugin.xml
.
1.2.3. Plug-in Schema Definitions
rhq-configuration.xsd
. Server-side plug-ins extend that schema with an additional schema definition file, rhq-serverplugin.xsd
, and then custom schema definitions for each server-side plug-in type.
1.2.4. Java Files
- Agent plug-ins can define both parent and children elements (platforms, servers, and services) in the same plug-in, and each resource type uses its own plug-in code.
- Agent plug-ins have two and sometimes three discrete functions. Almost every agent plug-in must have a discovery component (discovery Java file) that dictates how to identify and inventory whatever resource type is defined by the plug-in. Additionally, agent plug-ins may enable event collection for resources, which requires a separate component (event poller Java file) to track the resource logs. Last, there has to be a component (Java file) which actually implements the plug-in functionality.
- Agent plug-ins allow dependencies. Parent plug-ins can share classes with their children. An agent plug-in can set a dependency on any other agent plug-in that allows it to load that plug-ins classes. To make plug-ins perform better and to make it easier to access the relevant plug-in code, agent plug-ins are frequently broken into smaller Java files to allow the plug-in code to be reused.
1.2.5. External Libraries
lib/
directory within the JAR file.
1.3. Downloading the Plug-in Files
git clone http://git.fedorahosted.org/git/rhq/rhq.git
/etc/samples/
directory. These include both fully-developed examples and plug-in templates that can be used for writing new plug-ins. Rather than checking out the entire source code, you can manually download the sample files at this URL:
http://git.fedorahosted.org/git/?p=rhq/rhq.git;a=tree;f=etc/samples;hb=master
Chapter 2. Writing Server-Side Plug-ins: Background
2.1. An Intro to Server-Side Plug-ins
- Alert sender plug-ins for methods to send alert notifications for resources
- Bundle plug-ins for deploying files and application
- Drift plug-ins for monitoring resource or filesystem configuration and files
- Content plug-ins for managing resource configurations
- Generic plug-ins for everything else
- Once the server-side plug-in is built and deployed, the plug-in is a JAR file with a
META-INF/
directory which contains therhq-serverplugin.xml
plug-in descriptor. - Each plug-in is independent of every other plug-in. Unlike agent plug-ins, server-side plug-ins do not interact with each other. There are no plug-in dependencies for server-side plug-ins.
Figure 2.1. Server-Side Plug-in Containers

Table 2.1. Available Plug-in Containers
Plug-in Type | Description | Container Name |
---|---|---|
Generic | Catch-all type for any custom plug-ins. This type of plug-in only interacts with the plug-in container for the container to start and stop the plug-in and to initialize and shutdown the plug-in libraries. | Generic Plugin |
Alert methods | Defines an alert notification method, or the way that an alert is sent. | AlertHandler |
Bundle | Defines and processes a type of bundle. This type of plug-in performs tasks that the core server needs to process and manage bundles of specific bundle types, such as Ant recipes or file-based bundles. Each bundle server plug-in knows about and can process a single bundle type. | Bundle Plugin |
Drift | Processes drift operations and configuration. This stores and retrieves content (files) being managed for drift detection and remediation. | Drift JPA Plugin |
Content | Contains metadata for a a repository or a group of repositories. | PackageSource |
Repository (also Package) | Defines a content repository. Plug-ins can define a single repository,which is then used for provisioning, entitlements, and updates for JBoss ON-managed resources. | ChannelSource |
2.2. The Breakdown of Server-Side Plug-in Configuration
.jar
files.The directory structure, libraries, and classes used by those .jar
files is completely up to the discretion and requirements of the plug-in writer, with only one requirement: All plug-in .jar
files must have a plug-in descriptor file, META-INF/rhq-serverplugin.xml
.
org.rhq.enterprise.server.plugin.pc.ServerPluginComponent
class. This controls the lifecycle of the plug-in within the container.
- An XML file which functions as the plug-in's descriptor
- Java files which pull in the descriptor information and implement the classes for the plug-in.
- Optional library dependencies. Any third-party libraries must be stored in the plug-in JAR file's
lib/
directory.
2.2.1. Descriptor and Configuration
rhq-serverplugin.xml
file in the META-INF/
directory in the plug-in's JAR file. (Default server-side plug-ins follow this same configuration.) This file is required.
MANIFEST.MF
file.
- Scheduling actions periodically or using cron schedules
- Setting global parameters for all instances of a specific plug-in type
- Allowing local or instance-specific configuration for a plug-in type
2.2.1.1. Definitions and Classes
Example 2.1. Plug-in Descriptor: Definition
<alert-plugin name="alert-email" displayName="Alert:Email" xmlns="urn:xmlns:rhq-serverplugin.alert" xmlns:c="urn:xmlns:rhq-configuration" xmlns:serverplugin="urn:xmlns:rhq-serverplugin" package="org.rhq.enterprise.server.plugins.alertEmail" description="Alert sender plugin that sends alert notifications via email" version="1.0" >
org.rhq.enterprise.server.plugin.pc.ServerPluginComponent
class, which provides simple lifecycle management for the plug-in. This component provides the hook for the container to initialize, start, stop, and shut down the plug-in. When a plug-in is initialized, it is given a server plug-in context that provides information about the runtime environment of the plug-in.
- Using the <plugin-component> tag to specify the class (this is available to every type of plug-in)
- Using a user-defined tag to identify the class (this is available to some types of server-side plug-ins, depending on the available schema for the plug-in container)
Example 2.2. Plug-in Descriptor: Class Info
<serverplugin:plugin-component class="MyLifecycleListener" />
<plugin-class>RolesSender</plugin-class>
2.2.1.2. Control Operations
ServerPluginComponent
class can optionally implement the ControlFacet interface. These control operations can then be invoked directly in the JBoss ON web interface, in the plug-in configuration area.
Example 2.3. Control Operation Configuration
<serverplugin:plugin-component class="MyLifecycleListener"> <serverplugin:control name="testControl" description="A test control operation"> <serverplugin:parameters> <c:simple-property name="paramProp" required="true" description="Set to 'fail' to simulate an error"/> </serverplugin:parameters> <serverplugin:results> <c:simple-property name="resultProp" required="false"/> </serverplugin:results> </serverplugin:control> </serverplugin:plugin-component>
2.2.1.3. Scheduling Jobs
ScheduledJobInvocationContext
component.
- A job class can be stateless (meaning each job class is instantiated for each job invocation) or it can be stateful by invoking the plug-in component instance.NOTEAny server-side plug-in can define a plug-in component to act as the lifecycle listener for the plug-in. Using a plug-in component is extremely useful; in fact, it is the only mechanism for a Generic server-side plug-in to connect with the core server.
- A job can be concurrent, meaning more than one invocation can be performed at any one time on any number of servers (including on the same server). If a job is not concurrent, that means one and only one job invocation can be performed at any time. (If a job is not concurrent and is not clustered, then only one job invocation can be performed anywhere in the JBoss ON server cloud).
- A job can be clustered, meaning the job can be run from any server in the JBoss ON server cloud. If a job is not clustered, the job always runs on the machine where the job was scheduled. This works in conjunction with the concurrent setting.
- The schedule can be either periodic (such as running every hour) or recurring on a pattern (such as every Monday at 5pm).
- There can be multiple jobs scheduled for the same plug-in, each in its own <map-property> under the plug-in's <scheduled-jobs> entry.
Example 2.4. Plug-in Descriptor: Scheduled Jobs
<serverplugin:scheduled-jobs> <!-- notice that we use the map name as the methodName --> <c:map-property name="myScheduledJobMethod1"> <c:simple-property name="enabled" type="boolean" required="true" default="true" summary="true" description="Whether or not the job should be scheduled"/> <c:simple-property name="scheduleType" type="string" required="true" default="cron" summary="true" description="Indicates when the schedule triggers"> <c:property-options> <c:option value="periodic"/> <c:option value="cron" default="true"/> </c:property-options> </c:simple-property> <c:simple-property name="scheduleTrigger" type="string" required="true" default="0 0/5 * * * ?" summary="true" description="Based on the schedule type, this is either the period, in milliseconds, or the cron expression"/> <c:simple-property name="concurrent" type="boolean" required="false" default="false" summary="true" description="Whether or not the job can be run multiple times concurrently"/> <c:simple-property name="clustered" type="boolean" required="false" default="true" summary="true" description="Whether or not the job can be run anywhere in the JBoss ON server cluster, or if it must be run on the server where the job was schedule."/> </c:map-property> </serverplugin:scheduled-jobs>
2.2.1.3.1. States for Jobs
Example 2.5. Stateless Job Configuration
<c:map-property name="statelessJob1" description="invokes a stateless job class but given a job context"> <c:simple-propertyname="class"
type="string" required="true" readOnly="true" default="MyScheduledJob" summary="true" /> <c:simple-propertyname="methodName"
type="string" required="true" readOnly="true" default="executeWithContext" summary="true" /> </c:map-property>
- A method name for the job to invoke. For stateful jobs, the target method is in the plug-in component; for stateless jobs, it is in the class specified with the class property. Either way, the method name tells the server what to call. A default method is already defined in the plug-in component, and stateful jobs can call on that without having a specific method name property.
<c:simple-property
name="methodName"
type="string" required="true" readOnly="true" default="executeWithContext" summary="true" />Any method must either have no arguments or have a single argument of the typeScheduledJobInvocationContext
. - A setting showing whether the job is enabled.
<simple-property name="enabled" type="boolean" ... />
- A schedule type showing whether it's a periodic or cron job. The type of job is identified in the option which is set to true. For example:
<simple-property name="scheduleType" ... default="periodic" ... > <c:property-options> <c:option value="periodic" default="true"/> <c:option value="cron" /> </c:property-options> </c:simple-property>
- The actual schedule for when to run the job (the "trigger"), which can be a time period or a cron schedule. For a periodic job, this gives a time interval, in milliseconds:
<simple-property name="scheduleTrigger" type="string" required="true" default="60000" ... />
For a cron job, the default argument contains the full cron expression:<simple-property name="scheduleTrigger" type="string" required="true" default="0 0/5 * * * ?" ... />
(A full description of the cron schedule format is at http://www.quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/tutorial-lesson-06.html.) - A setting on whether the job is concurrent (meaning, whether this job can be running multiple times on more than one server or at the same time). If this is false, so that only one instance of the job can be running at a time, then even if multiple servers are scheduled to run the job, it will only run on one of them.
<simple-property name="concurrent" type="boolean" ... />
- A job can allow a setting on whether it runs anywhere in the JBoss ON server cloud or if it must be run on the same machine where the job was scheduled. Setting the cluster value to true allows the job to be called from any server in the JBoss ON cloud, so the job is clustered. This value should be false if the job must be run on all machines on schedule. Since all plug-ins are registered on all servers automatically, a non-clustered job will run on each server, independently.
<simple-property name="clustered" type="boolean" default="true" ... />
- A job can optionally contain custom strings which accept callback data.
<simple-property name="custom1" type="boolean" required="true" default="true" summary="true" description="A custom boolean for callback data"/>
Callback data can be of any type — boolean, string, long, or whatever else is appropriate for the job being performed. - Stateless jobs have a property that passes the method name of the class. The method name can identify the class that is called in the plug-in component or, alternatively, it can call a class to instantiate when the job is invoked. Both the method and the class keys are shown in Example 2.5, “Stateless Job Configuration”. Whatever class is used as the target, it must have the method defined in the method name simple property.Typically, the class isn't specified because the job will target the stateful plug-in component. The class property allows the option of writing a stateless job, however.
2.2.1.3.2. Concurrent and Clustered Jobs
scheduleTrigger
setting). Where and how a job is run is determined by two settings: concurrent and clustered.
Table 2.2. Comparison of Concurrent and Clustered Behavior
Concurrent | Clustered | When the schedule is triggered... |
---|---|---|
true | true | ... the job will always be invoked. It may be invoked on any server in the JBoss ON server cloud. |
true | false | ... the job will always be invoked and will run on the server where the job is scheduled. |
false | true | ... the JBoss ON server checks to see if this job is running anywhere else in the JBoss ON server cloud. If it is, the new job must wait until that old job has finished before being invoked. Only one instance of this job can ever be running anywhere in the JBoss ON server cloud. |
false | false | ... the scheduler checks to see if the job is already running locally before invoking the job. Only one job invocation may be running on the server at any time, but multiple servers in the cloud may be running the job at the same time. |
2.2.1.4. Plug-in Configuration (Both Global and Local)
Example 2.6. Plug-in Descriptor: Global Configuration
<serverplugin:plugin-configuration> <c:simple-property name="user" type="string" required="false"/> <c:simple-property name="password" type="password" required="false"/> </serverplugin:plugin-configuration>
Example 2.7. Plug-in Descriptor: Instance-Specific Configuration (Alerts)
<alert-configuration> <c:simple-property name="emailAddress" displayName="Receiver Email Address(es)" type="longString" description="Email addresses (separated by comma) used for notifications."/> h5. </alert-configuration>
Example 2.8. Plug-in Descriptor: Instance-Specific Configuration (Perspectives)
<perspectivePlugin description="The Core Perspective defining Core UI Elements" displayName="Core Perspective" name="CorePerspective" package="org.rhq.perspective.core" xmlns="urn:xmlns:rhq-serverplugin.perspective" xmlns:serverplugin="urn:xmlns:rhq-serverplugin" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <!-- Menu --> <menuItem name="logo" displayName="" url="/" iconUrl="/images/JBossLogo_small.png"> <position placement="firstChild" /> </menuItem>
/modules/enterprise/server/xml-schemas/src/main/resources
directory to see what elements are available for the specific type of plug-in. Not all plug-in types accept local configuration settings; generic plug-ins, for example, only accept global plug-in configuration.
git clone http://git.fedorahosted.org/git/rhq/rhq.git
/etc/samples/custom-serverplugin/
directory which can be used as a template for writing new plug-ins. Rather than checking out the entire source code, you can manually download the custom-serverplugin files at this URL:
http://git.fedorahosted.org/git/?p=rhq/rhq.git;a=tree;f=etc/samples/custom-serverplugin;hb=master
2.2.2. Schema Files
rhq-configuration.xsd
file. This file defines the basic configuration options available to any plug-in.
rhq-configuration.xsd
file is extended by rhq-serverplugin.xsd
. This file provides additional XML elements that are specific to the functions of server-side plug-ins. This file is referenced by every server-side plug-in.
/modules/enterprise/server/xml-schemas/src/main/resources
directory.
2.2.2.1. Parsing the Plug-in Container Schema Files
- Elements
- Attributes
<xs:element name="alert-plugin">
<alert-plugin> Stuff </alert-plugin>
<xs:attribute name="name">
<alert-plugin name="myAlertPlugin"> Stuff </alert-plugin>
/modules/enterprise/server/xml-schemas/src/main/resources
directory and search for <xs:element name=""> and <xs:attribute name=""> entries.
git clone http://git.fedorahosted.org/git/rhq/rhq.git
2.2.2.2. The rhq-configuration.xsd File
rhq-configuration.xsd
file provides schema which is available for all JBoss ON plug-ins. This is used by both agent and server-side plug-ins.
rhq-configuration.xsd
file is in source/modules/core/client-api/src/main/resources
.
git clone http://git.fedorahosted.org/git/rhq/rhq.git
/etc/samples/custom-serverplugin/
directory which can be used as a template for writing new plug-ins. Rather than checking out the entire source code, you can manually download the custom-serverplugin files at this URL:
http://git.fedorahosted.org/git/?p=rhq/rhq.git;a=tree;f=etc/samples/custom-serverplugin;hb=master
rhq-configuration
schema relate to setting configuration values for a plug-in, like <simple-property> and <map-property>.
Table 2.3. rhq-configuration.xsd Schema Elements
Element | Description |
---|---|
configuration-property | For adding a configuration attribute to a plug-in for user-defined settings. |
simple-property | For setting a default configuration value. |
option | For setting whether a property's values come from an enumerated list (false) or can be anything defined by the user (true). |
rhq-configuration.xsd file
also defines the most common flags that can be used for the plug-in descriptor, including the required name
and optional displayName
attributes.
Table 2.4. rhq-configuration.xsd Schema Element Attributes
Attribute | Description |
---|---|
name | Required. Gives a unique name for the plug-in. |
displayName | Gives the name to use for the plug-in in the GUI. If this isn't given, then the name value is used. |
description | Gives a short description of the plug-in. |
rhq-configuration.xsd
file. Each one is described by the text in the <xs:annotation> tags for the item.
2.2.2.3. The rhq-serverplugin.xsd File
rhq-serverplugin.xsd
is the central server-side plug-in schema file.
rhq-serverplugin.xsd
file provides schema elements that are important for every server-side plug-in. Possibly the two most important elements are <server-plugin> (for the plug-in's root element) and <scheduled-jobs> (for running jobs on a resource or server).
rhq-serverplugin.xsd
file is in source/modules/enterprise/server/xml-schemas/src/main/resources
.
rhq-serverplugin.xsd
file are listed in Table 2.5, “rhq-serverplugin.xsd Schema Elements”.
Table 2.5. rhq-serverplugin.xsd Schema Elements
Element | Description |
---|---|
server-plugin | Contains the root element for the plug-in descriptor. |
help | Contains additional usage information or other tips that can help users integrate the plug-in with other applications. |
plugin-component | Identifies a class that will be notified when the plug-in stops or starts. This is a stateful object and is the target of any scheduled stateful jobs. |
scheduled-jobs | Defines a schedule for the plug-in to execute any specified task |
rhq-serverplugin.xsd
contain flags that are used within the root element of the plug-in descriptor. These add additional management attributes for controlling the release and updates of server-side plug-ins.
Table 2.6. rhq-serverplugin.xsd Schema Element Attributes
Attribute | Description |
---|---|
package | For setting the plug-in package name. |
version | For setting the version of the plug-in. If the version isn't set in the descriptor, the plug-ins JAR file, META-INF/MANIFEST.MF , must define the version number in the Implementation-Version setting. |
apiVersion | For setting the version of the API used to write the plug-in. |
rhq-serverplugin.xsd
file. Each one is described by the text in the <xs:annotation> tags for the item.
2.2.3. Java Class Files
2.3. Anatomy of Alert Sender Server-Side Plug-ins
2.3.1. Default Alert Senders
Table 2.7. Default Alert Senders
Alert Method | Description | Plug-in Name |
---|---|---|
Sends emails with the alert information to a user or list of users. | alert-email | |
Roles | Sends an internal message to a JBoss ON user role. | alert-roles |
SNMP | Sends a notification to an SNMP trap. | alert-snmp |
Operations | Initiated a JBoss ON-supported task on a target resource. | alert-operations |
Subject | Sends a notification to a user in JBoss ON. | alert-subject |
2.3.2. Breakdown of a Real Alert Sender Plug-in
- An XML plug-in descriptor that conforms to a given XML schema file (XSD)
- Java files
2.3.2.1. Descriptor
rhq-serverplugin.xml
in the src/main/resources/META-INF/
file for that plug-in.
<alert-plugin name="alert-email" displayName="Alert:Email" xmlns="urn:xmlns:rhq-serverplugin.alert" xmlns:c="urn:xmlns:rhq-configuration" xmlns:serverplugin="urn:xmlns:rhq-serverplugin" package="org.rhq.enterprise.server.plugins.alertEmail" description="Alert sender plug-in that sends alert notifications via email" >
<serverplugin:help> Used to send notifications to direct email addresses. </serverplugin:help>
Figure 2.2. Alert Help Text

<!-- startup & tear down listener, + scheduled jobs <serverplugin:plugin-component /> -->
<!-- Global preferences for all email alerts --> <serverplugin:plugin-configuration> <c:simple-property name="mailserver" displayName="Mail server address" type="longString" description="Address of the mail server to use (if not the default JBoss ON one )" required="false"/> <c:simple-property name="senderEmail" displayName="Email of sender" type="string" description="Email of the account from which alert emails should come from" required="false"/> <c:simple-property name="needsLogin" displayName="Needs credentials?" description="Mark this field if the server needs credentials to send email and give them below" type="boolean" default="false"/> <c:simple-property name="user" type="string" required="false"/> <c:simple-property name="password" type="password" required="false"/> </serverplugin:plugin-configuration>
<!-- How does this sender show up in drop downs etc --> <short-name>Email</short-name>
org.rhq.enterprise.server.plugins.
pluginName, taken from the package element in the <plugin> element of the descriptor. For the alert-email plug-in, the full package name is org.rhq.enterprise.server.plugins.alertEmail
, pointing to the EmailSender.java
class.
<!-- Class that does the actual sending --> <plugin-class>EmailSender</plugin-class>
<!-- What can a user configure when defining an alert --> <alert-configuration> <c:simple-property name="emailAddress" displayName="Receiver Email Address(es)" type="longString" description="Email addresses (separated by comma) used for notifications."/> </alert-configuration>
2.3.2.2. Java Resource
package org.rhq.enterprise.server.plugins.alertEmail; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; import org.rhq.core.domain.alert.Alert; import org.rhq.core.domain.alert.notification.SenderResult; import org.rhq.enterprise.server.plugin.pc.alert.AlertSender; import org.rhq.enterprise.server.util.LookupUtil;
public class EmailSender extends AlertSender { @Override public SenderResult send(Alert alert) { String emailAddressString = alertParameters.getSimpleValue("emailAddress", null); if (emailAddressString == null) { return SenderResult.getSimpleFailure("No email address given"); }
List<String> emails = AlertSender.unfence(emailAddressString, String.class, ","); try { Set<String> uniqueEmails = new HashSet<String>(emails); Collection<String> badEmails = LookupUtil.getAlertManager() .sendAlertNotificationEmails(alert, uniqueEmails); List<String> goodEmails = new ArrayList<String>(uniqueEmails); goodEmails.removeAll(badEmails); SenderResult result = new SenderResult(); result.setSummary("Target addresses were: " + uniqueEmails); if (goodEmails.size() > 0) { result.addSuccessMessage("Successfully sent to: " + goodEmails); } if (badEmails.size() > 0) { result.addFailureMessage("Failed to send to: " + badEmails); } return result; } catch (Throwable t) { return SenderResult.getSimpleFailure("Error sending email notifications to " + emails + ", cause: " + t.getMessage()); } } @Override public String previewConfiguration() { String emailAddressString = alertParameters.getSimpleValue("emailAddress", null); if (emailAddressString == null || emailAddressString.trim().length() == 0) { return "<empty>"; } return emailAddressString; } }
catch (Exception e) { log.warn("Sending of email failed: " + e); return SenderResult.getSimpleFailure("Sending failed :" + e.getMessage()); } return SenderResult.getSimpleSuccess("Send notification to " + txt + ", msg-id: " + status.getId()); } }
2.3.2.3. Schema Elements
rhq-configuration.xsd
, which is used by all JBoss ON plug-insrhq-serverplugin.xsd
, which is used by all server-side plug-insrhq-serverplugin-alert.xsd
, which is used by alert plug-ins
rhq-serverplugin-alert.xsd
file is required for any alert sender plug-in. While additional schema files can be added to contain other elements, the alert schema already contains several very useful schema elements for the alert sender plug-ins.
Table 2.8. Useful Alert Schema Elements
Schema Element | Description | Parent Tag |
---|---|---|
alert-plugin | The root element for a single alert plug-in definition. | None. |
short-name | The display name for the plug-in, which is used in the UI. | alert-plugin |
plugin-class | The class which implements the plug-in's functionality. | alert-plugin |
alert-configuration | A (default) configuration element to display in the UI when the alert instance is configured. This includes general data like a user name, password, URL, server name, or port. | alert-plugin |
Chapter 3. Writing Server-Side Plug-ins: Procedures
3.1. Tip: Checking XSD Annotations
rhq-configuration.xsd
, rhq-serverplugin.xsd
, and type-specific files like rhq-serverplugin-alert.xsd
.
<xs:element name="control" type="serverplugin:ControlType" minOccurs="0" maxOccurs="unbounded"> <xs:annotation> <xs:documentation> Defines operations a user can invoke on the plugin component. Typically, a user interface will allow a user to invoke these operations to control the server plugin component during runtime. </xs:documentation> </xs:annotation> </xs:element>
3.2. Writing Server-Side Plug-ins
- Optional. Manually download example plug-ins to use as a template from The RHQ Project GitHub Page.
- Identify the type of plug-in. Each server-side plug-in is managed by a higher level plug-in container, which correlates to the type or function of the plug-in.
- Optional. Write custom schema for the plug-in configuration.
- Create the directory for the custom plugin in the sourceRoot
/modules/enterprise/server/plugins
directory. For example:mkdir myPlugin cd myPlugin/ mkdir -p src/main/java/org/rhq/enterprise/server/plugins/myPlugin mkdir -p src/main/resources/META-INF
- Copy the
pom.xml
file from a similar existing plug-in to use for the Maven builds to package your new plug-in. For example:cp ../alert-email/pom.xml .
- Edit the
pom.xml
file so that its properties reflect the new plug-in.NOTEBe sure to include the location of the parent repositories used by server-side plug-ins, which are inhttps://repository.jboss.org/nexus/content/groups/public/org/rhq/rhq-enterprise-server-plugins-parent/
. For example:<repositories> <repository> <snapshots> <enabled>true</enabled> </snapshots> <id>jboss</id> <name>JBoss Repository</name> <url>https://repository.jboss.org/nexus/content/groups/public/org/rhq/rhq-enterprise-server-plugins-parent/</url> </repository> ... </repositories>
- Write the plug-in descriptor that defines that specific plug-in instance. The plug-in descriptor defines everything from the plug-in classes to scheduled jobs. Plug-in descriptor elements are covered in Section 2.2.1.4, “Plug-in Configuration (Both Global and Local)”.
- Implement the Java classes for the plug-in.
- Build the plug-in. During the Maven build process, the plug-in files can be validated.
mvn install
- Deploy the plug-in, as in Section 3.4, “Deploying Server-Side Plug-ins”. When a server-side plug-in is deployed on one server, it is automatically propagated to all of the other JBoss ON servers in the cloud.
3.3. Validating Server-Side Plug-ins
- The XML is well-formed and validates with the configured server plug-in XML schema
- If a plug-in component is specified, its class is found in the plug-in JAR and can be instantiated
- All scheduled jobs are configured properly
- The plug-in has a valid version
- The plug-in configuration is declared correctly
pom.xml
configuration file.
- Open the
pom.xml
file in the sourceRoot/modules/enterprise/server/plugins/validate-all-serverplugins/
directory. - Add a <pathelement> line to the file which points to the custom server-side plug-in JAR file. For example:
<pathelement location="../myPlugin/target/myPlugin.jar" />
- Build the plug-in.
mvn install
org.rhq.enterprise.server.plugin.pc.ServerPluginValidatorUtil
class.
3.4. Deploying Server-Side Plug-ins
- Copying the plug-in JAR file into the sourceRoot
/plugins/
folder in the server root directory (locally). - Uploading the plug-in JAR file through the web interface (remotely).
Figure 3.1. Server-Side Plug-in Propagation

- Deployed and enabled
- Deployed and disabled
3.4.1. Remotely Deploying Server-Side Plug-ins
- In the top menu, click the Administration tab.
- In the Configuration box on the left navigation bar, click the Server Plugins link.
- Scroll to the Upload Plugin section at the bottom of the page.
- Click the Browse... button, and browse to the plug-in JAR file's location.
- To deploy the plug-in, click the Upload button.
3.4.2. Locally Deploying Server-Side Plug-ins
/plugins/
directory and the server will deploy it.
3.5. Updating Server-Side Plug-ins
META-INF/MANIFEST.MF
file in the JAR file) to identify later version of the plug-in and to update the plug-ins on the JBoss ON servers in the cloud.
3.6. Disabling Server-Side Plug-ins
- In the top menu, click the Administration tab.
- In the Configuration box on the left navigation bar, click the Server Plugins link.
- Select the server-side plug-in to be disabled.
- Click the DISABLE button.
3.7. Restarting Server-Side Plug-in Containers
- In the top menu, click the Administration tab.
- In the Configuration box on the left navigation bar, click the Server Plugins link.
- Scroll to the bottom of the table, and click the RESTART MASTER PLUGIN CONTAINER button.
- When the restart process is done (and assuming no problems were encountered), a success message is shown in the upper right corner.
3.8. Setting Plug-in Configuration Properties
rhq-plugin.xml
file, and the values are then supplied in the JBoss ON UI.
- In the top menu, click the Administration tab.
- In the Configuration box on the left navigation bar, click the Server Plugins link.
- Click the name of the server-side plug-in in the table.
- In the middle of the plug-in details page, expand the Plugin Configuration section to access the configuration properties.NoteIf necessary, unselect the Unset checkbox to activate a field to be edited.
- Click the SAVE button at the top of the configuration section.
3.9. Deleting Server-Side Plug-ins
- In the top menu, click the Administration tab.
- In the Configuration box on the left navigation bar, click the Server Plugins link.
- Select the plug-in to delete.
- Click the Delete button.
Chapter 4. Writing Agent Plug-ins: Background
4.1. About the Advanced Management Plug-in System (AMPS) for Agent Plug-ins
- The agent's plug-in container. The plug-in contain runs inside the JBoss ON agent and it provides a manager for all of the deployed resource plug-ins.The plug-in container is what actually manages the lifecycle of the resource plug-ins. The agent starts the plug-in container, and the plug-in container starts the resource plug-ins. The plug-in container also handles all the classloading, threading, and running for resource plug-ins.Plug-in developers never need to interact with the plug-in container. As long as a plug-in is written with the appropriate components and with a valid plug-in descriptor, the agent will be able to manage the resource.
- Domain objects. This defines the individual objects for plug-ins, specifically resources, resource types, and configuration. All of the other elements in AMPS use the domain objects to define resource elements.One of the largest API sets within the domain object is configuration. The configuration API is used anywhere that a set of configuration properties is required, from plug-in configuration settings to connect to a resource to operation arguments.
- The plug-in components. These components define the actual component interfaces that are used by agent plug-ins, well as the facets that plug-ins can support.The plug-in components are the public API.This element within AMPS is the part that plug-in writers use. This contains the interfaces that plug-in writers implement in the resource plug-in.
- Native System. A lot of information require to monitor or manage a resource is available from the operating system information. The native system provides JNI or native access to that operating system information and can pull information from the process table, run external programs, or gather system metrics.
- Resource plug-ins.. JBoss ON has a set of resource plug-ins already defined. Each individual resource plug-in manages a particular product (applications and servers, services, or platforms). These plug-ins are loaded into the agent's plug-in container and implement the plug-in components defined in the API.
4.2. The Breakdown of Agent Plug-in Configuration
rhq-plugin.xml
inside the META-INF/
directory).
- A plug-in component file that contains all of the code for the plug-in functionality
- A
*Discovery.java
file that configures the discovery process for the resources defined in the plug-in - A
*EventPoller.java
that defines the events that can be collected by the resource
rhq-plugin.xml
plug-in descriptor.
4.2.1. Schema Files
rhq-configuration.xsd
file to define the basic configuration options available.
rhq-plugin.xsd
file, which extends the rhq-configuration.xsd
schema and adds additional elements specifically for resource-related plug-ins.
rhq-configuration.xsd
file provides schema which is available for all JBoss ON plug-ins. The rhq-configuration.xsd
file is in source/modules/core/client-api/src/main/resources
.
rhq-configuration
schema relate to setting configuration values for a plug-in, like <simple-property> and <map-property>.
Table 4.1. rhq-configuration.xsd Schema Elements
Element | Description |
---|---|
configuration-property | For adding a configuration attribute to a plug-in for user-defined settings. |
simple-property | For setting a default configuration value. |
option | For setting whether a property's values come from an enumerated list (false) or can be anything defined by the user (true). |
rhq-configuration.xsd file
also defines the most common flags that can be used for the plug-in descriptor, including the required name
and optional displayName
attributes.
Table 4.2. rhq-configuration.xsd Schema Attributes
Attribute | Description |
---|---|
name | Required. Gives a unique name for the plug-in. |
displayName | Gives the name to use for the plug-in in the GUI. If this isn't given, then the name value is used. |
description | Gives a short description of the plug-in. |
rhq-plugin.xsd
provides all of the schema elements specifically for agent plug-ins. The rhq-plugin.xsd
file is in the source/modules/core/client-api/src/main/resources
directory.
rhq-plugin.xsd
file are listed in Table 4.3, “rhq-plugin.xsd Schema Elements”.
Table 4.3. rhq-plugin.xsd Schema Elements
Element | Description |
---|---|
plugin | Contains the root element for the plug-in descriptor. |
depends | Identifies any other plug-ins which this plug-in requires or extends. |
platforms, servers, services | Identifies the type for a resource defined within the agent plug-in. <platforms> are top-level elements, but <servers> and <services> are added as children of platforms or other server and service resources. |
metric |
An element within a platform, server, or service which defines metrics which can be collected for that resource type.
Child elements and attributes for this resource element are listed in the
rhq-plugin.xsd file.
Values that form part of a larger data structure, such as an array of values, need to be deconstructed into individual values before they can be monitored.
|
event | An element within a platform, server, or service which defines whether that resource supports events. There are no other configuration properties with events; the events themselves are culled from the resource's log files. |
bundle-target |
Configures whether and how bundles can be deployed to a resource.
Child elements and attributes for this resource element are listed in the
rhq-plugin.xsd file.
|
drift-definition |
Configures whether and how drift monitoring can be performed for a resource.
Child elements and attributes for this resource element are listed in the
rhq-plugin.xsd file.
|
resource-configuration |
Defines a configuration property for a resource type.
Child elements and attributes for this resource element are listed in the
rhq-plugin.xsd file.
|
operation |
Defines an operation that can be performed on that resource type.
Child elements and attributes for this resource element are listed in the
rhq-plugin.xsd file.
|
content |
Configures what types of packages can be uploaded or deployed on a resource type.
Child elements and attributes for this resource element are listed in the
rhq-plugin.xsd file.
|
rhq-plugin.xsd
contain flags that are used within the root element of the plug-in descriptor. These add additional management attributes for controlling the release and updates of agent plug-ins.
Table 4.4. rhq-plugin.xsd Schema Attributes
Attribute | Description |
---|---|
package | For setting the plug-in package name. |
version | For setting the version of the plug-in. This must be in an OSGi-compatible format. |
ampsVersion | For the agent plug-in system version that this plug-in requires. This must be in an OSGi-compatible format. |
pluginLifecycleListener | For the listener which initializes and shuts down the plug-in. |
discovery | Sets whether a resource type is detected by discovery scans. This flag may not be necessary for child resources that will be discovered by the parent resource. |
rhq-plugin.xsd
file. Each one is described by the text in the <xs:annotation> tags for the item.
4.2.2. Descriptor and Configuration
- The names of the resource types (servers and services) supported by the plug-in
- Any configuration settings that the agent's plug-in components use to connect to the resource
- Any metrics (measurement definitions) to use to monitor the resource; this depends on the type of data issued by the resource itself.
- A set of operations that can be invoked on the resource. This is commonly start and stop operations, but it can include application-specific operations or other actions, like running a script.
- Resource configuration values that can be edited in the actual configuration of the resource.The plug-in configuration tells the components how to connect to the resource. The resource configuration, on the other hand, are settings in the resource itself that can be edited externally.
- Any child resources that are part of the resource hierarchy. For example, a JBoss server has data source services running within them, so the data source services are defined in the JBoss server resource plug-in, as a child resource of the JBoss server.
4.2.2.1. Resource Type, Metadata, and Plug-in Configuration
<plugin name="JMX" displayName="Generic JMX" package="org.rhq.plugins.jmx" description="Supports management of JMX MBean Servers via various remoting systems." ampsVersion="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:xmlns:rhq-plugin" xmlns:c="urn:xmlns:rhq-configuration">
name
anddisplayName
give the internal and GUI name of the plug-in.ampsVersion
gives the version number of the plug-in itself.package
gives the name of the classes used by the components in the plug-in.
<server name="JMX Server" discovery="JMXDiscoveryComponent" class="JMXServerComponent" description="Generic JMX Server" supportsManualAdd="true" createDeletePolicy="neither">
discovery
identifies the discovery component used to identify the resource type.class
identifies the plug-in component which contains the actual code of the plug-in.
supportsManualAdd
allows resources to be added to the inventory by administrators.createDeletePolicy
sets whether children can be added or removed manually from inventory.
<plugin-configuration> <c:list-property name="Servers"> <c:map-property name="OneServer"> <c:simple-property name="host"/> <c:simple-property name="port"> <c:integer-constraint minimum="0" maximum="65535"/> </c:simple-property> <c:simple-property name="protocol"> <c:property-options> <c:option value="http" default="true"/> <c:option value="https"/> </c:property-options> </c:simple-property> </c:map-property> </c:list-property> </plugin-configuration>
- <simple-property>, which defines a one key-value pair
- <map-property>, which defines multiple key-value pairs related to a single entity, following the
java.util.Map
concept - <list-property>, which contains a list of properties
<c:template name="JDK 5" description="Connect to JDK 5"> <c:simple-property name="type" default="org.mc4j.ems.connection.support.metadata.J2SE5ConnectionTypeDescriptor"/> <c:simple-property name="connectorAddress" default="service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi"/> </c:template>
4.2.2.2. Discovery and Process Scans
discovery
attribute which identifies the discovery Java file for the resource plug-in. (If there are multiple resources defined in the plug-in, then there will be multiple discovery components.)
/** * Discovery class */ public class testDiscovery implements ResourceDiscoveryComponent ,ManualAddFacet { private final Log log = LogFactory.getLog(this.getClass()); /** * Do the manual add of this one resource */ public DiscoveredResourceDetails discoverResource(Configuration pluginConfiguration, ResourceDiscoveryContext context) throws InvalidPluginConfigurationException { // TODO implement this DiscoveredResourceDetails detail = null; // new DiscoveredResourceDetails( // context.getResourceType(), // ResourceType // ); return detail; } }
public DiscoveredResourceDetails discoverResource(Configuration pluginConfig, ResourceDiscoveryContext discoveryContext) throws InvalidPluginConfigurationException { // TODO: Connect to the remote JVM to verify the user-specified conn props are valid, and if connecting // fails, throw an exception. String resourceKey = pluginConfig.getSimpleValue(CONNECTOR_ADDRESS_CONFIG_PROPERTY, null); String connectionType = pluginConfig.getSimpleValue(CONNECTION_TYPE, null); // TODO (ips, 09/04/09): We should connect to the remote JVM in order to obtain its version. String version = null; DiscoveredResourceDetails resourceDetails = new DiscoveredResourceDetails(discoveryContext.getResourceType(), resourceKey, "Java VM", version, connectionType + " [" + resourceKey + "]", pluginConfig, null); return resourceDetails; }
name
and query
. name
identifies the specific scan method. query
is the attribute that does something. The query
is a string written in Process Info Query Language (PIQL). This value is used to search for the process.
process|attribute|match=value,arg|attribute|match=value
jsmith 2035 0.0 -1.5 724712 30616 p7 S+ 9:49PM 0:01.61java
-Dprogram.name=run.sh -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.platform.mbeanserver -Djava.endorsed.dirs=/devel/jboss-4.0.5.GA/lib/endorsed -classpath /devel/jboss-4.0.5.GA/bin/run.jar:/lib/tools.jarorg.jboss.Main
-c minimal
process|attribute|match=value,arg|attribute|match=value | | |____ |_ |____ |______ | | | | | | | | | | | | | | | | | | | | | | | | process|basename|match=^java.*,arg|org.jboss.Main|match=.*
process|attribute|match=value
process|pidfile|match=/etc/product/lock.pid
rhq-plugin.xml
descriptor file, then the discovery component must be written to implement the scan and process results.
Example 4.1. Process Scan Method in the Discovery Component
List<ProcessScanResult< autoDiscoveryResults = context.getAutoDiscoveredProcesses(); for (ProcessScanResult result : autoDiscoveryResults) { ProcessInfo procInfo = result.getProcessInfo(); .... // as before DiscoveredResourceDetails detail = new DiscoveredResourceDetails( resourceType, key, name, null, description, childConfig, procInfo ); result.add(detail); }
<metric displayName="Bytes Sent" description="Shows the rate that data bytes are sent by the Web service." property="Bytes Sent/sec" defaultOn="true" displayType="summary" measurementType="trendsup" units="bytes"/>
property
identifies the resource monitoring property.measurementType
sets the data type being collected.units
sets the units of the thing being monitored.
public class testComponent implements ResourceComponent , MeasurementFacet , OperationFacet
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception { String propertyBase = "\\Web Service(_Total)\\"; Pdh pdh = new Pdh(); for (MeasurementScheduleRequest request : metrics) { double value = pdh.getRawValue(propertyBase + request.getName()); report.addData(new MeasurementDataNumeric(request, value)); } }
4.2.2.3. Events
<event name="errorLogEntry" description="an entry in the error log file"/>
EventPoller
component. This can be in the larger plug-in Java component, but it is usually broken into a separate *EventPoller.java
component. The way to implement event polling depends on the resource and the nature of its logging. One of the simplest ways is to call the EventPoller()
, then define the event type and set how the event is polled.
public PerfTestEventPoller(ResourceContext resourceContext) { this.resourceContext = resourceContext; } public String getEventType() { return PERFTEST_EVENT_TYPE; } public Set<Event> poll() { int count = Integer.parseInt(System.getProperty(SYSPROP_EVENTS_COUNT, "1")); String severityString = System.getProperty(SYSPROP_EVENTS_SEVERITY, EventSeverity.INFO.name()); EventSeverity severity = EventSeverity.valueOf(severityString); Set<Event> events = new HashSet<Event>(count); for (int i = 0; i < count; i++) { Event event = new Event(PERFTEST_EVENT_TYPE, "source.loc", System.currentTimeMillis(), severity, "event #" + i); events.add(event); } return events; }
4.2.2.4. Resource Configuration
<resource-configuration> <c:group name="Attributes"> <c:simple-property name="appBase" required="true" readOnly="true" description="The Application Base directory for this virtual host." /> <c:simple-property name="autoDeploy" type="boolean" description="Does this host deploy new applications dropped in appBase at runtime?" /> <c:simple-property name="deployOnStartup" type="boolean" description="Does this host deploy applications in appBase at startup?" /> <c:simple-property name="deployXML" displayName="Deploy XML" type="boolean" description="deploy Context XML config files?" /> <c:simple-property name="unpackWARs" displayName="Unpack WARs" type="boolean" description="Does this Host automatically unpack deployed WAR files?" /> <c:simple-property name="aliases" required="false" type="longString" description="Aliases assigned to the Host. When editing, each alias must be on a new line. Aliases are automatically lowercased." /> </c:group> </resource-configuration>
public Configuration loadResourceConfiguration() { Configuration configuration = super.loadResourceConfiguration(); try { resetConfig(CONFIG_ALIASES, configuration); } catch (Exception e) { log.error("Failed to reset role property value", e); } return configuration; }
public void updateResourceConfiguration(ConfigurationUpdateReport report) { Configuration reportConfiguration = report.getConfiguration(); // reserve the new alias settings PropertySimple newAliases = reportConfiguration.getSimple(CONFIG_ALIASES); // get the current alias settings resetConfig(CONFIG_ALIASES, reportConfiguration); PropertySimple currentAliases = reportConfiguration.getSimple(CONFIG_ALIASES); // remove the aliases config from the report so they are ignored by the mbean config processing reportConfiguration.remove(CONFIG_ALIASES); // perform standard processing on remaining config super.updateResourceConfiguration(report); // add back the aliases config so the report is complete reportConfiguration.put(newAliases); // if the mbean update failed, return now if (ConfigurationUpdateStatus.SUCCESS != report.getStatus()) { return; } // try updating the alias settings try { consolidateSettings(newAliases, currentAliases, "addAlias", "removeAlias", "alias"); } catch (Exception e) { newAliases.setErrorMessage(ThrowableUtil.getStackAsString(e)); report.setErrorMessage("Failed setting resource configuration - see property error messages for details"); log.info("Failure setting Tomcat VHost aliases configuration value", e); } // If all went well, persist the changes to the Tomcat server.xml try { storeConfig(); } catch (Exception e) { report .setErrorMessage("Failed to persist configuration change. Changes will not survive Tomcat restart unless a successful Store Configuration operation is performed."); } }
4.2.3. Lifecycle Listeners
org.rhq.core.pluginapi.plugin.PluginLifecycleListener
class allocates global resources needed by plug-in components and cleans up those resources.
pluginLifecycleListener
attribute in the top-level <plugin> element.
<plugin name="Apache" displayName="Apache HTTP Server" description="Management of Apache web servers" package="org.rhq.plugins.apache" pluginLifecycleListener="ApachePluginLifecycleListener" ...
4.2.4. Plug-in Dependencies: Defining Relationships Between Plug-ins
- Required dependencies are set using the <depends> element. Just using <depends> means that the required plug-in must be loaded or the other plug-in will fail to load. Adding the
useClasses
attribute makes the classes and JAR files for the parent plug-in available to the child plug-in. - An injection plug-in dependency means that a root-level resource runs inside another resource type, and that parent resource is defined as a parent plug-in. This essentially adds a new child to an existing resource type.
- An embedded plug-in dependency means that a new parent resource type is added for an existing child. This can allow the child to be extended to share the new parent's classloader (depending on both plug-ins' configuration) or simply expand discovery.
4.2.4.1. Required Plug-in Dependencies
useClasses
attribute. The useClasses
option can be set for only one required dependency in a single plug-in descriptor. If no <depends> element has a useClasses
attribute, the last <depends> element specified in the plug-in descriptor, by default, has its useClasses attribute to true.
4.2.4.2. Embedded Plug-in Dependencies
sourcePlugin
and sourceType
attributes on the resource elements. When a plug-in source is specified, the server or service is copied from the source resource type, which means it has the same metadata as the source, with the exception that the embedded server or service can override the discovery and resource classes and, potentially, have a different name.
4.2.4.3. Injection Plug-in Dependencies
<runs-inside> <parent-resource-type name="JMX Server" plugin="JMX" /> <parent-resource-type name="JBoss Server" plugin="JBoss AS" /> </runs-inside>
4.2.5. Class Sharing Between Plug-ins
Figure 4.1. Agent Components, Together

classLoader="instance"
on the resource type and make sure the resource type's discovery component implements the ClassLoaderFacet
so it tells the plug-in container where any additional connection classes can be found for the specific version of the specific resource being managed.
classLoader
option set to shared. This means that Z1.server resources share their classloaders with their parent resources, and that classloader may be a resource classloader or a plug-in classloader. Every Z1.server resource uses the same classloader.
Example 4.2. classLoader for Plug-in Z
<plug-in name="Z"> <depends plugin="A" /> <server name="Z1.server" classLoader="shared"> <runs-inside> <parent-resource-type name="B1.server" plugin="B"/> <parent-resource-type name="C1.server" plugin="C"/> </runs-inside> </server> <server name="Z2.server" sourcePlugin="D" sourceType="D1" classLoader="instance"> </server> <server name="Z3.server" classLoader="instance"> </server> </plugin>
classLoader
option to instance means that each resource uses its own resource plug-in. However, for Z2.server, the Z2.server plug-in is extended by embedding the values for Plug-in D, so Z2.server resources share their classloaders with their parent plug-in.
classLoader
option is set to instance and it has no injected or embedded dependencies. When the classLoader
option is set to instance, the ResourceDiscoveryComponent
implementation can optionally define a ClassLoaderFacet
with a method (getAdditionalClasspathUrls) that returns a List<URL> pointing to additional JARs that should be placed in the resource's classloader. When the plug-in container needs to create a classloader for a resource, it checks if the resource's discovery component implements this facet, and, if so, it gets the additional classpath URLs and adds them to the resource classloader when it creates it.
classLoader
attribute value and its parent's classLoader
attribute value.
Resource ClassLoader | Parent ClassLoader | ClassLoader Description |
---|---|---|
shared | shared | The useClasses value must be set to true so that the resource can access both its classes and the parent classes. |
instance | shared | The resource primarily needs its own classes, but it may be beneficial for useclasses to be set to true to so that the child can use parent classes. |
shared | instance | The resource uses only its own classloader. |
instance | instance | The resource uses only its own classloader. |
4.3. Extended Example: Content Types for Resources
<content name="InstalledSoftware" displayName="Installed Software" category="deployable" description="Installed Windows Software"> <configuration> <c:simple-property name="Publisher"/> <c:simple-property name="Comments"/> <c:simple-property name="Contact"/> <c:simple-property name="HelpLink"/> <c:simple-property name="HelpTelephone"/> <c:simple-property name="InstallLocation"/> <c:simple-property name="InstallSource"/> <c:simple-property name="EstimatedSize" units="kilobytes"/> </configuration> </content>
Package Attributes
- Display Name (Optional)
- A user interface friendly name of the package type.
- Description (Optional)
- Describes the type of content found in packages of this type.
- Category (Required)
- One of four enumerated options:
- Executable Script (which is potentially editable)
- Executable Binary
- Configuration (a configuration file for the resource)
- Deployable
- Discovery Interval (Optional)
- Defines the time between package discovery scans for this type; different package types can be configured with intervals to represent the likelihood of the package inventory changing.
- Creation Type Flag (Optional)
- If set to true, a package of this type is used when creating resources of the enclosing resource type. An example of this situation is a Java EAR file. There is an EAR resource type that represents the enterprise application in JBoss ON. Under that resource type, there is a package type defined to represent the EAR file itself. This package type is flagged as a creation type; when creating a new EAR resource, the EAR file must be created at the same time. The default for this attribute is false, as packages will typically not represent the creation of a new resource.
- Configuration (Optional)
- The configuration element allows the plug-in to define an open-ended set of attributes about the package type. These values will be populated during package discovery, and if not marked as read only, can be specified by the user at artifact creation time. An example of a property in this configuration element is a Boolean that describes if an EAR file is deployed as exploded or zipped. When EAR files are discovered, this flag will be populated and carry package type specified information. Additionally, when deploying a new EAR file through JBoss ON, this flag can be set to indicate how the package should be deployed on the AS instance.
4.4. Extended Example: HTTP Metrics
- Issue a GET or HEAD request to the base URL for the given server.
- Collect both the HTTP return code and the response time as a resource trait.
Figure 4.2. Basic Agent Plug-in Scenario

rhq-plugin.xml
file as the plug-in descriptor, which is required for JBoss ON to recognize the plug-in configuration. The plug-in is built as a maven project, so it has a pom.xml
file, although that is not a requirement, since any properly configured JAR file can be deployed as an agent plug-in.
Figure 4.3. Directory Layout of an Agent Plug-in Project

4.4.1. Looking at the Plug-in Descriptor (rhq-plugin.xml)
Example 4.3. Basic Plug-in Information
<?xml version="1.0" encoding="UTF-8" ?> <plugin name="HttpTest" displayName="HttpTest plugin" package="org.rhq.plugins.httptest" version="2.0" description="Monitoring of http servers" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:xmlns:rhq-plugin" xmlns:c="urn:xmlns:rhq-configuration">
package
attribute identifies the Java package for Java class names that are referenced in the plug-in configuration in the descriptor.
Example 4.4. Server Definition
<server name="HttpCheck" description="Httpserver pinging" discovery="HttpDiscoveryComponent" class="HttpComponent">
.java
files and classes. The supportsManualAdd
option sells JBoss ON that the HTTP services can be added manually through the UI, which is important for administration.
Example 4.5. Service Definition
<service name="HttpServiceCheck" discovery="HttpServiceDiscoveryComponent" class="HttpServiceComponent" description="One remote Http Server" supportsManualAdd="true"
Example 4.6. Simple Configuration Properties
<plugin-configuration> <c:simple-property name="url" type="string" required="true" /> </plugin-configuration>
Example 4.7. Complex Configuration Properties
<plugin-configuration> <c:list-property name="Servers"> <c:map-property name="OneServer"> <c:simple-property name="host"/> <c:simple-property name="port"> <c:integer-constraint minimum="0" maximum="65535"/> </c:simple-property> <c:simple-property name="protocol"> <c:property-options> <c:option value="http" default="true"/> <c:option value="https"/> </c:property-options> </c:simple-property> </c:map-property> </c:list-property> </plugin-configuration>
Example 4.8. Defined Metrics
<metric property="responseTime" displayName="Response Time" measurementType="dynamic" units="milliseconds" displayType="summary"/> <metric property="status" displayName="Status Code" data type="trait" displayType="summary"/> </service> </server> </plugin>
Table 4.5. metric Attributes
Attribute | Description |
---|---|
property | Gives the unique name of this metric. The name can also be obtained in the code using the getName() call. |
description | Gives a human readable description of the metric. |
displayName | Gives the name that gets displayed in the JBoss ON UI. |
data type | Sets the type of metric, such as numeric or trait. |
units | The measurement units to use for numerical data type. |
displayType | If the value is set to summary, the metric is displayed in the indicator charts and collected by default. |
defaultOn | Sets whether the metric collected by default. |
measurementType |
Sets what characteristics the numerical values have. The options are trends up, trends down, or dynamic. For both trends metrics, the system automatically creates additional per minute metrics.
Values that form part of a larger data structure, such as an array of values, need to be deconstructed into individual values before they can be monitored.
|
4.4.2. Looking at the Discovery Components (HttpDiscoveryComponent.java and HttpServiceDiscoveryComponent.java)
HttpDiscoveryComponent.java
, discovers the HTTP metrics server. The discovery component is called by the InventoryManager in the agent to discover resources. This can be done by a process table scan, querying the MBeanServer, or other means. Whatever the method, the most important thing is that the discovery component returns the same unique key each time for the same resource. The DiscoveryComponent needs to implement org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent
and you need to implement discoverResources()
.
Example 4.9. HttpDiscoveryComponent.java
public class HttpDiscoveryComponent implements ResourceDiscoveryComponent { public Set discoverResources(ResourceDiscoveryContext context) throws InvalidPluginConfigurationException, Exception { Set<DiscoveredResourceDetails> result = new HashSet<DiscoveredResourceDetails>(); String key = "http://localhost:7080/"; // Jon server String name = key; String description = "Http server at " + key; Configuration configuration = null; ResourceType resourceType = context.getResourceType(); DiscoveredResourceDetails detail = new DiscoveredResourceDetails(resourceType, key, name, null, description, configuration, null ); result.add(detail); return result; }
HttpServiceDiscoveryComponent.java
) relies on information passed through the GUI to configure its resources, rather than a discovery scan. The initial definition in the Java file is similar to the one for the server discovery, but this definition has an additional List<Configuration> childConfigs
which processes the information that is passed through the UI. This pulls the information for the required url information supplied by the user.
Example 4.10. Service Discovery
public class HttpServiceDiscoveryComponent implements ResourceDiscoveryComponent<HttpServiceComponent>; { public Set<DiscoveredResourceDetails> discoverResources (ResourceDiscoveryContext<HttpServiceComponent> context) throws InvalidPluginConfigurationException, Exception { Set<DiscoveredResourceDetails> result = new HashSet<DiscoveredResourceDetails>(); ResourceType resourceType = context.getResourceType(); List<Configuration> childConfigs = context.getPluginConfigurations(); for (Configuration childConfig : childConfigs) { String key = childConfig.getSimpleValue("url", null); if (key == null) throw new InvalidPluginConfigurationException( "No URL provided");
Example 4.11. Listing HTTP URL Resources
String name = key; String description = "Http server at " + key; DiscoveredResourceDetails detail = new DiscoveredResourceDetails( resourceType, key, name, null, description, childConfig, null ); result.add(detail); } return result; }
4.4.3. Looking at the Plug-in Components (HttpComponent.java and HttpServiceComponent.java)
HttpComponent.java
), the plug-in is pretty simple. The component only implements placeholder methods from the ResourceComponent interface to set the server availability. Setting the availability to UP automatically allows the resource component to start.
Example 4.12. Server Availability After Discovery
public AvailabilityType getAvailability() { return AvailabilityType.UP; }
HttpServiceComponent.java
) is more complex because it must carry out the operations defined in the plug-in descriptor.
MeasurementFacet
.
MeasurementFacet
implements the following method:
getValues(MeasurementReport report, Set metrics)
MeasurementReport
passed in is where the monitoring results are added. The metrics
value is a list of metrics for which data should be gathered. All of this information can be defined in the <metrics> element or in the UI configuration.
public class HttpComponent implements ResourceComponent, MeasurementFacet { URL url; // remote server url long time; // response time from last collection String status; // Status code from last collection
getValues()
method from the MeasurementFacet
must be implemented, but that's not the first step to take. A resource cannot be discovered if the resource is down, so the first step is to set a start value to start the service from ResourceContext
and give it an availability of UP.
Example 4.13. Service Resource Availability
public void start(ResourceContext context) throws InvalidPluginConfigurationException, Exception { url = new URL(context.getResourceKey()); // Provide an initial status, so // getAvailability() returns up status = "200"; }
getValues()
can be implemented. This actually collects the monitoring data from the given URLs.
Example 4.14. Implementing getValues()
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception { getData(); // Loop over the incoming requests and // fill in the requested data for (MeasurementScheduleRequest request : metrics) { if (request.getName().equals("responseTime")) { report.addData(new MeasurementDataNumeric( request, new Double(time))); } else if (request.getName().equals("status")) { report.addData(new MeasurementDataTrait (request, status)); } } }
getData()
method in the MeasurementFacet
loops the incoming request to see which metric is wanted and then to supply the collected value. Depending on the type of data, the data may be to be wrapped into the correct MeasurementData*
class.
Example 4.15. Implementing getData()
private void getData() { HttpURLConnection con = null; int code = 0; try { con = (HttpURLConnection) url.openConnection(); con.setConnectTimeout(1000); long now = System.currentTimeMillis(); con.connect(); code = con.getResponseCode(); long t2 = System.currentTimeMillis(); time = t2 - now; } catch (Exception e) { e.printStackTrace(); } if (con != null) con.disconnect(); status = String.valueOf(code); }
4.5. Examples: Embedded and Injected Plug-in Dependencies
4.5.1. Simple Dependency: JBoss AS and JMX Plug-ins
Example 4.16. JMX Plug-in Descriptor
<plugin name="JMX"> <server name="JMX Server" discovery="JMXDiscoveryComponent" class="JMXServerComponent"> ... </server> </plugin>
useClasses
argument is set to true), but the JBoss AS plug-in descriptor does not actually define or use any source types related to or referencing the JMX plug-in.
Example 4.17. JBoss AS Plug-in Descriptor
<plugin name="JBossAS"> <depends plugin="JMX" useClasses="true"/> <server name="JBossAS Server" discovery="JBossASDiscoveryComponent" class="JBossASServerComponent"> ... </server> </plugin>
4.5.2. Embedded Dependency: JVM MBeanServer and JBoss AS
Example 4.18. JMX Plug-in Descriptor
<plugin name="JMX"> <server name="JMX Server" discovery="JMXDiscoveryComponent" class="JMXServerComponent"> <service name="VM Memory System" discovery="MBeanResourceDiscoveryComponent" class="MBeanResourceComponent" description="The memory system of the Java virtual machine"> ... </service> ... </server> </plugin>
sourcePlugin
and sourceType
attributes. The reason for this is to run a second JMX discovery scan, this one using the org.rhq.plugins.jmx.EmbeddedJMXServerDiscoveryComponent
class to run a special discovery scan looking for a JVM embedded in a JBoss AS instance. The sourcePlugin
and sourceType
attributes, then, copy the resource type and give it a unique name so that any embedded JVMs are treated as different resource types than standalone JVMs.
Example 4.19. JBoss AS Plug-in Descriptor
<plugin name="JBossAS"> <depends plugin="JMX" useClasses="true"/> <server name="JBossAS Server" discovery="JBossASDiscoveryComponent" class="JBossASServerComponent"> <server name="JBoss AS JVM" description="JVM of the JBossAS" sourcePlugin="JMX" sourceType="JMX Server" discovery="org.rhq.plugins.jmx.EmbeddedJMXServerDiscoveryComponent" class="org.rhq.plugins.jmx.JMXServerComponent"> ... </server> ... </server> </plugin>
4.5.3. Injected Dependency: Hibernate with JVM and JBoss AS
Figure 4.4. Hibernate, JMX, and JBoss AS Dependencies

Example 4.20. JMX Plug-in Descriptor
<plugin name="JMX"> <server name="JMX Server" discovery="JMXDiscoveryComponent" class="JMXServerComponent"> ... </server> </plugin>
Example 4.21. JBoss AS Plug-in Descriptor
<plugin name="JBoss AS"> <depends plugin="JMX" useClasses="true"/> <server name="JBossAS Server" discovery="JBossASDiscoveryComponent" class="JBossASServerComponent"> ... </server> </plugin>
Example 4.22. Hibernate Plug-in Descriptor
<depends plugin="JMX" useClasses="true"/> <service name="Hibernate Statistics" discovery="org.rhq.plugins.jmx.MBeanResourceDiscoveryComponent" class="StatisticsComponent"> <runs-inside> <parent-resource-type name="JMX Server" plugin="JMX"/> <parent-resource-type name="JBossAS Server" plugin="JBossAS"/> </runs-inside> ... </service> </plugin>
4.6. Extended Example: Drift Monitoring
- fileSystem, which is any directory on the machine local to the resource
- pluginConfiguration, which is defined property in the resource plug-in, like a home directory
- resourceConfiguration, a resource configuration property
- measurementTrait, a trait that is gathered about the resource
/etc/
, the elements in the drift definition are:
Value name: fileSystem Value context: /etc
Example 4.23. Base Directory Only
<drift-definition name="Template-File System" description="Monitor the file system for drift. Definitions should set a more specific base directory as the file system root is not recommended."> <basedir> <value-context>fileSystem</value-context> <value-name>/</value-name> </basedir> </drift-definition>
Example 4.24. Included Paths and Patterns
<drift-definition name="Template-Base Files" description="Monitor base application server files for drift. It defines monitoring for some standard sub-directories of the HOME directory. Note, it is not recommeded to monitor all files for an application server. There are many files, and many temp files."> <basedir> <value-context>pluginConfiguration</value-context> <value-name>homeDir</value-name> </basedir> <includes> <include path="bin" pattern="*/*.sh" /> <include path="lib" /> <include path="client" /> </includes> </drift-definition>
4.7. Extended Example: Provisioning and Content Deployments (Bundles)
- fileSystem, which is any directory on the machine local to the resource
- pluginConfiguration, which is defined property in the resource plug-in, like a home directory
- resourceConfiguration, a resource configuration property
- measurementTrait, a trait that is gathered about the resource
Example 4.25. A Single Bundle Base Directory
<bundle-target> <destination-base-dir name="Root File System" description="The top root directory on the platform (/)" > <value-context>fileSystem</value-context> <value-name>/</value-name> </destination-base-dir> </bundle-target>
Example 4.26. Multiple Bundle Base Directories
<bundle-target> <destination-base-dir name="Install Directory" description="The top directory where the JBossAS Server is installed. "> <value-context>pluginConfiguration</value-context> <value-name>homeDir</value-name> </destination-base-dir> <destination-base-dir name="Profile Directory" description="The profile configuration directory."> <value-context>pluginConfiguration</value-context> <value-name>serverHomeDir</value-name> </destination-base-dir> </bundle-target>
4.8. Extended Example: Asynchronous Availability Checks
getAvailability()
.
AvailabilityCollectorRunnable
class.
Example 4.27. Part 1: The Collector
public class YourResourceComponent implements ResourceComponent { // your component needs this data member - it is your availability collector private AvailabilityCollectorRunnable availCollector;
Example 4.28. Part 2: Start the Availability Collector
public void start(ResourceContext context) { availCollector = resourceContext.createAvailabilityCollectorRunnable(new AvailabilityFacet() { public AvailabilityType getAvailability() { // Perform the actual check to see if the managed resource is up or not // This method is not on a timer and can return the availability in any amount of time // that it needs to take. return ...AvailabilityType...; } }, 60000L); // 1 minute - the minimum interval allowed // Now that you've created your availability collector, start it to assign it a thread in the pool. availCollector.start(); // ... and the rest of your component's start method goes here ... } public void stop() { // Stop your availability collector to cancel the collector and kill its thread. availCollector.stop(); // ... and the rest of your component's stop method goes here ... }
getAvailability()
method. When the async availability collector is created, then the getAvailability()
method needs to return the last known results stored in the collector rather than attempting to run a new availability scan.
getAvailability()
method.
Example 4.29. Part 2: Return the Last Known Availability
public AvailabilityType getAvailability() { // This method quickly returns the last known availability that was recorded // by the availability collector. return availCollector.getLastKnownAvailability(); } }
Chapter 5. Writing Agent Plug-ins: Procedures
5.1. Tip: Checking XSD Annotations
rhq-configuration.xsd
and rhq-plugin.xsd
.
<xs:attribute name="subCategory" use="optional"> <xs:annotation> <xs:documentation> Resource types can be grouped into subcategories. A subcategory defines "like" resource types so they can, for example, be shown together in a UI group tab. You can, therefore, define multiple resource types and group them together by making their subCategory attributes the same. </xs:documentation> </xs:annotation> </xs:attribute>
5.2. Validating Agent Plug-ins
mvn org.rhq:rhq-plugin-validator:rhq-plugin-validate
<build> <plugins> <plugin> <groupId>org.rhq</groupId> <artifactId>rhq-core-plugin-validator</artifactId> <version>1.0.1-SNAPSHOT</version> </plugin> </plugins> </build> ... ... <pluginRepositories> <pluginRepository> <id>jboss</id> <name>JBoss Plugin Repository</name> <url>http://repository.jboss.org/maven2/</url> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> ...
5.3. Notes on Editing Agent Plug-ins
rhq-plugin.xml
file and rebuilding the plug-in.
5.4. Deploying Agent Plug-ins
/rhq-agent/plugins/
directory. Agent plug-ins are deployed by uploading them to the JBoss ON server, and the JBoss ON servers distribute them to the agents. As with server-side plug-ins, agent plug-ins can be deployed to a local JBoss ON server or through the JBoss ON UI.
5.4.1. Remotely Deploying Agent Plug-ins
- In the top menu, click the Administration tab.
- In the Configuration box on the left navigation bar, click the Agent Plugins link.
- Scroll to the Upload Plugin section at the bottom of the page.
- Click the Browse... button, and browse to the plug-in JAR file's location.
- When the plug-in to be deployed is listed in the box, click the Upload button.
- Once you have finished uploading agent plug-ins, use the Scan For Updates button. The update process may take several minutes depending on the size and number of resource types defined by the added plug-ins.
- To deploy the plug-in updates to the agents within the system, use the Update Plugins On Agents button.NoteThe plug-in can also be deployed by restarting each RHQ Agent or by invoking the Update All Plugins resource operation for each RHQ Agent resource:
- Select main Inventory tab,
- select the All Resources option from the Resources menu on the left,
- select the name of the relevant agent,
- create a schedule under the Operations tab.
5.4.2. Locally Deploying Agent Plug-ins
plugins/
directory. The server periodically polls this directory. Any new or updated JAR files are copied to the appropriate directory in the server configuration, and then the original JAR file is deleted from the plugins/
directory.
/plugins/
directory and the server will deploy it.
5.5. Updating Agent Plug-ins
META-INF/MANIFEST.MF
file in the JAR file) to identify the later version of the plug-in and to update the plug-ins on the JBoss ON servers in the cloud.
5.6. Disabling Agent Plug-ins
- In the top menu, click the Administration tab.
- In the Configuration box on the left navigation bar, click the Agent Plugins link.
- Select the agent plug-in to be disabled.
- Click the DISABLE button.
5.7. Deleting Agent Plug-ins
- In the top menu, click the Administration tab.
- In the Configuration box on the left navigation bar, click the Agent Plugins link.
- Select the plug-in to delete.
- Click the Delete button.
Chapter 6. Agent Advanced Management Plug-in System (AMPS) Reference
6.1. Domain Objects
6.1.1. Resource and ResourceType
6.2. Plug-in Facets
6.2.1. AvailabilityFacet
6.2.2. ConfigurationFacet
6.2.3. ContentFacet
6.2.4. ManualAddFacet
6.2.5. MeasurementFacet
6.2.6. OperationFacet
6.2.7. ResourceFactoryFacet
6.2.8. SupportFacet
6.3. Plug-in Components
6.3.1. ResourceDiscoveryComponent
ResourceDiscoveryContext
object to the discovery component. This context contains all the information the component needs to perform its duties of finding and creating new resources. The discovery context is also used to inject resources into the discovery component, in the case where the plug-in container was able to discover new resources on behalf of the discovery component. A plug-in container can only auto-discover resources if the appropriate metadata is supplied to it via the plug-in's descriptor.
6.3.2. ResourceComponent
6.4. Native System Information Access
6.4.1. SystemInfoFactory and SystemInfo
ResourceDiscoveryContext
or ResourceContext
), it can make calls to that object which will call down into the native libraries to obtain the requested data from the operating system. If there are no native libraries available, the SystemInfo will be backed with a pure Java implementation of some, but not all, of the methods defined in the SystemInfo interface (see the JavaSystemInfo implementation of that interface). The methods that are not supported by the pure Java implementation will throw an UnsupportedOperationException
.
6.4.2. ProcessInfoQuery
Chapter 7. Document Information
7.1. Giving Feedback
- Select the JBoss products group.
- Select Red Hat JBoss Operations Network from the list.
- Set the component to Documentation.
- Set the version number to 3.3.
- For errors, give the page number (for the PDF) or URL (for the HTML), and give a succinct description of the problem, such as incorrect procedure or typo.For enhancements, put in what information needs to be added and why.
- Give a clear title for the bug. For example, "Incorrect command example for setup script options" is better than "Bad example".
Appendix A. Document History
Revision History | |||
---|---|---|---|
Revision 3.3.2-7 | Thu Jun 25 2015 | Jared Morgan | |
| |||
Revision 3.3.1-1 | Wed Feb 18 2015 | Jared Morgan | |
| |||
Revision 3.3-10 | Mon Nov 17 2014 | Jared Morgan | |
|