Search in sources :

Example 1 with CloudSolrServer

use of org.apache.solr.client.solrj.impl.CloudSolrServer in project jackrabbit-oak by apache.

the class RemoteSolrServerProviderIT method canCreateCollections.

private boolean canCreateCollections(String host) throws Exception {
    UpdateRequest req = new UpdateRequest("/admin/collections");
    req.setParam("action", "CREATE");
    String solrCollection = "solr_" + System.nanoTime();
    req.setParam("name", solrCollection);
    req.setParam("numShards", "2");
    req.setParam("replicationFactor", "2");
    req.setParam("collection.configName", "myconf");
    CloudSolrServer cloudSolrServer = new CloudSolrServer(host);
    cloudSolrServer.setZkConnectTimeout(1000);
    NamedList<Object> request = cloudSolrServer.request(req);
    return request != null && request.get("success") != null;
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) CloudSolrServer(org.apache.solr.client.solrj.impl.CloudSolrServer)

Example 2 with CloudSolrServer

use of org.apache.solr.client.solrj.impl.CloudSolrServer in project jackrabbit-oak by apache.

the class RemoteSolrServerProvider method initializeWithCloudSolrServer.

private SolrServer initializeWithCloudSolrServer() throws IOException {
    // try SolrCloud client
    CloudSolrServer cloudSolrServer = new CloudSolrServer(remoteSolrServerConfiguration.getSolrZkHost());
    cloudSolrServer.setZkConnectTimeout(100);
    if (connectToZK(cloudSolrServer)) {
        // workaround for first request when the needed collection may not exist
        cloudSolrServer.setDefaultCollection("collection1");
        // create specified collection if it doesn't exists
        try {
            createCollectionIfNeeded(cloudSolrServer);
        } catch (Throwable t) {
            if (log.isWarnEnabled()) {
                log.warn("could not create the collection on {}", remoteSolrServerConfiguration.getSolrZkHost(), t);
            }
        }
        cloudSolrServer.setDefaultCollection(remoteSolrServerConfiguration.getSolrCollection());
        // SolrCloud may need some time to sync on collection creation (to spread it over the shards / replicas)
        int i = 0;
        while (i < 3) {
            try {
                SolrPingResponse ping = cloudSolrServer.ping();
                if (ping != null && 0 == ping.getStatus()) {
                    return cloudSolrServer;
                } else {
                    throw new IOException("the found SolrCloud server is not alive");
                }
            } catch (Exception e) {
                // wait a bit
                try {
                    if (log.isDebugEnabled()) {
                        log.debug("server is not alive yet, wait a bit", e);
                    }
                    Thread.sleep(3000);
                } catch (InterruptedException e1) {
                // do nothing
                }
            }
            i++;
        }
        throw new IOException("the found SolrCloud server is not alive");
    } else {
        throw new IOException("could not connect to Zookeeper hosted at " + remoteSolrServerConfiguration.getSolrZkHost());
    }
}
Also used : SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) CloudSolrServer(org.apache.solr.client.solrj.impl.CloudSolrServer) IOException(java.io.IOException) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException)

Aggregations

CloudSolrServer (org.apache.solr.client.solrj.impl.CloudSolrServer)2 IOException (java.io.IOException)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)1 SolrPingResponse (org.apache.solr.client.solrj.response.SolrPingResponse)1