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