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

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


The following commit(s) were added to refs/heads/branch_10x by this push:
     new 8aef123b567 SOLR-17318 VersionTool now reports remote server version 
(#4275)
8aef123b567 is described below

commit 8aef123b567d1956215ecadfa0addac9a93b27da
Author: Jan Høydahl <[email protected]>
AuthorDate: Fri May 15 21:41:43 2026 +0200

    SOLR-17318 VersionTool now reports remote server version (#4275)
    
    (cherry picked from commit d8f8b3f8dddae5136edbdbb56deea177333ede97)
---
 .../unreleased/SOLR-17318-version-server-info.yml  |  8 +++
 .../core/src/java/org/apache/solr/cli/SolrCLI.java |  2 +-
 .../src/java/org/apache/solr/cli/VersionTool.java  | 27 +++++++++-
 .../test/org/apache/solr/cli/VersionToolTest.java  | 57 ++++++++++++++++++++++
 solr/packaging/test/test_version.bats              |  8 ++-
 5 files changed, 95 insertions(+), 7 deletions(-)

diff --git a/changelog/unreleased/SOLR-17318-version-server-info.yml 
b/changelog/unreleased/SOLR-17318-version-server-info.yml
new file mode 100644
index 00000000000..ac4027a25e2
--- /dev/null
+++ b/changelog/unreleased/SOLR-17318-version-server-info.yml
@@ -0,0 +1,8 @@
+title: VersionTool (bin/solr version) now reports remote server version when 
`--solr-url` is provided
+type: changed
+authors:
+  - name: Jan Høydahl
+    url: https://home.apache.org/phonebook.html?uid=janhoy
+links:
+  - name: SOLR-17318
+    url: https://issues.apache.org/jira/browse/SOLR-17318
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 9f34c32cb37..48bb693e505 100755
--- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
@@ -70,7 +70,7 @@ public class SolrCLI implements CLIO {
     }
 
     if (Arrays.asList("-v", "--version").contains(args[0])) {
-      // select the version tool to be run
+      // select the version tool to be run, printing the CLIENT version
       args = new String[] {"version"};
     }
     if (Arrays.asList("upconfig", "downconfig", "cp", "rm", "mv", "ls", 
"mkroot", "updateacls")
diff --git a/solr/core/src/java/org/apache/solr/cli/VersionTool.java 
b/solr/core/src/java/org/apache/solr/cli/VersionTool.java
index b8ae826ebc6..ca004e380c5 100644
--- a/solr/core/src/java/org/apache/solr/cli/VersionTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/VersionTool.java
@@ -18,8 +18,17 @@
 package org.apache.solr.cli;
 
 import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
 import org.apache.solr.client.api.util.SolrVersion;
+import org.apache.solr.client.solrj.request.SystemInfoRequest;
+import org.apache.solr.client.solrj.response.SystemInfoResponse;
 
+/**
+ * Supports version command in the bin/solr script.
+ *
+ * <p>Prints the client (CLI) version. When {@code --solr-url} is provided, 
also prints the version
+ * of the remote Solr server.
+ */
 public class VersionTool extends ToolBase {
 
   public VersionTool(ToolRuntime runtime) {
@@ -31,8 +40,24 @@ public class VersionTool extends ToolBase {
     return "version";
   }
 
+  @Override
+  public Options getOptions() {
+    return super.getOptions()
+        .addOption(CommonCLIOptions.SOLR_URL_OPTION)
+        .addOption(CommonCLIOptions.CREDENTIALS_OPTION);
+  }
+
   @Override
   public void runImpl(CommandLine cli) throws Exception {
-    CLIO.out("Solr version is: " + SolrVersion.LATEST);
+    echo("Client version: " + SolrVersion.LATEST);
+
+    String solrUrl = cli.getOptionValue(CommonCLIOptions.SOLR_URL_OPTION);
+    if (solrUrl != null) {
+      String credentials = 
cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION);
+      try (var solrClient = CLIUtils.getSolrClient(solrUrl, credentials)) {
+        SystemInfoResponse sysResponse = new 
SystemInfoRequest().process(solrClient);
+        echo("Server version: " + sysResponse.getSolrImplVersion());
+      }
+    }
   }
 }
diff --git a/solr/core/src/test/org/apache/solr/cli/VersionToolTest.java 
b/solr/core/src/test/org/apache/solr/cli/VersionToolTest.java
new file mode 100644
index 00000000000..b8e4ebd4eee
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/cli/VersionToolTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.cli;
+
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.embedded.JettySolrRunner;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class VersionToolTest extends SolrCloudTestCase {
+
+  @BeforeClass
+  public static void setupCluster() throws Exception {
+    configureCluster(1).configure();
+  }
+
+  @Test
+  public void testClientVersionOnly() throws Exception {
+    String[] toolArgs = new String[] {"version"};
+    CLITestHelper.TestingRuntime runtime = new 
CLITestHelper.TestingRuntime(true);
+    VersionTool tool = new VersionTool(runtime);
+    tool.runTool(SolrCLI.processCommandLineArgs(tool, toolArgs));
+
+    String output = runtime.getOutput();
+    assertTrue("Output should contain 'Client version:'", 
output.contains("Client version:"));
+    assertFalse("Output should not contain 'Server version:'", 
output.contains("Server version:"));
+  }
+
+  @Test
+  public void testClientAndServerVersion() throws Exception {
+    JettySolrRunner randomJetty = cluster.getRandomJetty(random());
+    String baseUrl = randomJetty.getBaseUrl().toString();
+
+    String[] toolArgs = new String[] {"version", "--solr-url", baseUrl};
+    CLITestHelper.TestingRuntime runtime = new 
CLITestHelper.TestingRuntime(true);
+    VersionTool tool = new VersionTool(runtime);
+    tool.runTool(SolrCLI.processCommandLineArgs(tool, toolArgs));
+
+    String output = runtime.getOutput();
+    assertTrue("Output should contain 'Client version:'", 
output.contains("Client version:"));
+    assertTrue("Output should contain 'Server version:'", 
output.contains("Server version:"));
+  }
+}
diff --git a/solr/packaging/test/test_version.bats 
b/solr/packaging/test/test_version.bats
index f4d888033e6..0708044a1b6 100644
--- a/solr/packaging/test/test_version.bats
+++ b/solr/packaging/test/test_version.bats
@@ -23,12 +23,10 @@ setup() {
 
 @test "--version returns Solr version" {
   run solr --version
-  assert_output --partial "Solr version is:"    
+  assert_output --partial "Client version:"
 }
 
-@test "version as direct tool call still runs" {  
-  #run ! solr version
-  #assert_output --partial "version is not a valid command!  Did you mean 
--version?"  
+@test "version as direct tool call still runs" {
   run solr version
-  assert_output --partial "Solr version is:"
+  assert_output --partial "Client version:"
 }

Reply via email to