Apache Solr open-source search software
SOLR-17318 VersionTool now reports remote server version (#4275)
Jan Høydahld8f8b3f8ddda
diff --git a/changelog/unreleased/SOLR-17318-version-server-info.yml b/changelog/unreleased/SOLR-17318-version-server-info.ymlnew file mode 100644index 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-17318diff --git a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java b/solr/core/src/java/org/apache/solr/cli/SolrCLI.javaindex 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 versionargs = 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.javaindex 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);+ }+@Overridepublic 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.javanew file mode 100644index 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.batsindex 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:"}