Package 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 Description static classSolrCLI.ApiToolUsed to send an arbitrary HTTP request to a Solr API endpoint.static classSolrCLI.AssertionFailureExceptionstatic classSolrCLI.AssertToolAsserts various conditions and exists with error code if fails, else continues with no outputstatic classSolrCLI.AuthToolstatic classSolrCLI.AutoscalingToolstatic classSolrCLI.ConfigSetDownloadToolstatic classSolrCLI.ConfigSetUploadToolstatic classSolrCLI.ConfigToolSends a POST to the Config API to perform a specified action.static classSolrCLI.CreateCollectionToolSupports create_collection command in the bin/solr script.static classSolrCLI.CreateCoreToolstatic classSolrCLI.CreateToolstatic classSolrCLI.DeleteToolstatic classSolrCLI.HealthcheckToolRequests health information about a specific collection in SolrCloud.static classSolrCLI.RunExampleToolSupports an interactive session with the user to launch (or relaunch the -e cloud example)static classSolrCLI.SolrCloudToolHelps build SolrCloud aware tools by initializing a CloudSolrClient instance before running the tool.static classSolrCLI.StatusToolGet the status of a Solr server.static interfaceSolrCLI.ToolDefines the interface to a Solr tool that can be run from this command-line app.static classSolrCLI.ToolBasestatic classSolrCLI.UtilsToolstatic classSolrCLI.ZkCpToolstatic classSolrCLI.ZkLsToolstatic classSolrCLI.ZkMkrootToolstatic classSolrCLI.ZkMvToolstatic classSolrCLI.ZkRmTool
-
Field Summary
Fields Modifier and Type Field Description static org.apache.commons.cli.Option[]cloudOptionsstatic StringDEFAULT_SOLR_URLstatic StringJSON_CONTENT_TYPEstatic StringZK_HOST
-
Constructor Summary
Constructors Constructor Description SolrCLI()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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 LongasLong(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 StringasString(String jsonPath, Map<String,Object> json)Helper function for reading a String value from a JSON Object tree.static ObjectatPath(String jsonPath, Map<String,Object> json)Helper function for reading an Object of unknown type from a JSON Object tree.static booleancheckCommunicationError(Exception exc)Determine if a request to Solr failed due to a communication error, which is generally retry-able.protected static voidcheckSslStoreSysProp(String solrInstallDir, String key)static voidcloseHttpClient(org.apache.http.impl.client.CloseableHttpClient httpClient)static SolrCLI.ToolfindTool(String[] args)static org.apache.commons.cli.Option[]getCommonToolOptions()Support options common to all tools.static org.apache.http.impl.client.CloseableHttpClientgetHttpClient()static Map<String,Object>getJson(String getUrl)Useful when a tool just needs to send one request to Solr.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 StringgetZkHost(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 voidmain(String[] args)Runs a tool.static org.apache.commons.cli.CommandLineparseCmdLine(String[] args, org.apache.commons.cli.Option[] toolOptions)static <T> TpathAs(Class<T> clazz, String jsonPath, Map<String,Object> json)static NamedList<Object>postJsonToSolr(SolrClient solrClient, String updatePath, String jsonBody)static org.apache.commons.cli.CommandLineprocessCommandLineArgs(org.apache.commons.cli.Option[] customOptions, String[] args)Parses the command-line arguments passed by the user.static StringresolveSolrUrl(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 booleansafeCheckCollectionExists(String url, String collection)static booleansafeCheckCoreExists(String coreStatusUrl, String coreName)
-
-
-
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
-
-
Method Detail
-
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
-
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)
-
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.
-
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)
-
-