Running the RHQ CLI

compared with
Current by Jay Shaughnessy
on Jul 22, 2010 12:33.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (38)

View Page History
{toc}
{panel}

h1. Introduction

The Jopr RHQ CLI is a standalone Java application. It uses the [Java Scripting API|http://java.sun.com/javase/6/docs/api/javax/script/package-summary.html], and therefore requires Java 6 or later. The CLI offers a way to interact with Jopr RHQ programmatically, allowing developers and administrators to further integrate Jopr RHQ into their environments. Java 6 ships with the [Rhino|http://www.mozilla.org/rhino/] JavaScript engine, and as such, JavaScript is the supported scripting language in the CLI. A large subset of Jopr RHQ functionality is exposed in the CLI including,

h1. Running the Jopr RHQ CLI

The CLI is a shell/interpreter that allows you to execute statements in an interactive fashion. This can be useful for prototyping. Scripts, stored in files, can be executed as well, providing the capability to develop more fully automated solutions.
h2. Running on Windows

The Jopr RHQ CLI can be run from within a console window.

h3. Setting Environment Variables
The rhq-cli-env.bat file, located in the _<cli-install-dir>_\bin directory, contains a detailed listing of the environment variables that the CLI requires to run. For most variables, sensible defaults are used and therefore do not need editing. It is important, however, to set the correct path to your Java installation.

{note}You should not edit rhq-cli.bat - if you need to customize the launch parameters of the Jopr RHQ CLI, edit the environment variable values in rhq-cli-env.bat.{note}

h3. Running in a Windows Console

To run the Jopr RHQ CLI, execute the rhq-cli.bat located in _<cli-install-dir>_\bin directory of the installation. You can pass in any of the [Jopr [RHQ CLI Command Line Options|#Jopr Options|#RHQ CLI Command Line Options].

The rhq-cli.bat script looks for specific environment variables during its execution. These variables can be modified to suit your system requirements. For example, you can point the Jopr RHQ CLI at a new JVM or you can define VM options. Note that you should not edit the rhq-cli.bat file. If you need to customize the launch parameters of the Jopr RHQ CLI, either set the environment variables at the command prompt, or edit the values in rhq-cli-env.bat. The comments at the top of the rhq-cli-env.bat file contain a detailed list of these environment variables. You do not have to set any specific variables to get the Jopr RHQ CLI to run; sensible defaults are used.

h2. Running on Linux/Unix

The Jopr RHQ CLI can be run from within a shell of a terminal window.

h3. Setting Environment Variables

The rhq-cli-env.sh file, located in the _<cli-install-dir>_/bin/ directory, contains a detailed list of the environment variables that the Jopr RHQ CLI requires to run. For most variables, sensible defaults are used and therefore do not need editing. It is important however, to set the correct path to your Java installation. Before starting the Jopr RHQ CLI, it is best to ensure that either the {{RHQ_CLI_JAVA_HOME}} or the {{RHQ_CLI_JAVA_EXE_FILE_PATH}} variable is set appropriately.

{note}You should not edit rhq-cli.sh - if you need to customize the launch parameters of the Jopr RHQ CLI, edit the environment variable values in rhq-cli-env.sh.{note}

h3. Running in a Shell

To run the Jopr RHQ CLI, run the rhq-cli.sh script located in the _<cli-install-dir>_/bin directory of the installation. You can pass in any of the [Jopr [RHQ CLI Command Line Options|#Jopr Options|#RHQ CLI Command Line Options].

h1. Jopr RHQ CLI Command Line Options

Both rhq-cli.bat and rhq-cli.sh accept the following command line options.
|| Option || Description ||
| *\-h, \--help* | Displays the help text of the command line options of the CLI |
| *\-u, \--user* | The username used to log into the Jopr RHQ server |
| *\-p, \--password* | The password used to log into the Jopr RHQ server |
| *\-P* | Display a password prompt where input is not echoed backed to the screen |
| *\-s, \--host* | The Jopr RHQ server against which the CLI will execute commands. Defaults to localhost. |
| *\-t, \--port* | The port on which the Jopr RHQ server is accepting HTTP requests. Defaults to 7080. |
| *\-c, \--command* | A command to be executed. The command must be surrounded in double quotes. The CLI will exit after the command has finished executing. |
| *\-f, \--file* | The pathname of a script to execute. See [Executing Scripts|#Executing Scripts] below for additional information on running scripts. |
| *\-v, \--version* | Causes the CLI and Jopr RHQ server version information to be displayed once connected to the the CLI. |
| *\--transport* | Determines whether or not SSL will be used for the communication layer protocol between the CLI and the Jopr RHQ server. If not specified the value is determined from the {{port} option. If you use a port that ends in 443, SSL will be used. You only need to explicitly specify the transport when your Jopr RHQ server is listening over SSL on a port that does not end with 443. |
| *\--args-style* | Indicates the style or format of arguments passed to the script. See [Executing Scripts|#Executing Scripts] below for additional information. |

$ rhq-cli
{code}
This is the simplest way to start the CLI, without any options. You will be connected to the CLI but not logged into the Jopr RHQ server. While not logged in you can execute scripts and script commands; however, most of the Jopr RHQ functionality is not available until you are logged in.

\\
$ rhq-cli -u rhqadmin -p rhqadmin
{code}
This will connect to the CLI and attempt to log you in with the specified credentials on the Jopr RHQ server running on localhost.

\\
$ rhq-cli -u rhqadmin -p rhqadmin -s 192.168.1.100 -t 70443
{code}
This will connect to the CLI, attempt to log you into the Jopr RHQ server on 192.168.1.100 that is listening on port 70443. Because the port number ends with 443, the CLI will attempt to communicate with the Jopr RHQ server over SSL using the sslservlet transport strategy.

\\
$ rhq-cli -u rhqadmin -u rhqadmin -c "pretty.print(ResourceTypeManager.findResourceTypesByCriteria(new ResourceTypeCriteria()))" > resource_types.txt
{code}
This connects to the CLI, logs you into the Jopr RHQ server running on localhost, executes the command in quotes, redirecting the output to the file resource_types.txt. There is a quite a bit going on with that single command. Let's start with {{ResourceTypeManager.findResourceTypesByCriteria(new ResourceTypeCriteria())}}. This invokes the findResourceTypesByCriteria operation on ResourceTypeManager. A new ResourceTypeCriteria object is passed as the argument. Because nothing has been specified on the criteria object, all resource types will be returned. Now let's looks at the {{pretty.print(...)}} portion. pretty is an implicit object made available to commands and scripts by the CLI. It is very useful for outputting objects in a readable, tabular format, designed with enhanced capabilities for domain objects. In review, this single command gives us a nicely formatted,text-based report of the resource types in our inventory.

\\

*Description*
Log into a Jopr RHQ server with the specified username and password. The host name (or IP address) and port can be optionally specified. The host name defaults to localhost and the port defaults to 7080. The transport argument is optional. It determines whether or not SSL will be used for the communication layer protocol between the CLI and the Jopr RHQ server. If not specified the value is determined from the port argument.. If you use a port that ends in 443, SSL will be used. You only need to explicitly specify the transport when your Jopr RHQ server is listening over SSL on a port that does not end with 443.

h2. logout

*Description*
Log out from the Jopr RHQ server but does not exit from the CLI interpreter.

h2. quit
{code:title=executing a named script with named arguments}localhost:7080(rhqadmin)> exec --style=named -f myscript.js x=1 y=2 y=3
{code}

h2. record

h2. The API

This is a first pass at the services and related classes within RHQ to be exposed.
The CLI makes available the entire [Remote API|API Documentation] as well as enhanced [#Proxy] objects for writing scripts.

[Domain Classes|http://jopr.org/javadoc/domain/index.html]
[Plugin API Classes|http://jopr.org/javadoc/plugin-api/index.html]
[Remote API Classes|http://jopr.org/javadoc/remote-api/index.html]

h2. Implicit Variables

var resource = new Resource();
{code}

h2. Auto Completor

AND LOWER( r.agent.name ) like 'localhost.localdomain' ESCAPE '\\' )
{code}

h3. Fetching Associations

...
{noformat}
The actual output you see will vary depending on what you have inventoried. These are the child resources of my Jopr RHQ server. The JPA-QL query that is generated looks like,

{code}
rhqadmin@localhost:7080$ exporter.write(resources)
{noformat}

h1. Proxy

waitLoad: 0%
{code}

h2. Running Operations

jbossas.restart();
{code}

h2. Configurations

datasource.editResourceConfiguration()
{code}

h2. Content

myCustomEAR.updateBackingContent('CustomEAR_v2.ear');
{code}

h1. References