This is an automated email from the ASF dual-hosted git repository.

epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new ee1255558e0 SOLR-17213: Make warning optional so we can warn only when 
solrUrl is user entered (#2377)
ee1255558e0 is described below

commit ee1255558e0afb65e1df965aa11cd88b22bbfbe7
Author: Eric Pugh <[email protected]>
AuthorDate: Wed Apr 10 10:42:11 2024 -0400

    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 ++
 .../core/src/java/org/apache/solr/cli/SolrCLI.java | 27 +++++++++++++++++-----
 .../src/test/org/apache/solr/cli/SolrCLITest.java  |  2 ++
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 94c269e3ffb..e485de5fc08 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -172,6 +172,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 23713833e9b..c81326e7702 100755
--- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
@@ -505,15 +505,29 @@ public class SolrCLI implements CLIO {
    * @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("/")) {
@@ -551,6 +565,7 @@ public class SolrCLI implements CLIO {
 
           String firstLiveNode = liveNodes.iterator().next();
           solrUrl = 
ZkStateReader.from(cloudSolrClient).getBaseUrlForNodeName(firstLiveNode);
+          solrUrl = normalizeSolrUrl(solrUrl, false);
         }
       }
     }
diff --git a/solr/core/src/test/org/apache/solr/cli/SolrCLITest.java 
b/solr/core/src/test/org/apache/solr/cli/SolrCLITest.java
index 091fb4daa3a..db9138e3311 100644
--- a/solr/core/src/test/org/apache/solr/cli/SolrCLITest.java
+++ b/solr/core/src/test/org/apache/solr/cli/SolrCLITest.java
@@ -26,6 +26,8 @@ public class SolrCLITest extends SolrTestCase {
     assertEquals(SolrCLI.normalizeSolrUrl("http://localhost:8983/solr/";), 
"http://localhost:8983";);
     assertEquals(SolrCLI.normalizeSolrUrl("http://localhost:8983/";), 
"http://localhost:8983";);
     assertEquals(SolrCLI.normalizeSolrUrl("http://localhost:8983";), 
"http://localhost:8983";);
+    assertEquals(
+        SolrCLI.normalizeSolrUrl("http://localhost:8983/solr/";, false), 
"http://localhost:8983";);
   }
 
   @Test

Reply via email to