Search in sources :

Example 6 with Builder

use of org.apache.solr.client.solrj.impl.HttpSolrClient.Builder in project lucene-solr by apache.

the class DatabaseMetaDataImpl method getDatabaseProductVersion.

@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 "";
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Builder(org.apache.solr.client.solrj.impl.HttpSolrClient.Builder) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Aggregations

Builder (org.apache.solr.client.solrj.impl.HttpSolrClient.Builder)6 SolrException (org.apache.solr.common.SolrException)3 IOException (java.io.IOException)2 SolrClient (org.apache.solr.client.solrj.SolrClient)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)2 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)2 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 HttpClient (org.apache.http.client.HttpClient)1 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)1 ResponseParser (org.apache.solr.client.solrj.ResponseParser)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)1