org.apache.solr.util

## Class SolrCLI

- java.lang.Object
- - org.apache.solr.util.SolrCLI

-     public class SolrCLI
      extends Object

  Command-line utility for working with Solr.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `SolrCLI.ApiTool` Used to send an arbitrary HTTP request to a Solr API endpoint.
    `static class` | `SolrCLI.AssertTool` Asserts various conditions and exists with error code if fails, else continues with no output
    `static class` | `SolrCLI.ConfigSetDownloadTool`
    `static class` | `SolrCLI.ConfigSetUploadTool`
    `static class` | `SolrCLI.ConfigTool` Sends a POST to the Config API to perform a specified action.
    `static class` | `SolrCLI.CreateCollectionTool` Supports create_collection command in the bin/solr script.
    `static class` | `SolrCLI.CreateCoreTool`
    `static class` | `SolrCLI.CreateTool`
    `static class` | `SolrCLI.DeleteTool`
    `static class` | `SolrCLI.HealthcheckTool` Requests health information about a specific collection in SolrCloud.
    `static class` | `SolrCLI.RunExampleTool` Supports an interactive session with the user to launch (or relaunch the -e cloud example)
    `static class` | `SolrCLI.SolrCloudTool` Helps build SolrCloud aware tools by initializing a CloudSolrClient instance before running the tool.
    `static class` | `SolrCLI.StatusTool` Get the status of a Solr server.
    `static interface` | `SolrCLI.Tool` Defines the interface to a Solr tool that can be run from this command-line app.
    `static class` | `SolrCLI.ToolBase`
    `static class` | `SolrCLI.UtilsTool`
    `static class` | `SolrCLI.ZkCpTool`
    `static class` | `SolrCLI.ZkLsTool`
    `static class` | `SolrCLI.ZkMvTool`
    `static class` | `SolrCLI.ZkRmTool`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static org.apache.commons.cli.Option[]` | `cloudOptions`
    `static String` | `DEFAULT_SOLR_URL`
    `static String` | `JSON_CONTENT_TYPE`
    `static String` | `ZK_HOST`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SolrCLI()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static List<String>` | `asList(String jsonPath, Map<String,Object> json)` Helper function for reading a List of Strings from a JSON Object tree.
    `static Long` | `asLong(String jsonPath, Map<String,Object> json)` Helper function for reading a Long value from a JSON Object tree.
    `static Map<String,Object>` | `asMap(String jsonPath, Map<String,Object> json)` Helper function for reading a Map from a JSON Object tree.
    `static String` | `asString(String jsonPath, Map<String,Object> json)` Helper function for reading a String value from a JSON Object tree.
    `static Object` | `atPath(String jsonPath, Map<String,Object> json)` Helper function for reading an Object of unknown type from a JSON Object tree.
    `static boolean` | `checkCommunicationError(Exception exc)` Determine if a request to Solr failed due to a communication error, which is generally retry-able.
    `protected static void` | `checkSslStoreSysProp(String solrInstallDir, String key)`
    `static void` | `closeHttpClient(org.apache.http.impl.client.CloseableHttpClient httpClient)`
    `static SolrCLI.Tool` | `findTool(String[] args)`
    `static org.apache.commons.cli.Option[]` | `getCommonToolOptions()` Support options common to all tools.
    `static org.apache.http.impl.client.CloseableHttpClient` | `getHttpClient()`
    `static Map<String,Object>` | `getJson(org.apache.http.client.HttpClient httpClient, String getUrl)` Utility function for sending HTTP GET request to Solr and then doing some validation of the response.
    `static Map<String,Object>` | `getJson(org.apache.http.client.HttpClient httpClient, String getUrl, int attempts, boolean isFirstAttempt)` Utility function for sending HTTP GET request to Solr with built-in retry support.
    `static Map<String,Object>` | `getJson(String getUrl)` Useful when a tool just needs to send one request to Solr.
    `static String` | `getZkHost(org.apache.commons.cli.CommandLine cli)` Get the ZooKeeper connection string from either the zkHost command-line option or by looking it up from a running Solr instance based on the solrUrl option.
    `static org.apache.commons.cli.Option[]` | `joinCommonAndToolOptions(org.apache.commons.cli.Option[] toolOpts)`
    `static org.apache.commons.cli.Option[]` | `joinOptions(org.apache.commons.cli.Option[] lhs, org.apache.commons.cli.Option[] rhs)`
    `static void` | `main(String[] args)` Runs a tool.
    `static org.apache.commons.cli.CommandLine` | `parseCmdLine(String[] args, org.apache.commons.cli.Option[] toolOptions)`
    `static <T> T` | `pathAs(Class<T> clazz, String jsonPath, Map<String,Object> json)`
    `static NamedList<Object>` | `postJsonToSolr(SolrClient solrClient, String updatePath, String jsonBody)`
    `static org.apache.commons.cli.CommandLine` | `processCommandLineArgs(org.apache.commons.cli.Option[] customOptions, String[] args)` Parses the command-line arguments passed by the user.
    `static String` | `resolveSolrUrl(org.apache.commons.cli.CommandLine cli)` Get the base URL of a live Solr instance from either the solrUrl command-line option from ZooKeeper.
    `static boolean` | `safeCheckCollectionExists(String url, String collection)`
    `static boolean` | `safeCheckCoreExists(String coreStatusUrl, String coreName)`
    `protected static void` | `setBasicAuth()` Inspects system property basicauth and enables authentication for HttpClient

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

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

