From 5ea995906f8491dd5418e18f51c62e9ef168e443 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Wed, 10 Apr 2024 10:42:11 -0400 Subject: [PATCH] SOLR-17213: Make warning optional so we can warn only when solrUrl is user entered (#2377) Prevent spurious warnings to the console for Solr URL's that are NOT entered by the user, but instead are looked up by the CLI from Solr itself. --- solr/CHANGES.txt | 2 ++ .../src/java/org/apache/solr/cli/SolrCLI.java | 27 ++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index a9c5766322e..84b0ee0ab3d 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -88,6 +88,8 @@ Bug Fixes * SOLR-17206: Eliminate the possibility of a -1 status code for SolrCloud update requests that are distributed. (Paul McArthur) +* SOLR-17213: Fix spurious warnings about solr url format in Solr CLI when users aren't providing a deprecated solr url. (Eric Pugh) + Dependency Upgrades --------------------- diff --git a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java index 23b60ff6725..a29c636aca9 100755 --- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java +++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java @@ -527,15 +527,29 @@ public static String uptime(long uptimeMs) { * @return the solrUrl in the format that Solr expects to see internally. */ public static String normalizeSolrUrl(String solrUrl) { + return normalizeSolrUrl(solrUrl, true); + } + + /** + * 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. + * + * @param solrUrl The user supplied url to Solr. + * @param logUrlFormatWarning If a warning message should be logged about the url format + * @return the solrUrl in the format that Solr expects to see internally. + */ + public static String normalizeSolrUrl(String solrUrl, boolean logUrlFormatWarning) { if (solrUrl != null) { if (solrUrl.contains("/solr")) { // String newSolrUrl = solrUrl.substring(0, solrUrl.indexOf("/solr")); - CLIO.out( - "WARNING: URLs provided to this tool needn't include Solr's context-root (e.g. \"/solr\"). Such URLs are deprecated and support for them will be removed in a future release. Correcting from [" - + solrUrl - + "] to [" - + newSolrUrl - + "]."); + if (logUrlFormatWarning) { + CLIO.out( + "WARNING: URLs provided to this tool needn't include Solr's context-root (e.g. \"/solr\"). Such URLs are deprecated and support for them will be removed in a future release. Correcting from [" + + solrUrl + + "] to [" + + newSolrUrl + + "]."); + } solrUrl = newSolrUrl; } if (solrUrl.endsWith("/")) { @@ -572,6 +586,7 @@ public static String resolveSolrUrl(CommandLine cli) throws Exception { String firstLiveNode = liveNodes.iterator().next(); solrUrl = ZkStateReader.from(cloudSolrClient).getBaseUrlForNodeName(firstLiveNode); + solrUrl = normalizeSolrUrl(solrUrl, false); } } }