Example usage for org.apache.solr.common.cloud SolrZkClient isConnected

List of usage examples for org.apache.solr.common.cloud SolrZkClient isConnected

Introduction

In this page you can find the example usage for org.apache.solr.common.cloud SolrZkClient isConnected.

Prototype

public boolean isConnected() 

Source Link

Document

Returns true if client is connected

Usage

From source file:org.apache.jackrabbit.oak.plugins.index.solr.server.RemoteSolrServerProvider.java

License:Apache License

private void createCollectionIfNeeded(CloudSolrServer cloudSolrServer) throws SolrServerException {
    String solrCollection = remoteSolrServerConfiguration.getSolrCollection();
    try {/*from   ww w .j ava 2  s. com*/
        ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader();
        SolrZkClient zkClient = zkStateReader.getZkClient();
        if (zkClient.isConnected() && !zkClient.exists("/configs/" + solrCollection, false)) {
            String solrConfDir = remoteSolrServerConfiguration.getSolrConfDir();
            File dir;
            if (solrConfDir != null && solrConfDir.length() > 0) {
                dir = new File(solrConfDir);
            } else {
                dir = new File(getClass().getResource("/solr/oak/conf").getFile());
            }
            ZkController.uploadConfigDir(zkClient, dir, solrCollection);
            UpdateRequest req = new UpdateRequest("/admin/collections");
            req.setParam("action", "CREATE");
            req.setParam("numShards", String.valueOf(remoteSolrServerConfiguration.getSolrShardsNo()));
            req.setParam("replicationFactor",
                    String.valueOf(remoteSolrServerConfiguration.getSolrReplicationFactor()));
            req.setParam("collection.configName", solrCollection);
            req.setParam("name", solrCollection);
            cloudSolrServer.request(req);
        }
    } catch (Exception e) {
        log.warn("could not create collection {}", solrCollection);
        throw new SolrServerException(e);
    }
}