SOLR-5902: Corecontainer level mbeans are not exposed

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1605081 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2014-06-24 13:53:52 +00:00
parent 5f77544bce
commit f2eacfd18b
4 changed files with 44 additions and 27 deletions

View File

@ -105,6 +105,8 @@ Other Changes
* SOLR-6178, LUCENE-5775: Deprecate JaspellLookupFactory. (Uwe Schindler, * SOLR-6178, LUCENE-5775: Deprecate JaspellLookupFactory. (Uwe Schindler,
Mike McCandless) Mike McCandless)
* SOLR-5902: Corecontainer level mbeans are not exposed (noble)
================== 4.9.0 ================== ================== 4.9.0 ==================
Versions of Major Components Versions of Major Components

View File

@ -816,4 +816,7 @@ public class SolrResourceLoader implements ResourceLoader,Closeable
public void close() throws IOException { public void close() throws IOException {
IOUtils.close(classLoader); IOUtils.close(classLoader);
} }
public List<SolrInfoMBean> getInfoMBeans(){
return Collections.unmodifiableList(infoMBeans);
}
} }

View File

@ -34,6 +34,7 @@ import java.io.StringReader;
import java.net.URL; import java.net.URL;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
@ -131,38 +132,41 @@ public class SolrInfoMBeanHandler extends RequestHandlerBase {
Map<String, SolrInfoMBean> reg = req.getCore().getInfoRegistry(); Map<String, SolrInfoMBean> reg = req.getCore().getInfoRegistry();
for (Map.Entry<String, SolrInfoMBean> entry : reg.entrySet()) { for (Map.Entry<String, SolrInfoMBean> entry : reg.entrySet()) {
String key = entry.getKey(); addMBean(req, cats, requestedKeys, entry.getKey(),entry.getValue());
SolrInfoMBean m = entry.getValue(); }
if ( ! ( requestedKeys.isEmpty() || requestedKeys.contains(key) ) ) continue; for (SolrInfoMBean infoMBean : req.getCore().getCoreDescriptor().getCoreContainer().getResourceLoader().getInfoMBeans()) {
addMBean(req,cats,requestedKeys,infoMBean.getName(),infoMBean);
NamedList<NamedList<Object>> catInfo = cats.get(m.getCategory().name());
if ( null == catInfo ) continue;
NamedList<Object> mBeanInfo = new SimpleOrderedMap<>();
mBeanInfo.add("class", m.getName());
mBeanInfo.add("version", m.getVersion());
mBeanInfo.add("description", m.getDescription());
mBeanInfo.add("src", m.getSource());
// Use an external form
URL[] urls = m.getDocs();
if(urls!=null) {
List<String> docs = new ArrayList<>(urls.length);
for(URL url : urls) {
docs.add(url.toExternalForm());
}
mBeanInfo.add("docs", docs);
}
if (req.getParams().getFieldBool(key, "stats", false))
mBeanInfo.add("stats", m.getStatistics());
catInfo.add(key, mBeanInfo);
} }
return cats; return cats;
} }
private void addMBean(SolrQueryRequest req, NamedList<NamedList<NamedList<Object>>> cats, Set<String> requestedKeys, String key, SolrInfoMBean m) {
if ( ! ( requestedKeys.isEmpty() || requestedKeys.contains(key) ) ) return;
NamedList<NamedList<Object>> catInfo = cats.get(m.getCategory().name());
if ( null == catInfo ) return;
NamedList<Object> mBeanInfo = new SimpleOrderedMap<>();
mBeanInfo.add("class", m.getName());
mBeanInfo.add("version", m.getVersion());
mBeanInfo.add("description", m.getDescription());
mBeanInfo.add("src", m.getSource());
// Use an external form
URL[] urls = m.getDocs();
if(urls!=null) {
List<String> docs = new ArrayList<>(urls.length);
for(URL url : urls) {
docs.add(url.toExternalForm());
}
mBeanInfo.add("docs", docs);
}
if (req.getParams().getFieldBool(key, "stats", false))
mBeanInfo.add("stats", m.getStatistics());
catInfo.add(key, mBeanInfo);
}
protected NamedList<NamedList<NamedList<Object>>> getDiff( protected NamedList<NamedList<NamedList<Object>>> getDiff(
NamedList<NamedList<NamedList<Object>>> ref, NamedList<NamedList<NamedList<Object>>> ref,
NamedList<NamedList<NamedList<Object>>> now, NamedList<NamedList<NamedList<Object>>> now,

View File

@ -61,5 +61,13 @@ public class MBeansHandlerTest extends SolrTestCaseJ4 {
//System.out.println("stats:"+stats); //System.out.println("stats:"+stats);
assertEquals("Was: 1, Now: 2, Delta: 1", stats.get("requests")); assertEquals("Was: 1, Now: 2, Delta: 1", stats.get("requests"));
xml = h.query(req(
CommonParams.QT,"/admin/mbeans",
"stats","true",
"key","org.apache.solr.handler.admin.CollectionsHandler"
));
NamedList<NamedList<NamedList<Object>>> nl = SolrInfoMBeanHandler.fromXML(xml);
assertNotNull( nl.get("QUERYHANDLER").get("org.apache.solr.handler.admin.CollectionsHandler"));
} }
} }