Skip to content

Commit

Permalink
SOLR-17469: CLI: Resolve -f flag conflicts (#2740)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
epugh authored Oct 5, 2024
1 parent f0b5291 commit 08a17da
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 18 deletions.
22 changes: 18 additions & 4 deletions solr/core/src/java/org/apache/solr/cli/DeleteTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String getHeader() {
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:";
}
Expand Down Expand Up @@ -102,8 +102,14 @@ public List<Option> getOptions() {
.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.")
Expand All @@ -114,12 +120,18 @@ public List<Option> getOptions() {
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,
Expand Down Expand Up @@ -180,7 +192,9 @@ protected void deleteCollection(CloudSolrClient cloudSolrClient, CommandLine cli
}

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);
Expand Down
16 changes: 15 additions & 1 deletion solr/core/src/java/org/apache/solr/cli/PostTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ public List<Option> getOptions() {
.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(
Expand Down Expand Up @@ -307,7 +318,10 @@ public void runImpl(CommandLine cli) throws Exception {
// 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");
Expand Down
2 changes: 1 addition & 1 deletion solr/prometheus-exporter/bin/solr-exporter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion solr/prometheus-exporter/bin/solr-exporter.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,28 @@ public static void main(String[] args) {
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();
Expand Down Expand Up @@ -327,13 +341,20 @@ public static void main(String[] args) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
====
Expand All @@ -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
----
====
======
Expand Down Expand Up @@ -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]
|===
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,11 +829,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: `true`
|Optional |Default: none
|===
+
Skip safety checks when deleting the configuration directory used by a collection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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.
Expand Down

0 comments on commit 08a17da

Please sign in to comment.