Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st. We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here. Need help or have questions? Drop us a line at [email protected]
Sometimes, however, it might be the case that the user would like to interact with the DistributedMapCacheServer programmatically (and external to NiFi), say for removing specific entries, inserting/populating entries, etc. To that end I have written a Groovy script (dcachegroovy.txt, rename to dcache.groovy) to allow manipulation of the entries in a DistributedMapCacheServer from the command-line, e.g.
The usage is as follows:
Usage: groovy dcache.groovy <hostname> <port> <command> <args>
Where <command> is one of the following:
get: Retrieves the values for the keys (provided as arguments)
remove: Removes the keys (specified as arguments)
put: Sets the given keys to the given values, specified as arguments in the form: key1 value1 key2 value2 ... keyN valueN
So to insert entries "a = Hello" and "b = World" (assuming a local DistributedMapCacheServer at the default port), you can enter:
groovy dcache.groovy localhost 4557 put a Hello b World
Which outputs the following:
Set a = Hello
Set b = World
Then to retrieve the values:
groovy dcache.groovy localhost 4557 get a b
Which gives:
a = Hello
b = World
To remove an entry:
groovy dcache.groovy localhost 4557 remove b
Giving:
Removed b
Trying the get again for both values (where b no longer exists):
groovy dcache.groovy localhost 4557 get a b
Gives:
a = Hello
b =
This script can be used to pre-populate, clear, or inspect a DistributedMapCacheServer. I'd be interested to hear if you try it, whether you find it useful or not, and of course all suggestions for improvements are welcome. Cheers!