Skip to content

Commit

Permalink
SOLR-17429, SOLR-17338: Use stderr for SolrCLI deprecation logs (#2679)
Browse files Browse the repository at this point in the history
  • Loading branch information
HoustonPutman authored Aug 30, 2024
1 parent e352072 commit 26d00c3
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions solr/core/src/java/org/apache/solr/cli/SolrCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,20 @@ public static Options getToolOptions(Tool tool) {
return options;
}

// TODO: SOLR-17429 - remove the custom logic when CommonsCLI is upgraded and
// makes stderr the default, or makes Option.toDeprecatedString() public.
private static void deprecatedHandlerStdErr(Option o) {
if (o.isDeprecated()) {
final StringBuilder buf =
new StringBuilder().append("Option '-").append(o.getOpt()).append('\'');
if (o.getLongOpt() != null) {
buf.append(",'--").append(o.getLongOpt()).append('\'');
}
buf.append(": ").append(o.getDeprecated());
CLIO.err(buf.toString());
}
}

/** Parses the command-line arguments passed by the user. */
public static CommandLine processCommandLineArgs(Tool tool, String[] args) {
List<Option> customOptions = tool.getOptions();
Expand All @@ -387,7 +401,11 @@ public static CommandLine processCommandLineArgs(Tool tool, String[] args) {

CommandLine cli = null;
try {
cli = (new DefaultParser()).parse(options, args);
cli =
DefaultParser.builder()
.setDeprecatedHandler(SolrCLI::deprecatedHandlerStdErr)
.build()
.parse(options, args);
} catch (ParseException exp) {
// Check if we passed in a help argument with a non parsing set of arguments.
boolean hasHelpArg = false;
Expand Down Expand Up @@ -642,7 +660,7 @@ public static String normalizeSolrUrl(String solrUrl, boolean logUrlFormatWarnin
String newSolrUrl =
uri.resolve(urlPath.substring(0, urlPath.lastIndexOf("/solr") + 1)).toString();
if (logUrlFormatWarning) {
CLIO.out(
CLIO.err(
"WARNING: URLs provided to this tool needn't include Solr's context-root (e.g. \"/solr\"). Such URLs are deprecated and support for them will be removed in a future release. Correcting from ["
+ solrUrl
+ "] to ["
Expand Down Expand Up @@ -670,13 +688,11 @@ public static String normalizeSolrUrl(CommandLine cli) throws Exception {
cli.hasOption("zk-host") ? cli.getOptionValue("zk-host") : cli.getOptionValue("zkHost");
if (zkHost == null) {
solrUrl = SolrCLI.getDefaultSolrUrl();
CLIO.getOutStream()
.println(
"Neither --zk-host or --solr-url parameters provided so assuming solr url is "
+ solrUrl
+ ".");
CLIO.err(
"Neither --zk-host or --solr-url parameters provided so assuming solr url is "
+ solrUrl
+ ".");
} else {

try (CloudSolrClient cloudSolrClient = getCloudHttp2SolrClient(zkHost)) {
cloudSolrClient.connect();
Set<String> liveNodes = cloudSolrClient.getClusterState().getLiveNodes();
Expand Down

0 comments on commit 26d00c3

Please sign in to comment.