Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/SOLR-17318-version-server-info.yml
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
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/cli/SolrCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
27 changes: 26 additions & 1 deletion solr/core/src/java/org/apache/solr/cli/VersionTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -31,8 +40,24 @@ public String getName() {
return "version";
}

@Override
public Options getOptions() {
return super.getOptions()
.addOption(CommonCLIOptions.SOLR_URL_OPTION)
Copy link
Copy Markdown
Contributor

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??

Copy link
Copy Markdown
Contributor Author

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.

.addOption(CommonCLIOptions.CREDENTIALS_OPTION);
}

@Override
public void runImpl(CommandLine cli) throws Exception {
CLIO.out("Solr version is: " + SolrVersion.LATEST);
echo("Client version: " + SolrVersion.LATEST);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 --version calls the version tool and gets this change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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());
}
}
}
}
57 changes: 57 additions & 0 deletions solr/core/src/test/org/apache/solr/cli/VersionToolTest.java
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:"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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:"));
}
}
8 changes: 3 additions & 5 deletions solr/packaging/test/test_version.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
}
Loading