-
Notifications
You must be signed in to change notification settings - Fork 820
SOLR-17318 VersionTool now reports remote server version #4275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 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); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a back compatibility break, but I think one we can live with? Note that also
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! |
||
|
|
||
| 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()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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:")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other code I saw a nicer assert style for contains in a setting🤔, though I can't remember right now what it was!! |
||
| 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:")); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to support the --zk option to connect for consistency? Don't all our tools allow both??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted out of supporting --zk-host as it feels redundant for this command. Can add later if needed.