From a0eaf6f7fc9e69f9315a1ccea4a9d602c40a36db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Thu, 9 Apr 2026 12:22:59 +0200 Subject: [PATCH 1/2] SOLR-17318 VersionTool (bin/solr version) now reports remote server version when `--solr-url` is provided --- .../SOLR-17318-version-server-info.yml | 8 +++ .../java/org/apache/solr/cli/VersionTool.java | 27 ++++++++- .../org/apache/solr/cli/VersionToolTest.java | 57 +++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/SOLR-17318-version-server-info.yml create mode 100644 solr/core/src/test/org/apache/solr/cli/VersionToolTest.java 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 000000000000..ac4027a25e23 --- /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/VersionTool.java b/solr/core/src/java/org/apache/solr/cli/VersionTool.java index b8ae826ebc6a..ca004e380c57 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. + * + *

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 String getName() { 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 000000000000..b8e4ebd4eee1 --- /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:")); + } +} From 4d3d8652035d15bb8199d9650f8448cc3b5e4077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Sat, 11 Apr 2026 23:29:15 +0200 Subject: [PATCH 2/2] Fix bats test to expect "Client version:" instead of "Solr version is:" --- solr/core/src/java/org/apache/solr/cli/SolrCLI.java | 2 +- solr/packaging/test/test_version.bats | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) 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 9f34c32cb371..48bb693e5052 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 static void main(String[] args) throws Exception { } 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/packaging/test/test_version.bats b/solr/packaging/test/test_version.bats index f4d888033e65..0708044a1b62 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:" }