SOLR-447 -- automatically register standard Admin request handlers

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@607451 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2007-12-29 17:40:41 +00:00
parent aa3db299e4
commit 54fa88b6b5
3 changed files with 154 additions and 1 deletions

View File

@ -169,6 +169,13 @@ New Features
multiple cores and enables runtime core manipulation. For more informaion see:
http://wiki.apache.org/solr/MultiCore (Henri Biestro, ryan)
34. SOLR-447: Added an single request handler that will automatically register all
standard admin request handlers. This replaces the need to register (and maintain)
the set of admin request handlers. Assuming solrconfig.xml includes:
<requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />
This will register: Luke/SystemInfo/PluginInfo/ThreadDump/PropertiesRequestHandler.
(ryan)
Changes in runtime behavior
Optimizations

View File

@ -493,13 +493,19 @@
<requestHandler name="/update/csv" class="solr.CSVRequestHandler" startup="lazy" />
<!-- Admin Handlers. TODO? There could be a single handler that loads them all... -->
<!--
Admin Handlers - This will register all the standard admin RequestHandlers. Adding
this single handler is equivolent to registering:
<requestHandler name="/admin/luke" class="org.apache.solr.handler.admin.LukeRequestHandler" />
<requestHandler name="/admin/system" class="org.apache.solr.handler.admin.SystemInfoHandler" />
<requestHandler name="/admin/plugins" class="org.apache.solr.handler.admin.PluginInfoHandler" />
<requestHandler name="/admin/threads" class="org.apache.solr.handler.admin.ThreadDumpHandler" />
<requestHandler name="/admin/properties" class="org.apache.solr.handler.admin.PropertiesRequestHandler" />
-->
<requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />
<!-- ping/healthcheck -->
<requestHandler name="/admin/ping" class="PingRequestHandler">
<lst name="defaults">

View File

@ -0,0 +1,140 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.handler.admin;
import java.net.URL;
import java.util.Map;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.util.plugin.SolrCoreAware;
/**
* A special Handler that registers all standard admin handlers
*
* @version $Id$
* @since solr 1.3
*/
public class AdminHandlers implements SolrCoreAware, SolrRequestHandler
{
NamedList initArgs = null;
private static class StandardHandler {
final String name;
final SolrRequestHandler handler;
public StandardHandler( String n, SolrRequestHandler h )
{
this.name = n;
this.handler = h;
}
}
/**
* Save the args and pass them to each standard handler
*/
public void init(NamedList args) {
this.initArgs = args;
}
public void inform(SolrCore core)
{
String path = null;
for( Map.Entry<String, SolrRequestHandler> entry : core.getRequestHandlers().entrySet() ) {
if( entry.getValue() == this ) {
path = entry.getKey();
break;
}
}
if( path == null ) {
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
"The AdminHandler is not registered with the current core." );
}
if( !path.startsWith( "/" ) ) {
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
"The AdminHandler needs to be registered to a path. Typically this is '/admin'" );
}
// Remove the parent handler
core.registerRequestHandler(path, null);
if( !path.endsWith( "/" ) ) {
path += "/";
}
StandardHandler[] list = new StandardHandler[] {
new StandardHandler( "luke", new LukeRequestHandler() ),
new StandardHandler( "system", new SystemInfoHandler() ),
new StandardHandler( "plugins", new PluginInfoHandler() ),
new StandardHandler( "threads", new ThreadDumpHandler() ),
new StandardHandler( "properties", new PropertiesRequestHandler() )
};
for( StandardHandler handler : list ) {
if( core.getRequestHandler( path+handler.name ) == null ) {
handler.handler.init( initArgs );
core.registerRequestHandler( path+handler.name, handler.handler );
if( handler.handler instanceof SolrCoreAware ) {
((SolrCoreAware)handler).inform(core);
}
}
}
}
public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
"The AdminHandler should never be called directly" );
}
//////////////////////// SolrInfoMBeans methods //////////////////////
public String getDescription() {
return "Register Standard Admin Handlers";
}
public String getVersion() {
return "$Revision$";
}
public String getSourceId() {
return "$Id$";
}
public String getSource() {
return "$URL$";
}
public Category getCategory() {
return Category.QUERYHANDLER;
}
public URL[] getDocs() {
return null;
}
public String getName() {
return this.getClass().getName();
}
public NamedList getStatistics() {
return null;
}
}