Skip to content

Commit

Permalink
SOLR-17489: CLI: Deprecate variations on solr urls options (#2756)
Browse files Browse the repository at this point in the history
Use --solr-url and --name consistently.

(cherry picked from commit 0f4a465)
  • Loading branch information
epugh committed Oct 17, 2024
1 parent 6dbd8d1 commit ce4edd2
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 93 deletions.
32 changes: 29 additions & 3 deletions solr/core/src/java/org/apache/solr/cli/ExportTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.util.function.Consumer;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DeprecatedAttributes;
import org.apache.commons.cli.Option;
import org.apache.lucene.util.SuppressForbidden;
import org.apache.solr.client.solrj.SolrClient;
Expand Down Expand Up @@ -97,11 +98,22 @@ public List<Option> getOptions() {
return List.of(
Option.builder("url")
.longOpt("solr-collection-url")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --solr-url and -c / --name instead")
.get())
.hasArg()
.argName("URL")
.required()
.desc("Address of the collection, example http://localhost:8983/solr/gettingstarted.")
.build(),
Option.builder("c")
.longOpt("name")
.hasArg()
.argName("NAME")
.desc("Name of the collection.")
.build(),
Option.builder("out")
.hasArg()
.argName("PATH")
Expand All @@ -128,7 +140,8 @@ public List<Option> getOptions() {
.hasArg()
.argName("FIELDA,FIELDB")
.desc("Comma separated list of fields to export. By default all fields are fetched.")
.build());
.build(),
SolrCLI.OPTION_SOLRURL);
}

