use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class TestHttpShardHandlerFactory method testLoadBalancerRequestsMinMax.
public void testLoadBalancerRequestsMinMax() throws Exception {
final Path home = Paths.get(TEST_HOME());
CoreContainer cc = null;
ShardHandlerFactory factory = null;
try {
cc = CoreContainer.createAndLoad(home, home.resolve("solr-shardhandler-loadBalancerRequests.xml"));
factory = cc.getShardHandlerFactory();
// test that factory is HttpShardHandlerFactory with expected url reserve fraction
assertTrue(factory instanceof HttpShardHandlerFactory);
final HttpShardHandlerFactory httpShardHandlerFactory = ((HttpShardHandlerFactory) factory);
assertEquals(expectedLoadBalancerRequestsMinimumAbsolute, httpShardHandlerFactory.permittedLoadBalancerRequestsMinimumAbsolute, 0.0);
assertEquals(expectedLoadBalancerRequestsMaximumFraction, httpShardHandlerFactory.permittedLoadBalancerRequestsMaximumFraction, 0.0);
// create a dummy request and dummy url list
final QueryRequest queryRequest = null;
final List<String> urls = new ArrayList<>();
for (int ii = 0; ii < 10; ++ii) {
urls.add(null);
}
// create LBHttpSolrClient request
final LBHttpSolrClient.Req req = httpShardHandlerFactory.newLBHttpSolrClientReq(queryRequest, urls);
// actual vs. expected test
final int actualNumServersToTry = req.getNumServersToTry().intValue();
int expectedNumServersToTry = (int) Math.floor(urls.size() * expectedLoadBalancerRequestsMaximumFraction);
if (expectedNumServersToTry < expectedLoadBalancerRequestsMinimumAbsolute) {
expectedNumServersToTry = expectedLoadBalancerRequestsMinimumAbsolute;
}
assertEquals("wrong numServersToTry for" + " urls.size=" + urls.size() + " expectedLoadBalancerRequestsMinimumAbsolute=" + expectedLoadBalancerRequestsMinimumAbsolute + " expectedLoadBalancerRequestsMaximumFraction=" + expectedLoadBalancerRequestsMaximumFraction, expectedNumServersToTry, actualNumServersToTry);
} finally {
if (factory != null)
factory.close();
if (cc != null)
cc.shutdown();
}
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class TestIndexSearcher method createCoreAndValidateListeners.
private void createCoreAndValidateListeners(int numTimesCalled, int numTimesCalledFirstSearcher, int numTimesCalledAfterGetSearcher, int numTimesCalledFirstSearcherAfterGetSearcher) throws Exception {
CoreContainer cores = h.getCoreContainer();
CoreDescriptor cd = h.getCore().getCoreDescriptor();
SolrCore newCore = null;
// reset counters
MockSearcherListener.numberOfTimesCalled = new AtomicInteger();
MockSearcherListener.numberOfTimesCalledFirstSearcher = new AtomicInteger();
try {
// Create a new core, this should call all the firstSearcherListeners
newCore = cores.create("core1", cd.getInstanceDir(), ImmutableMap.of("config", "solrconfig-searcher-listeners1.xml"), false);
//validate that the new core was created with the correct solrconfig
assertNotNull(newCore.getSearchComponent("mock"));
assertEquals(MockSearchComponent.class, newCore.getSearchComponent("mock").getClass());
assertFalse(newCore.getSolrConfig().useColdSearcher);
doQuery(newCore);
assertEquals(numTimesCalled, MockSearcherListener.numberOfTimesCalled.get());
assertEquals(numTimesCalledFirstSearcher, MockSearcherListener.numberOfTimesCalledFirstSearcher.get());
addDummyDoc(newCore);
// Open a new searcher, this should call the newSearcherListeners
Future<?>[] future = new Future[1];
newCore.getSearcher(true, false, future);
future[0].get();
assertEquals(numTimesCalledAfterGetSearcher, MockSearcherListener.numberOfTimesCalled.get());
assertEquals(numTimesCalledFirstSearcherAfterGetSearcher, MockSearcherListener.numberOfTimesCalledFirstSearcher.get());
} finally {
if (newCore != null) {
cores.unload("core1");
}
}
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class MergeIndexesExampleTestBase method setupCoreContainer.
protected void setupCoreContainer() {
cores = new CoreContainer(getSolrHome());
cores.load();
//cores = CoreContainer.createAndLoad(getSolrHome(), new File(TEMP_DIR, "solr.xml"));
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class SearchHandler method getAndPrepShardHandler.
private ShardHandler getAndPrepShardHandler(SolrQueryRequest req, ResponseBuilder rb) {
ShardHandler shardHandler = null;
CoreContainer cc = req.getCore().getCoreContainer();
boolean isZkAware = cc.isZooKeeperAware();
rb.isDistrib = req.getParams().getBool(DISTRIB, isZkAware);
if (!rb.isDistrib) {
// for back compat, a shards param with URLs like localhost:8983/solr will mean that this
// search is distributed.
final String shards = req.getParams().get(ShardParams.SHARDS);
rb.isDistrib = ((shards != null) && (shards.indexOf('/') > 0));
}
if (rb.isDistrib) {
shardHandler = shardHandlerFactory.getShardHandler();
shardHandler.prepDistributed(rb);
if (!rb.isDistrib) {
// request is not distributed after all and so the shard handler is not needed
shardHandler = null;
}
}
if (isZkAware) {
ZkController zkController = cc.getZkController();
NamedList<Object> headers = rb.rsp.getResponseHeader();
if (headers != null) {
headers.add("zkConnected", zkController != null ? !zkController.getZkClient().getConnectionManager().isLikelyExpired() : false);
}
}
return shardHandler;
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class CollectionsHandler method handleRequestBody.
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
// Make sure the cores is enabled
CoreContainer cores = getCoreContainer();
if (cores == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Core container instance missing");
}
// Make sure that the core is ZKAware
if (!cores.isZooKeeperAware()) {
throw new SolrException(ErrorCode.BAD_REQUEST, "Solr instance is not running in SolrCloud mode.");
}
// Pick the action
SolrParams params = req.getParams();
String a = params.get(CoreAdminParams.ACTION);
if (a != null) {
CollectionAction action = CollectionAction.get(a);
if (action == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown action: " + a);
}
CollectionOperation operation = CollectionOperation.get(action);
log.info("Invoked Collection Action :{} with params {} and sendToOCPQueue={}", action.toLower(), req.getParamString(), operation.sendToOCPQueue);
invokeAction(req, rsp, cores, action, operation);
} else {
throw new SolrException(ErrorCode.BAD_REQUEST, "action is a required param");
}
rsp.setHttpCaching(false);
}
Aggregations