}
private SolrServer initializeWithCloudSolrServer() throws IOException, SolrServerException {
// try SolrCloud client
CloudSolrServer cloudSolrServer = new CloudSolrServer(remoteSolrServerConfiguration.getSolrZkHost());
cloudSolrServer.setZkConnectTimeout(100);
if (connectToZK(cloudSolrServer)) {
cloudSolrServer.setDefaultCollection("collection1"); // workaround for first request when the needed collection may not exist
// 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");
}