Search in sources :

Example 81 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.

the class OneQuery method setupServer.

@Before
public void setupServer() throws Exception {
    coreCounts = new TreeMap<>();
    coreNames = new ArrayList<>();
    cumulativeDocs = 0;
    solrHomeDirectory = createTempDir().toFile();
    jetty = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), buildJettyConfig("/solr"));
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) Before(org.junit.Before)

Example 82 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.

the class StreamingTest method testDaemonTopicStream.

@Test
public void testDaemonTopicStream() throws Exception {
    Assume.assumeTrue(!useAlias);
    StreamContext context = new StreamContext();
    SolrClientCache cache = new SolrClientCache();
    context.setSolrClientCache(cache);
    try {
        SolrParams sParams = mapParams("q", "a_s:hello0", "rows", "500", "fl", "id");
        TopicStream topicStream = new TopicStream(zkHost, COLLECTIONORALIAS, COLLECTIONORALIAS, "50000000", -1, 1000000, sParams);
        DaemonStream daemonStream = new DaemonStream(topicStream, "daemon1", 1000, 500);
        daemonStream.setStreamContext(context);
        daemonStream.open();
        // Wait for the checkpoint
        JettySolrRunner jetty = cluster.getJettySolrRunners().get(0);
        SolrParams sParams1 = mapParams("qt", "/get", "ids", "50000000", "fl", "id");
        int count = 0;
        while (count == 0) {
            SolrStream solrStream = new SolrStream(jetty.getBaseUrl().toString() + "/" + COLLECTIONORALIAS, sParams1);
            solrStream.setStreamContext(context);
            List<Tuple> tuples = getTuples(solrStream);
            count = tuples.size();
            if (count > 0) {
                Tuple t = tuples.get(0);
                assertTrue(t.getLong("id") == 50000000);
            } else {
                System.out.println("###### Waiting for checkpoint #######:" + count);
            }
        }
        new UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1").add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2").add(id, "3", "a_s", "hello0", "a_i", "3", "a_f", "3").add(id, "4", "a_s", "hello0", "a_i", "4", "a_f", "4").add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5").commit(cluster.getSolrClient(), COLLECTIONORALIAS);
        for (int i = 0; i < 5; i++) {
            daemonStream.read();
        }
        new UpdateRequest().add(id, "5", "a_s", "hello0", "a_i", "4", "a_f", "4").add(id, "6", "a_s", "hello0", "a_i", "4", "a_f", "4").commit(cluster.getSolrClient(), COLLECTIONORALIAS);
        for (int i = 0; i < 2; i++) {
            daemonStream.read();
        }
        daemonStream.shutdown();
        Tuple tuple = daemonStream.read();
        assertTrue(tuple.EOF);
        daemonStream.close();
    } finally {
        cache.close();
    }
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) SolrClientCache(org.apache.solr.client.solrj.io.SolrClientCache) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 83 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner 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 84 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.

the class MiniSolrCloudCluster method shutdown.

/**
   * Shut down the cluster, including all Solr nodes and ZooKeeper
   */
public void shutdown() throws Exception {
    try {
        IOUtils.closeQuietly(solrClient);
        // accept no new tasks
        executorLauncher.shutdown();
        List<Callable<JettySolrRunner>> shutdowns = new ArrayList<>(jettys.size());
        for (final JettySolrRunner jetty : jettys) {
            shutdowns.add(() -> stopJettySolrRunner(jetty));
        }
        jettys.clear();
        Collection<Future<JettySolrRunner>> futures = executorCloser.invokeAll(shutdowns);
        Exception shutdownError = checkForExceptions("Error shutting down MiniSolrCloudCluster", futures);
        if (shutdownError != null) {
            throw shutdownError;
        }
    } finally {
        ExecutorUtil.shutdownAndAwaitTermination(executorLauncher);
        ExecutorUtil.shutdownAndAwaitTermination(executorCloser);
        try {
            if (!externalZkServer) {
                zkServer.shutdown();
            }
        } finally {
            System.clearProperty("zkHost");
        }
    }
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 85 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.

the class AbstractDistribZkTestBase method createServers.

@Override
protected void createServers(int numShards) throws Exception {
    // give everyone there own solrhome
    File controlHome = new File(new File(getSolrHome()).getParentFile(), "control" + homeCount.incrementAndGet());
    FileUtils.copyDirectory(new File(getSolrHome()), controlHome);
    setupJettySolrHome(controlHome);
    System.setProperty("collection", "control_collection");
    String numShardsS = System.getProperty(ZkStateReader.NUM_SHARDS_PROP);
    System.setProperty(ZkStateReader.NUM_SHARDS_PROP, "1");
    // let the shardId default to shard1
    controlJetty = createJetty(controlHome, null);
    System.clearProperty("collection");
    if (numShardsS != null) {
        System.setProperty(ZkStateReader.NUM_SHARDS_PROP, numShardsS);
    } else {
        System.clearProperty(ZkStateReader.NUM_SHARDS_PROP);
    }
    controlClient = createNewSolrClient(controlJetty.getLocalPort());
    StringBuilder sb = new StringBuilder();
    for (int i = 1; i <= numShards; i++) {
        if (sb.length() > 0)
            sb.append(',');
        // give everyone there own solrhome
        File jettyHome = new File(new File(getSolrHome()).getParentFile(), "jetty" + homeCount.incrementAndGet());
        setupJettySolrHome(jettyHome);
        JettySolrRunner j = createJetty(jettyHome, null, "shard" + (i + 2));
        jettys.add(j);
        clients.add(createNewSolrClient(j.getLocalPort()));
        sb.append(buildUrl(j.getLocalPort()));
    }
    shards = sb.toString();
    // now wait till we see the leader for each shard
    for (int i = 1; i <= numShards; i++) {
        ZkStateReader zkStateReader = jettys.get(0).getCoreContainer().getZkController().getZkStateReader();
        zkStateReader.getLeaderRetry("collection1", "shard" + (i + 2), 15000);
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) File(java.io.File)

Aggregations

JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)137 Test (org.junit.Test)52 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)29 Replica (org.apache.solr.common.cloud.Replica)28 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)25 SolrInputDocument (org.apache.solr.common.SolrInputDocument)20 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)20 File (java.io.File)19 SolrQuery (org.apache.solr.client.solrj.SolrQuery)19 DocCollection (org.apache.solr.common.cloud.DocCollection)18 Slice (org.apache.solr.common.cloud.Slice)18 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)15 Properties (java.util.Properties)15 SolrClient (org.apache.solr.client.solrj.SolrClient)15 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)15 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)15 CoreContainer (org.apache.solr.core.CoreContainer)14 BeforeClass (org.junit.BeforeClass)14 ClusterState (org.apache.solr.common.cloud.ClusterState)13