This is an automated email from the ASF dual-hosted git repository. epugh pushed a commit to branch branch_9x in repository https://gitbox.apache.org/repos/asf/solr.git
commit 1476a2e8fa0f2c6166b9709628ac5d76bdf5af7a Author: Eric Pugh <[email protected]> AuthorDate: Sat Oct 5 07:20:55 2024 -0400 SOLR-17469: CLI: Resolve -f flag conflicts (#2740) Keep -f for forcing actions since it is often used in other tools for "force" as well. This means keep -f for force in bin/solr and RunExampleTool to allow starting Solr as root user and also for force deleting configuration directories in DeleteTool. Deprecate (9x) and remove (10.0) by replacing the "force-delete-config" (--force-delete-config, -forceDeleteConfig, --forceDeleteConfig, -f) in DeleteTool with the "force" option ( --force, -f). Deprecate (9x) and remove (10.0) -f from the "format" option in PostTool. Deprecate (9x) and remove (10.0) -f from the "config file" option (-f, --config-file, -config-file) in SolrExporter. (cherry picked from commit 08a17da67b169b77b4cfb8698619aa88015234cf) --- .../src/java/org/apache/solr/cli/DeleteTool.java | 22 +++++++++++++++---- .../src/java/org/apache/solr/cli/PostTool.java | 16 +++++++++++++- solr/prometheus-exporter/bin/solr-exporter | 2 +- solr/prometheus-exporter/bin/solr-exporter.cmd | 2 +- .../solr/prometheus/exporter/SolrExporter.java | 25 ++++++++++++++++++++-- .../monitoring-with-prometheus-and-grafana.adoc | 12 +++++------ .../pages/solr-control-script-reference.adoc | 4 ++-- .../modules/indexing-guide/pages/post-tool.adoc | 2 +- 8 files changed, 67 insertions(+), 18 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/cli/DeleteTool.java b/solr/core/src/java/org/apache/solr/cli/DeleteTool.java index 50cac5d1512..1202ca79888 100644 --- a/solr/core/src/java/org/apache/solr/cli/DeleteTool.java +++ b/solr/core/src/java/org/apache/solr/cli/DeleteTool.java @@ -67,7 +67,7 @@ public class DeleteTool extends ToolBase { return "Deletes a core or collection depending on whether Solr is running in standalone (core) or SolrCloud" + " mode (collection). If you're deleting a collection in SolrCloud mode, the default behavior is to also" + " delete the configuration directory from Zookeeper so long as it is not being used by another collection.\n" - + " You can override this behavior by passing -deleteConfig false when running this command.\n" + + " You can override this behavior by passing --delete-config false when running this command.\n" + "\n" + "List of options:"; } @@ -104,8 +104,14 @@ public class DeleteTool extends ToolBase { .desc( "Flag to indicate if the underlying configuration directory for a collection should also be deleted; default is true.") .build(), - Option.builder("f") + Option.builder() .longOpt("force-delete-config") + .deprecated( + DeprecatedAttributes.builder() + .setForRemoval(true) + .setSince("9.8") + .setDescription("Use --force instead") + .get()) .required(false) .desc( "Skip safety checks when deleting the configuration directory used by a collection.") @@ -129,12 +135,18 @@ public class DeleteTool extends ToolBase { DeprecatedAttributes.builder() .setForRemoval(true) .setSince("9.7") - .setDescription("Use --force-delete-config instead") + .setDescription("Use --force instead") .get()) .required(false) .desc( "Skip safety checks when deleting the configuration directory used by a collection.") .build(), + Option.builder("f") + .longOpt("force") + .required(false) + .desc( + "Skip safety checks when deleting the configuration directory used by a collection.") + .build(), SolrCLI.OPTION_SOLRURL, SolrCLI.OPTION_SOLRURL_DEPRECATED, SolrCLI.OPTION_ZKHOST, @@ -199,7 +211,9 @@ public class DeleteTool extends ToolBase { } if (deleteConfig && configName != null) { - if (cli.hasOption("force-delete-config") || cli.hasOption("forceDeleteConfig")) { + if (cli.hasOption("force") + || cli.hasOption("force-delete-config") + || cli.hasOption("forceDeleteConfig")) { log.warn( "Skipping safety checks, configuration directory {} will be deleted with impunity.", configName); diff --git a/solr/core/src/java/org/apache/solr/cli/PostTool.java b/solr/core/src/java/org/apache/solr/cli/PostTool.java index c2d2409eda3..30e2c153205 100644 --- a/solr/core/src/java/org/apache/solr/cli/PostTool.java +++ b/solr/core/src/java/org/apache/solr/cli/PostTool.java @@ -266,6 +266,17 @@ public class PostTool extends ToolBase { .desc("sends Solr response outputs to console.") .build(), Option.builder("f") + .deprecated( + DeprecatedAttributes.builder() + .setForRemoval(true) + .setSince("9.8") + .setDescription("Use --format instead") + .get()) + .required(false) + .desc( + "sends application/json content as Solr commands to /update instead of /update/json/docs.") + .build(), + Option.builder() .longOpt("format") .required(false) .desc( @@ -305,7 +316,10 @@ public class PostTool extends ToolBase { // Turn off automatically looking up the mimetype in favour of what is passed in. auto = false; } - format = cli.hasOption("format") ? FORMAT_SOLR : ""; // i.e not solr formatted json commands + format = + cli.hasOption("format") || cli.hasOption("f") + ? FORMAT_SOLR + : ""; // i.e not solr formatted json commands if (cli.hasOption("filetypes")) { fileTypes = cli.getOptionValue("filetypes"); diff --git a/solr/prometheus-exporter/bin/solr-exporter b/solr/prometheus-exporter/bin/solr-exporter index b15f7ff9339..6f7ef98428b 100755 --- a/solr/prometheus-exporter/bin/solr-exporter +++ b/solr/prometheus-exporter/bin/solr-exporter @@ -104,7 +104,7 @@ fi EXPORTER_ARGS=() if [[ -n "$CONFIG_FILE" ]]; then - EXPORTER_ARGS+=(-f "$CONFIG_FILE") + EXPORTER_ARGS+=(--config-file "$CONFIG_FILE") fi if [[ -n "$PORT" ]]; then diff --git a/solr/prometheus-exporter/bin/solr-exporter.cmd b/solr/prometheus-exporter/bin/solr-exporter.cmd index 568f4f8b71d..e040553d0c8 100644 --- a/solr/prometheus-exporter/bin/solr-exporter.cmd +++ b/solr/prometheus-exporter/bin/solr-exporter.cmd @@ -76,7 +76,7 @@ set CLASSPATH=%REPO%\*;%BASEDIR%\conf;%BASEDIR%\..\server\lib\ext\*;%BASEDIR%\.. @REM Convert Environment Variables to Command Line Options set EXPORTER_ARGS= -IF NOT "%CONFIG_FILE%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% -f %CONFIG_FILE% +IF NOT "%CONFIG_FILE%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% --config-file %CONFIG_FILE% IF NOT "%PORT%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% -p %PORT% IF NOT "%SCRAPE_INTERVAL%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% -s %SCRAPE_INTERVAL% IF NOT "%NUM_THREADS%"=="" set EXPORTER_ARGS=%EXPORTER_ARGS% -n %NUM_THREADS% diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrExporter.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrExporter.java index b7918b90901..0a56c018856 100644 --- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrExporter.java +++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/exporter/SolrExporter.java @@ -174,14 +174,28 @@ public class SolrExporter { deprecatedOptions.addOption(baseUrlDepOption); Option configOption = - Option.builder("f") + Option.builder() .longOpt("config-file") .hasArg() .argName("CONFIG") .type(String.class) .desc("Specify the configuration file; the default is " + DEFAULT_CONFIG + ".") .build(); + Option configOptionDeprecated = + Option.builder("f") + .hasArg() + .argName("CONFIG") + .type(String.class) + .deprecated( + DeprecatedAttributes.builder() + .setForRemoval(true) + .setSince("9.8") + .setDescription("Use --config-file instead") + .get()) + .desc("Specify the configuration file; the default is " + DEFAULT_CONFIG + ".") + .build(); mainOptions.addOption(configOption); + mainOptions.addOption(configOptionDeprecated); Option helpOption = Option.builder("h").longOpt("help").desc("Prints this help message.").build(); @@ -327,13 +341,20 @@ public class SolrExporter { getSystemVariable("SOLR_SSL_TRUST_STORE_PASSWORD")); } + String configFile = DEFAULT_CONFIG; + if (commandLine.hasOption(configOptionDeprecated)) { + configFile = commandLine.getOptionValue(configOptionDeprecated); + } else if (commandLine.hasOption(configOption)) { + configFile = commandLine.getOptionValue(configOption); + } + SolrExporter solrExporter = new SolrExporter( port, commandLine.getParsedOptionValue(numThreadsOption, DEFAULT_NUM_THREADS), commandLine.getParsedOptionValue(scrapeIntervalOption, DEFAULT_SCRAPE_INTERVAL), scrapeConfiguration, - loadMetricsConfiguration(commandLine.getOptionValue(configOption, DEFAULT_CONFIG)), + loadMetricsConfiguration(configFile), clusterId); log.info("Starting Solr Prometheus Exporting on port {}", port); diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/monitoring-with-prometheus-and-grafana.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/monitoring-with-prometheus-and-grafana.adoc index d1d64ba821e..27ae739d4dc 100644 --- a/solr/solr-ref-guide/modules/deployment-guide/pages/monitoring-with-prometheus-and-grafana.adoc +++ b/solr/solr-ref-guide/modules/deployment-guide/pages/monitoring-with-prometheus-and-grafana.adoc @@ -62,14 +62,14 @@ Linux:: [source,bash] ---- $ cd prometheus-exporter -$ ./bin/solr-exporter -p 9854 -b http://localhost:8983/solr -f ./conf/solr-exporter-config.xml -n 8 +$ ./bin/solr-exporter -p 9854 -b http://localhost:8983/solr --config-file ./conf/solr-exporter-config.xml -n 8 ---- .SolrCloud [source,bash] ---- $ cd prometheus-exporter -$ ./bin/solr-exporter -p 9854 -z localhost:2181/solr -f ./conf/solr-exporter-config.xml -n 16 +$ ./bin/solr-exporter -p 9854 -z localhost:2181/solr --config-file ./conf/solr-exporter-config.xml -n 16 ---- ==== @@ -80,14 +80,14 @@ Windows:: [source,text] ---- > cd prometheus-exporter -> .\bin\solr-exporter.cmd -p 9854 -b http://localhost:8983/solr -f .\conf\solr-exporter-config.xml -n 8 +> .\bin\solr-exporter.cmd -p 9854 -b http://localhost:8983/solr --config-file .\conf\solr-exporter-config.xml -n 8 ---- .SolrCloud [source,text] ---- > cd prometheus-exporter -> .\bin\solr-exporter -p 9854 -z localhost:2181/solr -f .\conf\solr-exporter-config.xml -n 16 +> .\bin\solr-exporter -p 9854 -z localhost:2181/solr --config-file .\conf\solr-exporter-config.xml -n 16 ---- ==== ====== @@ -139,7 +139,7 @@ The ZooKeeper connect string (such as `localhost:9983`, or `localhost:2181/solr` If you are running a user-managed cluster or single-node installation, do not specify this parameter. If neither the `-b` parameter nor the `-z` parameter are defined, the `-b` parameter default is used. -`-f`, `--config-file`, `$CONFIG_FILE`:: +`--config-file`, `$CONFIG_FILE`:: + [%autowidth,frame=none] |=== @@ -285,7 +285,7 @@ $ cd prometheus-exporter $ export JAVA_OPTS="-Djavax.net.ssl.trustStore=truststore.p12 -Djavax.net.ssl.trustStorePassword=truststorePassword -Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory -Dsolr.httpclient.config=basicauth.properties" $ export ZK_CREDS_AND_ACLS="-DzkCredentialsProvider=org.apache.solr.common.cloud.VMParamsSingleSetCredentialsDigestZkCredentialsProvider -DzkDigestUsername=readonly-user -DzkDigestPassword=zkUserPassword" $ export CLASSPATH_PREFIX="../server/solr-webapp/webapp/WEB-INF/lib/commons-codec-1.11.jar" -$ ./bin/solr-exporter -p 9854 -z zk1:2181,zk2:2181,zk3:2181 -f ./conf/solr-exporter-config.xml -n 16 +$ ./bin/solr-exporter -p 9854 -z zk1:2181,zk2:2181,zk3:2181 --config-file ./conf/solr-exporter-config.xml -n 16 ---- NOTE:: The Exporter needs the `commons-codec` library for SSL/BasicAuth, but does not bring it. diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc index 451ddb8b021..d7e8a8889f8 100644 --- a/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc +++ b/solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc @@ -988,11 +988,11 @@ If the configuration directory is being used by another collection, then it will + *Example*: `bin/solr delete --delete-config false` -`--force-delete-config`:: +`-f` or `--force`:: + [%autowidth,frame=none] |=== -|Optional |Default: _see description_ +|Optional |Default: none |=== + Skip safety checks when deleting the configuration directory used by a collection. diff --git a/solr/solr-ref-guide/modules/indexing-guide/pages/post-tool.adoc b/solr/solr-ref-guide/modules/indexing-guide/pages/post-tool.adoc index 1b881976c88..4a8b6d81c60 100644 --- a/solr/solr-ref-guide/modules/indexing-guide/pages/post-tool.adoc +++ b/solr/solr-ref-guide/modules/indexing-guide/pages/post-tool.adoc @@ -55,7 +55,7 @@ usage: post without actually sending documents to Solr. Only works with files mode. - -f,--format sends application/json + --format sends application/json content as Solr commands to /update instead of /update/json/docs.
