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"));
}
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();
}
}
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;
}
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");
}
}
}
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);
}
}
Aggregations