Search in sources :

Example 6 with PluginInfo

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);
}
Also used : HashMap(java.util.HashMap) NamedList(org.apache.solr.common.util.NamedList) PluginInfo(org.apache.solr.core.PluginInfo) MockMetricReporter(org.apache.solr.metrics.reporters.MockMetricReporter)

Example 7 with PluginInfo

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();
    }
}
Also used : Random(java.util.Random) HashMap(java.util.HashMap) PluginInfo(org.apache.solr.core.PluginInfo) MockMetricReporter(org.apache.solr.metrics.reporters.MockMetricReporter) Test(org.junit.Test)

Example 8 with PluginInfo

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();
}
Also used : HashMap(java.util.HashMap) CloudConfig(org.apache.solr.core.CloudConfig) MetricsConfig(org.apache.solr.core.MetricsConfig) UpdateShardHandlerConfig(org.apache.solr.update.UpdateShardHandlerConfig) PluginInfo(org.apache.solr.core.PluginInfo) SolrJmxReporter(org.apache.solr.metrics.reporters.SolrJmxReporter) NodeConfig(org.apache.solr.core.NodeConfig)

Example 9 with PluginInfo

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());
}
Also used : Counter(com.codahale.metrics.Counter) SolrInfoBean(org.apache.solr.core.SolrInfoBean) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) ObjectInstance(javax.management.ObjectInstance) PluginInfo(org.apache.solr.core.PluginInfo) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 10 with PluginInfo

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());
}
Also used : Counter(com.codahale.metrics.Counter) Random(java.util.Random) SolrInfoBean(org.apache.solr.core.SolrInfoBean) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) ObjectInstance(javax.management.ObjectInstance) PluginInfo(org.apache.solr.core.PluginInfo) Test(org.junit.Test)

Aggregations

PluginInfo (org.apache.solr.core.PluginInfo)25 HashMap (java.util.HashMap)8 Random (java.util.Random)5 IOException (java.io.IOException)4 MockMetricReporter (org.apache.solr.metrics.reporters.MockMetricReporter)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 ObjectInstance (javax.management.ObjectInstance)3 NodeConfig (org.apache.solr.core.NodeConfig)3 SolrCore (org.apache.solr.core.SolrCore)3 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)3 Counter (com.codahale.metrics.Counter)2 File (java.io.File)2 NamedList (org.apache.solr.common.util.NamedList)2 SolrInfoBean (org.apache.solr.core.SolrInfoBean)2 SolrMetricProducer (org.apache.solr.metrics.SolrMetricProducer)2 SolrMetricReporter (org.apache.solr.metrics.SolrMetricReporter)2 Before (org.junit.Before)2