-
Language:
English
-
Language:
English
Red Hat Training
A Red Hat training course is available for Red Hat JBoss Operations Network
Running JBoss ON Command-Line Scripts
using the JBoss ON CLI and remote API
Ella Deon Lackey
dlackey@redhat.com
Abstract
1. Document Information
1.1. Document History
Revision History | ||||||
---|---|---|---|---|---|---|
Revision 3.0.1-5 | 2013-10-31 | Rüdiger Landmann | ||||
| ||||||
Revision 3.0.1-0 | March 18, 2012 | Ella Deon Lackey | ||||
| ||||||
Revision 3.0-1 | January 26, 2012 | Ella Deon Lackey | ||||
| ||||||
Revision 3.0-0 | December 5, 2011 | Ella Deon Lackey | ||||
|
2. Using the JBoss ON CLI to Script Tasks
2.1. About the JBoss ON CLI
- Web services, like the JBoss ON UI, using SOAP and leveraging the JBoss Remoting framework for communication
- Java clients using (obviously) Java and calling the remote JBoss ON APIs
Note
rhq-cli.sh|bat
. This script emulates a shell, accepting basic commands and allowing administrators to navigate the server with shell tools like autocomplete.
Important
Caused by: java.lang.IllegalArgumentException: interface org.rhq.enterprise.server.auth.SubjectManagerRemote is not visible from class loader at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353) at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581) at org.rhq.enterprise.client.RemoteClientProxy.getProcessor(RemoteClientProxy.java:69)
2.2. More Java Resources
3. Installing the JBoss ON Command-Line Tool
rhq-client-
3.0.zip
.
Note
- Open the JBoss ON GUI.
http://server.example.com:7080
- Click the Administration link in the main menu.
- Select the Downloads menu item.
- Scroll to the Command Line Client Download section, and click Download Client Installer.
- Save the
.zip
file into the directory where the CLI should be installed. - Unzip the packages.
unzip rhq-client-version.zip
4. Running the JBoss ON CLI
rhq-cli.sh|bat
, is run directly from its cli-install-dirbin
directory and used to log into the server. There are two files associated with launching the JBoss ON CLI:
- A script
- A file of environment variables
Table 1. JBoss ON CLI Files
Operating System | CLI Script | Environment Variables File |
---|---|---|
Red Hat Enterprise Linux | rhq-cli.sh | rhq-cli-env.sh |
Microsoft Windows | rhq-cli.bat | rhq-cli-env.bat |
rhq-cli-env.sh|bat
file use defaults that are reasonable for most deployments, so this file usually does not need to be edited. It is possible to reset variables to point a server that doesn't follow the default installation, such as a virtual machine or a JVM that isn't the default. If any variables need to be edited, always set them in this file. The comments at the top of the rhq-cli-env.|bat
file contain a detailed list of available environment variables.
Important
rhq-cli.sh|bat
file. Only set environment variables through the terminal or in the rhq-cli-env.sh|bat
file, not the script itself.
Note
RHQ_CLI_JAVA_HOME
or the RHQ_CLI_JAVA_EXE_FILE_PATH
variable.
rhq-cli.sh|bat
script has the following general syntax:
rhq-cli.sh|bat options commands
cliRoot/rhq-remoting-cli-3.0.0.GA1/bin/rhq-cli.sh RHQ - RHQ Enterprise Remote CLI unconnected$
rhq-cli -u rhqadmin -p rhqadmin
Important
quit
, are available only in interactive mode. They cannot be used in a script when the CLI is used in non-interactive mode, such as when running a script from file. In these instances, you must use the Java method.
4.1. JBoss ON CLI Options
rhq-cli.bat
and rhq-cli.sh
scripts accept the options listed in Table 2, “Command-Line Options”.
Table 2. Command-Line Options
Short Option | Long 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 JBoss ON server. |
-p | --password | The password used to log into the JBoss ON server. |
-P | Displays a password prompt where input is not echoed backed to the screen. | |
-s | --host | The JBoss ON server against which the CLI executes commands. Defaults to localhost. |
-t | --port | The port on which the JBoss ON server is accepting HTTP requests. The default is 7080. |
-c | --command | A command to be executed. The command must be encased in double quotes. The CLI will exit after the command has finished executing. |
-f | --file | The full path and filename of a script to execute. |
-v | --version | Displays CLI and JBoss ON server version information 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 JBoss ON 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 JBoss ON 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 the Executing Scripts below for additional information. |
4.2. JBoss ON CLI Commands
Important
4.2.1. login
login username password [host] [port]
4.2.2. logout
logout
4.2.3. quit
quit
java.lang.System.exit
.
4.2.4. exec
exec statement | [-s indexed|named] -f /path/to/file [args]
Option | Description |
---|---|
-f, --file
|
The full path filename of the script to execute. The full path must be given, or the CLI cannot locate the script.
|
-s, --style
|
Indicates the style or format of arguments passed to the script. It must have a value of either
indexed or named .
|
Example 1. Executing a Single Statement
localhost:7080> exec var x = 1
Example 2. Executing a Multi-Line Statement
localhost:7080(rhqadmin)> exec for (i = 1; i < 3; ++i) { \ localhost:7080(rhqadmin)> println(i); \ localhost:7080(rhqadmin)> } 1 2 localhost:7080(rhqadmin)>
Example 3. Executing a Named Script without Arguments
localhost:7080(rhqadmin)> exec -f myscript.js
Example 4. Executing a Named Script with Arguments
localhost:7080(rhqadmin)> exec -f myscript.js 1 2 3
Example 5. Executing a Named Script with Named Arguments
localhost:7080(rhqadmin)> exec --style=named -f myscript.js x=1 y=2 y=3
4.2.5. record
record [-b | -e] [-a] -f
Option | Description |
---|---|
-b, --start
|
Specify this option to start recording.
|
-e, --end
|
Specify this option to stop recording.
|
-a, --append
|
Appends output to the end of a file. If not specified, output will be written starting at the beginning of the file.
|
-f, --file
|
The file where output will be written.
|
4.3. Available Implicit Variables in the JBoss ON API
org.rhq.core.domain
class is automatically imported, which makes it easier to use the CLI for managing resources, alerts, and other aspects of JBoss ON.
org.rhq.core.domain.criteria.ResourceCriteria
is commonly used to query resources. The entire class path can be given when calling that class:
var criteria = new org.rhq.core.domain.criteria.ResourceCriteria(); var resource = new org.rhq.core.domain.resource.Resource();
var criteria = new ResourceCriteria(); var resource = new Resource();
Table 3. Variables Available by Default to the JBoss ON CLI
Variable | Type | Description | Access Requires Login |
---|---|---|---|
rhq | org.rhq.enterprise.client.Controller | Provides built-in commands to the interactive CLI: login, logout, quit, exec, and version. Two of these methods, login and logout, can be called in server script files, such as rhq.login('rhqadmin', 'rhqadmin') . | YES |
subject | org.rhq.core.domain.auth.Subject | Represents the current, logged in user. For security purposes, all remote service invocations require the subject to be passed; however, the CLI will implicitly pass the subject for you. | YES |
Assert | org.rhq.bindings.util.ScriptAssert | Provides assertion utilities for CLI scripts. | NO |
pretty |
org.rhq.enterprise.client.TabularWriter
| Provides for tabular-formatted printed and handles converting objects, particularly domain objects in the packages under org.rhq.core.domain, into a format suitable for display in the console. | NO |
unlimitedPC | org.rhq.core.domain.util.PageControl | NO | |
pageControl | org.rhq.core.domain.util.PageControl | Used to specify paging and sorting on data retrieval operations | NO |
exporter |
org.rhq.enterprise.client.Exporter
| Used to export output to a file. Supported formats are plain text in tabular format and CSV. | NO |
ProxyFactory |
org.rhq.enterprise.client.utility.ResourceClientProxy.Factory
| NO | |
scriptUtil |
org.rhq.enterprise.client.utility.ScriptUtil
| Provides methods that can be useful when writing scripts. | NO |
AlertManager | org.rhq.enterprise.server.alert.AlertManagerRemote | Provides an interface into the alerts subsystem. | YES |
AlertDefinitionManager | org.rhq.enterprise.server.alert.AlertDefinitionManagerRemote | Provides an interface into the alerts definition subsystem. | YES |
AvailabilityManager | org.rhq.enterprise.server.measurement.AvailabilityManagerRemote | Provides an interface into the measurement subsystem that can be used to determine resources' availability. | YES |
CallTimeDataManager | org.rhq.enterprise.server.measurement.CallTimeDataManagerRemote | Provides an interface into the measurement subsystem for retrieving call-time metric data. | YES |
RepoManager | org.rhq.enterprise.server.content.RepoManagerRemote | Provides an interface into the content subsystem for working with repositories. | YES |
ConfigurationManager | org.rhq.enterprise.server.configuration.ConfigurationManagerRemote | Provides an interface into the configuration subsystem. | YES |
DataAccessManager | org.rhq.enterprise.server.report.DataAccessRemote | Provides an interface for executing user-defined queries. | YES |
EventManager | org.rhq.enterprise.server.event.EventManagerRemote | Provides an interface into the events subsystem. | YES |
MeasurementBaselineManager | org.rhq.enterprise.server.measurement.MeasurementBaselineManagerRemote | Provides an interface into the measurement subsystem for working with measurement baselines. | YES |
MeasurementDataManager | org.rhq.enterprise.server.measurement.MeasurementDataManagerRemote | Provides an interface into the measurement subsystem for working with measurement data. | YES |
MeasurementDefinitionManager | org.rhq.enterprise.server.measurement.MeasurementDefinitionManagerRemote | Provides an interface into the measurement subsystem for working with measurement definitions. | YES |
MeasurementScheduleManager | org.rhq.enterprise.server.measurement.MeasurementScheduleManagerRemote | Provides an interface into the measurement subsystem for working with measurement schedules. | YES |
OperationManager | org.rhq.enterprise.server.operation.OperationManagerRemote | Provides an interface into the operation subsystem. | YES |
ResourceManager | org.rhq.enterprise.server.resource.ResourceManagerRemote | Provides an interface into the resource subsystem. | YES |
ResourceGroupManager | org.rhq.enterprise.server.resource.group.ResourceGroupManagerRemote | Provides an interface into the resource group subsystem. | YES |
ResourceTypeManager | org.rhq.enterprise.server.resource.ResourceTypeManagerRemote | Provides an interface into the resource subsystem for working with resource types. | YES |
RoleManager | org.rhq.enterprise.server.authz.RoleManagerRemote | Provides an interface into the security subsystem for working with security rules and roles. | YES |
SubjectManager | org.rhq.enterprise.server.auth.SubjectManagerRemote | Provides an interface into the security subsystem for working with users. | YES |
SupportManager | org.rhq.enterprise.server.support.SupportManagerRemote | Provides an interface into the reporting subsystem for getting reports of managed resources. | YES |
4.4. Passing Script Arguments in the JBoss ON CLI
main method
, and it takes a String array as an argument. That array holds any arguments passed to the program. Similarly, arguments can be passed to CLI scripts. Arguments passed to a script can be accessed in the implicit args array
:
Example 6. Handling Script Arguments
if (args.length > 2) { throw "Not enough arguments!"; } for (i in args) { println('args[' + i + '] = ' + args[i]); }
Important
args
variable is only available when executing a script in non-interactive mode or with exec -f
.
rhqadmin@localhost:7080$ exec -f echo_args.js --args-style=named x=1, y=2
Example 7. echo_args.js
for (i in args) { println('args[' + i + '] = ' + args[i]); } println('named args...'); println('x = ' + x); println('y = ' + y);
Example 8. echo_args.js
args[0] = 1 args[1] = 2 named args... x = 1 y = 2
- You have to explicitly specify that you are using named arguments via the
--args-style
option - The values of the named arguments are still accessible via the implicit
args array
- The named arguments,
x
andy
, are bound into the script context as variables
4.5. Configuring Criteria-Based Searching
4.5.1. Setting Basic Search Criteria
rhqadmin@localhost:7080$ var criteria = new ResourceCriteria() rhqadmin@localhost:7080$ var resources = ResourceManager.findResourcesByCriteria(criteria)
ResourceCriteria
class because the org.rhq.core.domain.criteria
package is automatically imported.
findResourcesByCriteria
follows the naming format of all criteria-based query operations, findXXXByCriteria
. This basic criteria search is translated into the following JPA-QL query:
SELECT r FROM Resource r WHERE ( r.inventoryStatus = InvetoryStatus.COMMITTED
4.5.2. Using Sorting
rhqadmin@localhost:7080$ criteria.addSortPluginName(PageOrdering.ASC) rhqadmin@localhost:7080$ resources = ResourceManager.findResourcesByCriteria(criteria)
SELECT r FROM Resource r WHERE ( r.inventoryStatus = InventoryStatus.COMMITTED ) ORDER BY r.resourceType.plugin ASC
criteria.addSortPluginName()
. Sorting criteria have methods in the form addSortXXX(PageOrdering order)
.
4.5.3. Using Filtering
rhqadmin@localhost:7080$ criteria.addFilterResourceTypeName('JBossAS Server') rhqadmin@localhost:7080$ resources = ResourceManager.findResourcesByCriteria(criteria)
addFilterXXX()
. The resulting JPA-QL query will appear as follows:
SELECT r FROM Resource r WHERE ( r.inventoryStatus = InventoryStatus.COMMITTED AND LOWER( r.resourceType.name ) like 'JBossAS Server' ESCAPE '\\' )
rhqadmin@localhost:7080$ criteria.addFilterResourceTypeName('JBossAS Server') rhqadmin@localhost:7080$ criteria.addFilterAgentName('localhost.localdomain') rhqadmin@localhost:7080$ resources = ResourceManager.findResourcesByCriteria(criteria)
SELECT r FROM Resource r WHERE ( r.inventoryStatus = InventoryStatus.COMMITTED AND LOWER( r.agent.name ) like 'localhost.localdomain' ESCAPE '\\' )
4.5.4. Fetching Associations
rhqadmin@localhost:7080$ criteria.addFilterResourceTypeName('JBossAS Server') rhqadmin@localhost:7080$ resources = ResourceManager.findResourcesByCriteria(criteria) rhqadmin@localhost:7080$ resource = resources.get(0) rhqadmin@localhost:7080$ if (resource.childResources == null) print('no child resources')
rhqadmin@localhost:7080$ criteria.addFilterResourceTypeName('JBossAS Server') rhqadmin@localhost:7080$ criteria.fetchChildResources(true) rhqadmin@localhost:7080$ resources = ResourceManager.findResourcesByCriteria(criteria) rhqadmin@localhost:7080$ resource = resources.get(0) rhqadmin@localhost:7080$ if (resource.childResources == null) print('no child resources'); else pretty.print(resource.childResources)
criteria.fetchChildResources(true)
, all criteria methods that specify that a particular lazy association should be fetched are of the form, fetchXXX()
.
rhqadmin@localhost:7080$ if (resource.childResources == null) print('no child resources'); else pretty.print(resource.childResources) id name versio resourceType ---------------------------------------------------------------------------------------------------------------------- 222 AlertManagerBean EJB3 Session Bean 222 SchedulerBean EJB3 Session Bean 222 AlertDefinitionManagerBean EJB3 Session Bean 222 AlertConditionConsumerBean EJB3 Session Bean 222 PartitionEventManagerBean EJB3 Session Bean 222 AlertTemplateManagerBean EJB3 Session Bean 223 RHQ Server Group Definition / DynaGroups Subsystem RHQ Server Group Definition / DynaGrou 222 DiscoveryTestBean EJB3 Session Bean 222 PerspectiveManagerBean EJB3 Session Bean 222 ResourceAvailabilityManagerBean EJB3 Session Bean 222 AlertDampeningManagerBean EJB3 Session Bean 218 localhost.localdomain Embedded JBossWeb Server 2.0. 2.0.1. Embedded Tomcat Server 222 ResourceGroupManagerBean EJB3 Session Bean 222 FailoverListManagerBean EJB3 Session Bean 222 ResourceFactoryManagerBean EJB3 Session Bean 222 AccessBean EJB3 Session Bean 222 MeasurementTestBean EJB3 Session Bean 223 wstools.sh Script 222 EventManagerBean EJB3 Session Bean 222 ContentSourceManagerBean EJB3 Session Bean 223 RHQ Server Alerts Engine Subsystem RHQ Server Alerts Engine Subsystem 222 AlertConditionManagerBean EJB3 Session Bean 222 ResourceMetadataManagerBean EJB3 Session Bean 222 ResourceManagerBean EJB3 Session Bean 222 GroupDefinitionExpressionBuilderManagerBean EJB3 Session Bean 222 MeasurementViewManagerBean EJB3 Session Bean 218 JmsXA Connection Factory ConnectionFactory 222 ResourceTypeManagerBean EJB3 Session Bean 223 JBoss Cache subsystem 1.0 JBossCacheSubsystem 218 NoTxRHQDS Datasource Datasource 222 DataAccessBean EJB3 Session Bean 222 AlertConditionCacheManagerBean EJB3 Session Bean 222 MeasurementProblemManagerBean EJB3 Session Bean 222 ServerManagerBean EJB3 Session Bean 222 OperationHistorySubsystemManagerBean EJB3 Session Bean 222 ClusterManagerBean EJB3 Session Bean 222 run.sh Script ...
SELECT r FROM Resource r LEFT JOIN FETCH r.childResources WHERE ( r.inventoryStatus = InventoryStatus.COMMITTED AND LOWER( r.resourceType.name ) like 'JBossAS Server' ESCAPE '\\' )
4.6. Displaying Output
4.6.1. TabularWriter
TabularWriter
provides for tabular-formatted output. In addition to formatting, it handles converting objects, particularly domain objects in the packages under org.rhq.core.domain, into a format suitable for display in the interactive console. Let's look at an example to illustrate the utility of TabularWriter
:
rhqadmin@localhost:7080$ criteria = ResourceCriteria() rhqadmin@localhost:7080$ criteria.addFilterResourceTypeName('service-alpha') rhqadmin@localhost:7080$ criteria.addFilterParentResourceName('server-omega-0') rhqadmin@localhost:7080$ resources = ResourceManager.findResourcesByCriteria(criteria) id name version resourceType ---------------------------------------------------------------------------------------------------------------------- 11373 service-alpha-8 1.0 service-alpha 11374 service-alpha-1 1.0 service-alpha 11375 service-alpha-0 1.0 service-alpha 11376 service-alpha-4 1.0 service-alpha 11377 service-alpha-2 1.0 service-alpha 11378 service-alpha-3 1.0 service-alpha 11379 service-alpha-5 1.0 service-alpha 11380 service-alpha-9 1.0 service-alpha 11381 service-alpha-6 1.0 service-alpha 11382 service-alpha-7 1.0 service-alpha 10 rows
TabularWriter
instance that is bound in the script context under the name pretty is implicitly invoked to display the results of ResourceManager.findResourcesByCriteria
. The returned resources are displayed in very readable, tabular format. Now let's look at the output if we do not use TabularWriter
.
rhqadmin@localhost:7080$ println(resources) PageList[Resource[id=11373, type=service-alpha, key=service-alpha-8, name=service-alpha-8, version=1.0], Resource[id=11374, type=service-alpha, key=service-alpha-1, name=service-alpha-1, version=1.0], Resource[id=11375, type=service-alpha, key=service-alpha-0, name=service-alpha-0, version=1.0], Resource[id=11376, type=service-alpha, key=service-alpha-4, name=service-alpha-4, version=1.0], Resource[id=11377, type=service-alpha, key=service-alpha-2, name=service-alpha-2, version=1.0], Resource[id=11378, type=service-alpha, key=service-alpha-3, name=service-alpha-3, version=1.0], Resource[id=11379, type=service-alpha, key=service-alpha-5, name=service-alpha-5, version=1.0], Resource[id=11380, type=service-alpha, key=service-alpha-9, name=service-alpha-9, version=1.0], Resource[id=11381, type=service-alpha, key=service-alpha-6, name=service-alpha-6, version=1.0], Resource[id=11382, type=service-alpha, key=service-alpha-7, name=service-alpha-7, version=1.0]]
rhqadmin@localhost:7080$ pretty.print(resources.get(0)) Resource: id: 11373 name: service-alpha-8 version: 1.0 resourceType: service-alpha
Resource
class are displayed. TabularWriter
determines the properties to display through the Summary
annotation. If a field of an entity has the @Summary
annotation, TabularWriter
will include it in the output.
4.6.2. Exporter
exporter
. It uses TabularWriter
; however, in addition to writing plain text in a tabular format, it also supports CSV-formatting. First, we will look at an example of exporting to a file as plain text:
rhqadmin@localhost:7080$ exporter.setTarget('raw', 'output.txt') rhqadmin@localhost:7080$ exporter.write(resources)
exporter
handles the IO operations.
rhqadmin@localhost:7080$ exporter.setTarget('csv', 'output.csv') rhqadmin@localhost:7080$ exporter.write(resources)
4.7. Simple CLI Examples
Example 9. Logging in to a Specified Server
rhq-cli -u rhqadmin -p rhqadmin -s 192.168.1.100 -t 70443
Example 10. Prompting for a Password
rhq-cli -u rhqadmin -P
Example 11. Passing Variables to the Server
rhq-cli -u rhqadmin -p rhqadmin -c "pretty.print(ResourceTypeManager.findResourceTypesByCriteria(new ResourceTypeCriteria()))" > resource_types.txt
resource_types.txt
.
ResourceTypeManager.findResourceTypesByCriteria(new ResourceTypeCriteria())
class invokes the findResourceTypesByCriteria
operation on ResourceTypeManager
. A new ResourceTypeCriteria
object is passed as the argument.
pretty.print(...)
. An implicit object made available to commands and scripts by the CLI, pretty
is useful for outputting objects in a readable, tabular format, designed with enhanced capabilities for domain objects. This single command provides a nicely formatted, text-based report of the resource types in the inventory.
Example 12. Running a Script in the JBoss ON CLI
cliRoot/rhq-remoting-cli-3.0.0.GA1/bin/rhq-cli.sh -f my_script.js
my_script.js
. The CLI will terminate immediately after the script has finished executing.
4.8. Using Resource Proxies
ProxyFactory
to interact with the remote and domain API.
Note
ProxyFactory
is available to the JBoss ON CLI in interactive mode or when using a script file. It is also available to server scripts, such as scripts used for alerting.
ProxyFactory
gets information about a resource, which is identified in the getResource()
method with the resource's ID number.
ProxyFactory
can return a complete summary of information about the specified resource, such as its current monitoring data and traits, resource name, available metrics, available operations, content information, and child inventory, all dependent on the resource type. For example:
rhqadmin@localhost:7080$ ProxyFactory.getResource(10001) ResourceClientProxy_$$_javassist_0: OSName: Linux OSVersion: 2.6.32-220.4.1.el6.x86_64 architecture: x86_64 children: contentTypes: {rpm=RPM File} createdDate: Mon Feb 06 11:24:50 EST 2012 description: Linux Operating System distributionName: Red Hat Enterprise Linux Server distributionVersion: release 6.2 (Santiago) freeMemory: 16.7GB freeSwapSpace: 25.6GB handler: hostname: sun-x8420-01.rhts.eng.bos.redhat.com id: 10001 idle: 70.8% measurements: [Wait Load, Used Memory, System Load, Distribution Version, Total Memory, OS Name, Free Memory, Hostname, Architecture, Distribution Name, Idle, Total Swap Space, Used Swap Space, User Load, OS Version, Free Swap Space] modifiedDate: Mon Feb 06 11:24:50 EST 2012 name: sun-x8420-01.rhts.eng.bos.redhat.com operations: [viewProcessList, cleanYumMetadataCache, manualAutodiscovery] pluginConfiguration: pluginConfigurationDefinition: ConfigurationDefinition[id=10009, name=Linux] resourceType: Linux systemLoad: 0.0% totalMemory: 23.5GB totalSwapSpace: 25.6GB usedMemory: 6.8GB usedSwapSpace: 0.0B userLoad: 15.8% version: Linux 2.6.32-220.4.1.el6.x86_64 waitLoad: 0.0%
ProxyFactory
creates a resource proxy object.
Example 13. Creating a Platform Proxy Resource
var rhelServerOne = ProxyFactory.getResource(10001)
- Viewing basic information about the resource, such as its children
- Getting measurement information
- Running operations
- Changing resource and plug-in configuration
- Updating and retrieving content
Note
Example 14. Viewing a Resource's Children
ProxyFactory
has a method for all proxy objects, children
, which lists all of the children for the proxy resource.
var rhelServerOne = ProxyFactory.getResource(10001) rhqadmin@localhost:7080$ platform.children Array of org.rhq.bindings.client.ResourceClientProxy [10027] Bundle Handler - Ant (Ant Bundle Handler::AntBundlePlugin) [10026] CPU 6 (CPU::Platforms) [10025] CPU 0 (CPU::Platforms) [10024] CPU 5 (CPU::Platforms) [10023] CPU 1 (CPU::Platforms) [10022] CPU 4 (CPU::Platforms) [10021] CPU 2 (CPU::Platforms) [10020] CPU 3 (CPU::Platforms) [10019] CPU 7 (CPU::Platforms) [10018] /boot (File System::Platforms) [10017] / (File System::Platforms) [10016] /dev/shm (File System::Platforms) [10015] /home (File System::Platforms) [10014] eth1 (Network Adapter::Platforms) [10013] eth2 (Network Adapter::Platforms) [10012] eth0 (Network Adapter::Platforms) [10011] lo (Network Adapter::Platforms) [10004] postgres (Postgres Server::Postgres) [10003] AS tyan-gt24-04.rhts.eng.bos.redhat.com RHQ Server (JBossAS Server::JBos sAS) [10002] RHQ Agent (RHQ Agent::RHQAgent)
Example 15. Viewing Resource Metrics
ProxyFactory
provides a set of shortcut metrics for each individual measurement for a resource type. This corresponds to the findLiveData()
method in the remote API, but it is much easier to get monitoring information quickly and it is simpler to identify what metrics are available.
var jbossas = ProxyFactory.getResource(14832) rhqadmin@localhost:7080$ jbossas.JVMTotalMemory Measurement: name: JVM Total Memory displayValue: 995.3MB description: The total amount of memory currently available in the app server JVM for current and fut...
measurements
method:
var rhelServerOne = ProxyFactory.getResource(10001) rhqadmin@localhost:7080$ rhelServerOne.measurements Array of org.rhq.bindings.client.ResourceClientProxy$Measurement name displayValue description ----------------------------------------------------------------------------------------------------------------------- Wait Load 0.0% Percentage of all CPUs waiting on I/O Used Memory 6.3GB The total used system memory System Load 0.0% Percentage of all CPUs running in system mode Distribution Version release 6.2 (Santiago) version of the Linux distribution Total Memory 31.4GB The total system memory OS Name Linux Name that the operating system is known as Free Memory 25.2GB The total free system memory Hostname tyan-gt24-04.rhts.eng.bos.redhat.com Name that this platform is known as Architecture x86_64 Hardware architecture of the platform Distribution Name Red Hat Enterprise Linux Server name of the Linux distribution Idle 92.6% Idle percentage of all CPUs Total Swap Space 33.6GB The total system swap Used Swap Space 0.0B The total used system swap User Load 16.7% Percentage of all CPUs running in user mode OS Version 2.6.32-220.4.2.el6.x86_64 Version of the operating system Free Swap Space 33.6GB The total free system swap 16 rows
Example 16. Running Operations on a Proxy
ProxyFactory
has a shortcut method for every operation available for a resource.
operations
method:
var rhelServerOne = ProxyFactory.getResource(10001) rhqadmin@localhost:7080$ rhelServerOne.operations Array of org.rhq.bindings.client.ResourceClientProxy$Operation name description ----------------------------------------------------------------------------------------------------------------------- viewProcessList View running processes on this system cleanYumMetadataCache Deletes all cached package metadata manualAutodiscovery Run an immediate discovery to search for resources 3 rows
rhqadmin@localhost:7080$ rhelServerOne.viewProcessList(); Invoking operation viewProcessList Configuration [11951] - null processList [305] { pid name size userTime kernelTime ------------------------------------------------------------------------------------------------------------------ 1 init 19865600 150 10050 .... 26285 httpd 214618112 90 80 26286 httpd 214618112 90 80 26288 httpd 214618112 110 70 26289 httpd 214618112 90 80 27357 java 4734758912 1289650 373890 30458 postgres 218861568 1820 27440 30460 postgres 180985856 1210 5330 30462 postgres 218984448 13080 42200 30463 postgres 218861568 3970 26940 30464 postgres 219328512 10600 15320 30465 postgres 181407744 18680 78760 30482 httpd 185905152 1660 7520 32410 bash 108699648 0 10 32420 java 6024855552 3890240 669810 305 rows }
Example 17. Changing Configuration Properties
editResourceConfiguration()
and editPluginConfiguration()
, respectively — to edit those properties.
get*Configuration)
. For example, for the plug-in configuration:
var rhelServerOne = ProxyFactory.getResource(10001) rhqadmin@localhost:7080$ rhelServerOne.getPluginConfiguration() Configuration [10793] - null metadataCacheTimeout = 1800 enableContentDiscovery = false yumPort = 9080 enableInternalYumServer = false logs [0] { }
edit*Configuration()
method brings up a configuration wizard that goes through all of the properties individually and prompts to keep or change each value. The properties are even grouped according to the same organization that the JBoss ON web UI uses. For example:
rhqadmin@localhost:7080$ rhelServerOne.editPluginConfiguration(); Non-Grouped Properties: Group: Content enableContentDiscovery[false]: enableInternalYumServer[false]: yumPort[9080]: metadataCacheTimeout[1800]: Group: Event Logs [R]eview, [E]dit, Re[V]ert [S]ave or [C]ancel: ...
Keys | Action |
---|---|
return | Selects the default or existing value for a property. |
ctrl-d | The same as selecting the unset checkbox in the configuration UI. |
ctrl-k | Exits the configuration wizard. |
ctrl-e | Displays the help description for the current property. |
Example 18. Managing Content on Resources
var contentResource = ProxyFactory.getResource(14932) contentResource.retrieveBackingContent("/resources/backup/original.war")
updateBackingContent
method and specify the filename with the path on the application server to put the content and the version number of the content. For example:
contentResource.updateBackingContent("/resources/current/new.war", "2.0")
5. Simple Example: Scripts to Manage Inventory
5.1. Automatically Import New Resources: autoimport.js
NEW
. That's an in-between state, because JBoss ON is aware that the resource exists, but the resource has not been committed so JBoss ON can't manage it.
- It identifies new resources using the
findUncommittedResources()
method. - It gets those new resources' IDs.
- It then imports those resources by invoking the discovery system's import operation.
//Usage: autoImport.js //Description: Imports all auto-discovered inventory into JON // autoImport.js rhq.login('rhqadmin', 'rhqadmin'); println("Running autoImport.js"); var resources = findUncommittedResources(); var resourceIds = getIds(resources); DiscoveryBoss.importResources(resourceIds); rhq.logout();
importResources
. The other two functions — findUncommittedResources
and getIds
— have to be defined in the script.
ResourceCriteria
search by adding a search parameter based on the inventory status.
// returns a java.util.List of Resource objects // that have not yet been committed into inventory function findUncommittedResources() { var criteria = ResourceCriteria(); criteria.addFilterInventoryStatus(InventoryStatus.NEW); return ResourceManager.findResourcesByCriteria(criteria); }
// returns an array of ids for a given list // of Resource objects. Note the resources argument // can actually be any Collection that contains // elements having an id property. function getIds(resources) { var ids = []; if (resources.size() > 0) { println("Found resources to import: "); for (i = 0; i < resources.size(); i++) { resource = resources.get(i); ids[i] = resource.id; println(" " + resource.name); } } else { println("No resources found awaiting import..."); } return ids; }
5.2. Simple Inventory Count: inventoryCount.js
*Criteria
classes; for resources, this is ResourceCriteria
. A search can be very specific, passing criteria so that it returns only one resource or a small subset of resource. It is also possible to return everything in inventory.
ResourceCriteria()
), so that every resource matches the search. It then takes the size of the results to produce a simple inventory count.
// inventory.js rhq.login('rhqadmin', 'rhqadmin'); var resources = ResourceManager.findResourcesByCriteria(ResourceCriteria()); println('There are ' + resources.size() + ' resources in inventory'); // end script
5.3. Uninventory a Resource After an Alert: uninventory.js
uninventoryResource
method:
List<Integer> uninventoryResources(Subject subject, int[] resourceIds);
5.4. JNDI Lookups for a JBoss AS 5 Server After an Alert: jndi.js
Important
-f
parameter or through a server-side alert script. This cannot be run using the interactive CLI.
assertNotNull
method to get the JMX object. The script then prints the JMX information.
//This test requires a remote JBoss AS 5 server running with JNDI directory remotely accessible using JNP (without authz) //This script assumes that there is a bound object called "jmx" in the directory (which it should be) var jbossHost = 'localhost'; var jbossJnpPort = 1299; var env = new java.util.Hashtable(); env.put('java.naming.factory.initial', 'org.jboss.naming.NamingContextFactory'); env.put('java.naming.provider.url', "jnp://" + jbossHost + ":" + jbossJnpPort); var ctx = new javax.naming.InitialContext(env); var jmx = ctx.lookup('jmx'); assertNotNull(jmx); pretty.print(jmx);
6. Example: Scripting Resource Deployments
- Find all JBoss EAP instances for a specified JBoss ON group.
- Shut down each EAP instance.
- Update binaries for existing deployed applications or create new deployments.
- Restart the EAP instance.
- End the loop.
Note
6.1. Scripting JBoss AS 4 Deployments
This script will use two custom functions to deploy the packages to create new resources.
function usage() { println("Usage: deployToGroup <fileName> <groupName>"); throw "Illegal arguments"; } function PackageParser(fullPathName) { var file = new java.io.File(fullPathName); var fileName = file.getName(); var packageType = fileName.substring(fileName.lastIndexOf('.')+1); var tmp = fileName.substring(0, fileName.lastIndexOf('.')); var realName = tmp.substring(0, tmp.lastIndexOf('-')); var version = tmp.substring(tmp.lastIndexOf('-') + 1); var packageName = realName + "." + packageType; this.packageType = packageType.toLowerCase(); this.packageName = packageName; this.version = version; this.realName = realName; }
The script should have two command-line parameters. The first should be the path of the new application that is installed in the group. The second is the name of the group itself. These parameters are parsed in the script (as described in more detail in Section 4.4, “Passing Script Arguments in the JBoss ON CLI”).
if( args.length < 2 ) usage(); var fileName = args[0]; var groupName = args[1];
// check that the file exists and that we can read it var file = new java.io.File(fileName); if( !file.exists() ) { println(fileName + " does not exist!"); usage(); } if( !file.canRead() ) { println(fileName + " can't be read!"); usage(); }
// find resource group var rgc = new ResourceGroupCriteria(); rgc.addFilterName(groupName); rgc.fetchExplicitResources(true); var groupList = ResourceGroupManager.findResourceGroupsByCriteria(rgc);
rgc.fetchExplicitResources(true);
if( groupList == null || groupList.size() != 1 ) { println("Can't find a resource group named " + groupName); usage(); } var group = groupList.get(0); println(" Found group: " + group.name ); println(" Group ID : " + group.id ); println(" Description: " + group.description);
if( group.explicitResources == null || group.explicitResources.size() == 0 ) { println(" Group does not contain explicit resources --> exiting!" ); usage(); } var resourcesArray = group.explicitResources.toArray();
resourceArray
now contains all resources which are part of the group. Next, check if there are JBoss AS 4 Server instances which need to be restarted before the application is deployed.
for( i in resourcesArray ) { var res = resourcesArray[i]; var resType = res.resourceType.name; println(" Found resource " + res.name + " of type " + resType + " and ID " + res.id); if( resType != "JBossAS Server") { println(" ---> Resource not of required type. Exiting!"); usage(); } // get server resource to start/stop it and to redeploy application var server = ProxyFactory.getResource(res.id); }
server
contains the JBossAS instance. This requires re-reading the server because it needs to be fully populated. Internally, the CLI is using simple JPA persistence, and it is necessary to not always fetch all dependent objects.
var children = server.children; for( c in children ) { var child = children[c]; if( child.name == packageName ) { } }
packageName
is the name of the application without version information and path as shown in the JBoss ON GUI as deployed applications.
println(" download old app to /tmp"); child.retrieveBackingContent("/tmp/" + packageName + "_" + server.name + "_old");
/tmp/
directory.
println(" stopping " + server.name + "...."); try { server.shutdown() } catch( ex ) { println(" --> Caught " + ex ); } println(" uploading new application code"); child.updateBackingContent(fileName); println(" restarting " + server.name + "....." ); try { server.start(); } catch( ex ) { println(" --> Caught " + ex ); }
At this point, existing application can be updated. The next step is to create the resource through the CLI and then deploy it to the JBoss server.
- The type of the application (e.g., WAR or EAR)
- The type of the container the app needs to be deployed on (such as Tomcat or JBoss AS 4)
Note
rhq-plugin.xml
descriptor. The attributes, configuration parameters, operations, and metrics for each default resource type are listed in the Resource Monitoring and Operations Reference.
var appType = ResourceTypeManager.getResourceTypeByNameAndPlugin( appTypeName, "JBossAS" ); if( appType == null ) { println(" Could not find application type. Exit."); usage(); }
var realPackageType = ContentManager.findPackageTypes( appTypeName, "JBossAS" ); if( realPackageType == null ) { println(" Could not find JBoss ON's packageType. Exit."); usage(); }
rhq-plugin.xml
descriptor. To be able to create a new resource, these parameters need to be filled in.
// create deployConfig var deployConfig = new Configuration(); deployConfig.put( new PropertySimple("deployDirectory", "deploy")); deployConfig.put( new PropertySimple("deployZipped", "true")); deployConfig.put( new PropertySimple("createBackup", "false"));
var deployConfigDef = ConfigurationManager.getPackageTypeConfigurationDefinition(realPackageType.getId());
var inputStream = new java.io.FileInputStream(file); var fileLength = file.length(); var fileBytes = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, fileLength); for (numRead=0, offset=0; ((numRead >= 0) && (offset < fileBytes.length)); offset += numRead ) { numRead = inputStream.read(fileBytes, offset, fileBytes.length - offset); }
rhq-plugin.xml
descriptor. For example:
ResourceFactoryManager.createPackageBackedResource( server.id, appType.id, packageName, null, // pluginConfiguration packageName, packageVersion, null, // architectureId deployConfig, fileBytes, null // timeout );
6.2. Scripting JBoss AS 5 Deployments
This script will use two custom functions to deploy the packages to create new resources.
function usage() { println("Usage: deployToGroup <fileName> <groupName>"); throw "Illegal arguments"; } function PackageParser(fullPathName) { var file = new java.io.File(fullPathName); var fileName = file.getName(); var packageType = fileName.substring(fileName.lastIndexOf('.')+1); var tmp = fileName.substring(0, fileName.lastIndexOf('.')); var realName = tmp.substring(0, tmp.lastIndexOf('-')); var version = tmp.substring(tmp.lastIndexOf('-') + 1); var packageName = realName + "." + packageType; this.packageType = packageType.toLowerCase(); this.packageName = packageName; this.version = version; this.realName = realName; }
The script should have two command-line parameters. The first should be the path of the new application that is installed in the group. The second is the name of the group itself. These parameters are parsed in the script (as described in more detail in Section 4.4, “Passing Script Arguments in the JBoss ON CLI”).
if( args.length < 2 ) usage(); var fileName = args[0]; var groupName = args[1];
// check that the file exists and that we can read it var file = new java.io.File(fileName); if( !file.exists() ) { println(fileName + " does not exist!"); usage(); } if( !file.canRead() ) { println(fileName + " can't be read!"); usage(); }
// find resource group var rgc = new ResourceGroupCriteria(); rgc.addFilterName(groupName); rgc.fetchExplicitResources(true); var groupList = ResourceGroupManager.findResourceGroupsByCriteria(rgc);
rgc.fetchExplicitResources(true);
if( groupList == null || groupList.size() != 1 ) { println("Can't find a resource group named " + groupName); usage(); } var group = groupList.get(0); println(" Found group: " + group.name ); println(" Group ID : " + group.id ); println(" Description: " + group.description);
if( group.explicitResources == null || group.explicitResources.size() == 0 ) { println(" Group does not contain explicit resources --> exiting!" ); usage(); } var resourcesArray = group.explicitResources.toArray();
resourceArray
now contains all resources which are part of the group. Next, check if there are JBoss AS 5 Server instances which need to be restarted before the application is deployed.
for( i in resourcesArray ) { var res = resourcesArray[i]; var resType = res.resourceType.name; println(" Found resource " + res.name + " of type " + resType + " and ID " + res.id); if( resType != "JBossAS5 Server") { println(" ---> Resource not of required type. Exiting!"); usage(); } // get server resource to start/stop it and to redeploy application var server = ProxyFactory.getResource(res.id); }
server
contains the JBoss AS 5 instance. This requires re-reading the server because it needs to be fully populated. Internally, the CLI is using simple JPA persistence, and it is necessary to not always fetch all dependent objects.
var children = server.children; for( c in children ) { var child = children[c]; if( child.name == packageName ) { } }
packageName
is the name of the application without version information and path as shown in the JBoss ON GUI as deployed applications.
println(" download old app to /tmp"); child.retrieveBackingContent("/tmp/" + packageName + "_" + server.name + "_old");
/tmp/
directory.
println(" stopping " + server.name + "...."); try { server.shutDown(); } catch( ex ) { println(" --> Caught " + ex ); } println(" uploading new application code"); child.updateBackingContent(fileName); println(" restarting " + server.name + "....." ); try { server.start(); } catch( ex ) { println(" --> Caught " + ex ); }
At this point, existing application can be updated. The next step is to create the resource through the CLI and then deploy it to the JBoss server.
- The type of the application (e.g., WAR or EAR)
- The type of the container the app needs to be deployed on (such as Tomcat or JBoss AS 5)
Note
rhq-plugin.xml
descriptor. The attributes, configuration parameters, operations, and metrics for each default resource type are listed in the Resource Monitoring and Operations Reference.
var appType = ResourceTypeManager.getResourceTypeByNameAndPlugin( appTypeName, "JBossAS5" ); if( appType == null ) { println(" Could not find application type. Exit."); usage(); }
var realPackageType = ContentManager.findPackageTypes( appTypeName, "JBossAS5" ); if( realPackageType == null ) { println(" Could not find JBoss ON's packageType. Exit."); usage(); }
rhq-plugin.xml
descriptor. To be able to create a new resource, these parameters need to be filled in.
// create deployConfig var deployConfig = new Configuration(); deployConfig.put( new PropertySimple("deployExploded", "false")); deployConfig.put( new PropertySimple("deployFarmed", "false"));
var deployConfigDef = ConfigurationManager.getPackageTypeConfigurationDefinition(realPackageType.getId());
var inputStream = new java.io.FileInputStream(file); var fileLength = file.length(); var fileBytes = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, fileLength); for (numRead=0, offset=0; ((numRead >= 0) && (offset < fileBytes.length)); offset += numRead ) { numRead = inputStream.read(fileBytes, offset, fileBytes.length - offset); }
rhq-plugin.xml
descriptor. For example:
ResourceFactoryManager.createPackageBackedResource( server.id, appType.id, packageName, null, // pluginConfiguration packageName, packageVersion, null, // architectureId deployConfig, fileBytes, null // timeout );
7. Example: Managing Grouped Servers
7.1. The Plan for the Scripts
-f
parameter. The idea here is to create a series of small management scripts that perform specific tasks on a group of JBoss EAP servers. This example has seven scripts for:
- Creating a group
- Adding EAP instances to the group
- Checking EAP status
- Starting the EAP instance
- Scheduling an operation
- Deploying new content to the group
- Checking metrics
7.2. Creating the Wrapper Script and .conf File
- The wrapper script is run as a regular user, which means that any JavaScript files must be acessible to a regular user.
- The scripts are located in a
scripts/
directory that is in the same directory as the wrapper script. - A separate configuration file defines connection information for the JBoss ON server.
- Each JavaScript file is invoked by a separate CLI command invocation, defined in the wrapper.
- Any options or information required by the JBoss ON CLI command is defined in the JavaScript file and can, potentially, be passed with the wrapper script as an option.
#!/bin/bash # # groupcontrol # ------------ # This is a simple wrapper script for all the java script scripts in this folder. # Start this script with some parameters to automate group handling from within the # command line. # # With groupcontrol you can do the following: # create : Create a new group # addMember: Add a new EAP instance to the specified group # status : Print the status of all resources of a group # start : start all EAP instances specified by group name # deploy : Deploys an application to all AS instances specified by group name # ops : Runs an operation on all AS instances specified by group name # metrics : Gets the specified metric value for all AS instances specified by group name # # ## Should not be run as root. if [ "$EUID" = "0" ]; then echo " Please use a normal user account and not the root account" exit 1 fi ## Figure out script home MY_HOME=$(cd `dirname $0` && pwd) SCRIPT_HOME=$MY_HOME/scripts ## Source some defaults . $MY_HOME/groupcontrol.conf ## Check to see if we have a valid CLI home if [ ! -d ${JON_CLI_HOME} ]; then echo "JON_CLI_HOME not correctly set. Please do so in the file" echo $MY_HOME/groupcontrol.conf exit 1 fi RHQ_OPTS="-s $JON_HOST -u $JON_USER -t $JON_PORT" # If JBoss ON_PWD is given then use it as argument. Else let the user enter the password if [ "x$JON_PWD" == "x" ]; then RHQ_OPTS="$RHQ_OPTS -P" else RHQ_OPTS="$RHQ_OPTS -p $JON_PWD" fi #echo "Calling groupcontrol with $RHQ_OPTS" usage() { echo " Usage $0:" echo " Use this tool to control most group related tasks with a simple script." echo " ------------------------------------------------------------------------- " <....> }
do
Command()
section which defines the JBoss ON CLI command to run and the JavaScript file to use. For example, for the deploy
command to deploy content to the EAP instances:
doDeploy() { $JON_CLI_HOME/bin/rhq-cli.sh $RHQ_OPTS -f $SCRIPT_HOME/deployToGroup.js $2 $3 } case "$1" in 'deploy') doDeploy $* ;; *) usage $* ;; esac
groupcontrol.conf
, which defines the connection information to connect to the JBoss ON server (which is required by the JBoss ON CLI).
## ## This file contains some defaults for the groupcontrol script ## ON_CLI_HOME=cliRoot/rhq-remoting-cli-3.0.0.GA1 JON_HOST=localhost JON_PORT=7080 # The user you want to connect with JON_USER=rhqadmin # if you omit the password here, you'll be prompted for it. JON_PWD=rhqadmin
7.3. Defining Arguments and Other Parameters for the CLI Scripts
args
methods. At a minimum, each script should accept the name of the group on which to perform the task.
usage
function, so that each command can print what options are expected. For example:
function usage() { println("Usage: deploy groupName"); throw "Illegal arguments"; } if( args.length < 1 ) usage(); var groupName = args[0];
Note
$2 $3
.
doDeploy() {
$JON_CLI_HOME/bin/rhq-cli.sh $RHQ_OPTS -f $SCRIPT_HOME/deploy.js $2 $3
}
groupcriteria = new ResourceGroupCriteria(); groupcriteria.addFilterName(groupName); var groups = ResourceGroupManager.findResourceGroupsByCriteria(groupcriteria); if( groups != null ) { if( groups.size() > 1 ) { println("Found more than one group."); } else if( groups.size() == 1 ) { group = groups.get(0); } }
7.4. Creating a Group: group.js
function usage() { println("Usage: deploy groupName"); throw "Illegal arguments"; } if( args.length < 1 ) usage(); var groupName = args[0];
var rg = new ResourceGroup(resType); rg.setRecursive(false); rg.setDescription("Created via groupcontrol scripts on " + new java.util.Date().toString()); rg.setName(groupName); rg = ResourceGroupManager.createResourceGroup(rg); var resType = ResourceTypeManager.getResourceTypeByNameAndPlugin("JBossAS 5 Server","JBossAS5");
7.5. Adding Resources to a Group: addMember.js
- groupName for the group to add the resources to
- resourceName for the name of the resource to add; this is one of the search criteria
- resourceTypeName for the type of resource to add; this is one of the search criteria
function usage() { println("Usage: addMember groupName resourceName resourceTypeName"); throw "Illegal arguments"; } if( args.length < 3 ) usage(); var groupName = args[0]; var resourceName = args[1]; var resourceTypeName = args[2]; groupcriteria = new ResourceGroupCriteria(); groupcriteria.addFilterName(groupName); var groups = ResourceGroupManager.findResourceGroupsByCriteria(groupcriteria); if( groups != null ) { if( groups.size() > 1 ) { println("Found more than one group."); } else if( groups.size() == 1 ) { group = groups.get(0); } }
criteria = new ResourceCriteria(); criteria.addFilterName(resourceName); criteria.addFilterResourceTypeName(resourceTypeName); var resources = ResourceManager.findResourcesByCriteria(criteria); if( resources != null ) { if( resources.size() > 1 ) { println("Found more than one JBossAS Server instance. Try to specialize."); for( i =0; i < resources.size(); ++i) { var resource = resources.get(i); println(" found " + resource.name ); } } else if( resources.size() == 1 ) { resource = resources.get(0); println("Found one JBossAS Server instance. Trying to add it."); println(" " + resource.name ); ResourceGroupManager.addResourcesToGroup(group.id, [resource.id]); println(" Added to " + group.name + "!"); } else { println("Did not find any JBossAS Server instance matching your pattern. Try again."); } }
[jsmith@server cli]$ ./wrapper.sh addMember myGroup "JBossAS App 1" "JBossAS Server" Remote server version is: 3.0.1.GA (b2cb23b:859b914) Login successful Found one JBossAS Server instance. Trying to add it. AS server.example.com JBossAS App 1 Added to myGroup!
7.6. Getting Inventory and Status Information: status.js
function usage() { println("Usage: status groupName"); throw "Illegal arguments"; } if( args.length < 1 ) usage(); var groupName = args[0]; groupcriteria = new ResourceGroupCriteria(); groupcriteria.addFilterName(groupName); var groups = ResourceGroupManager.findResourceGroupsByCriteria(groupcriteria); if( groups != null ) { if( groups.size() > 1 ) { println("Found more than one group."); } else if( groups.size() == 1 ) { group = groups.get(0); } }
criteria = new ResourceCriteria(); criteria.addFilterExplicitGroupIds(group.id); var resources = ResourceManager.findResourcesByCriteria(criteria); for( i =0; i < resources.size(); ++i) { var resource = resources.get(i); println(" found " + resource.name ); }
var server = ProxyFactory.getResource(resource.id); var avail = AvailabilityManager.getCurrentAvailabilityForResource(server.id); println(" " + server.name ); println(" - Availability: " + avail.availabilityType.getName()); println(" - Started : " + avail.startTime.toGMTString()); println(""); var avail = AvailabilityManager.getCurrentAvailabilityForResource(server.id); if( avail.availabilityType.toString() == "DOWN" ) { println(" Server is DOWN. Please first start the server and run this script again!"); println(""); }
[jsmith@server cli]$ ./wrapper.sh status myGroup Remote server version is: 3.0.1.GA (b2cb23b:859b914) Login successful found AS server.example.com JBossAS App 1 AS server.example.com JBossAS App 1 - Availability: UP - Started : 11 Feb 2012 04:07:37 GMT
7.7. Starting, Stopping, and Restarting the Server: restart.js
shutdown()
for AS4 servers andshutDown()
for AS5 serversstart()
criteria = new ResourceCriteria(); criteria.addFilterExplicitGroupIds(group.id); var resources = ResourceManager.findResourcesByCriteria(criteria); for( i =0; i < resources.size(); ++i) { var resource = resources.get(i); var resType = resource.resourceType.name; println(" found " + resource.name ); if( resType != "JBossAS Server") { println(" ---> Resource not of required type. Exiting!"); usage(); } var server = ProxyFactory.getResource(resource.id); println(" stopping " + server.name + "...."); try { server.shutdown() } catch( ex ) { println(" --> Caught " + ex ); } println(" restarting " + server.name + "....." ); try { server.start(); } catch( ex ) { println(" --> Caught " + ex ); } }
7.8. Deploying Applications to the Group Members: deploy.js
// we need check to see if the given server is up and running var avail = AvailabilityManager.getCurrentAvailabilityForResource(server.id); // unfortunately, we can only proceed with deployment if the server is running. Why? if( avail.availabilityType.toString() == "DOWN" ) { println(" Server is DOWN. Please first start the server and run this script again!"); println(""); continue; }
7.9. Scheduling an Operation: ops.js
println("Scanning all RHQ Agent instances"); var rc = ResourceCriteria(); var resType = ResourceTypeManager.getResourceTypeByNameAndPlugin("RHQ Agent", "RHQAgent"); rc.addFilterPluginName("RHQAgent"); rc.addFilterResourceTypeName("RHQ Agent"); rc.addFilterParentResourceTypeId("10001"); var resources = ResourceManager.findResourcesByCriteria(rc).toArray(); var idx=0; for( i in resources ) { if( resources[i].resourceType.id == resType.id ) { resources[idx] = resources[i]; idx = idx + 1; } }
for( a in resources ) { var agent = resources[a] var resType = agent.resourceType.name; println(" Found resource " + agent.name + " of type " + resType + " and ID " + agent.id); println(" executing availability scan on agent" ); println(" -> " + agent.name + " / " + agent.id); var config = new Configuration(); config.put(new PropertySimple("changesOnly", "true") ); var ros = OperationManager.scheduleResourceOperation( agent.id, "executeAvailabilityScan", 0, 1, 0, 10000000, config, "test from cli" ); println(ros); println(""); }
7.10. Gathering Metric Data of Managed Servers: metrics.js
findLiveData
method, which returns the current active value for the resource.
function usage() { println("Usage: metrics groupName metricName"); throw "Illegal arguments"; } if( args.length < 2 ) usage(); var groupName = args[0]; var metricName = args[1]; groupcriteria = new ResourceGroupCriteria(); groupcriteria.addFilterName(groupName); var groups = ResourceGroupManager.findResourceGroupsByCriteria(groupcriteria); if( groups != null ) { if( groups.size() > 1 ) { println("Found more than one group."); } else if( groups.size() == 1 ) { group = groups.get(0); } } criteria = new ResourceCriteria(); criteria.addFilterExplicitGroupIds(group.id);
var rt = ResourceTypeManager.getResourceTypeByNameAndPlugin("JBossAS 5 Server","JBossAS5"); var mdc = MeasurementDefinitionCriteria(); mdc.addFilterDisplayName(metricName); mdc.addFilterResourceTypeId(rt.id); var mdefs = MeasurementDefinitionManager.findMeasurementDefinitionsByCriteria(mdc); var resources = ResourceManager.findResourcesByCriteria(criteria); var metrics = MeasurementDataManager.findLiveData(resources.get(0).id, [mdefs.get(0).id]); if( metrics !=null ) { println(" Metric value for " + resources.get(0).id + " is " + metrics ); }
[jsmith@server cli]$ ./wrapper.sh metrics myGroup "Active Thread Count" Remote server version is: 3.0.1.GA (b2cb23b:859b914) Login successful Metric value for 10003 is [MeasurementDataNumeric[value=[64.0], MeasurementData [MeasurementDataPK: timestamp=[Wed Feb 15 22:14:38 EST 2012], scheduleId=[1]]]]
8. Example: Writing a Custom Java Client
Important
Caused by: java.lang.IllegalArgumentException: interface org.rhq.enterprise.server.auth.SubjectManagerRemote is not visible from class loader at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353) at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581) at org.rhq.enterprise.client.RemoteClientProxy.getProcessor(RemoteClientProxy.java:69)
{ Client joprClient = new Client(...) jopClient.getResourceManager().findResources(...) ... }
8.1. Getting the API
8.2. Example Custom Java Client
Note
8.2.1. Sample Java Class Using the JBoss ON API
package org.rhq.sample.client.java.ldap; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.rhq.core.domain.auth.Subject; import org.rhq.core.domain.authz.Permission; import org.rhq.core.domain.authz.Role; import org.rhq.core.domain.criteria.ResourceCriteria; import org.rhq.core.domain.criteria.ResourceGroupCriteria; import org.rhq.core.domain.criteria.RoleCriteria; import org.rhq.core.domain.resource.Resource; import org.rhq.core.domain.resource.group.ResourceGroup; import org.rhq.core.domain.util.PageList; import org.rhq.enterprise.client.RemoteClient; import org.rhq.enterprise.server.auth.SubjectManagerRemote; import org.rhq.enterprise.server.authz.RoleManagerRemote; import org.rhq.enterprise.server.resource.ResourceManagerRemote; import org.rhq.enterprise.server.resource.group.ResourceGroupManagerRemote; /** * This sample program utilizes the RHQ Remote API via a Java Client. * * The RHQ CLI is the preferred remote client approach for script-based clients. Programmatic Java clients * can utilize the Remote API via the same mechanism used by the CLI, making use of ClientMain object, as * done in this sample. This is the recommended mechanism although a remote Java client could als use the * remote API exposed as WebServices. * * @author Jay Shaughnessy */ public class SampleLdapClientMain { // A remote session always starts with a login, define default user/password/server/port private static String username = "rhqadmin"; private static String password = "rhqadmin"; private static String host = "localhost"; private static int port = 7080; /** * This is a standalone remote client but calls to the remote API could be embedded into another application. */ public static void main(String[] args) { if (args.length > 0) { if ((args.length != 2) && (args.length != 4)) { System.out .println("\nUsage: SampleLdapClientMain [ [ username password ] | [username password host port] ]"); System.out.println("\n\nDefault credentials: rhqadmin/rhqadmin"); System.out.println("\n\nDefault host: determined from wsconsume of WSDL"); return; } else { username = args[0]; password = args[1]; if (args.length == 4) { host = args[2]; port = Integer.valueOf(args[3]); } } } LdapClient ldapClient = null; try { ldapClient = new LdapClient(); ldapClient.synchLdapJbasManagers(); } catch (Throwable t) { System.out.println("Error: " + t); t.printStackTrace(); } finally { if (null != ldapClient) { // clean up the session by logging out from the RHQ server ldapClient.logout(); } } } /** * The LdapClient interacts with the RHQ Server to help synchronize a (fake) LDAP server with RHQ. */ public static class LdapClient { // group containing all jbas resources private static final String JBAS_GROUP = "jbas-resource-group"; // role for jbas managers private static final String JBAS_MANAGER_ROLE = "jbas-manager-role"; // the users that should be assigned the JBAS_MANAGER_ROLE private static final List<String> JBAS_MANAGERS = new ArrayList<String>(); // the prmissions that should be assigned the JBAS_MANAGER_ROLE private static final Set<Permission> JBAS_MANAGER_PERMISSIONS = new HashSet<Permission>(); // jbas AS Server resource type (note, this picks up AS4 and AS5 resources as they share the same type name) private static final String JBAS_SERVER_NAME = "JBossAS Server"; /* The Remote API offers different remote "managers" roughly broken down by subsystem/function * Below are the managers needed by this client, there are several others that offer * interfaces into areas such as operations, alerting, content, etc. See the API. */ private ResourceGroupManagerRemote resourceGroupManager; private ResourceManagerRemote resourceManager; private RoleManagerRemote roleManager; private SubjectManagerRemote subjectManager; /* This represents the RHQ user that is logged in and making the remote calls. This user must * already exist. For the work being done here the user must also have SECURITY_MANAGER permissions. */ private Subject subject; /* This is the object through which we access the remote API */ private RemoteClient remoteClient; static { // add some fake users since we're not actually hooked into an ldap server JBAS_MANAGERS.add("mgr-1"); JBAS_MANAGERS.add("mgr-2"); // add some permissions since we're not actually hooked into an ldap server JBAS_MANAGER_PERMISSIONS.addAll(Permission.RESOURCE_ALL); } public LdapClient() throws Exception { this.remoteClient = new RemoteClient(null, host, port); this.subject = remoteClient.login(username, password); this.resourceGroupManager = this.remoteClient.getResourceGroupManagerRemote(); this.resourceManager = this.remoteClient.getResourceManagerRemote(); this.roleManager = this.remoteClient.getRoleManagerRemote(); this.subjectManager = this.remoteClient.getSubjectManagerRemote(); } /* * This method simulates a sync between an Ldap server that has defined a group of JBAS managers * and wants to associate them with a role allowing jbas management. Meaning, a role that * has the proper permissions and is associated with the jbas resources. */ private void synchLdapJbasManagers() throws Exception { // create the jbas manager role if necessary // use a criteria search with a name filter to look for the role RoleCriteria roleCriteria = new RoleCriteria(); roleCriteria.setFilterName(JBAS_MANAGER_ROLE); PageList<Role> jbasManagerRoles = roleManager.findRolesByCriteria(subject, roleCriteria); Role jbasManagerRole; if (1 == jbasManagerRoles.size()) { jbasManagerRole = jbasManagerRoles.get(0); } else { // if it doesn't exist, create it jbasManagerRole = new Role(JBAS_MANAGER_ROLE); jbasManagerRole = roleManager.createRole(subject, jbasManagerRole); } // ensure the proper permissions are granted to the role by using an update jbasManagerRole.setPermissions(JBAS_MANAGER_PERMISSIONS); roleManager.updateRole(subject, jbasManagerRole); // create, populate and associate the jbas group if necessary ResourceGroupCriteria resourceGroupCriteria = new ResourceGroupCriteria(); resourceGroupCriteria.addFilterName(JBAS_GROUP); PageList<ResourceGroup> jbasGroups = resourceGroupManager.findResourceGroupsByCriteria(subject, resourceGroupCriteria); ResourceGroup jbasGroup; if (1 == jbasGroups.size()) { jbasGroup = jbasGroups.get(0); } else { jbasGroup = new ResourceGroup(JBAS_GROUP); jbasGroup = resourceGroupManager.createResourceGroup(subject, jbasGroup); // Ensure the group is recursive to make all the children available. // In this case a specific method is available, so a general update call is not needed. resourceGroupManager.setRecursive(subject, jbasGroup.getId(), true); } // Now find all of the JBAS server resources by adding a criteria filter on resource type name ResourceCriteria resourceCriteria = new ResourceCriteria(); resourceCriteria.addFilterResourceTypeName(JBAS_SERVER_NAME); PageList<Resource> jbasServers = resourceManager.findResourcesByCriteria(subject, resourceCriteria); if (!jbasServers.isEmpty()) { int[] jbasServerIds = new int[jbasServers.size()]; int i = 0; for (Resource jbasServer : jbasServers) { jbasServerIds[i++] = jbasServer.getId(); } // ..and add them to the group which will be associated with the manager role resourceGroupManager.addResourcesToGroup(subject, jbasGroup.getId(), jbasServerIds); } // Now, associate the mixed group of Jbas servers to the manager role roleManager.addResourceGroupsToRole(subject, jbasManagerRole.getId(), new int[] { jbasGroup.getId() }); // sync managers with the role // 1. remove obsolete managers roleCriteria = new RoleCriteria(); roleCriteria.setFilterId(jbasManagerRole.getId()); // add a fetch criteria to the criteria object to get the optionally returned subjects for the role. roleCriteria.setFetchSubjects(true); jbasManagerRole = roleManager.findRolesByCriteria(subject, roleCriteria).get(0); Set<Subject> subjects = jbasManagerRole.getSubjects(); if ((null != subjects) && !subjects.isEmpty()) { for (Subject subject : subjects) { if (!JBAS_MANAGERS.contains(subject.getName())) { roleManager.removeSubjectsFromRole(subject, jbasManagerRole.getId(), new int[] { subject .getId() }); } } } // 2. add new managers, create subjects for the managers, if necessary Subject jbasManagerSubject; for (String jbasManager : JBAS_MANAGERS) { jbasManagerSubject = subjectManager.getSubjectByName(jbasManager); // add the required fields for a subject, note that we skip credentials since this is // simulating ldap if (null == jbasManagerSubject) { jbasManagerSubject = new Subject(); jbasManagerSubject.setName(jbasManager); jbasManagerSubject.setEmailAddress("jbas.manager@sample.com"); jbasManagerSubject.setFactive(true); jbasManagerSubject.setFsystem(false); jbasManagerSubject = subjectManager.createSubject(subject, jbasManagerSubject); } // Finally, make sure my current set of jbas managers is associated with the manager role. roleManager.addSubjectsToRole(subject, jbasManagerRole.getId(), new int[] { jbasManagerSubject.getId() }); } } public void logout() { if ((null != subjectManager) && (null != subject)) { try { subjectManager.logout(subject); } catch (Exception e) { // just suppress the exception, nothing else we can do } } } } }
8.2.2. Sample LDAP Script
.bat
script invokes the custom Java class.
@echo off rem =========================================================================== rem RHQ Remote Client LDAP Example Startup Script rem rem The following variables must be set rem rem RHQ_CLIENT_HOME The home directory of the RHQ Client Installation. The rem RHQ Client can be downloaded from the RHQ GUI under rem the Administration->Downloads menu. rem =========================================================================== rem ---------------------------------------------------------------------- rem Set Environment Variables rem ---------------------------------------------------------------------- set RHQ_CLIENT_HOME=*MUST BE SET* rem ---------------------------------------------------------------------- rem Prepare the classpath rem Add all jar files supplied by the RHQ remote client install rem ---------------------------------------------------------------------- set CLASSPATH=. call :append_classpath "%RHQ_CLIENT_HOME%\conf" for /R "%RHQ_CLIENT_HOME%\lib" %%G in ("*.jar") do ( call :append_classpath "%%G" ) rem ---------------------------------------------------------------------- rem Prepare the VM command line options to be passed in rem ---------------------------------------------------------------------- if not defined RHQ_CLIENT_JAVA_OPTS ( set RHQ_CLIENT_JAVA_OPTS=-Xms64m -Xmx128m -Djava.net.preferIPv4Stack=true ) rem ---------------------------------------------------------------------- rem Uncomment For debugging on port 9999 rem ---------------------------------------------------------------------- rem set RHQ_CLIENT_ADDITIONAL_JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,address=9999,server=y,suspend=y rem ---------------------------------------------------------------------- rem Execute the VM which starts the CLIENT rem ---------------------------------------------------------------------- set CMD="%JAVA_HOME%\bin\java.exe" %RHQ_CLIENT_JAVA_OPTS% %RHQ_CLIENT_ADDITIONAL_JAVA_OPTS% -cp "%CLASSPATH%" org.rhq.sample.client.java.ldap.SampleLdapClientMain %RHQ_CLIENT_CMDLINE_OPTS% %* cmd.exe /S /C "%CMD%" goto :done rem ---------------------------------------------------------------------- rem CALL subroutine that appends the first argument to CLASSPATH rem ---------------------------------------------------------------------- :append_classpath set _entry=%1 if not defined CLASSPATH ( set CLASSPATH=%_entry:"=% ) else ( set CLASSPATH=%CLASSPATH%;%_entry:"=% ) goto :eof rem ---------------------------------------------------------------------- rem CALL subroutine that exits this script normally rem ---------------------------------------------------------------------- :done endlocal exit /B 0
9. Reference: Methods Specific to the JBoss ON CLI
9.1. Methods Available to the CLI and Server Scripts
9.1.1. Assert
Method | Signature |
---|---|
Assert.assertEquals |
assertEquals(float, float, float, String) assertEquals(short, short, String) assertEquals(double, double, double) assertEquals(long, long, String) assertEquals(byte, byte, String) assertEquals(Object, Object) assertEquals(char, char, String) assertEquals(Object, Object, String) assertEquals(double, double, double, String) assertEquals(byte[], byte[]) assertEquals(boolean, boolean) assertEquals(Object[], Object[], String) assertEquals(Collection, Collection) assertEquals(Object[], Object[]) assertEquals(byte, byte) assertEquals(float, float, float) assertEquals(char, char) assertEquals(int, int) assertEquals(long, long) assertEquals(Collection, Collection, String) assertEquals(short, short) assertEquals(String, String, String) assertEquals(byte[], byte[], String) assertEquals(boolean, boolean, String) assertEquals(String, String) assertEquals(int, int, String) |
Assert.assertEqualsNoOrder |
assertEqualsNoOrder(Object[], Object[], String) assertEqualsNoOrder(Object[], Object[]) |
Assert.assertExists |
assertExists(String) |
Assert.assertFalse |
assertFalse(boolean) assertFalse(boolean, String) |
Assert.assertNotNull |
assertNotNull(Object) assertNotNull(Object, String) |
Assert.assertNotSame |
assertNotSame(Object, Object, String) assertNotSame(Object, Object) |
Assert.assertNull |
assertNull(Object) assertNull(Object, String) |
Assert.assertNumberEqualsJS |
assertNumberEqualsJS(double, double, String) |
Assert.assertSame |
assertSame(Object, Object, String) assertSame(Object, Object) |
Assert.assertTrue |
assertTrue(boolean, String) assertTrue(boolean) |
Assert.fail |
fail() fail(String, Throwable) fail(String) |
9.1.2. Subject
Method | Signature |
---|---|
subject.addLdapRole |
addLdapRole(Role) |
subject.addRole |
addRole(Role) addRole(Role, boolean) |
subject.department | Prints the department value (if any) for the current user. |
subject.emailAddress | Prints the email address for the current user. |
subject.factive | Prints whether the user account is active. |
subject.firstName | Prints whether the first name of the user. |
subject.fsystem | |
subject.id | Prints the ID number for the user account within JBoss ON. |
subject.lastName | Prints the surname for the user. |
subject.ldapRoles | Lists any roles associated with LDAP groups to which the current user is a member. |
subject.name | Prints the JBoss ON user ID of the current user. |
subject.ownedGroups | |
subject.phoneNumber | Prints thephone number, if any exists, for the current user. |
subject.removeLdapRole |
removeLdapRole(Role) |
subject.removeRole |
removeRole(Role) |
subject.roles | Prints the role name, permissions, associated LDAP users and groups, associated resource groups, and other information about every role to which the current user belongs. |
subject.sessionId | Prints the current session ID number. |
subject.smsAddress | Returns the pager number, if it exists, for the user. |
subject.toString |
String toString() |
subject.userConfiguration | Returns all of the dashboard information, based on the configured portlets, dashboards, and settings that are specific to the logged-in user. |
9.1.3. pretty
Method | Signature |
---|---|
pretty.exportMode | Prints the current export setting for the server. |
pretty.print |
print(String[][]) print(PropertySimple, int) print(Configuration) print(PropertyMap, int) print(PropertyList, int) print(Collection) print(Map) print(Object[]) print(Object) |
pretty.width | Prints the current width settings for the console display. |
9.1.4. unlimitedPC and pageControl
Method | Signature |
---|---|
unlimitedPC.addDefaultOrderingField |
addDefaultOrderingField(String, PageOrdering) addDefaultOrderingField(String) |
unlimitedPC.clone |
clone() |
unlimitedPC.firstRecord | Returns the first record in the results page. |
unlimitedPC.getExplicitPageControl |
PageControl getExplicitPageControl(int, int) |
unlimitedPC.getSingleRowInstance |
PageControl getSingleRowInstance() |
unlimitedPC.getUnlimitedInstance |
PageControl getUnlimitedInstance() |
unlimitedPC.initDefaultOrderingField |
initDefaultOrderingField(String) initDefaultOrderingField(String, PageOrdering) |
unlimitedPC.orderingFields | |
unlimitedPC.orderingFieldsAsArray | |
unlimitedPC.pageNumber | Returns the current page number for paged results. |
unlimitedPC.pageSize | Returns the current configured page size (number of returned entries per page). |
unlimitedPC.primarySortColumn | |
unlimitedPC.primarySortOrder | |
unlimitedPC.removeOrderingField |
removeOrderingField(String) |
unlimitedPC.reset |
reset() |
unlimitedPC.setPrimarySort |
setPrimarySort(String, PageOrdering) |
unlimitedPC.setPrimarySortOrder |
setPrimarySortOrder(PageOrdering) |
unlimitedPC.sortBy |
sortBy(String) |
unlimitedPC.startRow | Returns the current starting row number. |
unlimitedPC.toString |
String toString() |
unlimitedPC.truncateOrderingFields |
truncateOrderingFields(int) |
9.1.5. exporter
Method | Signature |
---|---|
exporter.close |
close() |
exporter.file | |
exporter.format | Shows the current configured output format. |
exporter.pageWidth | Shows the configured line length ofor content in the output file. |
exporter.setFormat |
setFormat(String) |
exporter.setFile |
setFile(String) |
exporter.setPageWidth |
setPageWidth(int) |
exporter.setTarget |
setTarget(String, String) |
exporter.write |
write(Object) |
9.1.6. ProxyFactory
Method | Signature |
---|---|
ProxyFactory.getResource |
ResourceClientProxy getResource(int) |
ProxyFactory.outputWriter | |
ProxyFactory.remoteClient | Returns information about the managers and configuration used by the remote client. In the interactive CLI, this prints information about the manager beans used by the interactive CLI. |
ProxyFactory.resource |
9.1.7. scriptUtil
Method | Signature |
---|---|
scriptUtil.findResources |
PageList<Resource> findResources(String) |
scriptUtil.getFileBytes |
byte[] getFileBytes(String) |
scriptUtil.isDefined |
boolean isDefined(String) |
scriptUtil.saveBytesToFile |
saveBytesToFile(byte[], String) |
scriptUtil.sleep |
sleep(long) |
scriptUtil.waitForScheduledOperationToComplete |
ResourceOperationHistory waitForScheduledOperationToComplete(ResourceOperationSchedule, long, int) ResourceOperationHistory waitForScheduledOperationToComplete(ResourceOperationSchedule) |
9.2. Methods Available to Proxy Resources
Note
Table 4. Proxy Methods for Platforms
Information Methods | |
---|---|
measurements | Displays a pretty-print list of the available metrics, current values, and description of all measurements for the platform resource. |
operations | Lists the available operations for the resource type. |
Shortcut Metric Methods | |||
---|---|---|---|
OSName | OSVersion | architecture | createdDate |
description | distributionName | distributionVersion | freeMemory |
freeSwapSpace | hostname | idle | totalMemory |
systemLoad | totalSwapSpace | usedSwapSpace | usedMemory |
userLoad | modifiedDate | waitLoad | version |
Shortcut Resource Entry Methods | ||
---|---|---|
id (inventory ID number) | resourceType | name (inventory name) |
Shortcut Operation Methods | ||
---|---|---|
manualAutodiscovery | cleanYumMetadataCache | viewProcessList |
Shortcut Configuration Methods | |
---|---|
editPluginConfiguration() | pluginConfiguration |
pluginConfigurationDefinition |
Shortcut Content Methods |
---|
contentTypes |
Shortcut Inventory Methods |
---|
children |
Method | Signature |
---|---|
platform.getChild |
ResourceClientProxy getChild(String) |
platform.getMeasurement |
Measurement getMeasurement(String) |
platform.updatePluginConfiguration |
PluginConfigurationUpdate updatePluginConfiguration(Configuration) |
platform.toString |
String toString() |
Table 5. Proxy Methods for JBoss AS/EAP Servers
Information Methods | |
---|---|
measurements | Displays a pretty-print list of the available metrics, current values, and description of all measurements for the JBoss resource. |
operations | Lists the available operations for the resource type. |
Shortcut Metric Methods | |||
---|---|---|---|
JVMFreeMemory | JVMMaxMemory | JVMTotalMemory | activeThreadCount |
activeThreadGroupCount | buildDate | createdDate | description |
modifiedDate | startDate | totalTransactions | totalTransactionsperMinute |
transactionsCommitted | transactionsCommittedperMinute | transactionsRolledback | transactionsRolledbackperMinute |
partitionName | versionName | version |
Shortcut Resource Entry Methods | ||
---|---|---|
id (inventory ID number) | resourceType | name (inventory name) |
Shortcut Operation Methods | ||
---|---|---|
restart | shutdown | start |
Shortcut Configuration Methods | |
---|---|
editPluginConfiguration() | pluginConfiguration |
pluginConfigurationDefinition |
Shortcut Content Methods |
---|
contentTypes |
Shortcut Inventory Methods |
---|
children |
Method | Signature |
---|---|
jbossas.getChild |
ResourceClientProxy getChild(String) |
jbossas.getMeasurement |
Measurement getMeasurement(String) |
jbossas.updatePluginConfiguration |
PluginConfigurationUpdate updatePluginConfiguration(Configuration) |
jbossas.toString |
String toString() |
Table 6. Proxy Methods for Content Sources (EARs, WARs, JARs)
Information Methods | |
---|---|
measurements | Displays a pretty-print list of the available metrics, current values, and description of all measurements for the content resource. |
operations | Lists the available operations for the resource type. |
Shortcut Metric Methods | ||
---|---|---|
createdDate | modifiedDate | description |
path | version | exploded |
Shortcut Resource Entry Methods | ||
---|---|---|
id (inventory ID number) | resourceType | name (inventory name) |
Shortcut Operation Methods |
---|
revert |
Shortcut Configuration Methods | |
---|---|
editPluginConfiguration() | pluginConfiguration |
pluginConfigurationDefinition |
Shortcut Content Methods | |
---|---|
contentTypes | backingContent |
Shortcut Inventory Methods |
---|
children |
Method | Signature |
---|---|
content.getChild |
ResourceClientProxy getChild(String) |
content.getMeasurement |
Measurement getMeasurement(String) |
content.updatePluginConfiguration |
PluginConfigurationUpdate updatePluginConfiguration(Configuration) |
content.toString |
String toString() |
content.retrieveBackingContent |
retrieveBackingContent(String fileName) |
content.updateBackingContent |
updateBackingContent(String filename, String displayVersion) |