- - ### Field Detail

    - #### DEFAULT_SOLR_URL

          public static final String DEFAULT_SOLR_URL

      See Also:
        Constant Field Values

    - #### ZK_HOST

          public static final String ZK_HOST

      See Also:
        Constant Field Values

    - #### cloudOptions

          public static org.apache.commons.cli.Option[] cloudOptions

    - #### JSON_CONTENT_TYPE

          public static final String JSON_CONTENT_TYPE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SolrCLI

          public SolrCLI()

  - ### Method Detail

    - #### main

          public static void main(String[] args)
                           throws Exception

      Runs a tool.
      Throws:
        `Exception`

    - #### findTool

          public static SolrCLI.Tool findTool(String[] args)
                                       throws Exception

      Throws:
        `Exception`

    - #### parseCmdLine

          public static org.apache.commons.cli.CommandLine parseCmdLine(String[] args,
                                                                        org.apache.commons.cli.Option[] toolOptions)
                                                                 throws Exception

      Throws:
        `Exception`

    - #### checkSslStoreSysProp

          protected static void checkSslStoreSysProp(String solrInstallDir,
                                                     String key)

    - #### getCommonToolOptions

          public static org.apache.commons.cli.Option[] getCommonToolOptions()

      Support options common to all tools.

    - #### joinCommonAndToolOptions

          public static org.apache.commons.cli.Option[] joinCommonAndToolOptions(org.apache.commons.cli.Option[] toolOpts)

    - #### joinOptions

          public static org.apache.commons.cli.Option[] joinOptions(org.apache.commons.cli.Option[] lhs,
                                                                    org.apache.commons.cli.Option[] rhs)

    - #### processCommandLineArgs

          public static org.apache.commons.cli.CommandLine processCommandLineArgs(org.apache.commons.cli.Option[] customOptions,
                                                                                  String[] args)

      Parses the command-line arguments passed by the user.

    - #### setBasicAuth

          protected static void setBasicAuth()
                                      throws Exception

      Inspects system property basicauth and enables authentication for HttpClient
      Throws:
        `Exception` - if the basicauth SysProp has wrong format

    - #### checkCommunicationError

          public static boolean checkCommunicationError(Exception exc)

      Determine if a request to Solr failed due to a communication error, which is generally retry-able.

    - #### getHttpClient

          public static org.apache.http.impl.client.CloseableHttpClient getHttpClient()

    - #### closeHttpClient

          public static void closeHttpClient(org.apache.http.impl.client.CloseableHttpClient httpClient)

    - #### postJsonToSolr

          public static NamedList<Object> postJsonToSolr(SolrClient solrClient,
                                                         String updatePath,
                                                         String jsonBody)
                                                  throws Exception

      Throws:
        `Exception`

    - #### getJson

          public static Map<String,Object> getJson(String getUrl)
                                            throws Exception

      Useful when a tool just needs to send one request to Solr.
      Throws:
        `Exception`

    - #### getJson

          public static Map<String,Object> getJson(org.apache.http.client.HttpClient httpClient,
                                                   String getUrl,
                                                   int attempts,
                                                   boolean isFirstAttempt)
                                            throws Exception

      Utility function for sending HTTP GET request to Solr with built-in retry support.
      Throws:
        `Exception`

    - #### getJson

          public static Map<String,Object> getJson(org.apache.http.client.HttpClient httpClient,
                                                   String getUrl)
                                            throws Exception

      Utility function for sending HTTP GET request to Solr and then doing some validation of the response.
      Throws:
        `Exception`

    - #### asString

          public static String asString(String jsonPath,
                                        Map<String,Object> json)

      Helper function for reading a String value from a JSON Object tree.

    - #### asLong

          public static Long asLong(String jsonPath,
                                    Map<String,Object> json)

      Helper function for reading a Long value from a JSON Object tree.

    - #### asList

          public static List<String> asList(String jsonPath,
                                            Map<String,Object> json)

      Helper function for reading a List of Strings from a JSON Object tree.

    - #### asMap

          public static Map<String,Object> asMap(String jsonPath,
                                                 Map<String,Object> json)

      Helper function for reading a Map from a JSON Object tree.

    - #### pathAs

          public static <T> T pathAs(Class<T> clazz,
                                     String jsonPath,
                                     Map<String,Object> json)

    - #### atPath

          public static Object atPath(String jsonPath,
                                      Map<String,Object> json)

      Helper function for reading an Object of unknown type from a JSON Object tree.

    - #### resolveSolrUrl

          public static String resolveSolrUrl(org.apache.commons.cli.CommandLine cli)
                                       throws Exception

      Get the base URL of a live Solr instance from either the solrUrl command-line option from ZooKeeper.
      Throws:
        `Exception`

    - #### getZkHost

          public static String getZkHost(org.apache.commons.cli.CommandLine cli)
                                  throws Exception

      Get the ZooKeeper connection string from either the zkHost command-line option or by looking it up from a running Solr instance based on the solrUrl option.
      Throws:
        `Exception`

    - #### safeCheckCollectionExists

          public static boolean safeCheckCollectionExists(String url,
                                                          String collection)

    - #### safeCheckCoreExists

          public static boolean safeCheckCoreExists(String coreStatusUrl,
                                                    String coreName)

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