You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ep...@apache.org on 2024/07/19 10:25:58 UTC
(solr) branch main updated: SOLR-17367 - org.apache.solr.cli.PostTool is ignoring -params option (#2557)
This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 1084db9477e SOLR-17367 - org.apache.solr.cli.PostTool is ignoring -params option (#2557)
1084db9477e is described below
commit 1084db9477ec33cbe228f44c82e8612dc051222d
Author: bogdanstoik <bo...@gmail.com>
AuthorDate: Fri Jul 19 13:25:53 2024 +0300
SOLR-17367 - org.apache.solr.cli.PostTool is ignoring -params option (#2557)
---------
Co-authored-by: Eric Pugh <ep...@opensourceconnections.com>
---
solr/CHANGES.txt | 2 +
.../src/java/org/apache/solr/cli/PostTool.java | 11 ++++++
.../src/test/org/apache/solr/cli/PostToolTest.java | 46 ++++++++++++++++++++++
3 files changed, 59 insertions(+)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 51c8655f67f..b18f53d3dad 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -202,6 +202,8 @@ Bug Fixes
* SOLR-17333: Rate-limiting feature: fix live-update of config (Michael Gibney)
+* SOLR-17367: Restore the use of -params option to PostTool. (Bostoi via Eric Pugh)
+
Dependency Upgrades
---------------------
(No changes)
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 93286d427fc..9c81486906f 100644
--- a/solr/core/src/java/org/apache/solr/cli/PostTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/PostTool.java
@@ -108,6 +108,7 @@ public class PostTool extends ToolBase {
boolean dryRun; // Avoids actual network traffic to Solr
String[] args;
+ String params;
boolean auto = true;
private int currentDepth;
@@ -311,6 +312,8 @@ public class PostTool extends ToolBase {
args = cli.getArgs();
+ params = cli.getOptionValue("params", "");
+
execute(mode);
}
@@ -911,6 +914,14 @@ public class PostTool extends ToolBase {
return true;
}
+ if (params.length() > 0) {
+ try {
+ uri = new URI(appendParam(uri.toString(), params));
+ } catch (URISyntaxException e) {
+ warn("Malformed params");
+ }
+ }
+
boolean success = true;
if (type == null) {
type = DEFAULT_CONTENT_TYPE;
diff --git a/solr/core/src/test/org/apache/solr/cli/PostToolTest.java b/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
index 862c48363de..1f507b281b5 100644
--- a/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
@@ -147,6 +147,52 @@ public class PostToolTest extends SolrCloudTestCase {
assertEquals("*:* found unexpected number of documents", expectedDocCount, numFound);
}
+ @Test
+ public void testRunCsvWithCustomSeparatorParam() throws Exception {
+ final String collection = "testRunCsvWithCustomSeparatorParam";
+
+ // Provide the port for the PostTool to look up.
+ EnvUtils.setProperty("jetty.port", cluster.getJettySolrRunner(0).getLocalPort() + "");
+
+ withBasicAuth(CollectionAdminRequest.createCollection(collection, "conf1", 1, 1, 0, 0))
+ .processAndWait(cluster.getSolrClient(), 10);
+
+ File tsvDoc = File.createTempFile("temp", ".tsv");
+
+ FileWriter fw = new FileWriter(tsvDoc, StandardCharsets.UTF_8);
+ fw.write("1\tmytitle\n");
+ fw.close();
+
+ String[] args = {
+ "post",
+ "-c",
+ collection,
+ "-credentials",
+ SecurityJson.USER_PASS,
+ "--params",
+ "\"separator=%09&header=false&fieldnames=id,title_s\"",
+ "--type",
+ "text/csv",
+ tsvDoc.getAbsolutePath()
+ };
+ assertEquals(0, runTool(args));
+
+ int numFound = 0;
+ int expectedDocCount = 1;
+
+ for (int idx = 0; idx < 100; ++idx) {
+ QueryRequest req = withBasicAuth(new QueryRequest(params("q", "*:*")));
+ QueryResponse rsp = req.process(cluster.getSolrClient(), collection);
+
+ numFound = (int) rsp.getResults().getNumFound();
+ if (numFound == expectedDocCount) {
+ break;
+ }
+ Thread.sleep(100);
+ }
+ assertEquals("*:* found unexpected number of documents", expectedDocCount, numFound);
+ }
+
private int runTool(String[] args) throws Exception {
Tool tool = findTool(args);
assertTrue(tool instanceof PostTool);