-
Language:
English
-
Language:
English
Chapter 30. Red Hat JBoss Data Grid CLIs
30.1. JBoss Data Grid CLIs
Red Hat JBoss Data Grid includes two Command Line Interfaces: a Library Mode CLI (see Red Hat JBoss Data Grid Library Mode CLI for details) and a Server Mode CLI (see Red Hat JBoss Data Grid Server CLI for details).
30.2. Red Hat JBoss Data Grid Library Mode CLI
30.2.1. Red Hat JBoss Data Grid Library Mode CLI
Red Hat JBoss Data Grid includes the Red Hat JBoss Data Grid Library Mode Command Line Interface (CLI) that is used to inspect and modify data within caches and internal components (such as transactions, cross-datacenter replication sites, and rolling upgrades). The JBoss Data Grid Library Mode CLI can also be used for more advanced operations such as transactions.
30.2.2. Start the Library Mode CLI (Server)
Start the Red Hat JBoss Data Grid CLI’s server-side module with the standalone and domain files. For Linux, use the standalone.sh or domain.sh script and for Windows, use the standalone.bat or domain.bat file.
30.2.3. Start the Library Mode CLI (Client)
Start the Red Hat JBoss Data Grid CLI client using the cli files in the bin directory. For Linux, run bin/cli.sh and for Windows, run bin\cli.bat .
When starting up the CLI client, specific command line switches can be used to customize the start up.
30.2.4. CLI Client Switches for the Command Line
The listed command line switches are appended to the command line when starting the Red Hat JBoss Data Grid CLI command:
Table 30.1. CLI Client Command Line Switches
Short Option | Long Option | Description |
---|---|---|
-c | --connect=${URL} |
Connects to a running Red Hat JBoss Data Grid instance. For example, for JMX over RMI use |
-f | --file=${FILE} |
Read the input from the specified file rather than using interactive mode. If the value is set to |
-h | --help | Displays the help information. |
-v | --version | Displays the CLI version information. |
30.2.5. Connect to the Application
Use the following command to connect to the application using the CLI:
[disconnected//]> connect 127.0.0.1:9990 [standalone@127.0.0.1:9990/>
The port value 9990
depends on the value the JVM is started with. This port may be changed by starting the JVM with the -Dcom.sun.management.jmxremote.port=$PORT_NUMBER
command line parameter. When the remoting protocol (remoting://localhost:9990
) is used, the Red Hat JBoss Data Grid server administration port is used (the default is port 9990
).
The command line prompt displays the active connection information, along with the current directory.
Use the container
command to select a cache manager, and then select a cache with the cache
command. A cache must be selected before performing cache operations. The CLI supports tab completion, therefore using the cache
and pressing the tab button displays a list of active caches. The following example assumes a cache manager, MyCacheManager
, defined in the configuration.
[standalone@127.0.0.1:9990/> container MyCacheManager [standalone@127.0.0.1:9990/MyCacheManager/> cache default namedCache [standalone@127.0.0.1:9990/MyCacheManager/]> cache default [standalone@127.0.0.1:9990/MyCacheManager/default]>
Additionally, pressing tab displays a list of valid commands for the CLI.
30.3. Red Hat JBoss Data Grid Server CLI
30.3.1. Red Hat Data Grid Server Mode CLI
Red Hat JBoss Data Grid includes a new Remote Client-Server mode CLI. This CLI can only be used for specific use cases, such as manipulating the server subsystem for the following:
- configuration
- management
- obtaining metrics
30.3.2. Start the Server Mode CLI
Use the following commands to run the JBoss Data Grid Server CLI from the command line:
For Linux:
$ JDG_HOME/bin/cli.sh
For Windows:
C:\>JDG_HOME\bin\cli.bat
30.4. CLI Commands
30.4.1. CLI Commands
Unless specified otherwise, all listed commands for the JBoss Data Grid CLIs can be used with both the Library Mode and Server Mode CLIs. Specifically, the deny
(see The deny Command), grant
(see The grant Command), and roles
(see The roles command) commands are only available on the Server Mode CLI.
30.4.2. The abort Command
The abort
command aborts a running batch initiated using the start
command. Batching must be enabled for the specified cache. The following is a usage example:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> start [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> abort [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> get a null
30.4.3. The begin Command
The begin
command starts a transaction. This command requires transactions enabled for the cache it targets. An example of this command’s usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> begin [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put b b [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> commit
30.4.4. The cache Command
The cache
command specifies the default cache used for all subsequent operations. If invoked without any parameters, it shows the currently selected cache. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> cache default [standalone@127.0.0.1:9990/MyCacheManager/default]> cache default [standalone@127.0.0.1:9990/MyCacheManager/default]>
30.4.5. The clearcache Command
The clearcache
command clears all content from the cache. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> clearcache [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> get a null
30.4.6. The commit Command
The commit
command commits changes to an ongoing transaction. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> begin [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put b b [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> commit
30.4.7. The container Command
The container
command selects the default cache container (cache manager). When invoked without any parameters, it lists all available containers. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> container MyCacheManager OtherCacheManager [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> container OtherCacheManager [standalone@127.0.0.1:9990/OtherCacheManager/]>
30.4.8. The create Command
The create
command creates a new cache based on the configuration of an existing cache definition. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> create newCache like namedCache [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> cache newCache [standalone@127.0.0.1:9990/MyCacheManager/newCache]>
30.4.9. The deny Command
When authorization is enabled and the role mapper has been configured to be the ClusterRoleMapper, principal to role mappings are stored within the cluster registry (a replicated cache available to all nodes). The deny
command can be used to deny roles previously assigned to a principal:
[standalone@127.0.0.1:9990]> deny supervisor to user1
The deny
command is only available to the JBoss Data Grid Server Mode CLI.
30.4.10. The disconnect Command
The disconnect
command disconnects the currently active connection, which allows the CLI to connect to another instance. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> disconnect [disconnected//]
30.4.11. The encoding Command
The encoding
command sets a default codec to use when reading and writing entries to and from a cache. If invoked with no arguments, the currently selected codec is displayed. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> encoding none [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> encoding --list memcached hotrod none rest [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> encoding hotrod
30.4.12. The end Command
The end
command ends a running batch initiated using the start
command. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> start [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> end [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> get a a
30.4.13. The evict Command
The evict
command evicts an entry associated with a specific key from the cache. An example of it usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> evict a
30.4.14. The get Command
The get
command shows the value associated with a specified key. For primitive types and Strings, the get
command prints the default representation. For other objects, a JSON
representation of the object is printed. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> get a a
30.4.15. The grant Command
When authorization is enabled and the role mapper has been configured to be the ClusterRoleMapper
, the principal to role mappings are stored within the cluster registry (a replicated cache available to all nodes). The grant
command can be used to grant new roles to a principal as follows:
[standalone@127.0.0.1:9990]> grant supervisor to user1
The grant
command is only available to the JBoss Data Grid Server Mode CLI.
30.4.16. The info Command
The info
command displays the configuration of a selected cache or container. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> info GlobalConfiguration{asyncListenerExecutor=ExecutorFactoryConfiguration{factory=org.infinispan.executors.DefaultExecutorFactory@98add58}, asyncTransportExecutor=ExecutorFactoryConfiguration{factory=org.infinispan.executors.DefaultExecutorFactory@7bc9c14c}, evictionScheduledExecutor=ScheduledExecutorFactoryConfiguration{factory=org.infinispan.executors.DefaultScheduledExecutorFactory@7ab1a411}, replicationQueueScheduledExecutor=ScheduledExecutorFactoryConfiguration{factory=org.infinispan.executors.DefaultScheduledExecutorFactory@248a9705}, globalJmxStatistics=GlobalJmxStatisticsConfiguration{allowDuplicateDomains=true, enabled=true, jmxDomain='jboss.infinispan', mBeanServerLookup=org.jboss.as.clustering.infinispan.MBeanServerProvider@6c0dc01, cacheManagerName='local', properties={}}, transport=TransportConfiguration{clusterName='ISPN', machineId='null', rackId='null', siteId='null', strictPeerToPeer=false, distributedSyncTimeout=240000, transport=null, nodeName='null', properties={}}, serialization=SerializationConfiguration{advancedExternalizers={1100=org.infinispan.server.core.CacheValue$Externalizer@5fabc91d, 1101=org.infinispan.server.memcached.MemcachedValue$Externalizer@720bffd, 1104=org.infinispan.server.hotrod.ServerAddress$Externalizer@771c7eb2}, marshaller=org.infinispan.marshall.VersionAwareMarshaller@6fc21535, version=52, classResolver=org.jboss.marshalling.ModularClassResolver@2efe83e5}, shutdown=ShutdownConfiguration{hookBehavior=DONT_REGISTER}, modules={}, site=SiteConfiguration{localSite='null'}}
30.4.17. The locate Command
The locate
command displays the physical location of a specified entry in a distributed cluster. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> locate a [host/node1,host/node2]
30.4.18. The put Command
The put
command inserts an entry into the cache. If a mapping exists for a key, the put
command overwrites the old value. The CLI allows control over the type of data used to store the key and value. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put b 100 [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put c 4139l [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put d true [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put e { "package.MyClass": {"i": 5, "x": null, "b": true } }
Optionally, the put
can specify a life span and maximum idle time value as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a expires 10s [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a expires 10m maxidle 1m
30.4.19. The replace Command
The replace
command replaces an existing entry in the cache with a specified new value. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> replace a b [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> get a b [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> replace a b c [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> get a c [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> replace a b d [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> get a c
30.4.20. The roles command
When authorization is enabled and the role mapper has been configured to be the ClusterRoleMapper
, the principal to role mappings are stored within the cluster registry (a replicated cache available to all nodes). The roles
command can be used to list the roles associated to a specific user, or to all users if one is not given:
[standalone@127.0.0.1:9990]> roles user1 [supervisor, reader]
The roles
command is only available to the JBoss Data Grid Server Mode CLI.
30.4.21. The rollback Command
The rollback
command rolls back any changes made by an ongoing transaction. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> begin [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put b b [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> rollback
30.4.22. The site Command
The site
command performs administration tasks related to cross-datacenter replication. This command also retrieves information about the status of a site and toggles the status of a site. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> site --status NYC online [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> site --offline NYC ok [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> site --status NYC offline [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> site --online NYC
30.4.23. The start Command
The start
command initiates a batch of operations. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> start [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put a a [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> put b b [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> end
30.4.24. The stats Command
The stats
command displays statistics for the cache. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> stats Statistics: { averageWriteTime: 143 evictions: 10 misses: 5 hitRatio: 1.0 readWriteRatio: 10.0 removeMisses: 0 timeSinceReset: 2123 statisticsEnabled: true stores: 100 elapsedTime: 93 averageReadTime: 14 removeHits: 0 numberOfEntries: 100 hits: 1000 } LockManager: { concurrencyLevel: 1000 numberOfLocksAvailable: 0 numberOfLocksHeld: 0 }
30.4.25. The upgrade Command
The upgrade
command implements the rolling upgrade procedure. For details about rolling upgrades, refer to Rolling Upgrades.
An example of the upgrade
command’s use is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> upgrade --synchronize=hotrod --all [standalone@127.0.0.1:9990/MyCacheManager/namedCache]> upgrade --disconnectsource=hotrod --all
30.4.26. The version Command
The version
command displays version information for the CLI client and server. An example of its usage is as follows:
[standalone@127.0.0.1:9990/MyCacheManager/namedCache]> version Client Version 5.2.1.Final Server Version 5.2.1.Final