Search in sources :

Example 1 with HttpShardHandlerFactory

use of org.apache.solr.handler.component.HttpShardHandlerFactory in project lucene-solr by apache.

the class OverseerTest method testOverseerStatsReset.

@Test
public void testOverseerStatsReset() throws Exception {
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    ZkTestServer server = new ZkTestServer(zkDir);
    ZkStateReader reader = null;
    MockZKController mockController = null;
    SolrZkClient zkClient = null;
    try {
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
        ZkController.createClusterZkNodes(zkClient);
        reader = new ZkStateReader(zkClient);
        reader.createClusterStateWatchersAndUpdate();
        mockController = new MockZKController(server.getZkAddress(), "node1");
        LeaderElector overseerElector = new LeaderElector(zkClient);
        if (overseers.size() > 0) {
            overseers.get(overseers.size() - 1).close();
            overseers.get(overseers.size() - 1).getZkStateReader().getZkClient().close();
        }
        UpdateShardHandler updateShardHandler = new UpdateShardHandler(UpdateShardHandlerConfig.DEFAULT);
        updateShardHandlers.add(updateShardHandler);
        HttpShardHandlerFactory httpShardHandlerFactory = new HttpShardHandlerFactory();
        httpShardHandlerFactorys.add(httpShardHandlerFactory);
        Overseer overseer = new Overseer(httpShardHandlerFactory.getShardHandler(), updateShardHandler, "/admin/cores", reader, null, new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "").build());
        overseers.add(overseer);
        ElectionContext ec = new OverseerElectionContext(zkClient, overseer, server.getZkAddress().replaceAll("/", "_"));
        overseerElector.setup(ec);
        overseerElector.joinElection(ec, false);
        mockController.publishState(COLLECTION, "core1", "core_node1", Replica.State.ACTIVE, 1);
        assertNotNull(overseer.getStats());
        assertTrue((overseer.getStats().getSuccessCount(OverseerAction.STATE.toLower())) > 0);
        // shut it down
        overseer.close();
        ec.cancelElection();
        // start it again
        overseerElector.setup(ec);
        overseerElector.joinElection(ec, false);
        assertNotNull(overseer.getStats());
        assertEquals(0, (overseer.getStats().getSuccessCount(OverseerAction.STATE.toLower())));
    } finally {
        close(mockController);
        close(zkClient);
        close(reader);
        server.shutdown();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) UpdateShardHandler(org.apache.solr.update.UpdateShardHandler) HttpShardHandlerFactory(org.apache.solr.handler.component.HttpShardHandlerFactory) Test(org.junit.Test)

Example 2 with HttpShardHandlerFactory

use of org.apache.solr.handler.component.HttpShardHandlerFactory in project lucene-solr by apache.

the class OverseerTest method tearDown.

@After
public void tearDown() throws Exception {
    super.tearDown();
    for (Overseer overseer : overseers) {
        overseer.close();
    }
    overseers.clear();
    for (ZkStateReader reader : readers) {
        reader.close();
    }
    readers.clear();
    for (HttpShardHandlerFactory handlerFactory : httpShardHandlerFactorys) {
        handlerFactory.close();
    }
    httpShardHandlerFactorys.clear();
    for (UpdateShardHandler updateShardHandler : updateShardHandlers) {
        updateShardHandler.close();
    }
    updateShardHandlers.clear();
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) UpdateShardHandler(org.apache.solr.update.UpdateShardHandler) HttpShardHandlerFactory(org.apache.solr.handler.component.HttpShardHandlerFactory) After(org.junit.After)

Example 3 with HttpShardHandlerFactory

use of org.apache.solr.handler.component.HttpShardHandlerFactory in project lucene-solr by apache.

the class ChaosMonkeyShardSplitTest method electNewOverseer.

/**
   * Elects a new overseer
   *
   * @return SolrZkClient
   */
private SolrZkClient electNewOverseer(String address) throws KeeperException, InterruptedException, IOException {
    SolrZkClient zkClient = new SolrZkClient(address, TIMEOUT);
    ZkStateReader reader = new ZkStateReader(zkClient);
    LeaderElector overseerElector = new LeaderElector(zkClient);
    UpdateShardHandler updateShardHandler = new UpdateShardHandler(UpdateShardHandlerConfig.DEFAULT);
    // TODO: close Overseer
    Overseer overseer = new Overseer(new HttpShardHandlerFactory().getShardHandler(), updateShardHandler, "/admin/cores", reader, null, new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "solr").build());
    overseer.close();
    ElectionContext ec = new OverseerElectionContext(zkClient, overseer, address.replaceAll("/", "_"));
    overseerElector.setup(ec);
    overseerElector.joinElection(ec, false);
    reader.close();
    return zkClient;
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) UpdateShardHandler(org.apache.solr.update.UpdateShardHandler) HttpShardHandlerFactory(org.apache.solr.handler.component.HttpShardHandlerFactory)

Example 4 with HttpShardHandlerFactory

use of org.apache.solr.handler.component.HttpShardHandlerFactory in project SearchServices by Alfresco.

the class Solr4QueryParser method fetchFingerPrint.

private Collection fetchFingerPrint(String shards, String nodeId) {
    shards = shards.replace(",", "|");
    List<String> urls = ((HttpShardHandlerFactory) shardHandlerFactory).buildURLList(shards);
    ExecutorService executorService = null;
    List<Future> futures = new ArrayList();
    Collection fingerPrint = null;
    try {
        executorService = Executors.newCachedThreadPool();
        for (String url : urls) {
            futures.add(executorService.submit(new FingerPrintFetchTask(url, nodeId)));
        }
        for (Future<Collection> future : futures) {
            Collection col = future.get();
            if (col != null) {
                fingerPrint = col;
            }
        }
    } catch (Exception e) {
        logger.error(e);
    } finally {
        executorService.shutdown();
    }
    return fingerPrint;
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Collection(java.util.Collection) HttpShardHandlerFactory(org.apache.solr.handler.component.HttpShardHandlerFactory) SAXPathException(org.jaxen.saxpath.SAXPathException) ParseException(org.apache.lucene.queryparser.classic.ParseException) FTSQueryException(org.alfresco.repo.search.impl.parsers.FTSQueryException) IOException(java.io.IOException)

Example 5 with HttpShardHandlerFactory

use of org.apache.solr.handler.component.HttpShardHandlerFactory 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)

Aggregations

HttpShardHandlerFactory (org.apache.solr.handler.component.HttpShardHandlerFactory)6 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)4 UpdateShardHandler (org.apache.solr.update.UpdateShardHandler)4 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Collection (java.util.Collection)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 FTSQueryException (org.alfresco.repo.search.impl.parsers.FTSQueryException)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 LBHttpSolrClient (org.apache.solr.client.solrj.impl.LBHttpSolrClient)1 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)1 CoreContainer (org.apache.solr.core.CoreContainer)1 ShardHandlerFactory (org.apache.solr.handler.component.ShardHandlerFactory)1 SAXPathException (org.jaxen.saxpath.SAXPathException)1 After (org.junit.After)1 Test (org.junit.Test)1