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