use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class UpdateRequestProcessorFactoryTest method testRequestTimeUrp.
public void testRequestTimeUrp() {
SolrCore core = h.getCore();
ModifiableSolrParams params = new ModifiableSolrParams().add("processor", "Template").add("Template.field", "id_t:${firstName}_${lastName}").add("Template.field", "another_t:${lastName}_${firstName}").add("Template.field", "missing_t:${lastName}_${unKnown}");
UpdateRequestProcessorChain chain = core.getUpdateProcessorChain(params);
List<UpdateRequestProcessorFactory> l = chain.getProcessors();
assertTrue(l.get(0) instanceof TemplateUpdateProcessorFactory);
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class UpdateRequestProcessorFactoryTest method testConfiguration.
public void testConfiguration() throws Exception {
SolrCore core = h.getCore();
// make sure it loaded the factories
UpdateRequestProcessorChain chained = core.getUpdateProcessingChain("standard");
// Make sure it got 3 items (4 configured, 1 is enable=false)
assertEquals("wrong number of (enabled) factories in chain", 3, chained.getProcessors().size());
// first one should be log, and it should be configured properly
UpdateRequestProcessorFactory first = chained.getProcessors().get(0);
assertEquals("wrong factory at front of chain", LogUpdateProcessorFactory.class, first.getClass());
LogUpdateProcessorFactory log = (LogUpdateProcessorFactory) first;
assertEquals("wrong config for LogUpdateProcessorFactory.maxNumToLog", 100, log.maxNumToLog);
assertEquals("wrong config for LogUpdateProcessorFactory.slowUpdateThresholdMillis", 2000, log.slowUpdateThresholdMillis);
UpdateRequestProcessorChain custom = core.getUpdateProcessingChain(null);
CustomUpdateRequestProcessorFactory link = (CustomUpdateRequestProcessorFactory) custom.getProcessors().get(0);
assertEquals(custom, core.getUpdateProcessingChain(""));
assertEquals(custom, core.getUpdateProcessingChain("custom"));
// Make sure the NamedListArgs got through ok
assertEquals("{name={n8=88,n9=99}}", link.args.toString());
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class ChaosMonkey method getRandomJetty.
public CloudJettyRunner getRandomJetty(String slice, boolean aggressivelyKillLeaders) throws KeeperException, InterruptedException {
int numActive = 0;
numActive = checkIfKillIsLegal(slice, numActive);
// TODO: stale state makes this a tough call
if (numActive < 2) {
// we cannot kill anyone
monkeyLog("only one active node in shard - monkey cannot kill :(");
return null;
}
// let's check the deadpool count
int numRunning = 0;
for (CloudJettyRunner cjetty : shardToJetty.get(slice)) {
if (!deadPool.contains(cjetty)) {
numRunning++;
}
}
if (numRunning < 2) {
// we cannot kill anyone
monkeyLog("only one active node in shard - monkey cannot kill :(");
return null;
}
boolean canKillIndexer = canKillIndexer(slice);
if (!canKillIndexer) {
monkeyLog("Number of indexer nodes (nrt or tlog replicas) is not enough to kill one of them, Will only choose a pull replica to kill");
}
int chance = chaosRandom.nextInt(10);
CloudJettyRunner cjetty = null;
if (chance <= 5 && aggressivelyKillLeaders && canKillIndexer) {
// if killLeader, really aggressively go after leaders
cjetty = shardToLeaderJetty.get(slice);
} else {
List<CloudJettyRunner> jetties = shardToJetty.get(slice);
// get random node
int attempt = 0;
while (true) {
attempt++;
int index = chaosRandom.nextInt(jetties.size());
cjetty = jetties.get(index);
if (canKillIndexer || getTypeForJetty(slice, cjetty) == Replica.Type.PULL) {
break;
} else if (attempt > 20) {
monkeyLog("Can't kill indexer nodes (nrt or tlog replicas) and couldn't find a random pull node after 20 attempts - monkey cannot kill :(");
return null;
}
}
ZkNodeProps leader = null;
try {
leader = zkStateReader.getLeaderRetry(collection, slice);
} catch (Throwable t) {
log.error("Could not get leader", t);
return null;
}
// cluster state can be stale - also go by our 'near real-time' is leader prop
boolean rtIsLeader;
CoreContainer cc = cjetty.jetty.getCoreContainer();
if (cc != null) {
try (SolrCore core = cc.getCore(leader.getStr(ZkStateReader.CORE_NAME_PROP))) {
if (core == null) {
monkeyLog("selected jetty not running correctly - skip");
return null;
}
rtIsLeader = core.getCoreDescriptor().getCloudDescriptor().isLeader();
}
} else {
return null;
}
boolean isLeader = leader.getStr(ZkStateReader.NODE_NAME_PROP).equals(cjetty.nodeName) || rtIsLeader;
if (!aggressivelyKillLeaders && isLeader) {
// we don't kill leaders...
monkeyLog("abort! I don't kill leaders");
return null;
}
}
if (cjetty.jetty.getLocalPort() == -1) {
// we can't kill the dead
monkeyLog("abort! This guy is already dead");
return null;
}
//System.out.println("num active:" + numActive + " for " + slice + " sac:" + jetty.getLocalPort());
monkeyLog("chose a victim! " + cjetty.jetty.getLocalPort());
return cjetty;
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class TestHarness method query.
/**
* Processes a "query" using a user constructed SolrQueryRequest, and closes the request at the end.
*
* @param handler the name of the request handler to process the request
* @param req the Query to process, will be closed.
* @return The XML response to the query
* @exception Exception any exception in the response.
* @exception IOException if there is a problem writing the XML
* @see LocalSolrQueryRequest
*/
public String query(String handler, SolrQueryRequest req) throws Exception {
try {
SolrCore core = req.getCore();
SolrQueryResponse rsp = new SolrQueryResponse();
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
core.execute(core.getRequestHandler(handler), req, rsp);
if (rsp.getException() != null) {
throw rsp.getException();
}
QueryResponseWriter responseWriter = core.getQueryResponseWriter(req);
if (responseWriter instanceof BinaryQueryResponseWriter) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(32000);
BinaryQueryResponseWriter writer = (BinaryQueryResponseWriter) responseWriter;
writer.write(byteArrayOutputStream, req, rsp);
return new String(byteArrayOutputStream.toByteArray(), "UTF-8");
} else {
StringWriter sw = new StringWriter(32000);
responseWriter.write(sw, req, rsp);
return sw.toString();
}
} finally {
req.close();
SolrRequestInfo.clearRequestInfo();
}
}
use of org.apache.solr.core.SolrCore in project lucene-solr by apache.
the class TestHarness method queryAndResponse.
/** It is the users responsibility to close the request object when done with it.
* This method does not set/clear SolrRequestInfo */
public SolrQueryResponse queryAndResponse(String handler, SolrQueryRequest req) throws Exception {
try (SolrCore core = getCoreInc()) {
SolrQueryResponse rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(handler), req, rsp);
if (rsp.getException() != null) {
throw rsp.getException();
}
return rsp;
}
}
Aggregations