Class CLIUtils

java.lang.Object
org.apache.solr.cli.CLIUtils

public final class CLIUtils extends Object
Utility class that holds various helper methods for the CLI.
  • Field Details

    • RED

      public static String RED
    • GREEN

      public static String GREEN
    • YELLOW

      public static String YELLOW
  • Method Details

    • getDefaultSolrUrl

      public static String getDefaultSolrUrl()
    • 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, String credentials, boolean barePath)
    • 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 for
      credentials - 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

      public static String normalizeSolrUrl(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. 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

      public static String normalizeSolrUrl(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. 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

      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
    • 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 line
      option - the commons cli Option
      sysprop - the system property to fall back to
      defaultValue - 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

      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 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

      public static org.apache.solr.client.solrj.impl.CloudSolrClient getCloudSolrClient(String zkHost)
    • getCloudSolrClient

      public static org.apache.solr.client.solrj.impl.CloudSolrClient getCloudSolrClient(String zkHost, HttpJettySolrClient.Builder builder)
    • portFromUrl

      public static int portFromUrl(String solrUrl) throws URISyntaxException
      Extracts the port from the provided solrUrl. 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 null
      URISyntaxException - If the given string violates RFC 2396, as augmented by the above deviations
    • safeCheckCollectionExists

      public static boolean safeCheckCollectionExists(String solrUrl, String collection, String credentials)
    • safeCheckCoreExists

      public static boolean safeCheckCoreExists(String solrUrl, String coreName, String credentials)
    • 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.SolrServerException
      IOException
    • getConfigSetsDir

      public static Path getConfigSetsDir(Path solrInstallDir)
    • isWindows

      public static boolean isWindows()