Class SolrCLI


  • public class SolrCLI
    extends Object
    Command-line utility for working with Solr.
    • Constructor Detail

      • SolrCLI

        public SolrCLI()
    • Method Detail

      • 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.
      • 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)
      • 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.
      • 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. To find a path to a child that starts with a slash (e.g. queryHandler named /query) you must escape the slash. For instance /config/requestHandler/\/query/defaults/echoParams would get the echoParams value for the "/query" request handler.
      • 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)