3
votes

Solr has a Admin UI where we can check each and every Collections that were deployed to Solr Cloud. For example, I can see a Slice/Shard in a collection up or not as mentioned in the below URL.

enter image description here

Our production environment doesn't provide access to this Admin UI due to security reasons. I need to provide an API to get the status of each and every collection, and its shards and each shard's replica. I am using Solr APIs to do that

http://lucene.apache.org/solr/4_7_2/solr-solrj/index.html

CloudSolrServer server = new CloudSolrServer(<zk quorum>);
ZkStateReader reader = server.getZkStateReader();
Collection<Slice> slices = reader.getClusterState().getSlices(collection);
Iterator<Slice> iter = slices.iterator();
while (iter.hasNext()) {
    Slice slice = iter.next();
    System.out.println(slice.getName());
    System.out.println(slice.getState());
}

The above piece of code is always returning Active only as the state of shard, even its replica is showing down in the UI. I assume this returns only the state of a shard, not the state of shard's leader or replica.

How can I get the replicas status through Solr APIs? is there any API for this? And what is the API being using by Solr Admin UI for getting shard's replicas/leader status?

Thanks

4

4 Answers

9
votes

The code is not looking at replica status. Here is one that prints out replica status:

CloudSolrServer server = new CloudSolrServer(zknodesurlstring);

    server.setDefaultCollection("mycollection");
    server.connect();

    ZkStateReader reader = server.getZkStateReader();
    Collection<Slice> slices = reader.getClusterState().getSlices("mycollection");
    Iterator<Slice> iter = slices.iterator();

    while (iter.hasNext()) {
        Slice slice = iter.next();
        for(Replica replica:slice.getReplicas()) {

            System.out.println("replica state for " + replica.getStr("core") + " : "+ replica.getStr( "state" ));

            System.out.println(slice.getName());
            System.out.println(slice.getState());
        }
    }
3
votes

check http://{ipaddress}:{port}/solr/admin/info/system

0
votes

Look at the Solr log when browsing the web interface. Since the web interface is purely a client side application, you can see which endpoints on the Solr server it queries to retrieve information about the current state of the cluster.

The response format used to create the graph is probably pretty straight forward (since it's parsed in the web interface).

This also works for the other information displayed in the Admin interface.

0
votes

You can use Solr's Ping API to check health status of all replicas for a given collection.

Request format: http://localhost:8983/solr/Collection-Name/admin/ping?distrib=true&wt=xml

This command will ping all replicas of the given collection name

In Java:

public boolean isActive(final String collectionName) {
      SolrPing ping = new SolrPing();
      ping.getParams().add("distrib", "true"); //To make it a distributed request against a collection
      SolrPingResponse response = ping.process(solrClient, collectionName);
      return response.getStatus() == 0;
  }