use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class SolrJmxReporterTest method createReporterPluginInfo.
private PluginInfo createReporterPluginInfo(String rootName, boolean enabled) {
Random random = random();
String className = SolrJmxReporter.class.getName();
String reporterName = TestUtil.randomSimpleString(random, 5, 10);
Map<String, Object> attrs = new HashMap<>();
attrs.put(FieldType.CLASS_NAME, className);
attrs.put(CoreAdminParams.NAME, reporterName);
attrs.put("rootName", rootName);
attrs.put("enabled", enabled);
attrs.put("serviceUrl", "service:jmx:rmi:///jndi/rmi://localhost:" + jmxPort + "/solrjmx");
boolean shouldOverrideDomain = random.nextBoolean();
if (shouldOverrideDomain) {
domain = TestUtil.randomSimpleString(random);
attrs.put("domain", domain);
}
return new PluginInfo(TestUtil.randomUnicodeString(random), attrs);
}
use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class SolrJmxReporterTest method beforeTest.
@Before
public void beforeTest() throws Exception {
initCore("solrconfig-basic.xml", "schema.xml");
final SolrCore core = h.getCore();
domain = core.getName();
rootName = TestUtil.randomSimpleString(random(), 5, 10);
coreMetricManager = core.getCoreMetricManager();
metricManager = core.getCoreContainer().getMetricManager();
PluginInfo pluginInfo = createReporterPluginInfo(rootName, true);
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo, coreMetricManager.getTag());
Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
assertTrue("reporters.size should be > 0, but was + " + reporters.size(), reporters.size() > 0);
reporterName = pluginInfo.name;
String taggedName = reporterName + "@" + coreMetricManager.getTag();
assertNotNull("reporter " + taggedName + " not present among " + reporters, reporters.get(taggedName));
assertTrue("wrong reporter class: " + reporters.get(taggedName), reporters.get(taggedName) instanceof SolrJmxReporter);
reporter = (SolrJmxReporter) reporters.get(taggedName);
mBeanServer = reporter.getMBeanServer();
assertNotNull("MBean server not found.", mBeanServer);
}
use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class SolrCoreMetricManagerTest method testLoadReporter.
@Test
public void testLoadReporter() throws Exception {
Random random = random();
String className = MockMetricReporter.class.getName();
String reporterName = TestUtil.randomUnicodeString(random);
String taggedName = reporterName + "@" + coreMetricManager.getTag();
Map<String, Object> attrs = new HashMap<>();
attrs.put(FieldType.CLASS_NAME, className);
attrs.put(CoreAdminParams.NAME, reporterName);
boolean shouldDefineConfigurable = random.nextBoolean();
String configurable = TestUtil.randomUnicodeString(random);
if (shouldDefineConfigurable)
attrs.put("configurable", configurable);
boolean shouldDefinePlugin = random.nextBoolean();
PluginInfo pluginInfo = shouldDefinePlugin ? new PluginInfo(TestUtil.randomUnicodeString(random), attrs) : null;
try {
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo, String.valueOf(coreMetricManager.getCore().hashCode()));
assertNotNull(pluginInfo);
Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
assertTrue("reporters.size should be > 0, but was + " + reporters.size(), reporters.size() > 0);
assertNotNull("reporter " + reporterName + " not present among " + reporters, reporters.get(taggedName));
assertTrue("wrong reporter class: " + reporters.get(taggedName), reporters.get(taggedName) instanceof MockMetricReporter);
} catch (IllegalArgumentException e) {
assertTrue(pluginInfo == null || attrs.get("configurable") == null);
assertNull(metricManager.getReporters(coreMetricManager.getRegistryName()).get(taggedName));
}
}
use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class SolrMetricManagerTest method testReporters.
@Test
public void testReporters() throws Exception {
Random r = random();
SolrResourceLoader loader = new SolrResourceLoader();
SolrMetricManager metricManager = new SolrMetricManager();
PluginInfo[] plugins = new PluginInfo[] { createPluginInfo("universal_foo", null, null), createPluginInfo("multigroup_foo", "jvm, node, core", null), createPluginInfo("multiregistry_foo", null, "solr.node, solr.core.collection1"), createPluginInfo("specific_foo", null, "solr.core.collection1"), createPluginInfo("node_foo", "node", null), createPluginInfo("core_foo", "core", null) };
String tag = "xyz";
metricManager.loadReporters(plugins, loader, tag, SolrInfoBean.Group.node);
Map<String, SolrMetricReporter> reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.node));
assertEquals(4, reporters.size());
assertTrue(reporters.containsKey("universal_foo@" + tag));
assertTrue(reporters.containsKey("multigroup_foo@" + tag));
assertTrue(reporters.containsKey("node_foo@" + tag));
assertTrue(reporters.containsKey("multiregistry_foo@" + tag));
metricManager.loadReporters(plugins, loader, tag, SolrInfoBean.Group.core, "collection1");
reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.core, "collection1"));
assertEquals(5, reporters.size());
assertTrue(reporters.containsKey("universal_foo@" + tag));
assertTrue(reporters.containsKey("multigroup_foo@" + tag));
assertTrue(reporters.containsKey("specific_foo@" + tag));
assertTrue(reporters.containsKey("core_foo@" + tag));
assertTrue(reporters.containsKey("multiregistry_foo@" + tag));
metricManager.loadReporters(plugins, loader, tag, SolrInfoBean.Group.jvm);
reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm));
assertEquals(2, reporters.size());
assertTrue(reporters.containsKey("universal_foo@" + tag));
assertTrue(reporters.containsKey("multigroup_foo@" + tag));
metricManager.removeRegistry("solr.jvm");
reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm));
assertEquals(0, reporters.size());
metricManager.removeRegistry("solr.node");
reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.node));
assertEquals(0, reporters.size());
metricManager.removeRegistry("solr.core.collection1");
reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.core, "collection1"));
assertEquals(0, reporters.size());
}
use of org.apache.solr.core.PluginInfo 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);
}
Aggregations