This is an automated email from the ASF dual-hosted git repository.
malliaridis pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 40b039cdb10 SOLR-17383: Fix support for deprecated options in 9x
(#2819)
40b039cdb10 is described below
commit 40b039cdb10143e5795a1e3f4c79e3a1315e9bc4
Author: Christos Malliaridis <[email protected]>
AuthorDate: Thu Oct 31 00:20:21 2024 +0100
SOLR-17383: Fix support for deprecated options in 9x (#2819)
* Fix support for deprecated options
* Support deprecated url param in PackageTool
---
.../org/apache/solr/cli/ConfigSetUploadTool.java | 10 ++---
.../src/java/org/apache/solr/cli/CreateTool.java | 44 ++++++++++------------
.../src/java/org/apache/solr/cli/PackageTool.java | 3 +-
.../java/org/apache/solr/cli/RunExampleTool.java | 4 +-
.../core/src/java/org/apache/solr/cli/SolrCLI.java | 5 +--
5 files changed, 29 insertions(+), 37 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/cli/ConfigSetUploadTool.java
b/solr/core/src/java/org/apache/solr/cli/ConfigSetUploadTool.java
index d9e5ae5dd24..8978a48cce7 100644
--- a/solr/core/src/java/org/apache/solr/cli/ConfigSetUploadTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/ConfigSetUploadTool.java
@@ -110,12 +110,8 @@ public class ConfigSetUploadTool extends ToolBase {
final String solrInstallDir = System.getProperty("solr.install.dir");
Path solrInstallDirPath = Paths.get(solrInstallDir);
- String confName =
- cli.hasOption("conf-name")
- ? cli.getOptionValue("conf-name")
- : cli.getOptionValue("confname");
- String confDir =
- cli.hasOption("conf-dir") ? cli.getOptionValue("conf-dir") :
cli.getOptionValue("confdir");
+ String confName = SolrCLI.getOptionWithDeprecatedAndDefault(cli,
"conf-name", "confname", null);
+ String confDir = SolrCLI.getOptionWithDeprecatedAndDefault(cli,
"conf-dir", "confdir", null);
try (SolrZkClient zkClient = SolrCLI.getSolrZkClient(cli, zkHost)) {
echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...", cli);
@@ -126,7 +122,7 @@ public class ConfigSetUploadTool extends ToolBase {
"Uploading "
+ confPath.toAbsolutePath()
+ " for config "
- + cli.getOptionValue("conf-name")
+ + confName
+ " to ZooKeeper at "
+ zkHost);
FileTypeMagicUtil.assertConfigSetFolderLegal(confPath);
diff --git a/solr/core/src/java/org/apache/solr/cli/CreateTool.java
b/solr/core/src/java/org/apache/solr/cli/CreateTool.java
index 69313dc0a8b..b2e7e063baa 100644
--- a/solr/core/src/java/org/apache/solr/cli/CreateTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/CreateTool.java
@@ -199,13 +199,14 @@ public class CreateTool extends ToolBase {
protected void createCore(CommandLine cli, SolrClient solrClient) throws
Exception {
String coreName = cli.getOptionValue("name");
- String solrUrl = cli.getOptionValue("solr-url",
SolrCLI.getDefaultSolrUrl());
+ String solrUrl =
+ SolrCLI.getOptionWithDeprecatedAndDefault(
+ cli, "solr-url", "solrUrl", SolrCLI.getDefaultSolrUrl());
final String solrInstallDir = System.getProperty("solr.install.dir");
final String confDirName =
- cli.hasOption("confdir")
- ? cli.getOptionValue("confdir")
- : cli.getOptionValue("conf-dir", SolrCLI.DEFAULT_CONFIG_SET);
+ SolrCLI.getOptionWithDeprecatedAndDefault(
+ cli, "conf-dir", "confdir", SolrCLI.DEFAULT_CONFIG_SET);
// we allow them to pass a directory instead of a configset name
Path configsetDir = Paths.get(confDirName);
@@ -285,14 +286,10 @@ public class CreateTool extends ToolBase {
String collectionName = cli.getOptionValue("name");
final String solrInstallDir = System.getProperty("solr.install.dir");
- String confName =
- cli.hasOption("conf-name")
- ? cli.getOptionValue("conf-name")
- : cli.getOptionValue("confname");
+ String confName = SolrCLI.getOptionWithDeprecatedAndDefault(cli,
"conf-name", "confname", null);
String confDir =
- cli.hasOption("confdir")
- ? cli.getOptionValue("confdir")
- : cli.getOptionValue("conf-dir", SolrCLI.DEFAULT_CONFIG_SET);
+ SolrCLI.getOptionWithDeprecatedAndDefault(
+ cli, "conf-dir", "confdir", SolrCLI.DEFAULT_CONFIG_SET);
Path solrInstallDirPath = Paths.get(solrInstallDir);
Path confDirPath = Paths.get(confDir);
ensureConfDirExists(solrInstallDirPath, confDirPath);
@@ -304,7 +301,7 @@ public class CreateTool extends ToolBase {
"No live nodes found! Cannot create a collection until "
+ "there is at least 1 live node in the cluster.");
- String solrUrl = cli.getOptionValue("solr-url");
+ String solrUrl = SolrCLI.getOptionWithDeprecatedAndDefault(cli,
"solr-url", "solrUrl", null);
if (solrUrl == null) {
String firstLiveNode = liveNodes.iterator().next();
solrUrl =
ZkStateReader.from(cloudSolrClient).getBaseUrlForNodeName(firstLiveNode);
@@ -312,13 +309,10 @@ public class CreateTool extends ToolBase {
// build a URL to create the collection
int numShards = Integer.parseInt(cli.getOptionValue("shards",
String.valueOf(1)));
- int replicationFactor = 1;
-
- if (cli.hasOption("replication-factor")) {
- replicationFactor =
Integer.parseInt(cli.getOptionValue("replication-factor"));
- } else if (cli.hasOption("replicationFactor")) {
- replicationFactor =
Integer.parseInt(cli.getOptionValue("replicationFactor"));
- }
+ int replicationFactor =
+ Integer.parseInt(
+ SolrCLI.getOptionWithDeprecatedAndDefault(
+ cli, "replication-factor", "replicationFactor", "1"));
boolean configExistsInZk =
confName != null
@@ -415,15 +409,17 @@ public class CreateTool extends ToolBase {
private void printDefaultConfigsetWarningIfNecessary(CommandLine cli) {
final String confDirectoryName =
- cli.hasOption("confdir")
- ? cli.getOptionValue("confdir")
- : cli.getOptionValue("conf-dir", SolrCLI.DEFAULT_CONFIG_SET);
- final String confName = cli.getOptionValue("confname", "");
+ SolrCLI.getOptionWithDeprecatedAndDefault(
+ cli, "conf-dir", "confdir", SolrCLI.DEFAULT_CONFIG_SET);
+ final String confName =
+ SolrCLI.getOptionWithDeprecatedAndDefault(cli, "conf-name",
"confname", "");
if (confDirectoryName.equals("_default")
&& (confName.equals("") || confName.equals("_default"))) {
final String collectionName = cli.getOptionValue("name");
- final String solrUrl = cli.getOptionValue("solrUrl",
SolrCLI.getDefaultSolrUrl());
+ final String solrUrl =
+ SolrCLI.getOptionWithDeprecatedAndDefault(
+ cli, "solr-url", "solrUrl", SolrCLI.getDefaultSolrUrl());
final String curlCommand =
String.format(
Locale.ROOT,
diff --git a/solr/core/src/java/org/apache/solr/cli/PackageTool.java
b/solr/core/src/java/org/apache/solr/cli/PackageTool.java
index 875f990594e..f172d310c83 100644
--- a/solr/core/src/java/org/apache/solr/cli/PackageTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/PackageTool.java
@@ -78,7 +78,8 @@ public class PackageTool extends ToolBase {
String solrUrl =
cli.hasOption("solr-url")
? cli.getOptionValue("solr-url")
- : cli.getOptionValue("solrUrl", SolrCLI.getDefaultSolrUrl());
+ : SolrCLI.getOptionWithDeprecatedAndDefault(
+ cli, "solrUrl", "url", SolrCLI.getDefaultSolrUrl());
solrBaseUrl = solrUrl.replaceAll("/solr$", ""); // strip out ending
"/solr"
log.debug("Solr url:{}, solr base url: {}", solrUrl, solrBaseUrl);
diff --git a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
index dc5f0b2d3f2..0f27fe4e79b 100644
--- a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
@@ -260,7 +260,7 @@ public class RunExampleTool extends ToolBase {
"techproducts".equals(exampleName) ? "sample_techproducts_configs" :
"_default";
boolean isCloudMode = cli.hasOption('c');
- String zkHost = cli.getOptionValue('z');
+ String zkHost = SolrCLI.getOptionWithDeprecatedAndDefault(cli, "z",
"zkHost", null);
int port =
Integer.parseInt(
cli.getOptionValue('p', System.getenv().getOrDefault("SOLR_PORT",
"8983")));
@@ -511,7 +511,7 @@ public class RunExampleTool extends ToolBase {
}
// deal with extra args passed to the script to run the example
- String zkHost = cli.getOptionValue('z');
+ String zkHost = SolrCLI.getOptionWithDeprecatedAndDefault(cli, "z",
"zkHost", null);
// start the first node (most likely with embedded ZK)
Map<String, Object> nodeStatus =
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 5b54b9dc9bf..090339e2382 100755
--- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
@@ -775,8 +775,7 @@ public class SolrCLI implements CLIO {
}
if (solrUrl == null) {
- String zkHost =
- cli.hasOption("zk-host") ? cli.getOptionValue("zk-host") :
cli.getOptionValue("zkHost");
+ String zkHost = getOptionWithDeprecatedAndDefault(cli, "zk-host",
"zkHost", null);
if (zkHost == null) {
solrUrl = SolrCLI.getDefaultSolrUrl();
CLIO.err(
@@ -838,7 +837,7 @@ public class SolrCLI implements CLIO {
if (zkHost == null) {
throw new IllegalStateException(
"Solr at "
- + cli.getOptionValue("solrUrl")
+ + getOptionWithDeprecatedAndDefault(cli, "solr-url", "solrUrl",
null)
+ " is running in standalone server mode, this command can only
be used when running in SolrCloud mode.\n");
}
return new SolrZkClient.Builder()