Author: ryan
Date: Fri Nov 9 11:24:18 2007
New Revision: 593627
URL: http://svn.apache.org/viewvc?rev=593627&view=rev
Log:
SOLR-408 adding PingRequestHandler.java and deprecating <pingQuery> syntax
Added:
lucene/solr/trunk/src/java/org/apache/solr/handler/PingRequestHandler.java
(with props)
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/SolrExampleTests.java
lucene/solr/trunk/example/solr/conf/solrconfig.xml
lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java
lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
lucene/solr/trunk/src/webapp/WEB-INF/web.xml
lucene/solr/trunk/src/webapp/resources/admin/ping.jsp
Modified: lucene/solr/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=593627&r1=593626&r2=593627&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Fri Nov 9 11:24:18 2007
@@ -148,6 +148,11 @@
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
Modified:
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java?rev=593627&r1=593626&r2=593627&view=diff
==============================================================================
---
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
(original)
+++
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
Fri Nov 9 11:24:18 2007
@@ -34,18 +34,19 @@
*/
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;
}
Modified:
lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/SolrExampleTests.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/SolrExampleTests.java?rev=593627&r1=593626&r2=593627&view=diff
==============================================================================
---
lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/SolrExampleTests.java
(original)
+++
lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/SolrExampleTests.java
Fri Nov 9 11:24:18 2007
@@ -28,6 +28,7 @@
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 @@
assertNumFound( "*:*", 0 ); // make sure it got out
}
-
public void testLukeHandler() throws Exception
{
SolrServer server = getSolrServer();
@@ -280,5 +280,29 @@
luke.setShowSchema( true );
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
+ }
}
}
Modified: lucene/solr/trunk/example/solr/conf/solrconfig.xml
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/example/solr/conf/solrconfig.xml?rev=593627&r1=593626&r2=593627&view=diff
==============================================================================
--- lucene/solr/trunk/example/solr/conf/solrconfig.xml (original)
+++ lucene/solr/trunk/example/solr/conf/solrconfig.xml Fri Nov 9 11:24:18 2007
@@ -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" ...
- & separated key=val pairs ... but there shouldn't be any
- URL escaping of the values -->
- <pingQuery>
- qt=standard&q=solrpingquery
- </pingQuery>
+
<!-- configure a healthcheck file for servers behind a loadbalancer
<healthcheck type="file">server-enabled</healthcheck>
-->
Modified: lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java?rev=593627&r1=593626&r2=593627&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java Fri Nov 9
11:24:18 2007
@@ -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 @@
// 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 @@
/**
* Returns a Request object based on the admin/pingQuery section
* of the Solr config file.
+ *
+ * @use [EMAIL PROTECTED] PingRequestHandler} instead
*/
+ @Deprecated
public SolrQueryRequest getPingQueryRequest(SolrCore core) {
return new LocalSolrQueryRequest(core, pingQueryParams);
}
Modified: lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java?rev=593627&r1=593626&r2=593627&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java Fri Nov 9
11:24:18 2007
@@ -42,6 +42,7 @@
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 @@
/**
- * @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 @@
/**
* Returns a Request object based on the admin/pingQuery section
* of the Solr config file.
+ *
+ * @use [EMAIL PROTECTED] PingRequestHandler} instead
*/
+ @Deprecated
public SolrQueryRequest getPingQueryRequest() {
return solrConfig.getPingQueryRequest(this);
}
Added:
lucene/solr/trunk/src/java/org/apache/solr/handler/PingRequestHandler.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/PingRequestHandler.java?rev=593627&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/PingRequestHandler.java
(added)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/PingRequestHandler.java
Fri Nov 9 11:24:18 2007
@@ -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$";
+ }
+}
Propchange:
lucene/solr/trunk/src/java/org/apache/solr/handler/PingRequestHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
lucene/solr/trunk/src/java/org/apache/solr/handler/PingRequestHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: lucene/solr/trunk/src/webapp/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/webapp/WEB-INF/web.xml?rev=593627&r1=593626&r2=593627&view=diff
==============================================================================
--- lucene/solr/trunk/src/webapp/WEB-INF/web.xml (original)
+++ lucene/solr/trunk/src/webapp/WEB-INF/web.xml Fri Nov 9 11:24:18 2007
@@ -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>
Modified: lucene/solr/trunk/src/webapp/resources/admin/ping.jsp
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/webapp/resources/admin/ping.jsp?rev=593627&r1=593626&r2=593627&view=diff
==============================================================================
--- lucene/solr/trunk/src/webapp/resources/admin/ping.jsp (original)
+++ lucene/solr/trunk/src/webapp/resources/admin/ping.jsp Fri Nov 9 11:24:18
2007
@@ -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();