Search in sources :

Example 1 with SolrInfoBean

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

the class SolrInfoBeanTest method testCallMBeanInfo.

/**
   * Gets a list of everything we can find in the classpath and makes sure it has
   * a name, description, etc...
   */
public void testCallMBeanInfo() throws Exception {
    List<Class> classes = new ArrayList<>();
    classes.addAll(getClassesForPackage(StandardRequestHandler.class.getPackage().getName()));
    classes.addAll(getClassesForPackage(SearchComponent.class.getPackage().getName()));
    classes.addAll(getClassesForPackage(LukeRequestHandler.class.getPackage().getName()));
    classes.addAll(getClassesForPackage(DefaultSolrHighlighter.class.getPackage().getName()));
    classes.addAll(getClassesForPackage(LRUCache.class.getPackage().getName()));
    // System.out.println(classes);
    int checked = 0;
    SolrMetricManager metricManager = h.getCoreContainer().getMetricManager();
    String registry = h.getCore().getCoreMetricManager().getRegistryName();
    String scope = TestUtil.randomSimpleString(random(), 2, 10);
    for (Class clazz : classes) {
        if (SolrInfoBean.class.isAssignableFrom(clazz)) {
            try {
                SolrInfoBean info = (SolrInfoBean) clazz.newInstance();
                if (info instanceof SolrMetricProducer) {
                    ((SolrMetricProducer) info).initializeMetrics(metricManager, registry, scope);
                }
                //System.out.println( info.getClass() );
                assertNotNull(info.getName());
                assertNotNull(info.getDescription());
                assertNotNull(info.getCategory());
                if (info instanceof LRUCache) {
                    continue;
                }
                assertNotNull(info.toString());
                checked++;
            } catch (InstantiationException ex) {
            // expected...
            //System.out.println( "unable to initialize: "+clazz );
            }
        }
    }
    assertTrue("there are at least 10 SolrInfoBean that should be found in the classpath, found " + checked, checked > 10);
}
Also used : SolrInfoBean(org.apache.solr.core.SolrInfoBean) ArrayList(java.util.ArrayList) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) LRUCache(org.apache.solr.search.LRUCache) LukeRequestHandler(org.apache.solr.handler.admin.LukeRequestHandler) SearchComponent(org.apache.solr.handler.component.SearchComponent) DefaultSolrHighlighter(org.apache.solr.highlight.DefaultSolrHighlighter) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) BeforeClass(org.junit.BeforeClass) StandardRequestHandler(org.apache.solr.handler.StandardRequestHandler)

Example 2 with SolrInfoBean

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

the class PluginInfoHandler method getSolrInfoBeans.

private static SimpleOrderedMap<Object> getSolrInfoBeans(SolrCore core, boolean stats) {
    SimpleOrderedMap<Object> list = new SimpleOrderedMap<>();
    for (SolrInfoBean.Category cat : SolrInfoBean.Category.values()) {
        SimpleOrderedMap<Object> category = new SimpleOrderedMap<>();
        list.add(cat.name(), category);
        Map<String, SolrInfoBean> reg = core.getInfoRegistry();
        for (Map.Entry<String, SolrInfoBean> entry : reg.entrySet()) {
            SolrInfoBean m = entry.getValue();
            if (m.getCategory() != cat)
                continue;
            String na = "Not Declared";
            SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
            category.add(entry.getKey(), info);
            info.add(NAME, (m.getName() != null ? m.getName() : na));
            info.add("description", (m.getDescription() != null ? m.getDescription() : na));
            if (stats) {
                info.add("stats", m.getMetricsSnapshot());
            }
        }
    }
    return list;
}
Also used : SolrInfoBean(org.apache.solr.core.SolrInfoBean) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map)

Example 3 with SolrInfoBean

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

the class SolrInfoMBeanHandler method getMBeanInfo.

protected NamedList<NamedList<NamedList<Object>>> getMBeanInfo(SolrQueryRequest req) {
    NamedList<NamedList<NamedList<Object>>> cats = new NamedList<>();
    String[] requestedCats = req.getParams().getParams("cat");
    if (null == requestedCats || 0 == requestedCats.length) {
        for (SolrInfoBean.Category cat : SolrInfoBean.Category.values()) {
            cats.add(cat.name(), new SimpleOrderedMap<NamedList<Object>>());
        }
    } else {
        for (String catName : requestedCats) {
            cats.add(catName, new SimpleOrderedMap<NamedList<Object>>());
        }
    }
    Set<String> requestedKeys = arrayToSet(req.getParams().getParams("key"));
    Map<String, SolrInfoBean> reg = req.getCore().getInfoRegistry();
    for (Map.Entry<String, SolrInfoBean> entry : reg.entrySet()) {
        addMBean(req, cats, requestedKeys, entry.getKey(), entry.getValue());
    }
    for (SolrInfoBean infoMBean : req.getCore().getCoreContainer().getResourceLoader().getInfoMBeans()) {
        addMBean(req, cats, requestedKeys, infoMBean.getName(), infoMBean);
    }
    return cats;
}
Also used : SolrInfoBean(org.apache.solr.core.SolrInfoBean) NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map)

Example 4 with SolrInfoBean

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

the class SolrIndexSearcher method register.

/**
   * Register sub-objects such as caches and our own metrics
   */
public void register() {
    final Map<String, SolrInfoBean> infoRegistry = core.getInfoRegistry();
    // register self
    infoRegistry.put(STATISTICS_KEY, this);
    infoRegistry.put(name, this);
    for (SolrCache cache : cacheList) {
        cache.setState(SolrCache.State.LIVE);
        infoRegistry.put(cache.name(), cache);
    }
    SolrMetricManager manager = core.getCoreContainer().getMetricManager();
    String registry = core.getCoreMetricManager().getRegistryName();
    for (SolrCache cache : cacheList) {
        cache.initializeMetrics(manager, registry, SolrMetricManager.mkName(cache.name(), STATISTICS_KEY));
    }
    initializeMetrics(manager, registry, STATISTICS_KEY);
    registerTime = new Date();
}
Also used : SolrInfoBean(org.apache.solr.core.SolrInfoBean) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) Date(java.util.Date)

Aggregations

SolrInfoBean (org.apache.solr.core.SolrInfoBean)4 Map (java.util.Map)2 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)2 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 NamedList (org.apache.solr.common.util.NamedList)1 StandardRequestHandler (org.apache.solr.handler.StandardRequestHandler)1 LukeRequestHandler (org.apache.solr.handler.admin.LukeRequestHandler)1 SearchComponent (org.apache.solr.handler.component.SearchComponent)1 DefaultSolrHighlighter (org.apache.solr.highlight.DefaultSolrHighlighter)1 SolrMetricProducer (org.apache.solr.metrics.SolrMetricProducer)1 LRUCache (org.apache.solr.search.LRUCache)1 BeforeClass (org.junit.BeforeClass)1