Skip to end of metadata
Go to start of metadata

Script Sources

Existing impls

Note that the filename extension of the modules can be omitted for both javascript and python, but this is generally lanaguage-specific:

Repositories

Module ID format rhq://repositories/<repo_name>/<module_name>
Description Requires a user to be logged in to RHQ server. Downloads a module of given name from a repository of given name.
Javascript Example
Available In CLI, server
Implementation class RepoScriptSourceProvider

File System

Module ID format file:<absolute-path>
Description Allows for loading modules from absolute paths on the local filesystem.
Javascript Example
Available In CLI
Implementation class FileSystemScriptSourceProvider

Downloads

Module ID format rhq://downloads/<path-to-module>
Description Requires a user to be logged in to RHQ server. Downloads a module of given name from a "downloads" location on the RHQ server. The idea for this location is that in this location you will find scripts provided by RHQ itself that can be used both by the alert scripts and the CLI.
Javascript Example
Available In CLI, server
Implementation class RhqDownloadsScriptSourceProvider for the CLI version and RhqDownloadsScriptSourceProvider for the server-side version

Modules Directory

Module ID format modules:<path>
Description Allows for loading modules from a configured location on the local filesystem. You can configure the root location by passing rhq.scripting.modules.root-dir system property to the CLI process. E.g.
Javascript Example
Available In CLI
Implementation class ModulesDirectoryScriptSourceProvider

How it works

RHQ has a pluggable mechanism for locating scripts in various locations.

To add support for your location of choice, you need to implement the ScriptSourceProvider interface and put the Java service entry in META-INF/services of a jar your class is located in. Then you need to put this jar into $CLI_HOME/lib or on the server into $RHQ_HOME/modules/org/rhq/server-startup/main/deployments/rhq.ear/lib.

Example

Above we listed several existing implementations of the org.rhq.scripting.ScriptSourceProvider interface. This is a simple one method interface that you can implement yourself to provide new locations the scripts can be downloaded from.

For example the following implementation just tries to download the script from the URI if Java supports connecting to that location (i.e. it will support at least http and https protocols):

To install this source provider into CLI, you can use the Java services functionality. In the META-INF directory of the jar where you provider resides, create the "services" directory and in there, create a file called org.rhq.scripting.ScriptSourceProvider. In that file, place the full class names of any source providers you implemented in the jar, one per line. If the URLScriptSourceProvider from above was from the com.example package, this would be the layout of the jar:

  • com
    • example
      • URLScriptSourceProvider.class
  • META-INF
    • services
      • org.rhq.scripting.ScriptSourceProvider

and the file META-INF/services/org.rhq.scripting.ScriptSourceProvider would contain just a single line:

You'd put this jar into the lib directory of your CLI installation and you could start using it in your require calls. For example the following javascript code would cause the provider to download the file from the network:

If you'd like to use this source provider in your alert scripts on the RHQ server, you'd need to place the jar in the modules/org/rhq/server-startup/main/deployments/rhq.ear/lib of the RHQ server
installation.

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.