Search in sources :

Example 66 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.

the class ZkCLITest method printLayout.

private void printLayout(String zkHost) throws Exception {
    SolrZkClient zkClient = new SolrZkClient(zkHost, AbstractZkTestCase.TIMEOUT);
    zkClient.printLayoutToStdOut();
    zkClient.close();
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 67 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.

the class AbstractFullDistribZkTestBase method createJettys.

protected List<JettySolrRunner> createJettys(int numJettys) throws Exception {
    List<JettySolrRunner> jettys = new ArrayList<>();
    List<SolrClient> clients = new ArrayList<>();
    StringBuilder sb = new StringBuilder();
    if ("2".equals(getStateFormat())) {
        log.info("Creating " + DEFAULT_COLLECTION + " with stateFormat=2");
        SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT);
        Overseer.getStateUpdateQueue(zkClient).offer(Utils.toJSON(Utils.makeMap(Overseer.QUEUE_OPERATION, CollectionParams.CollectionAction.CREATE.toLower(), "name", DEFAULT_COLLECTION, "numShards", String.valueOf(sliceCount), DocCollection.STATE_FORMAT, getStateFormat(), ZkStateReader.NRT_REPLICAS, useTlogReplicas() ? "0" : "1", ZkStateReader.TLOG_REPLICAS, useTlogReplicas() ? "1" : "0", ZkStateReader.PULL_REPLICAS, String.valueOf(getPullReplicaCount()))));
        zkClient.close();
    }
    int numPullReplicas = getPullReplicaCount() * sliceCount;
    for (int i = 1; i <= numJettys; i++) {
        if (sb.length() > 0)
            sb.append(',');
        int cnt = this.jettyIntCntr.incrementAndGet();
        File jettyDir = createTempDir("shard-" + i).toFile();
        jettyDir.mkdirs();
        setupJettySolrHome(jettyDir);
        JettySolrRunner j;
        if (numPullReplicas > 0) {
            numPullReplicas--;
            log.info("create jetty {} in directory {} of type {}", i, jettyDir, Replica.Type.PULL);
            j = createJetty(jettyDir, useJettyDataDir ? getDataDir(testDir + "/jetty" + cnt) : null, null, "solrconfig.xml", null, Replica.Type.PULL);
        } else if (useTlogReplicas()) {
            log.info("create jetty {} in directory {} of type {}", i, jettyDir, Replica.Type.TLOG);
            j = createJetty(jettyDir, useJettyDataDir ? getDataDir(testDir + "/jetty" + cnt) : null, null, "solrconfig.xml", null, Replica.Type.TLOG);
        } else {
            log.info("create jetty {} in directory {} of type {}", i, jettyDir, Replica.Type.NRT);
            j = createJetty(jettyDir, useJettyDataDir ? getDataDir(testDir + "/jetty" + cnt) : null, null, "solrconfig.xml", null, null);
        }
        jettys.add(j);
        SolrClient client = createNewSolrClient(j.getLocalPort());
        clients.add(client);
    }
    this.jettys.addAll(jettys);
    this.clients.addAll(clients);
    int numReplicas = getTotalReplicas(DEFAULT_COLLECTION);
    int expectedNumReplicas = numJettys;
    // now wait until we see that the number of shards in the cluster state
    // matches what we expect
    int retries = 0;
    while (numReplicas != expectedNumReplicas) {
        numReplicas = getTotalReplicas(DEFAULT_COLLECTION);
        if (numReplicas == expectedNumReplicas)
            break;
        if (retries++ == 60) {
            printLayoutOnTearDown = true;
            fail("Number of replicas in the state does not match what we set:" + numReplicas + " vs " + expectedNumReplicas);
        }
        Thread.sleep(500);
    }
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    // make sure we have a leader for each shard
    for (int i = 1; i <= sliceCount; i++) {
        zkStateReader.getLeaderRetry(DEFAULT_COLLECTION, "shard" + i, 10000);
    }
    if (numReplicas > 0) {
        updateMappingsFromZk(this.jettys, this.clients);
    }
    // build the shard string
    for (int i = 1; i <= numJettys / 2; i++) {
        JettySolrRunner j = this.jettys.get(i);
        JettySolrRunner j2 = this.jettys.get(i + (numJettys / 2 - 1));
        if (sb.length() > 0)
            sb.append(',');
        sb.append(buildUrl(j.getLocalPort()));
        sb.append("|").append(buildUrl(j2.getLocalPort()));
    }
    shards = sb.toString();
    return jettys;
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) ArrayList(java.util.ArrayList) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) File(java.io.File)

Example 68 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.

the class AbstractDistribZkTestBase method printLayout.

protected void printLayout() throws Exception {
    SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT);
    zkClient.printLayoutToStdOut();
    zkClient.close();
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 69 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.

the class AbstractZkTestCase method makeSolrZkNode.

public static void makeSolrZkNode(String zkHost) throws Exception {
    SolrZkClient zkClient = new SolrZkClient(zkHost, TIMEOUT);
    zkClient.makePath("/solr", false, true);
    zkClient.close();
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 70 with SolrZkClient

use of org.apache.solr.common.cloud.SolrZkClient in project lucene-solr by apache.

the class AbstractZkTestCase method printLayout.

protected void printLayout(String zkHost) throws Exception {
    SolrZkClient zkClient = new SolrZkClient(zkHost, AbstractZkTestCase.TIMEOUT);
    zkClient.printLayoutToStdOut();
    zkClient.close();
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Aggregations

SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)130 Test (org.junit.Test)46 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)34 HashMap (java.util.HashMap)21 KeeperException (org.apache.zookeeper.KeeperException)18 SolrException (org.apache.solr.common.SolrException)15 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)14 IOException (java.io.IOException)13 ClusterState (org.apache.solr.common.cloud.ClusterState)13 DocCollection (org.apache.solr.common.cloud.DocCollection)12 Map (java.util.Map)11 Slice (org.apache.solr.common.cloud.Slice)11 Replica (org.apache.solr.common.cloud.Replica)10 ArrayList (java.util.ArrayList)9 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)8 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)8 Overseer (org.apache.solr.cloud.Overseer)8 ZkTestServer (org.apache.solr.cloud.ZkTestServer)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)7 NamedList (org.apache.solr.common.util.NamedList)7