org.apache.solr.handler

## Class PingRequestHandler

- java.lang.Object
- - org.apache.solr.handler.RequestHandlerBase
  - - org.apache.solr.handler.PingRequestHandler

- All Implemented Interfaces:
    SolrInfoMBean, NestedRequestHandler, SolrRequestHandler, SolrCoreAware

      public class PingRequestHandler
      extends RequestHandlerBase
      implements SolrCoreAware

  Ping Request Handler for reporting SolrCore health to a Load Balancer.

  This handler is designed to be used as the endpoint for an HTTP Load-Balancer to use when checking the "health" or "up status" of a Solr server.

  In its simplest form, the PingRequestHandler should be configured with some defaults indicating a request that should be executed. If the request succeeds, then the PingRequestHandler will respond back with a simple "OK" status. If the request fails, then the PingRequestHandler will respond back with the corresponding HTTP Error code. Clients (such as load balancers) can be configured to poll the PingRequestHandler monitoring for these types of responses (or for a simple connection failure) to know if there is a problem with the Solr server. Note in case isShard=true, PingRequestHandler respond back with what the delegated handler returns (by default it's /select handler).

       <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
         <lst name="invariants">
           <str name="qt">/search</str><!-- handler to delegate to -->
           <str name="q">some test query</str>
         </lst>
       </requestHandler>

  A more advanced option available, is to configure the handler with a "healthcheckFile" which can be used to enable/disable the PingRequestHandler.

       <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
         <!-- relative paths are resolved against the data dir -->
         <str name="healthcheckFile">server-enabled.txt</str>
         <lst name="invariants">
           <str name="qt">/search</str><!-- handler to delegate to -->
           <str name="q">some test query</str>
         </lst>
       </requestHandler>

  - If the health check file exists, the handler will execute the delegated query and return status as described above.
  - If the health check file does not exist, the handler will return an HTTP error even if the server is working fine and the delegated query would have succeeded

  This health check file feature can be used as a way to indicate to some Load Balancers that the server should be "removed from rotation" for maintenance, or upgrades, or whatever reason you may wish.

  The health check file may be created/deleted by any external system, or the PingRequestHandler itself can be used to create/delete the file by specifying an "action" param in a request:

  - `http://.../ping?action=enable` - creates the health check file if it does not already exist
  - `http://.../ping?action=disable` - deletes the health check file if it exists
  - `http://.../ping?action=status` - returns a status code indicating if the healthcheck file exists ("`enabled`") or not ("`disabled`")
  Since:
    solr 1.3

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `PingRequestHandler.ACTIONS`

    - ### Nested classes/interfaces inherited from interface org.apache.solr.core.SolrInfoMBean

      `SolrInfoMBean.Category`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `HEALTHCHECK_FILE_PARAM`

    - ### Fields inherited from class org.apache.solr.handler.RequestHandlerBase

      `appends, defaults, httpCaching, initArgs, invariants`

    - ### Fields inherited from interface org.apache.solr.request.SolrRequestHandler

      `TYPE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PingRequestHandler()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getDescription()` Simple one or two line description
    `protected void` | `handleEnable(boolean enable)`
    `protected void` | `handlePing(SolrQueryRequest req, SolrQueryResponse rsp)`
    `void` | `handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)`
    `void` | `inform(SolrCore core)`
    `void` | `init(NamedList args)` Initializes the `SolrRequestHandler` by creating three `SolrParams` named.
    `boolean` | `isPingDisabled()` Returns true if the healthcheck flag-file is enabled but does not exist, otherwise (no file configured, or file configured and exists) returns false.

    - ### Methods inherited from class org.apache.solr.handler.RequestHandlerBase

      `getCategory, getDocs, getInitArgs, getName, getPluginInfo, getRequestHandler, getSolrParamsFromNamedList, getSource, getStatistics, getSubHandler, getVersion, handleRequest, setPluginInfo`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### HEALTHCHECK_FILE_PARAM

          public static final String HEALTHCHECK_FILE_PARAM

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### PingRequestHandler

          public PingRequestHandler()

  - ### Method Detail

    - #### init

          public void init(NamedList args)

      Description copied from class: `RequestHandlerBase`
      Initializes the `SolrRequestHandler` by creating three `SolrParams` named.

      Name | Description
      --- | ---
      defaults | Contains all of the named arguments contained within the list element named "defaults".
      appends | Contains all of the named arguments contained within the list element named "appends".
      invariants | Contains all of the named arguments contained within the list element named "invariants".

      Example:

           <lst name="defaults">
           <str name="echoParams">explicit</str>
           <str name="qf">text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0</str>
           <str name="mm">2<-1 5<-2 6<90%</str>
           <str name="bq">incubationdate_dt:[* TO NOW/DAY-1MONTH]^2.2</str>
           </lst>
           <lst name="appends">
           <str name="fq">inStock:true</str>
           </lst>

           <lst name="invariants">
           <str name="facet.field">cat</str>
           <str name="facet.field">manu_exact</str>
           <str name="facet.query">price:[* TO 500]</str>
           <str name="facet.query">price:[500 TO *]</str>
           </lst>

      Specified by:
        `init` in interface `SolrRequestHandler`
      Overrides:
        `init` in class `RequestHandlerBase`
      Parameters:
        `args` - The `NamedList` to initialize from
      See Also:
        `RequestHandlerBase.handleRequest(org.apache.solr.request.SolrQueryRequest, org.apache.solr.response.SolrQueryResponse)`, `RequestHandlerBase.handleRequestBody(org.apache.solr.request.SolrQueryRequest, org.apache.solr.response.SolrQueryResponse)`, `SolrPluginUtils.setDefaults(org.apache.solr.request.SolrQueryRequest, org.apache.solr.common.params.SolrParams, org.apache.solr.common.params.SolrParams, org.apache.solr.common.params.SolrParams)`, `See also the example solrconfig.xml located in the Solr codebase (example/solr/conf).`

    - #### inform

          public void inform(SolrCore core)

      Specified by:
        `inform` in interface `SolrCoreAware`

    - #### isPingDisabled

          public boolean isPingDisabled()

      Returns true if the healthcheck flag-file is enabled but does not exist, otherwise (no file configured, or file configured and exists) returns false.

    - #### handleRequestBody

          public void handleRequestBody(SolrQueryRequest req,
                                        SolrQueryResponse rsp)
                                 throws Exception

      Specified by:
        `handleRequestBody` in class `RequestHandlerBase`
      Throws:
        `Exception`

    - #### handlePing

          protected void handlePing(SolrQueryRequest req,
                                    SolrQueryResponse rsp)
                             throws Exception

      Throws:
        `Exception`

    - #### handleEnable

          protected void handleEnable(boolean enable)
                               throws SolrException

      Throws:
        `SolrException`

    - #### getDescription

          public String getDescription()

      Description copied from interface: `SolrInfoMBean`
      Simple one or two line description
      Specified by:
        `getDescription` in interface `SolrInfoMBean`
      Specified by:
        `getDescription` in class `RequestHandlerBase`

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.