我已經下載並在本地系統上安裝了Solr(SolrCloud)v。4.10.3,並且可以在沒有任何問題的情況下運行它,索引文檔以及與其Web UI進行交互。我也可以使用下面的命令行與它的ZooKeeper進行交互:如何使用solrZkClient和zkStateReader獲取Solr Cloud的羣集狀態?
zkcli.sh -z localhost:9983 -cmd get /clusterstate.json
並且它返回關於SolrCloud的信息。現在我試圖通過使用Java以編程方式獲得類似的信息集。
我已經試過如下:
SolrZkClient solrZkClient = new SolrZkClient("localhost:9983", 4000);
ZkStateReader zkStateReader = new ZkStateReader(solrZkClient);
System.err.println(zkStateReader.getClusterState());
System.err.println(zkStateReader.getClusterState().getLiveNodes());
但不幸的是zkStateReader.getClusterState()回報null
。
在日誌輸出我看到以下內容:
2015-04-23 15:19:04 INFO ZooKeeper:100 - Client environment:zookeeper.version=3.4.5-1392090, built on 09/30/2012 17:52 GMT
2015-04-23 15:19:04 INFO ZooKeeper:100 - Client environment:host.name=emre-ubuntu
2015-04-23 15:19:04 INFO ZooKeeper:100 - Client environment:java.version=1.8.0_25
2015-04-23 15:19:04 INFO ZooKeeper:100 - Client environment:java.vendor=Oracle Corporation
2015-04-23 15:19:04 INFO ZooKeeper:100 - Client environment:java.home=/usr/lib/jvm/java-8-oracle/jre
...
2015-04-23 15:19:04 INFO ZooKeeper:438 - Initiating client connection, connectString=localhost:9983 sessionTimeout=4000 [email protected]
2015-04-23 15:19:04 INFO ConnectionManager:207 - Waiting for client to connect to ZooKeeper
2015-04-23 15:19:04 INFO ClientCnxn:966 - Opening socket connection to server localhost/127.0.0.1:9983. Will not attempt to authenticate using SASL (unknown error)
2015-04-23 15:19:04 INFO ClientCnxn:849 - Socket connection established to localhost/127.0.0.1:9983, initiating session
2015-04-23 15:19:04 INFO ClientCnxn:1207 - Session establishment complete on server localhost/127.0.0.1:9983, sessionid = 0x14ce5f89eec000d, negotiated timeout = 4000
2015-04-23 15:19:04 INFO ConnectionManager:102 - Watcher [email protected] name:ZooKeeperConnection Watcher:localhost:9983 got event WatchedEvent state:SyncConnected type:None path:null path:null type:None
2015-04-23 15:19:04 INFO ConnectionManager:225 - Client is connected to ZooKeeper
null
我缺少的東西?我如何使用Java獲取這些信息?
謝謝巴迪..從現在開始使用它! – Vijay