Package org.apache.solr.cli
Class SolrCLI
- java.lang.Object
-
- org.apache.solr.cli.SolrCLI
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSolrCLI.AssertionFailureException
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_CONFIG_SETstatic StringGREENstatic org.apache.commons.cli.OptionOPTION_CREDENTIALSstatic org.apache.commons.cli.OptionOPTION_CREDENTIALS_DEPRECATEDstatic org.apache.commons.cli.OptionOPTION_HELPstatic org.apache.commons.cli.OptionOPTION_RECURSE_DEPRECATEDstatic org.apache.commons.cli.OptionOPTION_RECURSIVEstatic org.apache.commons.cli.OptionOPTION_SOLRURLstatic org.apache.commons.cli.OptionOPTION_SOLRURL_DEPRECATEDstatic org.apache.commons.cli.OptionOPTION_SOLRURL_DEPRECATED_SHORTstatic org.apache.commons.cli.OptionOPTION_VERBOSEstatic org.apache.commons.cli.OptionOPTION_VERBOSE_DEPRECATEDstatic org.apache.commons.cli.OptionOPTION_ZKHOSTstatic org.apache.commons.cli.OptionOPTION_ZKHOST_DEPRECATEDstatic StringREDstatic StringYELLOWstatic StringZK_HOST
-
Constructor Summary
Constructors Constructor Description SolrCLI()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckCodeForAuthError(int code)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 voiddeprecatedHandlerStdErr(org.apache.commons.cli.Option o)static booleanexceptionIsAuthRelated(Exception exc)static ToolfindTool(String[] args, ToolRuntime runtime)static org.apache.solr.client.solrj.impl.CloudHttp2SolrClientgetCloudHttp2SolrClient(String zkHost)static org.apache.solr.client.solrj.impl.CloudHttp2SolrClientgetCloudHttp2SolrClient(String zkHost, org.apache.solr.client.solrj.impl.Http2SolrClient.Builder builder)static PathgetConfigSetsDir(Path solrInstallDir)static StringgetDefaultSolrUrl()static org.apache.commons.cli.HelpFormattergetFormatter()static StringgetOptionWithDeprecatedAndDefault(org.apache.commons.cli.CommandLine cli, String opt, String deprecated, String def)Returns the value of the option with the given name, or the value of the deprecated option.static org.apache.solr.client.solrj.SolrClientgetSolrClient(String solrUrl)Get a SolrClient for the given URL.static org.apache.solr.client.solrj.SolrClientgetSolrClient(org.apache.commons.cli.CommandLine cli)static org.apache.solr.common.cloud.SolrZkClientgetSolrZkClient(org.apache.commons.cli.CommandLine cli, String zkHost)static org.apache.commons.cli.OptionsgetToolOptions(Tool tool)Returns tool options for given tool, for usage display purposes.static StringgetZkHost(org.apache.commons.cli.CommandLine cli)Get the ZooKeeper connection string from either the zk-host command-line option or by looking it up from a running Solr instance based on the solr-url option.static booleanisCloudMode(org.apache.solr.client.solrj.SolrClient solrClient)static voidmain(String[] args)Runs a tool.static StringnormalizeSolrUrl(String solrUrl, boolean logUrlFormatWarning)static StringnormalizeSolrUrl(String solrUrl, boolean logUrlFormatWarning, String hostContext)Strips off the end of solrUrl any hostContext when a legacy solrUrl like http://localhost:8983/solr is used, and optionally logs a warning.static StringnormalizeSolrUrl(org.apache.commons.cli.CommandLine cli)Get the base URL of a live Solr instance from either the --solr-url command-line option or from ZooKeeper.static org.apache.commons.cli.CommandLineparseCmdLine(Tool tool, String[] args)static org.apache.solr.common.util.NamedList<Object>postJsonToSolr(org.apache.solr.client.solrj.SolrClient solrClient, String updatePath, String jsonBody)static voidprint(Object message)static voidprint(String color, Object message)static voidprintGreen(Object message)Console print using green colorstatic voidprintRed(Object message)Console print using red colorstatic org.apache.commons.cli.CommandLineprocessCommandLineArgs(Tool tool, String[] args)Parses the command-line arguments passed by the user.static voidraiseLogLevelUnlessVerbose(org.apache.commons.cli.CommandLine cli)static booleansafeCheckCollectionExists(String solrUrl, String collection)static booleansafeCheckCoreExists(String solrUrl, String coreName)static Stringuptime(long uptimeMs)
-
-
-
Field Detail
-
RED
public static String RED
-
GREEN
public static String GREEN
-
YELLOW
public static String YELLOW
-
ZK_HOST
public static final String ZK_HOST
- See Also:
- Constant Field Values
-
OPTION_ZKHOST_DEPRECATED
public static final org.apache.commons.cli.Option OPTION_ZKHOST_DEPRECATED
-
OPTION_ZKHOST
public static final org.apache.commons.cli.Option OPTION_ZKHOST
-
OPTION_SOLRURL_DEPRECATED
public static final org.apache.commons.cli.Option OPTION_SOLRURL_DEPRECATED
-
OPTION_SOLRURL
public static final org.apache.commons.cli.Option OPTION_SOLRURL
-
OPTION_SOLRURL_DEPRECATED_SHORT
public static final org.apache.commons.cli.Option OPTION_SOLRURL_DEPRECATED_SHORT
-
OPTION_VERBOSE
public static final org.apache.commons.cli.Option OPTION_VERBOSE
-
OPTION_VERBOSE_DEPRECATED
public static final org.apache.commons.cli.Option OPTION_VERBOSE_DEPRECATED
-
OPTION_HELP
public static final org.apache.commons.cli.Option OPTION_HELP
-
OPTION_RECURSE_DEPRECATED
public static final org.apache.commons.cli.Option OPTION_RECURSE_DEPRECATED
-
OPTION_RECURSIVE
public static final org.apache.commons.cli.Option OPTION_RECURSIVE
-
OPTION_CREDENTIALS
public static final org.apache.commons.cli.Option OPTION_CREDENTIALS
-
OPTION_CREDENTIALS_DEPRECATED
public static final org.apache.commons.cli.Option OPTION_CREDENTIALS_DEPRECATED
-
DEFAULT_CONFIG_SET
public static final String DEFAULT_CONFIG_SET
- See Also:
- Constant Field Values
-
-
Method Detail
-
findTool
public static Tool findTool(String[] args, ToolRuntime runtime) throws Exception
- Throws:
Exception
-
parseCmdLine
public static org.apache.commons.cli.CommandLine parseCmdLine(Tool tool, String[] args)
-
getDefaultSolrUrl
public static String getDefaultSolrUrl()
-
raiseLogLevelUnlessVerbose
public static void raiseLogLevelUnlessVerbose(org.apache.commons.cli.CommandLine cli)
-
getToolOptions
public static org.apache.commons.cli.Options getToolOptions(Tool tool)
Returns tool options for given tool, for usage display purposes. Hides deprecated options.
-
getOptionWithDeprecatedAndDefault
public static String getOptionWithDeprecatedAndDefault(org.apache.commons.cli.CommandLine cli, String opt, String deprecated, String def)
Returns the value of the option with the given name, or the value of the deprecated option. If both values are null, then it returns the default value.
-
deprecatedHandlerStdErr
public static void deprecatedHandlerStdErr(org.apache.commons.cli.Option o)
-
processCommandLineArgs
public static org.apache.commons.cli.CommandLine processCommandLineArgs(Tool tool, String[] args)
Parses the command-line arguments passed by the user.
-
getFormatter
public static org.apache.commons.cli.HelpFormatter getFormatter()
-
checkCommunicationError
public static boolean checkCommunicationError(Exception exc)
Determine if a request to Solr failed due to a communication error, which is generally retry-able.
-
checkCodeForAuthError
public static void checkCodeForAuthError(int code)
-
exceptionIsAuthRelated
public static boolean exceptionIsAuthRelated(Exception exc)
-
getSolrClient
public static org.apache.solr.client.solrj.SolrClient getSolrClient(String solrUrl)
Get a SolrClient for the given URL. The URL can be with or without /solr suffix, the method will normalize it and add '/solr'. To support certain unit tests, the hostContext can be overridden via the system property 'hostContext'.Note that from Solr 10.0 Solr will use / as base URL to support /api and other contexts, so handling of hostContext differs between Solr 9.x and 10.x.
Note that this should not be used with individual core specific urls such as "http://127.0.0.1:51428/solr/bob_shard1_replica_n1/" as it removes the core name by converting the url to "http://127.0.0.1:51428/" before creating the client.
- Parameters:
solrUrl- the base URL of Solr- Returns:
- a SolrClient initialized with correct hostContext, default '/solr'
-
getSolrClient
public static org.apache.solr.client.solrj.SolrClient getSolrClient(org.apache.commons.cli.CommandLine cli) throws Exception- Throws:
Exception
-
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
-
uptime
public static String uptime(long uptimeMs)
-
normalizeSolrUrl
public static String normalizeSolrUrl(String solrUrl, boolean logUrlFormatWarning)
-
normalizeSolrUrl
public static String normalizeSolrUrl(String solrUrl, boolean logUrlFormatWarning, String hostContext)
Strips off the end of solrUrl any hostContext when a legacy solrUrl like http://localhost:8983/solr is used, and optionally logs a warning. In the future we'll have urls ending with /api as well.- Parameters:
solrUrl- The user supplied url to Solr.logUrlFormatWarning- If a warning message should be logged about the url formathostContext- context path for Solr, is normally '/solr' but can be overridden here. Should not end with '/'- Returns:
- the solrUrl in the format that Solr expects to see internally.
-
normalizeSolrUrl
public static String normalizeSolrUrl(org.apache.commons.cli.CommandLine cli) throws Exception
Get the base URL of a live Solr instance from either the --solr-url command-line option or 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 zk-host command-line option or by looking it up from a running Solr instance based on the solr-url option.- Throws:
Exception
-
getSolrZkClient
public static org.apache.solr.common.cloud.SolrZkClient getSolrZkClient(org.apache.commons.cli.CommandLine cli, String zkHost)
-
getCloudHttp2SolrClient
public static org.apache.solr.client.solrj.impl.CloudHttp2SolrClient getCloudHttp2SolrClient(String zkHost)
-
getCloudHttp2SolrClient
public static org.apache.solr.client.solrj.impl.CloudHttp2SolrClient getCloudHttp2SolrClient(String zkHost, org.apache.solr.client.solrj.impl.Http2SolrClient.Builder builder)
-
safeCheckCollectionExists
public static boolean safeCheckCollectionExists(String solrUrl, String collection)
-
isCloudMode
public static boolean isCloudMode(org.apache.solr.client.solrj.SolrClient solrClient) throws org.apache.solr.client.solrj.SolrServerException, IOException- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
print
public static void print(Object message)
-
printGreen
public static void printGreen(Object message)
Console print using green color
-
printRed
public static void printRed(Object message)
Console print using red color
-
-