1. Getting Started with the Infinispan CLI
The command line interface (CLI) lets you remotely connect to Infinispan servers to access data and perform administrative functions.
-
At least one running Infinispan server.
1.1. Starting the Infinispan CLI
Start the Infinispan CLI as follows:
-
Open a terminal in
$ISPN_HOME
. -
Run the CLI.
$ bin/cli.sh [disconnected]>
1.2. Connecting to Infinispan Servers
Do one of the following:
-
Run the
connect
command to connect to a Infinispan server on the default port of11222
:[disconnected]> connect [hostname1@cluster//containers/default]>
-
Specify the location of a Infinispan server. For example, connect to a local server that has a port offset of 100:
[disconnected]> connect 127.0.0.1:11322 [hostname2@cluster//containers/default]>
Press the tab key to display available commands and options. Use the |
1.3. Navigating CLI Resources
The Infinispan CLI exposes a navigable tree that allows you to list, describe, and manipulate Infinispan cluster resources.
When you connect to a Infinispan cluster, it opens in the context of the default cache container.
[//containers/default]>
-
Use
ls
to list resources.
[//containers/default]> ls caches counters configurations schemas
-
Use
cd
to navigate the resource tree.
[//containers/default]> cd caches
-
Use
describe
to view information about resources.
[//containers/default]> describe { "name" : "default", "version" : "xx.x.x-FINAL", "cluster_name" : "cluster", "coordinator" : true, "cache_configuration_names" : [ "org.infinispan.REPL_ASYNC", "___protobuf_metadata", "org.infinispan.DIST_SYNC", "org.infinispan.LOCAL", "org.infinispan.INVALIDATION_SYNC", "org.infinispan.REPL_SYNC", "org.infinispan.SCATTERED_SYNC", "org.infinispan.INVALIDATION_ASYNC", "org.infinispan.DIST_ASYNC" ], "physical_addresses" : "[192.0.2.0:7800]", "coordinator_address" : "<hostname>", "cache_manager_status" : "RUNNING", "created_cache_count" : "1", "running_cache_count" : "1", "node_address" : "<hostname>", "cluster_members" : [ "<hostname1>", "<hostname2>" ], "cluster_members_physical_addresses" : [ "192.0.2.0:7800", "192.0.2.0:7801" ], "cluster_size" : 2, "defined_caches" : [ { "name" : "mycache", "started" : true }, { "name" : "___protobuf_metadata", "started" : true } ] }
1.3.1. CLI Resources
The Infinispan CLI exposes different resources to:
-
create, modify, and manage local or clustered caches.
-
perform administrative operations for Infinispan clusters.
[//containers/default]> ls caches counters configurations schemas
caches
-
Infinispan cache instances. The default cache container is empty. Use the CLI to create caches from templates or
infinispan.xml
files. counters
-
Strong
orWeak
counters that record the count of objects. configurations
-
Configuration files.
schemas
-
Protocol Buffers (Protobuf) schemas that structure data in the cache.
[hostname@cluster/]> ls containers cluster server
containers
-
Cache containers on the Infinispan cluster.
cluster
-
Lists Infinispan servers joined to the cluster.
server
-
Resources for managing and monitoring Infinispan servers.
1.4. Shutting Down Infinispan Servers
Use the CLI to gracefully shutdown running servers. This ensures that Infinispan passivates all entries to disk and persists state.
-
Use the
shutdown server
command to stop individual servers, for example:[//containers/default]> shutdown server server_hostname
-
Use the
shutdown cluster
command to stop all servers joined to the cluster, for example:[//containers/default]> shutdown cluster
Infinispan servers log the following shutdown messages:
INFO [org.infinispan.SERVER] (pool-3-thread-1) ISPN080002: Infinispan Server stopping
INFO [org.infinispan.CONTAINER] (pool-3-thread-1) ISPN000029: Passivating all entries to disk
INFO [org.infinispan.CONTAINER] (pool-3-thread-1) ISPN000030: Passivated 28 entries in 46 milliseconds
INFO [org.infinispan.CLUSTER] (pool-3-thread-1) ISPN000080: Disconnecting JGroups channel cluster
INFO [org.infinispan.CONTAINER] (pool-3-thread-1) ISPN000390: Persisted state, version=<Infinispan version> timestamp=YYYY-MM-DDTHH:MM:SS
INFO [org.infinispan.SERVER] (pool-3-thread-1) ISPN080003: Infinispan Server stopped
INFO [org.infinispan.SERVER] (Thread-0) ISPN080002: Infinispan Server stopping
INFO [org.infinispan.SERVER] (Thread-0) ISPN080003: Infinispan Server stopped
When you shutdown Infinispan clusters, the shutdown messages include:
INFO [org.infinispan.SERVER] (pool-3-thread-1) ISPN080029: Cluster shutdown
INFO [org.infinispan.CLUSTER] (pool-3-thread-1) ISPN000080: Disconnecting JGroups channel cluster
2. Performing Cache Operations with the Infinispan CLI
The command line interface (CLI) lets you remotely connect to Infinispan servers to access data and perform administrative functions.
-
Start the Infinispan CLI.
-
Connect to a running Infinispan cluster.
2.1. Creating Caches from Templates
Use Infinispan cache templates to add caches with recommended default settings.
-
Create a distributed, synchronous cache from a template and name it "mycache".
[//containers/default]> create cache --template=org.infinispan.DIST_SYNC mycache
Press the tab key after the
--template=
argument to list available cache templates. -
Retrieve the cache configuration.
[//containers/default]> describe caches/mycache { "distributed-cache" : { "mode" : "SYNC", "remote-timeout" : 17500, "state-transfer" : { "timeout" : 60000 }, "transaction" : { "mode" : "NONE" }, "locking" : { "concurrency-level" : 1000, "acquire-timeout" : 15000, "striping" : false } } }
2.2. Adding Cache Entries
Add data to caches with the Infinispan CLI.
-
Create a cache named "mycache".
-
Add a key/value pair to
mycache
.[//containers/default]> put --cache=mycache hello world
If the CLI is in the context of a cache, do
put k1 v1
for example:[//containers/default]> cd caches/mycache [//containers/default/caches/mycache]> put hello world
-
List keys in the cache.
[//containers/default]> ls caches/mycache hello
-
Get the value for the
hello
key.-
Navigate to the cache.
[//containers/default]> cd caches/mycache
-
Use the
get
command to retrieve the key value.[//containers/default/caches/mycache]> get hello world
-
2.3. Deleting Cache Entries
Remove data from caches with the Infinispan CLI.
-
Create a cache named "mycache" and add entries.
Either delete all entries or remove specific entries as follows:
-
Delete all entries from a cache.
[//containers/default]> clearcache mycache
-
Remove specific entries from a cache.
[//containers/default]> remove --cache=mycache hello
2.4. Creating Custom Caches
Add caches with custom Infinispan configuration files in XML or JSON format.
-
Add the path to your configuration file with the
--file=
option as follows:
[//containers/default]> create cache --file=prod_dist_cache.xml dist_cache_01
- XML Configuration
-
A configuration in
XML
format must conform to the schema and include:-
<infinispan>
root element. -
<cache-container>
definition.The following example shows a valid
XML
configuration:<infinispan> <cache-container> <distributed-cache name="cacheName" mode="SYNC"> <memory> <object size="20"/> </memory> </distributed-cache> </cache-container> </infinispan>
-
- JSON Configuration
-
A configuration in
JSON
format payload:-
Requires the cache definition only.
-
Must follow the structure of an
XML
configuration.-
XML
elements becomeJSON
objects. -
XML
attributes becomeJSON
fields.The following example shows the previous
XML
configuration inJSON
format:{ "distributed-cache": { "mode": "SYNC", "memory": { "object": { "size": 20 } } } }
-
-
3. Performing Batch Operations
Process operations in groups, either interactively or using batch files.
-
A running Infinispan cluster.
3.1. Performing Batch Operations with Files
Create files that contain a set of operations and then pass them to the Infinispan CLI.
-
Create a file that contains a set of operations.
For example, create a file named
batch
that creates a cache namedmybatch
, adds two entries to the cache, and disconnects from the CLI.$ cat > batch<<EOF create cache --template=org.infinispan.DIST_SYNC mybatch put --cache=mybatch hello world put --cache=mybatch hola mundo disconnect EOF
-
Run the CLI and specify the file as input.
$ bin/cli.sh -c localhost:11222 -f batch
-
Open a new CLI connection to Infinispan and verify
mybatch
.[//containers/default]> ls caches ___protobuf_metadata mybatch [//containers/default]> ls caches/mybatch hola hello [//containers/default]> disconnect [disconnected]>
3.2. Performing Batch Operations Interactively
Use the standard input stream, stdin, to perform batch operations interactively.
-
Start the Infinispan CLI in interactive mode.
$ bin/cli.sh -c localhost:11222 -f -
If you do not use the
-c
flag, you must run theconnect
command.$ bin/cli.sh -f - connect
-
Run batch operations, for example:
create cache --template=org.infinispan.DIST_SYNC mybatch put --cache=mybatch hello world put --cache=mybatch hola mundo disconnect quit
Use |
The following example shows how to use echo describe
to get cluster information:
$ echo describe|bin/cli.sh -c localhost:11222 -f - { "name" : "default", "version" : "10.0.0-SNAPSHOT", "coordinator" : false, "cache_configuration_names" : [ "org.infinispan.REPL_ASYNC", "___protobuf_metadata", "org.infinispan.DIST_SYNC", "qcache", "org.infinispan.LOCAL", "dist_cache_01", "org.infinispan.INVALIDATION_SYNC", "org.infinispan.REPL_SYNC", "org.infinispan.SCATTERED_SYNC", "mycache", "org.infinispan.INVALIDATION_ASYNC", "mybatch", "org.infinispan.DIST_ASYNC" ], "cluster_name" : "cluster", "physical_addresses" : "[192.168.1.7:7800]", "coordinator_address" : "thundercat-34689", "cache_manager_status" : "RUNNING", "created_cache_count" : "4", "running_cache_count" : "4", "node_address" : "thundercat-47082", "cluster_members" : [ "thundercat-34689", "thundercat-47082" ], "cluster_members_physical_addresses" : [ "10.36.118.25:7801", "192.168.1.7:7800" ], "cluster_size" : 2, "defined_caches" : [ { "name" : "___protobuf_metadata", "started" : true }, { "name" : "mybatch", "started" : true } ] }
4. Querying Caches with Protobuf Metadata
Infinispan supports using Protocol Buffers (Protobuf) to structure data in the cache so that you can query it.
-
Start the Infinispan CLI.
-
Connect to a running Infinispan cluster.
4.1. Configuring Media Types
Encode cache entries with different media types to store data in a format that best suits your requirements.
For example, the following procedure shows you how to configure the application/x-protostream
media type.
-
Create a Infinispan configuration file that adds a distributed cache named
qcache
and configures the media type, for example:<infinispan> <cache-container> <distributed-cache name="qcache"> <encoding> <key media-type="application/x-protostream"/> <value media-type="application/x-protostream"/> </encoding> </distributed-cache> </cache-container> </infinispan>
-
Create
qcache
frompcache.xml
with the--file=
option.[//containers/default]> create cache --file=pcache.xml pcache
-
Verify
pcache
.[//containers/default]> ls caches pcache ___protobuf_metadata [//containers/default]> describe caches/pcache { "distributed-cache" : { "mode" : "SYNC", "encoding" : { "key" : { "media-type" : "application/x-protostream" }, "value" : { "media-type" : "application/x-protostream" } }, "transaction" : { "mode" : "NONE" } } }
-
Add an entry to
pcache
and check the encoding.[//containers/default]> put --cache=pcache good morning [//containers/default]> cd caches/pcache [//containers/default/caches/pcache]> get good { "_type" : "string", "_value" : "morning" }
4.2. Registering Protobuf Schemas
Protobuf schemas contain data structures known as messages in .proto
definition files.
-
Create a schema file named
person.proto
with the following messages:package org.infinispan.rest.search.entity; message Address { required string street = 1; required string postCode = 2; } message PhoneNumber { required string number = 1; } message Person { optional int32 id = 1; required string name = 2; required string surname = 3; optional Address address = 4; repeated PhoneNumber phoneNumbers = 5; optional uint32 age = 6; enum Gender { MALE = 0; FEMALE = 1; } optional Gender gender = 7; }
-
Register
person.proto
.[//containers/default]> schema --upload=person.proto person.proto
-
Verify
person.proto
.[//containers/default]> cd caches [//containers/default/caches/___protobuf_metadata]> ls person.proto [//containers/default/caches/___protobuf_metadata]> get person.proto
4.3. Querying Caches with Protobuf Schemas
Infinispan automatically converts JSON to Protobuf so that you can read and write cache entries in JSON format and use Protobuf schemas to query them.
For example, consider the following JSON documents:
lukecage.json
{ "_type":"org.infinispan.rest.search.entity.Person", "id":2, "name":"Luke", "surname":"Cage", "gender":"MALE", "address":{"street":"38th St","postCode":"NY 11221"}, "phoneNumbers":[{"number":4444},{"number":5555}] }
jessicajones.json
{ "_type":"org.infinispan.rest.search.entity.Person", "id":1, "name":"Jessica", "surname":"Jones", "gender":"FEMALE", "address":{"street":"46th St","postCode":"NY 10036"}, "phoneNumbers":[{"number":1111},{"number":2222},{"number":3333}] }
matthewmurdock.json
{ "_type":"org.infinispan.rest.search.entity.Person", "id":3, "name":"Matthew", "surname":"Murdock", "gender":"MALE", "address":{"street":"57th St","postCode":"NY 10019"}, "phoneNumbers":[] }
Each of the preceding JSON documents contains:
-
a
_type
field that identifies the Protobuf message to which the JSON document corresponds. -
several fields that correspond to datatypes in the
person.proto
schema.
-
Navigate to the
pcache
cache.[//containers/default/caches]> cd pcache
-
Add each JSON document as an entry to the cache, for example:
[//containers/default/caches/pcache]> put --encoding=application/json --file=jessicajones.json jessicajones [//containers/default/caches/pcache]> put --encoding=application/json --file=matthewmurdock.json matthewmurdock [//containers/default/caches/pcache]> put --encoding=application/json --file=lukecage.json lukecage
-
Verify that the entries exist.
[//containers/default/caches/pcache]> ls lukecage matthewmurdock jessicajones
-
Query the cache to return entries from the Protobuf
Person
entity where the gender datatype isMALE
.[//containers/default/caches/pcache]> query "from org.infinispan.rest.search.entity.Person p where p.gender = 'MALE'" { "total_results" : 2, "hits" : [ { "hit" : { "_type" : "org.infinispan.rest.search.entity.Person", "id" : 2, "name" : "Luke", "surname" : "Cage", "gender" : "MALE", "address" : { "street" : "38th St", "postCode" : "NY 11221" }, "phoneNumbers" : [ { "number" : "4444" }, { "number" : "5555" } ] } }, { "hit" : { "_type" : "org.infinispan.rest.search.entity.Person", "id" : 3, "name" : "Matthew", "surname" : "Murdock", "gender" : "MALE", "address" : { "street" : "57th St", "postCode" : "NY 10019" } } } ] }
5. Command Reference
View help pages for Infinispan CLI commands.
Use the |
5.1. ADD(1)
5.1.3. DESCRIPTION
The add adds or subtracts a value ('delta') to/from a counter. If no delta is specified, the counter is incremented by 1.
5.1.4. OPTIONS
- --delta='nnn'
-
The delta to add/subtract from the counter’s value. Defaults
- -q, --quiet='[true|false]'
-
Whether the value of the counter should be printed.
5.2. CACHE(1)
5.3. CAS(1)
5.3.4. OPTIONS
- --expect='nnn'
-
The expected value
- --value='nnn'
-
The new value
- -q, --quiet='[true|false]'
-
Whether the value of the counter should be printed.
5.4. CD(1)
5.5. CLEARCACHE(1)
5.6. CONNECT(1)
5.6.3. DESCRIPTION
The connect command connects to a running ${infinispan.brand.name} server. If the command is invoked without specifying an argument, the CLI will default to http://localhost:11222. If the connection requires authentication, the CLI will prompt for credentials.
5.7. CONTAINER(1)
5.8. COUNTER(1)
5.9. CREATE(1)
5.9.4. CREATE CACHE OPTIONS
- -f, --file='FILE'
-
A file containing a JSON or XML configuration.
- -t, --template='TEMPLATE'
-
The configuration template to use.
- -v, --volatile='[true|false]'
-
Whether the cache should be made volatile in the server so that it won’t survive restarts.
5.9.5. CREATE COUNTER OPTIONS
- -t, --type='[weak|strong]'
-
The type of counter.
- -s, --storage='[PERSISTENT|VOLATILE]'
-
Sets whether the counter should be PERSISTENT or VOLATILE.
- -c, --concurrency-level='nnn'
-
Sets the concurrency level of the counter
- -i, --initial-value='nnn'
-
Sets the initial value of the counter
- -l, --lower-bound='nnn'
-
Sets the lower bound of the counter. Only valid for strong counters
- -u, --upper-bound='nnn'
-
Sets the upper bound of the counter. Only valid for strong counters
5.10. DESCRIBE(1)
5.10.3. DESCRIPTION
The describe command retrieves and shows information about the specified resource or the currently selected one. The information displayed depends on the type of the resource.
5.10.4. EXAMPLES
describe //containers/default
Shows information about a container:
{
"name" : "default",
"version" : "10.0.0-SNAPSHOT",
"coordinator" : true,
"cache_configuration_names" : [ "org.infinispan.REPL_ASYNC", "___protobuf_metadata", "org.infinispan.DIST_SYNC", "org.infinispan.LOCAL", "org.infinispan.INVALIDATION_SYNC", "org.infinispan.REPL_SYNC", "org.infinispan.SCATTERED_SYNC", "mycache", "org.infinispan.INVALIDATION_ASYNC", "org.infinispan.DIST_ASYNC" ],
"cluster_name" : "cluster",
"physical_addresses" : "[172.17.0.1:7800]",
"cache_manager_status" : "RUNNING",
"created_cache_count" : "1",
"running_cache_count" : "1",
"node_address" : "host-29389",
"cluster_members" : [ "host-29389" ],
"cluster_members_physical_addresses" : [ "172.17.0.1:7800" ],
"cluster_size" : 1,
"defined_caches" : [ {
"name" : "mycache",
"started" : true
}, {
"name" : "___protobuf_metadata",
"started" : true
} ],
"coordinator_address" : "host-29389"
}
describe //containers/default
Shows information about a cache:
{
"distributed-cache" : {
"mode" : "SYNC",
"remote-timeout" : 17500,
"state-transfer" : {
"timeout" : 60000
},
"transaction" : {
"mode" : "NONE"
},
"locking" : {
"concurrency-level" : 1000,
"acquire-timeout" : 15000,
"striping" : false
}
}
}
describe //containers/default/caches/mycache/k1
Shows information about a cache key:
{
"cluster-backup-owners" : [ "" ],
"cluster-node-name" : [ "host-29389" ],
"cluster-primary-owner" : [ "host-29389" ],
"cluster-server-address" : [ "[172.17.0.1:7800]" ],
"connection" : [ "keep-alive" ],
"content-length" : [ "0" ],
"content-type" : [ "application/octet-stream" ],
"etag" : [ "1461965704" ],
"last-modified" : [ "Thu, 1 Jan 1970 01:00:00 +0100" ]
}
describe //containers/default/counters/cnt1
Shows information about a counter:
{
"strong-counter" : {
"name" : "cnt1",
"initial-value" : 0,
"storage" : "PERSISTENT",
"lower-bound" : -9223372036854775808,
"upper-bound" : 100
}
}
5.11. DISCONNECT(1)
5.13. ENCODING(1)
5.13.3. DESCRIPTION
The encoding command is used to set a default encoding to be used for subsequent put/get operations on a cache. When invoked without arguments it shows the currently selected encoding. Encodings must use the standard MIME types (IANA media types) naming convention. Examples of valid encodings are:
-
text/plain
-
application/json
-
application/xml
-
application/octet-stream
5.14. GET(1)
5.15. LS(1)
5.16. PUT(1)
5.16.3. DESCRIPTION
The put command puts an entry in a cache. The first argument is compulsory and indicates the key of the entry. The second argument is optional when the
5.16.4. OPTIONS
- -c, --cache='NAME'
-
The name of the cache. If not specified, the currently selected cache will be used.
- -e, --encoding='ENCODING'
-
The encoding to use when putting the trname of the cache. If not specified, the currently selected cache will be used.
- -f, --file='FILE'
-
The file to be used to supply the value.
- -l, --ttl='TTL'
-
The time-to-live of the entry in seconds. If 0 or not specified, the default expiration for the cache will be used. If a negative value, the entry never expires.
- -i, --max-idle='MAXIDLE'
-
The maximum idle time of the entry in seconds. If 0 or not specified, the default expiration for the cache will be used. If a negative value, the entry never expires.
- -a, --if-absent=[true|false]
-
Only puts an entry if it doesn’t already exist.
5.17. QUERY(1)
5.18. QUIT(1)
5.18.4. SEE ALSO
disconnect(1)
Removes the entry associated with the specified key from a cache. .SH ARGUMENTS .IP cache (optional) the name of the cache to use. If not specified, the currently selected cache will be used. See the .B cache command .IP key the key for which to remove the associated entry .SH OUTPUT
5.22. SITE(1)
5.22.2. SYNOPSIS
site status [OPTIONS]
site bring-online [OPTIONS]
site take-offline [OPTIONS]
site push-site-state [OPTIONS]
site cancel-push-state [OPTIONS]
site cancel-receive-state [OPTIONS]
site push-site-status [OPTIONS]
5.22.4. BRING-ONLINE OPTIONS
Brings a site online for the specified cache
- -c, --cache='CACHENAME'
-
The cache name
- -s, --site='SITENAME'
-
The name of the site
5.22.5. TAKE-OFFLINE OPTIONS
Takes a site offline for the specified cache
- -c, --cache='CACHENAME'
-
The cache name
- -s, --site='SITENAME'
-
The name of the site
5.22.6. PUSH-SITE-STATE OPTIONS
Pushes state to a remote site
- -c, --cache='CACHENAME'
-
The cache name
- -s, --site='SITENAME'
-
The name of the site
5.22.7. CANCEL-PUSH-STATE OPTIONS
Cancels pushing state to a remote site
- -c, --cache='CACHENAME'
-
The cache name
- -s, --site='SITENAME'
-
The name of the site