JBoss Community

Generic type CLI commands

modified by Alexey Loubyansky in JBoss AS7 Development - View the full document

A type generic command is a command that is assigned to a specific node type and which allows to perform any operation and/or modify any of the properties exposed by the type on any existing instance of that type.

 

For example, suppose there is a generic type command assigned to type /subsystem=datasources/data-source which is named data-source. Now using data-source command we can invoke any operation available for children of /subsystem=datasources/data-source and modify any of their properties (that have access-type read-write). The only thing left is to identify the target datasource we want to apply the action to. This is done by choosing one of the properties of the type as the identifying property. In case of this example, for datasources it could be, e.g., the jndi-name.

 

Now you can invoke operations on data sources like this


[standalone@localhost:9999 /] data-source flush-all-connection-in-pool --jndi-name=myds

 

 

flush-all-connection-in-pool is an operation name which is exposed by the management model for all datasources and jndi-name argument identifies the datasource flush-all-connection-in-pool should be performed on.

 

If the operation we want to perform requires properties, the properties can be added as command line arguments, i.e. here is an example of adding a new datasource


[standalone@localhost:9999 /] data-source add --jndi-name=myds --driver-name=h2 --pool-name=myds-pool --connection-url=curl

 

 

add is an operation name and the argument names match the operation property names prefixed with '--'.

 

Node properties can be modified in a similar way. Property names prefixed with '--' become arguments names. Except here we don't need an operation name, just the identifying property, i.e. the jndi-name in our case (which is a read-only property). E.g.

 

[standalone@localhost:9999 /] data-source --jndi-name=myds --min-pool-size=11 --max-pool-size=22

 

 

The examples above are actually for standalone mode. In domain mode, for the commands above to work they need one more argument - --profile. E.g.

 

[standalone@localhost:9999 /] data-source --profile=default --jndi-name=myds --min-pool-size=11 --max-pool-size=22

 

 

Getting help

 

Generic type commands support --help option. The help content is fetched from the management model and is based on the description of the node type, operations and properties it exposes. E.g. the following will print the description of the type


[standalone@localhost:9999 /] data-source --help
A jdbc data-source configuration

 

 

The following wil list all the properties and their descriptions (datasources hava lots of properties, so I'll paste only an exerpt here)


[standalone@localhost:9999 /] data-source --help --properties

 connection-url        - (required) The JDBC driver connection URL

 driver-class          - (required) The fully qualifed name of the JDBC driver class

 jndi-name             - (required) Specifies the JNDI name for the datasource

 new-connection-sql - (optional) Specifies an SQL statement to execute whenever a connection is added to the connection pool.

 

 

And this is how to list the operations that can be invoked on an instance of the type (btw, this list excludes some operations like

read-attribute, read-children-names, read-children-resources, read-children-types, read-operation-description, read-operation-names, read-resource, read-resource-description, validate-address, write-attribute)


[standalone@localhost:9999 /] data-source --help --commands
add
disable
enable
flush-all-connection-in-pool
flush-idle-connection-in-pool
remove
test-connection-in-pool
To read the description of a specific command execute 'data-source command_name --help'.

 

 

Here is an example of add operation description (again, it accepts a lot of properties, most of which are optional, so I paste only an exerpt of the complete description here)


[standalone@localhost:9999 /] data-source add --help 
Operation description:

    Adds a new data-source

Properties:

 --connection-url      - (STRING,required) The JDBC driver connection URL

 --driver-class        - (STRING,required) The fully qualifed name of the JDBC driver class

 --jndi-name           - (STRING,required) Specifies the JNDI name for the datasource

 --driver-name         - (STRING,required) Defines the JDBC driver the datasource should use. It is a symbolic name matching the the name of installed driver. In case the driver is deployed as jar, the name is the name of deployment unit

 --new-connection-sql  - (STRING,optional) Specifies an SQL statement to execute whenever a connection is added to the connection pool.

 

Managing commands

 

Generic type commands can be added and removed at runtime. There is a command called 'command' which can add new, list and remove existing generic type commands (but not other commands). For example


[standalone@localhost:9999 /] command list
data-source

 

 

To add a new command, you need to identify the node type, choose the identifying property and the name for the command. E.g.


[standalone@localhost:9999 /] command add --node-type=subsystem=resource-adapters/resource-adapter --property-id=archive --command-name=resource-adapter
[standalone@localhost:9999 /] command list
data-source        resource-adapter

 

 

Now there is resource-adapter command which can be used as any other CLI command, e.g.


[standalone@localhost:9999 /] resource-adapter --help --commands
add
flush-all-connection-in-pool
flush-idle-connection-in-pool
remove
test-connection-in-pool
To read the description of a specific command execute 'resource-adapter command_name --help'.

 

 

The command can be remove like this

 


[standalone@localhost:9999 /] command remove --command-name=resource-adapter
[standalone@localhost:9999 /] command list                                  
data-source

 

 

NOTE: chnages made to generic type commands don't survive CLI restart yet.

Comment by going to Community

Create a new document in JBoss AS7 Development at Community