From 03472717a97bf56e4023ccbfb82c3b20069d7a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Fri, 6 Dec 2024 15:45:45 +0100 Subject: [PATCH 1/3] SOLR-17586 Print zkcli.sh deprecation msg to stderr --- solr/CHANGES.txt | 2 ++ solr/server/scripts/cloud-scripts/zkcli.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 85a375a07f2..e332efe7bea 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -107,6 +107,8 @@ Bug Fixes * SOLR-17574: Fix AllowListUrlChecker when liveNodes changes. Remove ClusterState.getHostAllowList (Bruno Roustant, David Smiley) +* SOLR-17586: Print zkcli.sh deprecation msg to stderr, which fixes Solr Operator upload of security.json to zookeeper (Jan Høydahl) + Dependency Upgrades --------------------- (No changes) diff --git a/solr/server/scripts/cloud-scripts/zkcli.sh b/solr/server/scripts/cloud-scripts/zkcli.sh index c9dd7a50b66..197ee57b252 100755 --- a/solr/server/scripts/cloud-scripts/zkcli.sh +++ b/solr/server/scripts/cloud-scripts/zkcli.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -echo "WARNING: The zkcli.sh script has been deprecated in favour of the bin/solr equivalent commands." +>&2 echo "WARNING: The zkcli.sh script has been deprecated in favour of the bin/solr equivalent commands." # You can override pass the following parameters to this script: # From 1b7b183949360b40b3fddc9e46188e85e0fddc69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Fri, 6 Dec 2024 16:49:37 +0100 Subject: [PATCH 2/3] Print deprecation warnings to stderr --- .../src/java/org/apache/solr/cloud/ZkCLI.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java index 6b67fc76360..5097679e61a 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java @@ -29,6 +29,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.Locale; import java.util.Properties; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -36,12 +37,12 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.DeprecatedAttributes; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -import org.apache.commons.cli.PosixParser; import org.apache.solr.cli.CLIO; import org.apache.solr.cli.SolrCLI; import org.apache.solr.client.solrj.impl.SolrZkClientTimeout; @@ -159,7 +160,11 @@ public static void main(String[] args) SAXException, KeeperException { - CommandLineParser parser = new PosixParser(); + CommandLineParser parser = + DefaultParser.builder() + // Override deprecation handler since the default one prints to stdout, we want stderr + .setDeprecatedHandler(o -> System.err.println(toDeprecatedString(o))) + .build(); Options options = new Options(); Option cmdOption = @@ -717,6 +722,14 @@ public static void main(String[] args) } } + // TODO: Override toDeprecatedString since Option.toDeprecatedString has private visibility in + // Commons-CLI + private static String toDeprecatedString(Option o) { + return o.isDeprecated() + ? String.format(Locale.ROOT, "Option '%s': %s", o.getArgName(), o.getDeprecated()) + : ""; + } + private static boolean shouldCompressData( byte[] data, String path, int minStateByteLenForCompression) { if (path.endsWith("state.json") From e2739132a213d80723d5fde7fe36be2581faa9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Fri, 6 Dec 2024 16:53:17 +0100 Subject: [PATCH 3/3] Use deprecated handler from SolrCLI --- solr/core/src/java/org/apache/solr/cli/SolrCLI.java | 2 +- solr/core/src/java/org/apache/solr/cloud/ZkCLI.java | 11 +---------- 2 files changed, 2 insertions(+), 11 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 090339e2382..14b637e8e18 100755 --- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java +++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java @@ -450,7 +450,7 @@ public static String getOptionWithDeprecatedAndDefault( // TODO: SOLR-17429 - remove the custom logic when Commons CLI is upgraded and // makes stderr the default, or makes Option.toDeprecatedString() public. - private static void deprecatedHandlerStdErr(Option o) { + public static void deprecatedHandlerStdErr(Option o) { // Deprecated options without a description act as "stealth" options if (o.isDeprecated() && !o.getDeprecated().getDescription().isBlank()) { final StringBuilder buf = diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java index 5097679e61a..4e9906f5217 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java @@ -29,7 +29,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; -import java.util.Locale; import java.util.Properties; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -163,7 +162,7 @@ public static void main(String[] args) CommandLineParser parser = DefaultParser.builder() // Override deprecation handler since the default one prints to stdout, we want stderr - .setDeprecatedHandler(o -> System.err.println(toDeprecatedString(o))) + .setDeprecatedHandler(SolrCLI::deprecatedHandlerStdErr) .build(); Options options = new Options(); @@ -722,14 +721,6 @@ public static void main(String[] args) } } - // TODO: Override toDeprecatedString since Option.toDeprecatedString has private visibility in - // Commons-CLI - private static String toDeprecatedString(Option o) { - return o.isDeprecated() - ? String.format(Locale.ROOT, "Option '%s': %s", o.getArgName(), o.getDeprecated()) - : ""; - } - private static boolean shouldCompressData( byte[] data, String path, int minStateByteLenForCompression) { if (path.endsWith("state.json")