Skip to content

Commit

Permalink
SOLR-17068: Resolve mish mash of bin/post and bin/solr post reference…
Browse files Browse the repository at this point in the history
…s in favour of bin/solr post. (#2227)

* update various examples to use bin/solr post instead of bin/post.

* Restore the -c parameter to the post tool, and ensure it picks up default urls settings if specified.

* Remove special text about how to use tool on Windows as no longer needed

* move all our docker testing and actual docker scripts to using bin/solr post command instead of bin/post
  • Loading branch information
epugh committed Feb 2, 2024
1 parent e8ac06e commit f612313
Show file tree
Hide file tree
Showing 34 changed files with 189 additions and 84 deletions.
4 changes: 4 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Improvements
* SOLR-16397: The v2 endpoint to request the status of asynchronous CoreAdmin commands has been updated to be more REST-ful.
Now available at `GET /api/node/commands/someRequestId` (Sanjay Dutt via Jason Gerlowski)

* SOLR-17068: bin/solr post CLI use of options is now aligned closely with bin/post CLI tool, and is consistently
referenced throughout the Ref Guide and source code, and is used through out our tests. The bin/post tool
remains and has been tested to work. (Eric Pugh)

Optimizations
---------------------
* SOLR-17084: LBSolrClient (used by CloudSolrClient) now returns the count of core tracked as not live AKA zombies
Expand Down
22 changes: 19 additions & 3 deletions solr/core/src/java/org/apache/solr/cli/PostTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ public List<Option> getOptions() {
Option.builder("url")
.argName("url")
.hasArg()
.required(true)
.required(false)
.desc("<base Solr update URL>")
.build(),
Option.builder("c")
.longOpt("name")
.argName("NAME")
.hasArg()
.required(false)
.desc("Name of the collection.")
.build(),
Option.builder("commit").required(false).desc("Issue a commit at end of post").build(),
Option.builder("optimize").required(false).desc("Issue an optimize at end of post").build(),
Option.builder("mode")
Expand Down Expand Up @@ -101,8 +108,17 @@ public List<Option> getOptions() {
public void runImpl(CommandLine cli) throws Exception {
SolrCLI.raiseLogLevelUnlessVerbose(cli);

String url = cli.getOptionValue("url");
URL solrUrl = new URL(url);
URL solrUrl = null;
if (cli.hasOption("url")) {
String url = cli.getOptionValue("url");
solrUrl = new URL(url);
} else if (cli.hasOption("c")) {
String url = SolrCLI.getDefaultSolrUrl() + "/solr/" + cli.getOptionValue("c") + "/update";
solrUrl = new URL(url);
} else {
throw new IllegalArgumentException(
"Must specify either -url or -c parameter to post documents.");
}

String mode = SimplePostTool.DEFAULT_DATA_MODE;
if (cli.hasOption("mode")) {
Expand Down
28 changes: 27 additions & 1 deletion solr/core/src/java/org/apache/solr/cli/SolrCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,33 @@ public static String uptime(long uptimeMs) {
OPTION_VERBOSE);

/**
* Get the base URL of a live Solr instance from either the solrUrl command-line option from
* Strips off the end of solrUrl any /solr when a legacy solrUrl like http://localhost:8983/solr
* is used, and warns those users. In the future we'll have urls ending with /api as well.
*
* @param solrUrl The user supplied url to Solr.
* @return the solrUrl in the format that Solr expects to see internally.
*/
public static String normalizeSolrUrl(String solrUrl) {
if (solrUrl != null) {
if (solrUrl.contains("/solr")) { //
String newSolrUrl = solrUrl.substring(0, solrUrl.indexOf("/solr"));
CLIO.out(
"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 ["
+ newSolrUrl
+ "].");
solrUrl = newSolrUrl;
}
if (solrUrl.endsWith("/")) {
solrUrl = solrUrl.substring(0, solrUrl.length() - 1);
}
}
return solrUrl;
}

/**
* Get the base URL of a live Solr instance from either the solrUrl command-line option or from
* ZooKeeper.
*/
public static String resolveSolrUrl(CommandLine cli) throws Exception {
Expand Down
74 changes: 66 additions & 8 deletions solr/core/src/test/org/apache/solr/cli/PostToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,84 @@
import org.apache.commons.cli.CommandLine;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.common.util.Utils;
import org.apache.solr.security.BasicAuthPlugin;
import org.apache.solr.security.RuleBasedAuthorizationPlugin;
import org.junit.BeforeClass;
import org.junit.Test;

public class PostToolTest extends SolrCloudTestCase {

@BeforeClass
public static void setupCluster() throws Exception {
configureCluster(1)
.addConfig(
"config", TEST_PATH().resolve("configsets").resolve("cloud-minimal").resolve("conf"))
public static void setupClusterWithSecurityEnabled() throws Exception {
final String SECURITY_JSON =
Utils.toJSONString(
Map.of(
"authorization",
Map.of(
"class",
RuleBasedAuthorizationPlugin.class.getName(),
"user-role",
singletonMap(USER, "admin"),
"permissions",
singletonList(Map.of("name", "all", "role", "admin"))),
"authentication",
Map.of(
"class",
BasicAuthPlugin.class.getName(),
"blockUnknown",
true,
"credentials",
singletonMap(USER, getSaltedHashedValue(PASS)))));

configureCluster(2)
.addConfig("conf1", configset("cloud-minimal"))
.withSecurityJson(SECURITY_JSON)
.configure();
}

@Test
public void testBasicRun() throws Exception {
final String collection = "aliasedCollection";
CollectionAdminRequest.createCollection(collection, "config", 1, 1)
.process(cluster.getSolrClient());
final String collection = "testBasicRun";

withBasicAuth(CollectionAdminRequest.createCollection(collection, "conf1", 1, 1, 0, 0))
.processAndWait(cluster.getSolrClient(), 10);

File jsonDoc = File.createTempFile("temp", ".json");

FileWriter fw = new FileWriter(jsonDoc, StandardCharsets.UTF_8);
Utils.writeJson(Utils.toJSONString(Map.of("id", "1", "title", "mytitle")), fw, true);

String[] args = {
"post",
"-url",
cluster.getJettySolrRunner(0).getBaseUrl() + "/" + collection + "/update",
"-credentials",
USER + ":" + PASS,
jsonDoc.getAbsolutePath()
};
assertEquals(0, runTool(args));
}

@Test
public void testRunWithCollectionParam() throws Exception {
final String collection = "testRunWithCollectionParam";

// Provide the port as an environment variable for the PostTool to look up.
EnvUtils.setEnv("SOLR_PORT", cluster.getJettySolrRunner(0).getLocalPort() + "");

withBasicAuth(CollectionAdminRequest.createCollection(collection, "conf1", 1, 1, 0, 0))
.processAndWait(cluster.getSolrClient(), 10);

File jsonDoc = File.createTempFile("temp", "json");

FileWriter fw = new FileWriter(jsonDoc, StandardCharsets.UTF_8);
Utils.writeJson(Utils.toJSONString(Map.of("id", "1", "title", "mytitle")), fw, true);

String[] args = {"post", "-url", "http://localhost:8983/solr/aliasedCollection", "blah.json"};
String[] args = {
"post", "-c", collection, "-credentials", USER + ":" + PASS, jsonDoc.getAbsolutePath()
};
assertEquals(0, runTool(args));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
import org.slf4j.LoggerFactory;

/**
* Emulates bin/solr -e cloud -noprompt; bin/post -c gettingstarted example/exampledocs/*.xml; this
* test is useful for catching regressions in indexing the example docs in collections that use data
* driven functionality and managed schema features of the default configset (configsets/_default).
* Emulates bin/solr start -e cloud -noprompt; bin/solr post -c gettingstarted
* example/exampledocs/*.xml; this test is useful for catching regressions in indexing the example
* docs in collections that use data driven functionality and managed schema features of the default
* configset (configsets/_default).
*/
public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {

Expand Down Expand Up @@ -114,7 +115,7 @@ public void testLoadDocsIntoGettingStartedCollection() throws Exception {
invalidToolExitStatus,
tool.runTool(cli));

// now index docs like bin/post would, but we can't use SimplePostTool because it uses
// now index docs like bin/solr post would, but we can't use SimplePostTool because it uses
// System.exit when it encounters an error, which JUnit doesn't like ...
log.info("Created collection, now posting example docs!");
Path exampleDocsDir = Path.of(ExternalPaths.SOURCE_HOME, "example", "exampledocs");
Expand Down
10 changes: 3 additions & 7 deletions solr/docker/scripts/solr-demo
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,9 @@ else
/opt/solr/bin/solr create -c "$CORE"
echo "Created $CORE"
echo "Loading example data"
post_args=()
if [[ -n "${SOLR_PORT:-}" ]]; then
post_args+=(-p "$SOLR_PORT")
fi
/opt/solr/bin/post "${post_args[@]}" -c $CORE -commit no example/exampledocs/*.xml
/opt/solr/bin/post "${post_args[@]}" -c $CORE -commit no example/exampledocs/books.json
/opt/solr/bin/post "${post_args[@]}" -c $CORE -commit yes example/exampledocs/books.csv
/opt/solr/bin/solr post -c $CORE -commit no example/exampledocs/*.xml
/opt/solr/bin/solr post -c $CORE -commit no example/exampledocs/books.json
/opt/solr/bin/solr post -c $CORE -commit yes example/exampledocs/books.csv
echo "Loaded example data"
stop-local-solr

Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/create_core/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ docker run --name "$container_name" -d "$tag" solr-create -c gettingstarted
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c gettingstarted example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c gettingstarted -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/gettingstarted/select?q=id%3Adell')
Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/create_core_exec/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ wait_for_container_and_solr "$container_name"
echo "Creating core"
docker exec --user=solr "$container_name" bin/solr create_core -c gettingstarted
echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c gettingstarted example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c gettingstarted -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/gettingstarted/select?q=id%3Adell')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ docker run --user 7777:0 --name "$container_name" -d "$tag" solr-create -c getti
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c gettingstarted example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c gettingstarted -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/gettingstarted/select?q=id%3Adell')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ docker run \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c getting-started example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c getting-started -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/getting-started/select?q=id%3Adell')
Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/empty-varsolr-dir-solr/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ docker run \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c getting-started example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c getting-started -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/getting-started/select?q=id%3Adell')
Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/empty-varsolr-dir-user/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ docker run \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c getting-started example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c getting-started -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/getting-started/select?q=id%3Adell')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ docker run \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c getting-started example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c getting-started -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/getting-started/select?q=id%3Adell')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ docker run \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c getting-started example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c getting-started -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/getting-started/select?q=id%3Adell')
Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/empty-varsolr-vol-solr/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ docker run \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c getting-started example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c getting-started -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/getting-started/select?q=id%3Adell')
Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/empty-varsolr-vol-user/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ docker run \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c getting-started example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c getting-started -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/getting-started/select?q=id%3Adell')
Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/gosu/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ docker run --user 0:0 --name "$container_name" -d -e VERBOSE=yes \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c gettingstarted example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c gettingstarted -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/gettingstarted/select?q=id%3Adell')
Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/precreate_core/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ docker run --name "$container_name" -d -e VERBOSE=yes "$tag" solr-precreate gett
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c gettingstarted example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c gettingstarted -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/gettingstarted/select?q=id%3Adell')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ docker run \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c gettingstarted example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c gettingstarted -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/gettingstarted/select?q=id%3Adell')
Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/test_log4j/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ docker run --name "$container_name" -d -e VERBOSE=yes \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c gettingstarted example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c gettingstarted -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/gettingstarted/select?q=id%3Adell')
Expand Down
2 changes: 1 addition & 1 deletion solr/docker/tests/cases/user_volume/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ docker run \
wait_for_container_and_solr "$container_name"

echo "Loading data"
docker exec --user=solr "$container_name" bin/post -c mycore example/exampledocs/manufacturers.xml
docker exec --user=solr "$container_name" bin/solr post -c mycore -commit example/exampledocs/manufacturers.xml
sleep 1
echo "Checking data"
data=$(docker exec --user=solr "$container_name" wget -q -O - 'http://localhost:8983/solr/mycore/select?q=id%3Adell')
Expand Down
4 changes: 2 additions & 2 deletions solr/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ After starting a Solr example, direct your Web browser to:
http://localhost:8983/solr/
```

To add documents to the index, use bin/post, for example:
To add documents to the index, use bin/solr post, for example:

```
bin/post -c techproducts example/exampledocs/*.xml
bin/solr post -c techproducts example/exampledocs/*.xml
```

(where "techproducts" is the Solr core name)
Expand Down
3 changes: 1 addition & 2 deletions solr/example/exampledocs/utf8-example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<!--
After posting this to Solr with bin/post, searching for "êâîôû" from
After posting this to Solr with bin/solr post, searching for "êâîôû" from
the solr/admin/ search page must return this document.
-->

Expand All @@ -39,4 +39,3 @@
<field name="inStock">true</field>
</doc>
</add>

Loading

0 comments on commit f612313

Please sign in to comment.