Package org.apache.solr.cli
Class CLIUtils
java.lang.Object
org.apache.solr.cli.CLIUtils
Utility class that holds various helper methods for the CLI.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckCodeForAuthError(int code) static booleanDetermine if a request to Solr failed due to a communication error, which is generally retry-able.static booleanstatic StringgetCliOptionOrPropValue(org.apache.commons.cli.CommandLine cli, org.apache.commons.cli.Option option, String sysprop, String defaultValue) Get the value of the specified CLI option with fallback to system property and default value.static org.apache.solr.client.solrj.impl.CloudSolrClientgetCloudSolrClient(String zkHost) static org.apache.solr.client.solrj.impl.CloudSolrClientgetCloudSolrClient(String zkHost, HttpJettySolrClient.Builder builder) static PathgetConfigSetsDir(Path solrInstallDir) static Stringstatic org.apache.solr.client.solrj.SolrClientgetSolrClient(String solrUrl, String credentials) Helper method for all the places where we assume a /solr on the url.static org.apache.solr.client.solrj.SolrClientgetSolrClient(String solrUrl, String credentials, boolean barePath) static org.apache.solr.client.solrj.SolrClientgetSolrClient(org.apache.commons.cli.CommandLine cli) static org.apache.solr.client.solrj.SolrClientgetSolrClient(org.apache.commons.cli.CommandLine cli, boolean barePath) static org.apache.solr.common.cloud.SolrZkClientgetSolrZkClient(org.apache.commons.cli.CommandLine cli, String zkHost) static StringgetZkHost(org.apache.commons.cli.CommandLine cli) Get the ZooKeeper connection string from either the zk-host command-line option or if not configured, from the 'zkHost' system property aka the 'ZK_HOST' environment variable.static booleanisCloudMode(org.apache.solr.client.solrj.SolrClient solrClient) static booleanstatic StringnormalizeSolrUrl(String solrUrl) Strips off the end of solrUrl any /solr when a legacy solrUrl like http://localhost:8983/solr is used, and warns those users.static StringnormalizeSolrUrl(String solrUrl, boolean logUrlFormatWarning) Strips off the end of solrUrl any /solr 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 intportFromUrl(String solrUrl) Extracts the port from the providedsolrUrl.static booleansafeCheckCollectionExists(String solrUrl, String collection, String credentials) static booleansafeCheckCoreExists(String solrUrl, String coreName, String credentials)
-
Field Details
-
RED
-
GREEN
-
YELLOW
-
-
Method Details
-
getDefaultSolrUrl
-
checkCommunicationError
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
-
getSolrClient
-
getSolrClient
public static org.apache.solr.client.solrj.SolrClient getSolrClient(String solrUrl, String credentials) Helper method for all the places where we assume a /solr on the url.- Parameters:
solrUrl- The solr url that you want the client forcredentials- The username:password for basic auth.- Returns:
- The SolrClient
-
getSolrClient
public static org.apache.solr.client.solrj.SolrClient getSolrClient(org.apache.commons.cli.CommandLine cli, boolean barePath) throws Exception - Throws:
Exception
-
getSolrClient
public static org.apache.solr.client.solrj.SolrClient getSolrClient(org.apache.commons.cli.CommandLine cli) throws Exception - Throws:
Exception
-
normalizeSolrUrl
Strips off the end of solrUrl any /solr when a legacy solrUrl like http://localhost:8983/solr is used, and warns those users. In the future we'll have urls ending with /api as well.- Parameters:
solrUrl- The user supplied url to Solr.- Returns:
- the solrUrl in the format that Solr expects to see internally.
-
normalizeSolrUrl
Strips off the end of solrUrl any /solr 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 format- Returns:
- the solrUrl in the format that Solr expects to see internally.
-
normalizeSolrUrl
Get the base URL of a live Solr instance from either the --solr-url command-line option or from ZooKeeper.- Throws:
Exception
-
getCliOptionOrPropValue
public static String getCliOptionOrPropValue(org.apache.commons.cli.CommandLine cli, org.apache.commons.cli.Option option, String sysprop, String defaultValue) Get the value of the specified CLI option with fallback to system property and default value.- Parameters:
cli- the command lineoption- the commons cliOptionsysprop- the system property to fall back todefaultValue- the default value. Use null if no default value is desired- Returns:
- the value of the option or system property or the default value
-
getZkHost
Get the ZooKeeper connection string from either the zk-host command-line option or if not configured, from the 'zkHost' system property aka the 'ZK_HOST' environment variable. If neither is configured, we attempt 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) throws Exception - Throws:
Exception
-
getCloudSolrClient
-
getCloudSolrClient
public static org.apache.solr.client.solrj.impl.CloudSolrClient getCloudSolrClient(String zkHost, HttpJettySolrClient.Builder builder) -
portFromUrl
Extracts the port from the providedsolrUrl. If a URL is provided with https scheme and not explicitly defines the port, the default port for HTTPS (443) is used.If URL does not contain a port nor https as scheme, it falls back to port 80.
- Parameters:
solrUrl- the URL to extract the port from- Returns:
- The port that was found.
- Throws:
NullPointerException- If solrUrl is nullURISyntaxException- If the given string violates RFC 2396, as augmented by the above deviations
-
safeCheckCollectionExists
-
safeCheckCoreExists
-
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
-
getConfigSetsDir
-
isWindows
public static boolean isWindows()
-