Example usage for org.apache.solr.client.solrj.impl CloudSolrClient getZkHost

List of usage examples for org.apache.solr.client.solrj.impl CloudSolrClient getZkHost

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.impl CloudSolrClient getZkHost.

Prototype

public String getZkHost() 

Source Link

Usage

From source file:com.nridge.ds.solr.SolrDS.java

License:Open Source License

private String getSolrBaseURL(CloudSolrClient aSolrClient) throws DSException {
    Logger appLogger = mAppMgr.getLogger(this, "getSolrBaseURL");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    Set<String> liveNodes = aSolrClient.getZkStateReader().getClusterState().getLiveNodes();
    if (liveNodes.isEmpty())
        throw new DSException("No SolrCloud live nodes found - cannot determine 'solrUrl' from ZooKeeper: "
                + aSolrClient.getZkHost());

    String firstLiveNode = liveNodes.iterator().next();
    String solrBaseURL = aSolrClient.getZkStateReader().getBaseUrlForNodeName(firstLiveNode);

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);

    return solrBaseURL;
}

From source file:io.redlink.solrlib.cloud.SolrCloudConnectorTest.java

License:Apache License

@Test
public void testCreateClient() throws Exception {
    final String zkConnection = UUID.randomUUID().toString();
    SolrCloudConnectorConfiguration config = new SolrCloudConnectorConfiguration();
    config.setZkConnection(zkConnection);
    SolrCloudConnector connector = new SolrCloudConnector(Collections.<SolrCoreDescriptor>emptySet(), config,
            null);/*  w w  w .  j a v a  2s .c  om*/

    CloudSolrClient c1 = connector.createSolrClient();
    assertThat(c1.getZkHost(), Matchers.equalTo(zkConnection));

    for (int i = 0; i < 10; i++) {
        final String coreName = UUID.randomUUID().toString();
        SolrClient cI = connector.createSolrClient(coreName);
        assertThat(cI, Matchers.instanceOf(CloudSolrClient.class));
        CloudSolrClient c2 = (CloudSolrClient) cI;
        assertThat(c2.getZkHost(), Matchers.equalTo(zkConnection));
        assertThat(c2.getDefaultCollection(), Matchers.equalTo(coreName));
    }
}