public abstract static class Info {
Expand Down Expand Up @@ -236,7 +249,20 @@ public void streamDocListInfo(long numFound, long start, Float maxScore) {}

@Override
public void runImpl(CommandLine cli) throws Exception {
String url = cli.getOptionValue("solr-collection-url");
String url = null;
if (cli.hasOption("solr-url")) {
if (!cli.hasOption("name")) {
throw new IllegalArgumentException(
"Must specify -c / --name parameter with --solr-url to post documents.");
}
url = SolrCLI.normalizeSolrUrl(cli) + "/solr/" + cli.getOptionValue("name");

} else if (cli.hasOption("solr-collection-url")) {
url = cli.getOptionValue("solr-collection-url");
} else {
// Swap to required Option when --solr-collection-url removed.
throw new IllegalArgumentException("Must specify --solr-url.");
}
Info info = new MultiThreadedRunner(url);
info.query = cli.getOptionValue("query", "*:*");
info.setOutFormat(
Expand Down
32 changes: 29 additions & 3 deletions solr/core/src/java/org/apache/solr/cli/PostLogsTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DeprecatedAttributes;
import org.apache.commons.cli.Option;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
Expand Down Expand Up @@ -65,23 +66,48 @@ public List<Option> getOptions() {
return List.of(
Option.builder("url")
.longOpt("solr-collection-url")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --solr-url and -c / --name instead")
.get())
.hasArg()
.argName("ADDRESS")
.required(true)
.desc("Address of the collection, example http://localhost:8983/solr/collection1/.")
.build(),
Option.builder("c")
.longOpt("name")
.hasArg()
.argName("NAME")
.desc("Name of the collection.")
.build(),
Option.builder("rootdir")
.longOpt("rootdir")
.hasArg()
.argName("DIRECTORY")
.required(true)
.desc("All files found at or below the root directory will be indexed.")
.build());
.build(),
SolrCLI.OPTION_SOLRURL);
}

@Override
public void runImpl(CommandLine cli) throws Exception {
String url = cli.getOptionValue("url");
String url = null;
if (cli.hasOption("solr-url")) {
if (!cli.hasOption("name")) {
throw new IllegalArgumentException(
"Must specify -c / --name parameter with --solr-url to post documents.");
}
url = SolrCLI.normalizeSolrUrl(cli) + "/solr/" + cli.getOptionValue("name");

} else if (cli.hasOption("solr-collection-url")) {
url = cli.getOptionValue("solr-collection-url");
} else {
// Swap to required Option when --solr-collection-url removed.
throw new IllegalArgumentException("Must specify --solr-url.");
}
String rootDir = cli.getOptionValue("rootdir");
runCommand(url, rootDir);
}
Expand Down
24 changes: 17 additions & 7 deletions solr/core/src/java/org/apache/solr/cli/PostTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ public List<Option> getOptions() {
return List.of(
Option.builder("url")
.longOpt("solr-update-url")
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --solr-url and -c / --name instead")
.get())
.hasArg()
.argName("UPDATEURL")
.desc("Solr Update URL, the full url to the update handler, including the /update.")
Expand All @@ -180,12 +186,10 @@ public List<Option> getOptions() {
.longOpt("name")
.hasArg()
.argName("NAME")
.required(false)
.desc("Name of the collection.")
.build(),
Option.builder()
.longOpt("skip-commit")
.required(false)
.desc("Do not 'commit', and thus changes won't be visible till a commit occurs.")
.build(),
Option.builder()
Expand All @@ -196,19 +200,16 @@ public List<Option> getOptions() {
.setSince("9.7")
.setDescription("Use --skip-commit instead")
.get())
.required(false)
.desc("Do not 'commit', and thus changes won't be visible till a commit occurs.")
.build(),
Option.builder("o")
.longOpt("optimize")
.required(false)
.desc("Issue an optimize at end of posting documents.")
.build(),
Option.builder()
.longOpt("mode")
.hasArg()
.argName("mode")
.required(false)
.desc(
"Which mode the Post tool is running in, 'files' crawls local directory, 'web' crawls website, 'args' processes input args, and 'stdin' reads a command from standard in. default: files.")
.build(),
Expand Down Expand Up @@ -300,16 +301,25 @@ public List<Option> getOptions() {
.required(false)
.desc(
"Performs a dry run of the posting process without actually sending documents to Solr. Only works with files mode.")
.build());
.build(),
SolrCLI.OPTION_SOLRURL);
}

@Override
public void runImpl(CommandLine cli) throws Exception {
SolrCLI.raiseLogLevelUnlessVerbose(cli);

solrUpdateUrl = null;
if (cli.hasOption("solr-url")) {
if (!cli.hasOption("name")) {
throw new IllegalArgumentException(
"Must specify -c / --name parameter with --solr-url to post documents.");
}
String url =
SolrCLI.normalizeSolrUrl(cli) + "/" + cli.getOptionValue("name") + "/update";
solrUpdateUrl = new URI(url);

if (cli.hasOption("solr-update-url")) {
} else if (cli.hasOption("solr-update-url")) {
String url = cli.getOptionValue("solr-update-url");
solrUpdateUrl = new URI(url);
} else if (cli.hasOption("name")) {
Expand Down
14 changes: 8 additions & 6 deletions solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,15 @@ protected void runExample(CommandLine cli, String exampleName) throws Exception
}

if (exampledocsDir.isDirectory()) {
String updateUrl = String.format(Locale.ROOT, "%s/%s/update", solrUrl, collectionName);
echo("Indexing tech product example docs from " + exampledocsDir.getAbsolutePath());

String[] args =
new String[] {
"post",
"--solr-update-url",
updateUrl,
"--solr-url",
solrUrl,
"--name",
collectionName,
"--type",
"application/xml",
exampledocsDir.getAbsolutePath() + "/*.xml"
Expand Down Expand Up @@ -410,13 +411,14 @@ protected void runExample(CommandLine cli, String exampleName) throws Exception
+ " }\n");

File filmsJsonFile = new File(exampleDir, "films/films.json");
String updateUrl = String.format(Locale.ROOT, "%s/%s/update/json", solrUrl, collectionName);
echo("Indexing films example docs from " + filmsJsonFile.getAbsolutePath());
String[] args =
new String[] {
"post",
"--solr-update-url",
updateUrl,
"--solr-url",
solrUrl,
"--name",
collectionName,
"--type",
"application/json",
filmsJsonFile.getAbsolutePath()
Expand Down
6 changes: 4 additions & 2 deletions solr/core/src/test/org/apache/solr/cli/PostToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ public void testBasicRun() throws Exception {

String[] args = {
"post",
"--solr-update-url",
cluster.getJettySolrRunner(0).getBaseUrl() + "/" + collection + "/update",
"--solr-url",
cluster.getJettySolrRunner(0).getBaseUrl().toString(),
"--name",
collection,
jsonDoc.getAbsolutePath()
};
assertEquals(0, runTool(args));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ public void testLoadDocsIntoGettingStartedCollection() throws Exception {

String[] argsForPost =
new String[] {
"--solr-update-url",
solrUrl + "/" + testCollectionName + "/update",
"--solr-url",
solrUrl,
"--name",
testCollectionName,
"--filetypes",
"xml",
exampleDocsDir.toAbsolutePath().toString()
Expand Down
2 changes: 1 addition & 1 deletion solr/packaging/test/test_export.bats
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ teardown() {

@test "Check export command" {
run solr start -c -e techproducts
run solr export --solr-collection-url "http://localhost:${SOLR_PORT}/solr/techproducts" -query "*:* -id:test" -out "${BATS_TEST_TMPDIR}/output"
run solr export --solr-url http://localhost:${SOLR_PORT} --name techproducts -query "*:* -id:test" -out "${BATS_TEST_TMPDIR}/output"

refute_output --partial 'Unrecognized option'
assert_output --partial 'Export complete'
Expand Down
4 changes: 2 additions & 2 deletions solr/packaging/test/test_extraction.bats
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ teardown() {
}' "http://localhost:${SOLR_PORT}/solr/content_extraction/config"

# We filter to pdf to invoke the Extract handler.
run solr post --filetypes pdf -url http://localhost:${SOLR_PORT}/solr/content_extraction/update ${SOLR_TIP}/example/exampledocs
run solr post --filetypes pdf --solr-url http://localhost:${SOLR_PORT} --name content_extraction ${SOLR_TIP}/example/exampledocs

assert_output --partial '1 files indexed.'
refute_output --partial 'ERROR'
Expand All @@ -100,7 +100,7 @@ teardown() {
}' "http://localhost:${SOLR_PORT}/solr/website_extraction/config"

# Change to --recursive 1 to crawl multiple pages, but may be too slow.
run solr post --mode web --solr-update-url http://localhost:${SOLR_PORT}/solr/website_extraction/update --recursive 0 --delay 1 https://solr.apache.org/
run solr post --mode web --solr-url http://localhost:${SOLR_PORT} -c website_extraction --recursive 0 --delay 1 https://solr.apache.org/

assert_output --partial 'POSTed web resource https://solr.apache.org (depth: 0)'
refute_output --partial 'ERROR'
Expand Down
11 changes: 11 additions & 0 deletions solr/packaging/test/test_post.bats
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ teardown() {
refute_output --partial 'ERROR'
}

@test "basic post with solr-url and collection" {

run solr create -c monitors_solr_url_param -d _default
assert_output --partial "Created collection 'monitors_solr_url_param'"

run solr post --type application/xml -c monitors_solr_url_param --solr-url http://localhost:${SOLR_PORT} ${SOLR_TIP}/example/exampledocs/monitor.xml

assert_output --partial '1 files indexed.'
refute_output --partial 'ERROR'
}

@test "basic post WITHOUT a type specified" {

solr create -c monitors_no_type -d _default
Expand Down
2 changes: 1 addition & 1 deletion solr/packaging/test/test_snapshots.bats
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ teardown() {
run solr snapshot-create -c films --snapshot-name snapshot1 --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "Successfully created snapshot with name snapshot1 for collection films"

run solr snapshot-delete -c films --snapshot-name snapshot1 -url http://localhost:${SOLR_PORT}
run solr snapshot-delete -c films --snapshot-name snapshot1 --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "Successfully deleted snapshot with name snapshot1 for collection films"

# make sure you can create it again!
Expand Down
2 changes: 1 addition & 1 deletion solr/packaging/test/test_ssl.bats
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ teardown() {
run solr api -get "https://localhost:${SOLR2_PORT}/solr/test-single-shard/select?q=query4"
assert_output --partial '"numFound":0'

run solr post --solr-update-url https://localhost:${SOLR_PORT}/solr/test/update ${SOLR_TIP}/example/exampledocs/books.csv
run solr post --solr-url https://localhost:${SOLR_PORT} -c test ${SOLR_TIP}/example/exampledocs/books.csv

run solr api -get "https://localhost:${SOLR_PORT}/solr/test/select?q=*:*"
assert_output --partial '"numFound":10'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static void main(String[] args) {
Options mainOptions = new Options();
Options deprecatedOptions = new Options();

// Change to -s and --solr-url in main once -s for --scrape-interval removed.
// Change to -s and --solr-url in main once deprecated -s flag for --scrape-interval is removed.
Option baseUrlOption =
Option.builder("b")
.longOpt("base-url")
Expand Down Expand Up @@ -338,6 +338,7 @@ public static void main(String[] args) {
defaultClusterId = makeShortHash(zkHost);
scrapeConfiguration = SolrScrapeConfiguration.solrCloud(zkHost);
} else if (commandLine.hasOption(baseUrlOption) || commandLine.hasOption(baseUrlDepOption)) {
log.warn("-b and --base-url will be replaced with -s and --solr-url in Solr 10");
String baseUrl =
commandLine.hasOption(baseUrlOption)
? commandLine.getOptionValue(baseUrlOption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ Use `bin/solr post` to index some example documents to the SolrCloud collection

[source,console]
----
$ bin/solr post --solr-update-url https://localhost:8984/solr/mycollection/update example/exampledocs/*.xml
$ bin/solr post --solr-url https://localhost:8984 --name mycollection example/exampledocs/*.xml
----

=== Query Using curl
Expand Down
Loading

0 comments on commit ce4edd2

Please sign in to comment.