9

Suppose I have instance of Hazelcast running somewhere on remote machine and it executed in official Docker image. So I wolud like to see some data that Hazelcast stores just like in the first video here. So I'm wondering is there any way to connect to existing Hazelcast instance from any CLI utility to get the data but without Management Center?

Andrii Pischanski
  • 297
  • 1
  • 3
  • 11

4 Answers4

11

Andrii,

You can take advantage of Hazelcast demo application. You can find here:

  • com.hazelcast.console.ConsoleApp member console, part of hazelcast*.jar. See GH
  • com.hazelcast.client.console.ClientConsoleApp client console, part of hazelcast-client*.jar. See GH

You can modify server.sh to run member / client in CLI mode

java -server $JAVA_OPTS com.hazelcast.console.ConsoleApp

or

java -server $JAVA_OPTS com.hazelcast.client.console.ClientConsoleApp

Let me know if you have any questions. Thank you

Vik Gamov
  • 5,446
  • 1
  • 26
  • 46
  • Viktor, Thank you for the response. This is working for me. But there is inaccuracy in the javadoc that is provided in `com.hazelcast.client.console.ClientConsoleApp` for `main`. There specified that it expects `hazelcast.xml` file in the classpath but actually it expects `hazelcast-client.xml` file. Again thank you for your response. – Andrii Pischanski Dec 23 '16 at 18:32
3

Thanks to Viktor Gamov I have found the way to see the data from CLI with provided com.hazelcast.client.console.ClientConsoleApp that is part of hazelcast*.jar. Here is the small summary how to connect to existing instance using client:

  1. Modify clientConsole.sh (that is located under <hazelcast installation>/demo) script (or create new one if you want) and the line in it have to be like that: java -Djava.net.preferIPv4Stack=true -cp .:../lib/hazelcast-all-<version>.jar com.hazelcast.client.console.ClientConsoleApp
  2. Put your config file to the same directory with your script (possibly <hazelcast installation>/demo)
  3. Your config file should have the name exactly hazelcast-client.xml and may be look like the following:
<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config">
    <group>
        <name>dev</name>
        <password>dev-pass</password>
    </group>
    <network>
        <cluster-members>
            <address>localhost:5701</address>
        </cluster-members>
    </network>
</hazelcast-client>
jzheaux
  • 7,042
  • 3
  • 22
  • 36
Andrii Pischanski
  • 297
  • 1
  • 3
  • 11
0

Best way is to write a Java utility that can run from CLI. It can make use of HazelcastClient to connect to the cluster, get hold of IMap and print however you need. Also IMap.getLocalMapStats gives stats related to local map for that node.

A.K.Desai
  • 1,274
  • 1
  • 10
  • 16
0

Adding on to @Viktor Gamov's answer and @Andrii Pischanski's answer, I wrote a simple shell script to automate the process of:

  1. Downloading the correct version of hazelcast-all-<version>.jar (containing the ClientConsoleApp class),
  2. Creating the appropriate hazelcast-client.xml file for connecting to the cluster: https://github.com/YongJieYongJie/hazelcast-cli, and
  3. Running the appropriate java command actually connect to the cluster.

Hope this proves helpful to someone.

yongjieyongjie
  • 813
  • 10
  • 18