Search in sources :

Example 61 with CoreContainer

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();
    }
}
Also used : Path(java.nio.file.Path) HttpShardHandlerFactory(org.apache.solr.handler.component.HttpShardHandlerFactory) ShardHandlerFactory(org.apache.solr.handler.component.ShardHandlerFactory) CoreContainer(org.apache.solr.core.CoreContainer) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) ArrayList(java.util.ArrayList) HttpShardHandlerFactory(org.apache.solr.handler.component.HttpShardHandlerFactory) LBHttpSolrClient(org.apache.solr.client.solrj.impl.LBHttpSolrClient)

Example 62 with CoreContainer

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");
        }
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CoreDescriptor(org.apache.solr.core.CoreDescriptor) SolrCore(org.apache.solr.core.SolrCore) Future(java.util.concurrent.Future)

Example 63 with CoreContainer

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"));
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer)

Example 64 with CoreContainer

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;
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) ZkController(org.apache.solr.cloud.ZkController)

Example 65 with CoreContainer

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);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) CollectionAction(org.apache.solr.common.params.CollectionParams.CollectionAction) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) StrUtils.formatString(org.apache.solr.common.util.StrUtils.formatString) SolrException(org.apache.solr.common.SolrException)

Aggregations

CoreContainer (org.apache.solr.core.CoreContainer)95 SolrCore (org.apache.solr.core.SolrCore)30 Test (org.junit.Test)23 SolrException (org.apache.solr.common.SolrException)16 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)14 File (java.io.File)13 HashMap (java.util.HashMap)11 Replica (org.apache.solr.common.cloud.Replica)11 CoreDescriptor (org.apache.solr.core.CoreDescriptor)11 Path (java.nio.file.Path)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)8 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)8 Map (java.util.Map)7 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)7 Properties (java.util.Properties)6 DocCollection (org.apache.solr.common.cloud.DocCollection)6 Slice (org.apache.solr.common.cloud.Slice)6 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)6