Search in sources :

Example 56 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class SolrGangliaReporterTest method testReporter.

@Test
public void testReporter() throws Exception {
    Path home = Paths.get(TEST_HOME());
    // define these properties, they are used in solrconfig.xml
    System.setProperty("solr.test.sys.prop1", "propone");
    System.setProperty("solr.test.sys.prop2", "proptwo");
    GMetric ganglia = mock(GMetric.class);
    final List<String> names = new ArrayList<>();
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        names.add((String) args[0]);
        return null;
    }).when(ganglia).announce(anyString(), anyString(), any(GMetricType.class), anyString(), any(GMetricSlope.class), anyInt(), anyInt(), anyString());
    String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-gangliareporter.xml").toFile(), "UTF-8");
    NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml);
    CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml"));
    h.coreName = DEFAULT_TEST_CORENAME;
    SolrMetricManager metricManager = cc.getMetricManager();
    Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.node");
    assertTrue(reporters.toString(), reporters.size() >= 1);
    SolrMetricReporter reporter = reporters.get("test");
    assertNotNull(reporter);
    assertTrue(reporter instanceof SolrGangliaReporter);
    SolrGangliaReporter gangliaReporter = (SolrGangliaReporter) reporter;
    gangliaReporter.setGMetric(ganglia);
    gangliaReporter.start();
    Thread.sleep(5000);
    assertTrue(names.size() >= 3);
    String[] frozenNames = (String[]) names.toArray(new String[names.size()]);
    for (String name : frozenNames) {
        assertTrue(name, name.startsWith("test.solr.node.CONTAINER.cores."));
    }
}
Also used : Path(java.nio.file.Path) GMetricSlope(info.ganglia.gmetric4j.gmetric.GMetricSlope) ArrayList(java.util.ArrayList) GMetricType(info.ganglia.gmetric4j.gmetric.GMetricType) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) GMetric(info.ganglia.gmetric4j.gmetric.GMetric) CoreContainer(org.apache.solr.core.CoreContainer) TestHarness(org.apache.solr.util.TestHarness) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) NodeConfig(org.apache.solr.core.NodeConfig) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 57 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class ChaosMonkey method start.

public static boolean start(JettySolrRunner jetty) throws Exception {
    monkeyLog("starting jetty! " + jetty.getLocalPort());
    IpTables.unblockPort(jetty.getLocalPort());
    try {
        jetty.start();
    } catch (Exception e) {
        jetty.stop();
        Thread.sleep(3000);
        try {
            jetty.start();
        } catch (Exception e2) {
            jetty.stop();
            Thread.sleep(10000);
            try {
                jetty.start();
            } catch (Exception e3) {
                jetty.stop();
                Thread.sleep(30000);
                try {
                    jetty.start();
                } catch (Exception e4) {
                    log.error("Could not get the port to start jetty again", e4);
                    // we coud not get the port
                    jetty.stop();
                    return false;
                }
            }
        }
    }
    CoreContainer cores = jetty.getCoreContainer();
    if (cores != null) {
        if (cores.isZooKeeperAware()) {
            int zklocalport = ((InetSocketAddress) cores.getZkController().getZkClient().getSolrZooKeeper().getSocketAddress()).getPort();
            IpTables.unblockPort(zklocalport);
        }
    }
    return true;
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) InetSocketAddress(java.net.InetSocketAddress) KeeperException(org.apache.zookeeper.KeeperException)

Example 58 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class ChaosMonkey method causeConnectionLoss.

public static void causeConnectionLoss(JettySolrRunner jetty) {
    CoreContainer cores = jetty.getCoreContainer();
    if (cores != null) {
        monkeyLog("Will cause connection loss on " + jetty.getLocalPort());
        SolrZkClient zkClient = cores.getZkController().getZkClient();
        zkClient.getSolrZooKeeper().closeCnxn();
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient)

Example 59 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class TrackingShardHandlerFactory method setTrackingQueue.

/**
   * Sets the tracking queue for all nodes participating in this cluster. Once this method returns,
   * all search and core admin requests distributed to shards will be submitted to the given queue.
   *
   * @param runners a list of {@link org.apache.solr.client.solrj.embedded.JettySolrRunner} nodes
   * @param queue   an implementation of {@link java.util.Queue} which
   *                accepts {@link org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams}
   *                instances
   */
public static void setTrackingQueue(List<JettySolrRunner> runners, Queue<ShardRequestAndParams> queue) {
    for (JettySolrRunner runner : runners) {
        CoreContainer container = runner.getCoreContainer();
        ShardHandlerFactory factory = container.getShardHandlerFactory();
        assert factory instanceof TrackingShardHandlerFactory : "not a TrackingShardHandlerFactory: " + factory.getClass();
        TrackingShardHandlerFactory trackingShardHandlerFactory = (TrackingShardHandlerFactory) factory;
        trackingShardHandlerFactory.setTrackingQueue(queue);
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner)

Example 60 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class SuggestComponentTest method reloadCore.

private void reloadCore(boolean createNewCore) throws Exception {
    if (createNewCore) {
        CoreContainer cores = h.getCoreContainer();
        SolrCore core = h.getCore();
        String dataDir1 = core.getDataDir();
        CoreDescriptor cd = core.getCoreDescriptor();
        h.close();
        createCore();
        SolrCore createdCore = h.getCore();
        assertEquals(dataDir1, createdCore.getDataDir());
        assertEquals(createdCore, h.getCore());
    } else {
        h.reload();
        // On regular reloading, wait until the new searcher is registered
        waitForWarming();
    }
    assertQ(req("qt", "standard", "q", "*:*"), "//*[@numFound='11']");
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) CoreDescriptor(org.apache.solr.core.CoreDescriptor)

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