Search in sources :

Example 31 with SolrResourceLoader

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

the class MetricsConfigTest method setupLoader.

@BeforeClass
public static void setupLoader() throws Exception {
    solrHome = createTempDir().toFile();
    loader = new SolrResourceLoader(solrHome.toPath());
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) BeforeClass(org.junit.BeforeClass)

Example 32 with SolrResourceLoader

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

the class SolrMetricsIntegrationTest method beforeTest.

@Before
public void beforeTest() 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");
    String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-metricreporter.xml").toFile(), "UTF-8");
    NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml);
    cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml"));
    h.coreName = DEFAULT_TEST_CORENAME;
    jmxReporter = JmxUtil.findFirstMBeanServer() != null ? 1 : 0;
    metricManager = cc.getMetricManager();
    tag = h.getCore().getCoreMetricManager().getTag();
    // initially there are more reporters, because two of them are added via a matching collection name
    Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.core." + DEFAULT_TEST_CORENAME);
    assertEquals(INITIAL_REPORTERS.length + jmxReporter, reporters.size());
    for (String r : INITIAL_REPORTERS) {
        assertTagged(reporters, r);
    }
    // test rename operation
    cc.rename(DEFAULT_TEST_CORENAME, CORE_NAME);
    h.coreName = CORE_NAME;
    cfg = cc.getConfig();
    PluginInfo[] plugins = cfg.getMetricsConfig().getMetricReporters();
    assertNotNull(plugins);
    assertEquals(10 + jmxReporter, plugins.length);
    reporters = metricManager.getReporters("solr.node");
    assertEquals(4 + jmxReporter, reporters.size());
    assertTrue("Reporter '" + REPORTER_NAMES[0] + "' missing in solr.node", reporters.containsKey(REPORTER_NAMES[0]));
    assertTrue("Reporter '" + UNIVERSAL + "' missing in solr.node", reporters.containsKey(UNIVERSAL));
    assertTrue("Reporter '" + MULTIGROUP + "' missing in solr.node", reporters.containsKey(MULTIGROUP));
    assertTrue("Reporter '" + MULTIREGISTRY + "' missing in solr.node", reporters.containsKey(MULTIREGISTRY));
    SolrMetricReporter reporter = reporters.get(REPORTER_NAMES[0]);
    assertTrue("Reporter " + reporter + " is not an instance of " + MockMetricReporter.class.getName(), reporter instanceof MockMetricReporter);
    reporter = reporters.get(UNIVERSAL);
    assertTrue("Reporter " + reporter + " is not an instance of " + MockMetricReporter.class.getName(), reporter instanceof MockMetricReporter);
}
Also used : Path(java.nio.file.Path) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) PluginInfo(org.apache.solr.core.PluginInfo) MockMetricReporter(org.apache.solr.metrics.reporters.MockMetricReporter) NodeConfig(org.apache.solr.core.NodeConfig) Before(org.junit.Before)

Example 33 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader 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 34 with SolrResourceLoader

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

the class ContentStreamTest method testURLStream.

public void testURLStream() throws IOException {
    InputStream is = new SolrResourceLoader().openResource("solrj/README");
    assertNotNull(is);
    File file = new File(createTempDir().toFile(), "README");
    FileOutputStream os = new FileOutputStream(file);
    IOUtils.copy(is, os);
    os.close();
    is.close();
    ContentStreamBase stream = new ContentStreamBase.URLStream(new URL(file.toURI().toASCIIString()));
    InputStream s = stream.getStream();
    FileInputStream fis = new FileInputStream(file);
    FileInputStream fis2 = new FileInputStream(file);
    InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
    Reader r = stream.getReader();
    try {
        assertTrue(IOUtils.contentEquals(fis2, s));
        assertEquals(file.length(), stream.getSize().intValue());
        assertTrue(IOUtils.contentEquals(isr, r));
        assertEquals(file.length(), stream.getSize().intValue());
    } finally {
        r.close();
        s.close();
        isr.close();
        fis.close();
        fis2.close();
    }
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 35 with SolrResourceLoader

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

the class InvokeOp method invokeAClass.

static Map<String, Object> invokeAClass(SolrQueryRequest req, String c) {
    SolrResourceLoader loader = null;
    if (req.getCore() != null)
        loader = req.getCore().getResourceLoader();
    else if (req.getContext().get(CoreContainer.class.getName()) != null) {
        CoreContainer cc = (CoreContainer) req.getContext().get(CoreContainer.class.getName());
        loader = cc.getResourceLoader();
    }
    CoreAdminHandler.Invocable invokable = loader.newInstance(c, CoreAdminHandler.Invocable.class);
    Map<String, Object> result = invokable.invoke(req);
    log.info("Invocable_invoked {}", result);
    return result;
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer)

Aggregations

SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)54 Test (org.junit.Test)18 File (java.io.File)11 InputStream (java.io.InputStream)11 NamedList (org.apache.solr.common.util.NamedList)10 SolrException (org.apache.solr.common.SolrException)9 NodeConfig (org.apache.solr.core.NodeConfig)9 Path (java.nio.file.Path)8 CoreContainer (org.apache.solr.core.CoreContainer)8 InputStreamReader (java.io.InputStreamReader)7 Reader (java.io.Reader)7 Map (java.util.Map)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 XMLResponseParser (org.apache.solr.client.solrj.impl.XMLResponseParser)5 SolrCore (org.apache.solr.core.SolrCore)5 ArrayList (java.util.ArrayList)4 ZkSolrResourceLoader (org.apache.solr.cloud.ZkSolrResourceLoader)4 SolrConfig (org.apache.solr.core.SolrConfig)4