public Replica getLeader(String collection, String shard) throws InterruptedException { if (clusterState != null) { Replica replica = clusterState.getLeader(collection, shard); if (replica != null && getClusterState().liveNodesContain(replica.getNodeName())) { return replica; } } return null; }
final CloudSolrClient server = new CloudSolrClient("localhost:2181"); try { //probably this is the line that missed from your code... server.connect(); final ClusterState clusterState = server.getZkStateReader().getClusterState(); final DocCollection collection = clusterState.getCollection("collection1"); //EVRIKA! collection object // and get the leader of the collection...pretty easy. Replica leader = clusterState.getLeader("collection1", "shard1"); } catch (Exception e) { // do your stuff } finally { server.close(); }