Petals ESB CLI 3.2.0-SNAPSHOT

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

Changes (87)

View Page History
h1. Introduction

Petals ESB CLI is a command line client to administrate a set of Petals nodes.
Petals ESB CLI has 4 interaction modes:
* *Interactive Mode:* [in this mode|#Interactive console], the user types in commands directly in the shell.
* *Scripting Mode:* [in this mode|#Execution of a Petals script file], Petals ESB CLI executes a script file that contains Petals ESB CLI commands.
* *Executable Mode:* [in this mode|#Execution of a Petals ESB CLI command directly on the command line], Petals ESB CLI is launched with a command as an argument.
* *Redirection Mode:* [in this mode|#Execution of an inlined Petals script], Petals ESB CLI takes the commands to execute from the standard input.

To work, Petals ESB CLI needs to establish a connection with a Petals node.
The connection is a JMX connection (see the credentials defined in the _topology.xml_ file of Petals).

{warning}
Petals ESB CLI *1.0.0* works with Petals *4.0*, but may also work with Petals 3 versions.
Petals ESB CLI *2.0.0+* and *2.1.0+* work with Petals *4.1* and higher, but may also work with Petals 3 versions.
Petals ESB CLI *2.2.0+* works with Petals ESB Container *5.0.0*, but may also work with previous versions of Petals.
Petals ESB CLI *2.3.0* works with Petals ESB Container *5.0.1* and higher, but may also work with previous versions of Petals.
Petals ESB CLI *2.3.1+* works with Petals ESB Container *5.0.2* and higher, but may also work with previous versions of Petals.
Petals ESB CLI *3.0.0+* works with Petals ESB Container *5.1.0* and higher, but may also work with previous versions of Petals.
Petals ESB CLI *3.1.0* was not packaged because of [PETALSESBCLI-177|https://jira.petalslink.com/browse/PETALSESBCLI-177].
Petals ESB CLI *3.1.1+* works with Petals ESB Container *5.2.0* and higher, but may also work with previous versions of Petals.
Petals ESB CLI *3.2.0+* works with Petals ESB Container *5.2.0* and higher, but may also work with previous versions of Petals.
{warning}

h1. Usage of Petals ESB CLI

{code}
To get help on a command, use the command 'help' on command-line: petals-cli.sh -c -- help <command>

{tip}Options of Petals ESB CLI are [POSIX.1-2008|http://pubs.opengroup.org/onlinepubs/9699919799/] or [IEEE Std 1003.1|http://pubs.opengroup.org/onlinepubs/9699919799/] compliant.{tip}

{column}
{gliffy:name=Petals_CLI_Use_Cases|align=center|size=M|version=3}

h1. Petals ESB CLI: the Basis

h2. Installing Petals-CLI

The installation of Petals ESB CLI depends on your operating system. The following table resumes which archives is needed according to your operating system. Petals ESB CLI archives are available on the Petals's web-site: [http://download.petalslink.com/petals-esb.html].
|| Operating System || OS Version || Petals archive to use || Installation procedure ||
| Debian-based Linux | all | Debian packages | [Installing Petals ESB CLI using the Debian packages]|
| Linux | all | ZIP archive | [Installing Petals ESB CLI using the ZIP archive] |
| Microsoft Windows | all | ZIP archive | [Installing Petals ESB CLI using the ZIP archive] |
| Mac OS | all | ZIP archive | [Installing Petals ESB CLI using the ZIP archive] |

+Note:+ The ZIP archive can be used on Debian-based systems. In this case, Petals ESB CLI should be installed as a user software without integration with the operating system.

h2. Petals ESB CLI capabilities about script and shell usages

h3. Interactive console

Launching Petals ESB CLI with the following command line starts an interactive console with a prompt where the user can enter commands.
{code}
> ./petals-cli.sh -C
{code}

On Windows, to be able to launch Petals ESB CLI by a double-click, this command is wrapped by another script: *petals-cli-console.bat*.
On Linux, there is no wrapper script but a shell alias can be created.

h3. Execution of a Petals ESB CLI command directly on the command line

Launching Petals ESB CLI with the following command line executes the command specified on the command line.
{code}
> ./petals-cli.sh -c -- <command> <command-args>
h3. Execution of a Petals script file

Launching Petals ESB CLI with the following command line executes the commands from the specified Petals script.
{code}
> ./petals-cli.sh <filename>
{code}

{info}A Petals script is text file containing commands supported by Petals ESB CLI, and comments. Comments start by '{{#}}', optionally preceded by space(s).{info}

h3. Execution of an inlined Petals script

Launching Petals ESB CLI with the following command line executes commands provided through the standard input ("stdin").

{code}
* {{<command-description}} is a description of the command.

h2. Getting the version of Petals ESB CLI

To get the version of Petals ESB CLI, the version of the JVM running Petals ESB CLI, and its operating system, use the '_\-V_' option:
{code}
> ./petals-cli.sh -V
h2. Working with variables

Petals ESB CLI supports variables as properties or environment variables. A variable is a placeholder with a name: {{${variable-name\}}}, that is replaced by its value when evaluating the command in which it is used. By default, a variable is a property. An environment variable is identified by a name prefixed with "env:":
{code}
connect -h ${host.name} -n ${host.port} -u ${env:USER} -p ${host.password}
{code}

h2. Return codes of Petals ESB CLI

h3. Return code on error parsing mode options

If Petals ESB CLI is not able to determine the mode (interactive, scripting, executable or redirection) to use from arguments, the return code will be 1.

h3. Return code of Petals ESB CLI launched in interactive mode

Petals ESB CLI launched in interactive mode will exist always with the return code 0, even if error occurs executing a command.
If an error occurs during a command execution or parsing:
* The error message is displayed.
* Petals ESB CLI is not interrupted, the user can enter other commands.

h3. Return codes of Petals ESB CLI launched in command line mode

h4. Return code on parsing error of the command arguments

When there is an error about options and arguments of the command, the return code of Petals ESB CLI is 1.

h4. Return code on command execution

When there is an error about the command execution, the command is interrupted and the return code of Petals ESB CLI is 2.

h4. Return code on connection error

When there is an error about the connection establishment, the command is not executed the return code of Petals ESB CLI is 3. If the error is due to an unresolvable hostname, the return code is 1 (ie. error on arguments).

h4. Return code on successful command execution

When there is no error about options, arguments and execution of a the command, the return code of Petals ESB CLI is the return code of the command

h3. Return code of commands
All commands return the return code 0 when the execution succeeds, and 1 when the execution fails. Except the command '{{system}}' that returns the return code of the system command invoked.

h3. Return codes of Petals ESB CLI launched in scripting modes

h4. Return code on error reading script

When there is an error reading the command flow, Petals ESB CLI script is interrupted and the return code of Petals ESB CLI is 1.

h4. Return code on parsing error of the command arguments

When using the script mode or inlined mode, parsing errors (invalid options and/or arguments) result in an interruption of Petals ESB CLI.
The return code 1 then pushed back.

h4. Return code on command execution

When there is an error about a command execution, the command is interrupted, Petals ESB CLI script is interrupted and the return code of Petals ESB CLI is 2.

h4. Return code on connection error

When there is an error about the connection establishment, the command is not executed and the return code of Petals ESB CLI is 3. If the error is due to an unresolvable hostname, the return code is 1 (ie. error on arguments).

h4. Return code on successful command execution

When there is no error about options, arguments and execution of commands, the return code of Petals ESB CLI is the return code of the last command, except if a dedicated value is used through the command {{exit}}.

h4. Error management of a command read from stdin or a file
{note}If an asynchronous command is running, the command 'exit' will wait the end of these pending commands to really exit. If you have infinite asynchronous command as defect subscription, you can force to exit using Ctrl+C or kill the processus.{note}

h2. Petals ESB CLI Preferences

It is possible to define preferences in Petals ESB CLI. The preferences are defined in a properties file, as key/value pairs. Two levels of preference files are defined:
* a user level, by the file {{$HOME/.petals-cli/petals-cli.default}}
* and a system level. The location of this file is defined according to the operating system:

{tip}
If Petals ESB CLI is installed through the ZIP archive, and no user level file exists, it is possible to define another preference file through the environment variable _$PETALS_CLI_PREFS_.
{tip}

{tip}
If Petals ESB CLI is installed through the Debian archive, the default preference file is protected by system ACL and can be read only by users that are member of its group. So don't forget to add you users to the security group, or you can protect this file with your own group.
{tip}

* section 'Global preferences':
** *alias.default*: the default alias to use (required).
** *user.lang*: the language to use in Petals ESB CLI.
*** This property is optional. If not set, OS settings are used. If the OS language setting is not supported, then English is used.
*** If the value is specified and not supported, then English is picked up.
*** French and English are the two languages that must be supported. Others are optional (but contributions are welcome).
** *embedded.http.port*: the listening port of the embedded HTTP server (see the command {{deploy}}). Default value: 0 (any free port). To be able to use several Petals ESB CLI instances concurrently on the same machine, you must set {{embedded.http.port}} to 0 to force the use of a free port, otherwise an error will occur on deployments.
* section defining aliases. An alias identifies all the properties of a connection. An alias is defined as following:
** *<alias>.host*: the host of the default Petals node (required).
** *<alias>.username*: the JMX user name for the default Petals node (optional).
** *<alias>.password*: the JMX password for the default Petals node (optional).
** *<alias>.passphrase*: the security passphrase to access critical information or execute critical operation on other Petals nodes (than the one on which Petals ESB CLI is connected) of the topology (optional).

When optional keys are not defined, Petals ESB CLI will ask for their values manually (or you will have to use the right options with the commands).
If the file does not exist, or that _$PETALS_CLI_PREFS_ points to an invalid location, Petals ESB CLI will use default settings when possible. Otherwise, it will display an error message.

For a server, the *user* and *password* must both be set or both be absent. An error message is displayed if only one of them is specified.
{code}

h2. Petals ESB CLI extensions

Several Petals ESB CLI extensions are available, they comes with new command(s):
* [Petals BC SFTP tooling|Petals BC SFTP tooling],
* [Monitoring for Cacti|Command 'monitoring'].
If the preferences file does not exist and that _connect_ was invoked without an argument, the command returns the error code 2.

h2. Interacting with several Petals nodes without exiting Petals ESB CLI

In interactive mode or script mode, we should be able to close a connection and open another one without leaving Petals ESB CLI. This is achieved with the '_connect_' and '_disconnect_' commands. If no argument is set on the '_connect_' command, default values are used. These default values are specified in the preferences file. If a connection already exists, the '_connect_' command will realize a disconnection before to establish the new connection.

{code}
h2. Security

For security reasons, a Petals ESB CLI user may decide that there should be no default connection.
In that case, he may decide to delete the preference file, so that any user will have to type in the right information.
If the preference (properties file) does not exist, Petals ESB CLI displays an error message.

{code}
\\
Another possibility is that the user allows to record a default host and port but not the credentials.
In that case, Petals ESB CLI will ask the user to type in the credentials.

{code}
h3. Deploying and Starting an Artifact at once

Petals ESB CLI is able to deploy and start a JBI artifact without distinction between shared-library, component, service assembly and deployable service unit using the following command:
{code}
deploy -u <artifact-file> [-f,--file <configuration-file> | -D <configuration-properties>] [-s,--skip-startup]
{tip}Auto-completion is available on artifacts identifiers and artifact file names.{tip}

The command {{deploy}} is able to deploy an artifact local to Petals ESB CLI on a remote Petals ESB container. An artifact is local to Petals ESB CLI if deployed using a file or an URL with the protocol 'file'. In this case, the command {{deploy}} uses an embedded HTTP server. So the remote Petals ESB container will be able to download the artifact to deploy from Petals ESB CLI. See Petals ESB CLI preferences to configure the embedded HTTP server.

If the artifact to deploy is:
h3. Undeploying and Stopping an Artifact at once

Petals ESB CLI is able to stop and uninstall/undeploy a JBI artifact without distinction between shared-library, component and service assembly using the following command:
{code}
undeploy [ -u <artifact-file> | -a <artifact-id> [-t <artifact-type>] [-v <artifact-version>] ]

where:
* the container to move is the container on which Petals ESB CLI is connected
* *--target-domain*: the target domain name, the one that will be joined,
* *--target-host*: the host name of the container of the target domain. Default value: {{localhost}},

where:
* the container to detach is the container on which Petals ESB CLI is connected

A confirmation is expected, except if the '_yes_' flag is set on the command line or as command argument, otherwise an error will occur.
h2. Utility commands

Petals ESB CLI provides several utility commands:
* {{check-ssl-handshake}}: to check a SSL connection establishment.

h2. System Commands

Petals ESB CLI can directly execute system commands.
To achieve it, the system command is an argument of the '_system_' command.

{code}

displays the directory in which Petals ESB CLI runs.
The return code of the wrapping command is the return code of the system command.

h1. Advanced usage

h2. Logging in Petals ESB CLI

Petals ESB CLI is provided with a default Java Logging configuration. This configuration displays logging trace as following:
{code}
<LEVEL>: <message>
h2. To add your custom command

Petals ESB CLI is provided with an API to add your own command.

h3. Writing your command
To be auto-discovered, your command *MUST* be declared in a resource named '{{META-INF/service/org.ow2.petals.cli.api.command.Command}}' (put the class name with the package part in this file).

If the new command needs third party products in addition of the ones already provided by Petals ESB CLI, they *MUST* be installed with your command.
{warning}No classloader isolation is available between commands, pay attention to versions of third-party products. They MUST match the version of those provided with Petals ESB CLI or those custom commands.{warning}

h3. Custom command installation
To install your command just put all needed JAR files in the directory {{$PETALS_CLI_HOME/extensions}}.

h2. Monitoring Petals with Petals ESB CLI

An extension of Petals ESB CLI was created to monitor Petals ESB.

This extension has several implementations. Each implementation is adapted to a monitoring tool, but can be used as a normal command. Now, only one implementation exist, [the Cacti's implementation|Command 'monitoring']
<property1=value1,property2=value2> | -f <configuration-file>]
{code}
This is due to the option overriding: the command deploy and Petals ESB CLI have the same option: {{\-u}}. Both {{\-u}} are processed by Petals ESB CLI option parsing. Just add {{'--'}} before the command to exclude the second {{'u'}} of the Petals ESB CLI option parsing. So it will be available for the command option parsing.

h2. Can not connect using URI : service:jmx:rmi:///jndi/rmi://<host>:7700/jmxRmiConnector with petals/petals
This error can reveal several configuration problems:
* a mistake in the *Petals ESB container configuration* at topology level:
If you are running Petals ESB with its *default* configuration on a host 'A', you will get the following error connecting the Petals ESB CLI from another host 'B':
{code}
ERROR: org.ow2.petals.jmx.api.api.exception.ConnectionErrorException: Can not connect using URI : service:jmx:rmi:///jndi/rmi://192.168.0.11:7700/jmxRmiConnector with petals/petals
On Linux system, check your file {{/etc/hosts}}. If declared, the host running the Petals ESB container must be correctly defined with its IP address.

h2. Petals ESB CLI seems to be frozen on command 'exit'

You entered the command exit in the interactive mode, and the Petals ESB CLI seems to be frozen: no prompt.
You probably have launched asynchronous commands as defect subscriptions, use Ctrl-C to force to exit the Petals ESB CLI or kill its process.