You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ry...@apache.org on 2007/12/29 18:40:44 UTC

svn commit: r607451 - in /lucene/solr/trunk: CHANGES.txt example/solr/conf/solrconfig.xml src/java/org/apache/solr/handler/admin/AdminHandlers.java

Author: ryan
Date: Sat Dec 29 09:40:41 2007
New Revision: 607451

URL: http://svn.apache.org/viewvc?rev=607451&view=rev
Log:
SOLR-447 -- automatically register standard Admin request handlers

Added:
    lucene/solr/trunk/src/java/org/apache/solr/handler/admin/AdminHandlers.java   (with props)
Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/example/solr/conf/solrconfig.xml

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=607451&r1=607450&r2=607451&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Sat Dec 29 09:40:41 2007
@@ -169,6 +169,13 @@
     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

Modified: lucene/solr/trunk/example/solr/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/example/solr/conf/solrconfig.xml?rev=607451&r1=607450&r2=607451&view=diff
==============================================================================
--- lucene/solr/trunk/example/solr/conf/solrconfig.xml (original)
+++ lucene/solr/trunk/example/solr/conf/solrconfig.xml Sat Dec 29 09:40:41 2007
@@ -493,12 +493,18 @@
   <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">

Added: lucene/solr/trunk/src/java/org/apache/solr/handler/admin/AdminHandlers.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/admin/AdminHandlers.java?rev=607451&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/admin/AdminHandlers.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/admin/AdminHandlers.java Sat Dec 29 09:40:41 2007
@@ -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;
+  }
+}

Propchange: lucene/solr/trunk/src/java/org/apache/solr/handler/admin/AdminHandlers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/solr/trunk/src/java/org/apache/solr/handler/admin/AdminHandlers.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL