SOLR-408 adding PingRequestHandler.java and deprecating <pingQuery> syntax

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@593627 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2007-11-09 19:24:18 +00:00
parent ef18068055
commit c4f99ab049
9 changed files with 161 additions and 11 deletions

View File

@ -148,6 +148,11 @@ New Features
and a bevy of new and renamed options (see the wiki).
(Mike Krimerman, Scott Taber via klaas).
29. SOLR-408: Added PingRequestHandler and deprecated SolrCore.getPingQueryRequest().
Ping requests should be configured using standard RequestHandler syntax in
solrconfig.xml rather then using the <pingQuery></pingQuery> syntax.
(Karsten Sperling via ryan)
Changes in runtime behavior

View File

@ -34,18 +34,19 @@ import org.apache.solr.common.util.ContentStream;
*/
public class SolrPing extends RequestBase
{
private ModifiableSolrParams params;
public SolrPing()
{
super( METHOD.GET, "/admin/ping" );
params = new ModifiableSolrParams();
}
public Collection<ContentStream> getContentStreams() {
return null;
}
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set( "q", "solrpingquery" );
public ModifiableSolrParams getParams() {
return params;
}

View File

@ -28,6 +28,7 @@ import junit.framework.Assert;
import org.apache.solr.client.solrj.request.DirectXmlRequest;
import org.apache.solr.client.solrj.request.LukeRequest;
import org.apache.solr.client.solrj.request.SolrPing;
import org.apache.solr.client.solrj.response.LukeResponse;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
@ -255,7 +256,6 @@ abstract public class SolrExampleTests extends SolrExampleTestBase
assertNumFound( "*:*", 0 ); // make sure it got out
}
public void testLukeHandler() throws Exception
{
SolrServer server = getSolrServer();
@ -281,4 +281,28 @@ abstract public class SolrExampleTests extends SolrExampleTestBase
rsp = luke.process( server );
assertNotNull( rsp.getFieldTypeInfo() );
}
public void testPingHandler() throws Exception
{
SolrServer server = getSolrServer();
// Empty the database...
server.deleteByQuery( "*:*" );// delete everything!
server.commit();
assertNumFound( "*:*", 0 ); // make sure it got in
// should be ok
server.ping();
try {
SolrPing ping = new SolrPing();
ping.getParams().set( "qt", "unknown handler!" );
ping.process( server );
fail( "sent unknown query type!" );
}
catch( Exception ex ) {
// expected
}
}
}

View File

@ -455,6 +455,15 @@
<requestHandler name="/admin/threads" class="org.apache.solr.handler.admin.ThreadDumpHandler" />
<requestHandler name="/admin/properties" class="org.apache.solr.handler.admin.PropertiesRequestHandler" />
<!-- ping/healthcheck -->
<requestHandler name="/admin/ping" class="PingRequestHandler">
<lst name="defaults">
<str name="qt">standard</str>
<str name="q">solrpingquery</str>
<str name="echoParams">all</str>
</lst>
</requestHandler>
<!-- Echo the request contents back to the client -->
<requestHandler name="/debug/dump" class="solr.DumpRequestHandler" >
<lst name="defaults">
@ -523,12 +532,7 @@
<admin>
<defaultQuery>solr</defaultQuery>
<gettableFiles>solrconfig.xml schema.xml admin-extra.html</gettableFiles>
<!-- pingQuery should be "URLish" ...
&amp; separated key=val pairs ... but there shouldn't be any
URL escaping of the values -->
<pingQuery>
qt=standard&amp;q=solrpingquery
</pingQuery>
<!-- configure a healthcheck file for servers behind a loadbalancer
<healthcheck type="file">server-enabled</healthcheck>
-->

View File

@ -18,6 +18,7 @@
package org.apache.solr.core;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.handler.PingRequestHandler;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
@ -151,7 +152,9 @@ public class SolrConfig extends Config {
// default & main index configurations
public final SolrIndexConfig defaultIndexConfig;
public final SolrIndexConfig mainIndexConfig;
// ping query request parameters
@Deprecated
private final NamedList pingQueryParams;
static private NamedList readPingQueryParams(SolrConfig config) {
@ -172,7 +175,10 @@ public class SolrConfig extends Config {
/**
* Returns a Request object based on the admin/pingQuery section
* of the Solr config file.
*
* @use {@link PingRequestHandler} instead
*/
@Deprecated
public SolrQueryRequest getPingQueryRequest(SolrCore core) {
return new LocalSolrQueryRequest(core, pingQueryParams);
}

View File

@ -42,6 +42,7 @@ import org.apache.solr.common.params.CommonParams.EchoParamStyle;
import org.apache.solr.common.util.DOMUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.handler.PingRequestHandler;
import org.apache.solr.highlight.SolrHighlighter;
import org.apache.solr.request.JSONResponseWriter;
import org.apache.solr.request.PythonResponseWriter;
@ -235,7 +236,7 @@ public final class SolrCore {
/**
* @return the last core initalized. If you are using multiple cores,
* @return the last core initialized. If you are using multiple cores,
* this is not a function to use.
*/
@Deprecated
@ -389,7 +390,10 @@ public final class SolrCore {
/**
* Returns a Request object based on the admin/pingQuery section
* of the Solr config file.
*
* @use {@link PingRequestHandler} instead
*/
@Deprecated
public SolrQueryRequest getPingQueryRequest() {
return solrConfig.getPingQueryRequest(this);
}

View File

@ -0,0 +1,100 @@
/**
* 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;
import java.io.File;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse;
import org.apache.solr.request.SolrRequestHandler;
/**
* Ping solr core
*
* @since solr 1.3
*/
public class PingRequestHandler extends RequestHandlerBase
{
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
{
SolrParams params = req.getParams();
SolrParams required = params.required();
SolrCore core = req.getCore();
// Check if the service is available
String healthcheck = core.getSolrConfig().get("admin/healthcheck/text()", null );
if( healthcheck != null && !new File(healthcheck).exists() ) {
throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Service disabled", true);
}
// Get the RequestHandler
String qt = required.get( CommonParams.QT );
SolrRequestHandler handler = core.getRequestHandler( qt );
if( handler == null ) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Unknown RequestHandler: "+qt );
}
// Execute the ping query and catch any possible exception
Throwable ex = null;
try {
SolrQueryResponse pingrsp = new SolrQueryResponse();
core.execute(handler, req, pingrsp );
ex = pingrsp.getException();
}
catch( Throwable th ) {
ex = th;
}
// Send an error or an 'OK' message (response code will be 200)
if( ex != null ) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Ping query caused exception: "+ex.getMessage(), ex );
}
rsp.add( "status", "OK" );
}
//////////////////////// SolrInfoMBeans methods //////////////////////
@Override
public String getVersion() {
return "$Revision$";
}
@Override
public String getDescription() {
return "Reports application health to a load-balancer";
}
@Override
public String getSourceId() {
return "$Id$";
}
@Override
public String getSource() {
return "$URL$";
}
}

View File

@ -64,6 +64,7 @@
<load-on-startup>2</load-on-startup>
</servlet>
<!-- @Deprecated -->
<servlet>
<servlet-name>ping</servlet-name>
<jsp-file>/admin/ping.jsp</jsp-file>
@ -79,6 +80,7 @@
<url-pattern>/update/*</url-pattern>
</servlet-mapping>
<!-- @Deprecated -->
<servlet-mapping>
<servlet-name>ping</servlet-name>
<url-pattern>/admin/ping</url-pattern>

View File

@ -29,6 +29,10 @@
<solr>
<ping>
<%
//
// Deprecated -- use PingRequestHandler
//
Object ocore = request.getAttribute("org.apache.solr.SolrCore");
SolrCore core = ocore instanceof SolrCore? (SolrCore) ocore : SolrCore.getSolrCore();