Set<String> liveNodes = clusterState.getLiveNodes(); for (String liveNode : liveNodes) { theUrlList.add(zkStateReader.getBaseUrlForNodeName(liveNode));
public SimpleSolrResponse invoke(String solrNode, String path, SolrParams params) throws IOException, SolrServerException { String url = zkClientClusterStateProvider.getZkStateReader().getBaseUrlForNodeName(solrNode); GenericSolrRequest request = new GenericSolrRequest(SolrRequest.METHOD.POST, path, params); try (HttpSolrClient client = new HttpSolrClient.Builder() .withHttpClient(solrClient.getHttpClient()) .withBaseSolrUrl(url) .withResponseParser(new BinaryResponseParser()) .build()) { NamedList<Object> rsp = client.request(request); request.response.nl = rsp; return request.response; } }
@Override public String getDatabaseProductVersion() throws SQLException { // Returns the version for the first live node in the Solr cluster. SolrQuery sysQuery = new SolrQuery(); sysQuery.setRequestHandler("/admin/info/system"); CloudSolrClient cloudSolrClient = this.connection.getClient(); Set<String> liveNodes = cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes(); SolrClient solrClient = null; for (String node : liveNodes) { try { String nodeURL = cloudSolrClient.getZkStateReader().getBaseUrlForNodeName(node); solrClient = new Builder(nodeURL).build(); QueryResponse rsp = solrClient.query(sysQuery); return String.valueOf(((SimpleOrderedMap) rsp.getResponse().get("lucene")).get("solr-spec-version")); } catch (SolrServerException | IOException ignore) { return ""; } finally { if (solrClient != null) { try { solrClient.close(); } catch (IOException ignore) { // Don't worry about failing to close the Solr client } } } } // If no version found just return empty string return ""; }