Package org.apache.solr.util
Class SolrCLI
- java.lang.Object
-
- org.apache.solr.util.SolrCLI
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SolrCLI.ApiTool
Used to send an arbitrary HTTP request to a Solr API endpoint.static class
SolrCLI.AssertionFailureException
static class
SolrCLI.AssertTool
Asserts various conditions and exists with error code if fails, else continues with no outputstatic class
SolrCLI.AuthTool
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.ZkCpTool
static class
SolrCLI.ZkLsTool
static class
SolrCLI.ZkMkrootTool
static class
SolrCLI.ZkMvTool
static class
SolrCLI.ZkRmTool
-
Field Summary
Fields Modifier and Type Field 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 Description SolrCLI()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated 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 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(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 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)
Deprecated.Use the method that takes a tool name as the first argument instead.static org.apache.commons.cli.CommandLine
parseCmdLine(String toolName, String[] args, org.apache.commons.cli.Option[] toolOptions)
static <T> T
pathAs(Class<T> clazz, String jsonPath, Map<String,Object> json)
static org.apache.solr.common.util.NamedList<Object>
postJsonToSolr(org.apache.solr.client.solrj.SolrClient solrClient, String updatePath, String jsonBody)
static org.apache.commons.cli.CommandLine
processCommandLineArgs(String toolName, org.apache.commons.cli.Option[] customOptions, String[] args)
Parses the command-line arguments passed by the user.static org.apache.commons.cli.CommandLine
processCommandLineArgs(org.apache.commons.cli.Option[] customOptions, String[] args)
Deprecated.Use the method that takes a tool name as the first argument instead.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)
-
-
-
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
@Deprecated public static org.apache.commons.cli.CommandLine parseCmdLine(String[] args, org.apache.commons.cli.Option[] toolOptions) throws Exception
Deprecated.Use the method that takes a tool name as the first argument instead.- Throws:
Exception
-
parseCmdLine
public static org.apache.commons.cli.CommandLine parseCmdLine(String toolName, 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
@Deprecated public static org.apache.commons.cli.CommandLine processCommandLineArgs(org.apache.commons.cli.Option[] customOptions, String[] args)
Deprecated.Use the method that takes a tool name as the first argument instead.
-
processCommandLineArgs
public static org.apache.commons.cli.CommandLine processCommandLineArgs(String toolName, 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 org.apache.solr.common.util.NamedList<Object> postJsonToSolr(org.apache.solr.client.solrj.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)
-
-