use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class SolrMetricManagerTest method createPluginInfo.
private PluginInfo createPluginInfo(String name, String group, String registry) {
Map<String, String> attrs = new HashMap<>();
attrs.put("name", name);
attrs.put("class", MockMetricReporter.class.getName());
if (group != null) {
attrs.put("group", group);
}
if (registry != null) {
attrs.put("registry", registry);
}
NamedList initArgs = new NamedList();
initArgs.add("configurable", "true");
return new PluginInfo("SolrMetricReporter", attrs, initArgs, null);
}
use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class SolrMetricReporterTest method testInit.
@Test
public void testInit() throws Exception {
Random random = random();
SolrMetricManager metricManager = new SolrMetricManager();
final String registryName = TestUtil.randomSimpleString(random);
final MockMetricReporter reporter = new MockMetricReporter(metricManager, registryName);
Map<String, Object> attrs = new HashMap<>();
attrs.put(FieldType.CLASS_NAME, MockMetricReporter.class.getName());
attrs.put(CoreAdminParams.NAME, TestUtil.randomUnicodeString(random));
attrs.put("enabled", random.nextBoolean());
boolean shouldDefineConfigurable = random.nextBoolean();
String configurable = TestUtil.randomUnicodeString(random);
if (shouldDefineConfigurable)
attrs.put("configurable", configurable);
boolean shouldDefinePlugin = random.nextBoolean();
String type = TestUtil.randomUnicodeString(random);
PluginInfo pluginInfo = shouldDefinePlugin ? new PluginInfo(type, attrs) : null;
try {
reporter.init(pluginInfo);
assertNotNull(pluginInfo);
assertEquals(configurable, attrs.get("configurable"));
assertTrue(reporter.didValidate);
assertNotNull(reporter.configurable);
assertEquals(configurable, reporter.configurable);
} catch (IllegalStateException e) {
assertTrue(pluginInfo == null || attrs.get("configurable") == null);
assertTrue(reporter.didValidate);
assertNull(reporter.configurable);
} finally {
reporter.close();
}
}
use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class TestHarness method buildTestNodeConfig.
public static NodeConfig buildTestNodeConfig(SolrResourceLoader loader) {
CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder(System.getProperty("host"), Integer.getInteger("hostPort", 8983), System.getProperty("hostContext", "")).setZkClientTimeout(Integer.getInteger("zkClientTimeout", 30000)).build();
if (System.getProperty("zkHost") == null)
cloudConfig = null;
UpdateShardHandlerConfig updateShardHandlerConfig = new UpdateShardHandlerConfig(UpdateShardHandlerConfig.DEFAULT_MAXUPDATECONNECTIONS, UpdateShardHandlerConfig.DEFAULT_MAXUPDATECONNECTIONSPERHOST, 30000, 30000, UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY, UpdateShardHandlerConfig.DEFAULT_MAXRECOVERYTHREADS);
// universal default metric reporter
Map<String, Object> attributes = new HashMap<>();
attributes.put("name", "default");
attributes.put("class", SolrJmxReporter.class.getName());
PluginInfo defaultPlugin = new PluginInfo("reporter", attributes);
MetricsConfig metricsConfig = new MetricsConfig.MetricsConfigBuilder().setMetricReporterPlugins(new PluginInfo[] { defaultPlugin }).build();
return new NodeConfig.NodeConfigBuilder("testNode", loader).setUseSchemaCache(Boolean.getBoolean("shareSchema")).setCloudConfig(cloudConfig).setUpdateShardHandlerConfig(updateShardHandlerConfig).setMetricsConfig(metricsConfig).build();
}
use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class SolrJmxReporterTest method testEnabled.
@Test
public void testEnabled() throws Exception {
String root1 = TestUtil.randomSimpleString(random(), 5, 10);
PluginInfo pluginInfo1 = createReporterPluginInfo(root1, true);
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo1, coreMetricManager.getTag());
String root2 = TestUtil.randomSimpleString(random(), 5, 10);
assertFalse(root2.equals(root1));
PluginInfo pluginInfo2 = createReporterPluginInfo(root2, false);
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo2, coreMetricManager.getTag());
Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
assertTrue(reporters.containsKey(pluginInfo1.name + "@" + coreMetricManager.getTag()));
assertTrue(reporters.containsKey(pluginInfo2.name + "@" + coreMetricManager.getTag()));
String scope = SolrMetricTestUtils.getRandomScope(random(), true);
SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random(), true);
Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(random(), true);
SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
coreMetricManager.registerMetricProducer(scope, producer);
Set<ObjectInstance> objects = mBeanServer.queryMBeans(null, null);
assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && root1.equals(o.getObjectName().getDomain())).count());
assertEquals(0, objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && root2.equals(o.getObjectName().getDomain())).count());
}
use of org.apache.solr.core.PluginInfo in project lucene-solr by apache.
the class SolrJmxReporterTest method testReloadCore.
@Test
public void testReloadCore() throws Exception {
Random random = random();
String scope = SolrMetricTestUtils.getRandomScope(random, true);
SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random, true);
Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(random, true);
SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
coreMetricManager.registerMetricProducer(scope, producer);
Set<ObjectInstance> objects = mBeanServer.queryMBeans(null, null);
assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && o.getObjectName().getDomain().equals(rootName)).count());
h.getCoreContainer().reload(h.getCore().getName());
PluginInfo pluginInfo = createReporterPluginInfo(rootName, true);
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo, String.valueOf(coreMetricManager.getCore().hashCode()));
coreMetricManager.registerMetricProducer(scope, producer);
objects = mBeanServer.queryMBeans(null, null);
assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && rootName.equals(o.getObjectName().getDomain())).count());
}
Aggregations