Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@
import org.apache.solr.JSONTestUtil;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Create;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Unload;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.MetricsRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.SolrQuery;
Expand Down Expand Up @@ -1143,8 +1146,8 @@ protected CollectionAdminResponse createCollection(
}
params.set("name", collectionName);
params.set("collection.configName", configSetName);
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
var request =
new GenericSolrRequest(METHOD.POST, "/admin/collections", SolrRequestType.ADMIN, params);

CollectionAdminResponse res = new CollectionAdminResponse();
if (client == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import java.util.Random;
import org.apache.solr.client.solrj.RemoteSolrException;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.Create;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.SplitShard;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.response.RequestStatusState;
import org.apache.solr.common.params.CollectionParams;
import org.apache.solr.common.params.ModifiableSolrParams;
Expand Down Expand Up @@ -322,8 +324,8 @@ public void run() {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", "collection1");
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
var request =
new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params);

client.request(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import java.util.Properties;
import org.apache.lucene.tests.util.LuceneTestCase.AwaitsFix;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
import org.apache.solr.client.solrj.impl.LBSolrClient;
import org.apache.solr.client.solrj.jetty.LBJettySolrClient;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
Expand Down Expand Up @@ -116,8 +118,8 @@ private void setUrlScheme(String value) throws Exception {
"val",
value);
SolrParams params = new MapSolrParams(m);
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
var request =
new GenericSolrRequest(METHOD.POST, "/admin/collections", SolrRequestType.ADMIN, params);

LBSolrClient.Endpoint[] urls =
getReplicas().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public void testBasicPhrases() throws Exception {
params("q", input, "phrases", "true"),
params("q", "*:*", "phrases.q", input, "phrases", "true"),
params("q", "-*:*", "phrases.q", input, "phrases", "true"))) {
final QueryRequest req = new QueryRequest(p);
req.setPath(path);
final QueryRequest req = new QueryRequest(path, p);
final QueryResponse rsp = req.process(getRandClient(random()));
try {
@SuppressWarnings({"unchecked"})
Expand Down Expand Up @@ -169,8 +168,7 @@ public void testEmptyInput() throws Exception {
Arrays.asList(
params("q", "*:*", "phrases.q", input, "phrases", "true"),
params("q", "-*:*", "phrases.q", input, "phrases", "true"))) {
final QueryRequest req = new QueryRequest(p);
req.setPath("/phrases");
final QueryRequest req = new QueryRequest("/phrases", p);
final QueryResponse rsp = req.process(getRandClient(random()));
try {
@SuppressWarnings({"unchecked"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ public void testSingleShardInFlightRequestsDuringShutDown() throws Exception {
final List<Future<QueryResponse>> results = new ArrayList<>(13);

try (SolrClient jettyClient = nodeToStop.newClient()) {
final QueryRequest req = new QueryRequest(params("q", "foo_s:aaa"));
req.setPath(handler);
final QueryRequest req = new QueryRequest(handler, params("q", "foo_s:aaa"));

// check inflight requests using both clients...
for (SolrClient client : Arrays.asList(cloudClient, jettyClient)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
import java.util.concurrent.atomic.AtomicReference;
import org.apache.solr.client.solrj.RemoteSolrException;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.SolrQuery;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.client.solrj.response.QueryResponse;
Expand Down Expand Up @@ -1269,8 +1271,8 @@ protected void splitShard(
if (splitKey != null) {
params.set("split.key", splitKey);
}
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
var request =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally when I see a GSR I think "We should be using one of our strongly typed OpenAPI classes" ;-). But in this case, I think it's better ;-).

new GenericSolrRequest(METHOD.POST, "/admin/collections", SolrRequestType.ADMIN, params);

JettySolrRunner jetty = shardToJetty.get(SHARD1).getFirst().jetty;
try (SolrClient baseServer = jetty.newClient(30_000, 300_000)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.util.List;
import java.util.Map;
import org.apache.solr.client.solrj.RemoteSolrException;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.response.RequestStatusState;
import org.apache.solr.cloud.BasicDistributedZkTest;
import org.apache.solr.common.params.CollectionParams;
Expand Down Expand Up @@ -225,8 +227,8 @@ private NamedList<Object> sendStatusRequestWithRetry(ModifiableSolrParams params

protected NamedList<Object> sendRequest(ModifiableSolrParams params)
throws SolrServerException, IOException {
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
var request =
new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params);

return shardToJetty.get(SHARD1).getFirst().jetty.getSolrClient().request(request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void testFullStackTrace() throws Exception {
public void testRemoteSolrException() {
var client = solrTestRule.getSolrClient("collection1");
QueryRequest queryRequest =
new QueryRequest(new ModifiableSolrParams().set("q", "*:*").set("wt", "json"));
queryRequest.setPath("/withError");
new QueryRequest(
"/withError", new ModifiableSolrParams().set("q", "*:*").set("wt", "json"));
RemoteSolrException exception =
expectThrows(RemoteSolrException.class, () -> queryRequest.process(client, "collection1"));
assertTrue(exception.getRemoteErrorObject() instanceof NamedList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.solr.client.api.model.CoreStatusResponse;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.json.JacksonContentWriter;
import org.apache.solr.cloud.AbstractFullDistribZkTestBase;
import org.apache.solr.common.cloud.SolrZkClient;
Expand Down Expand Up @@ -54,8 +56,7 @@ protected String getCloudSolrConfig() {
public void test() throws Exception {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.STATUS.toString());
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/cores");
var request = new GenericSolrRequest(METHOD.GET, "/admin/cores", SolrRequestType.ADMIN, params);
int which = r.nextInt(clients.size());

// use a client that does not have the /collection1 as part of the URL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ public void assertJQ(SolrClient client, SolrParams args, String... tests)
throws Exception {
QueryRequest query = new QueryRequest(args);
query.setResponseParser(new SmileResponseParser());
String path = args.get("qt");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love seeing another qt bite the dust.

if (path != null) {
query.setPath(path);
}
NamedList<Object> rsp = client.request(query);
@SuppressWarnings({"rawtypes"})
Map m = rsp.asMap(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ private static void ensureFieldHasValues(
final ModifiableSolrParams solrParams = new ModifiableSolrParams();
solrParams.set("id", identifyingDocId);
solrParams.set("shards.preference", "replica.leader:" + tf);
QueryRequest request = new QueryRequest(solrParams);
request.setPath("/get");
QueryRequest request = new QueryRequest("/get", solrParams);
final QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION);

final NamedList<Object> rawResponse = response.getResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ private void ensureFieldHasValues(
String identifyingDocId, String fieldName, Object... expectedValues) throws Exception {
final ModifiableSolrParams solrParams = new ModifiableSolrParams();
solrParams.set("id", identifyingDocId);
QueryRequest request = new QueryRequest(solrParams);
request.setPath("/get");
QueryRequest request = new QueryRequest("/get", solrParams);
final QueryResponse response = request.process(cluster.getSolrClient(), COLLECTION);

final NamedList<Object> rawResponse = response.getResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public void distributedRerankCutoffScore_shouldBeReturnedForShardsWithHits() thr
final SolrQuery query = newBaseRerankQuery();
query.add("rq", "{!ltr model=powpularityS-model reRankDocs=3 echoReRankCutoff=true}");

final QueryRequest queryRequest = new QueryRequest(query);
queryRequest.setPath("/query");
final QueryRequest queryRequest = new QueryRequest("/query", query);
final QueryResponse queryResponse =
queryRequest.process(solrCluster.getSolrClient(), COLLECTION);

Expand All @@ -72,8 +71,7 @@ public void distributedRerankCutoffScore_defaultShouldNotBeReturnedPerShard() th
final SolrQuery query = newBaseRerankQuery();
query.add("rq", "{!ltr model=powpularityS-model reRankDocs=3}");

final QueryRequest queryRequest = new QueryRequest(query);
queryRequest.setPath("/query");
final QueryRequest queryRequest = new QueryRequest("/query", query);
final QueryResponse queryResponse =
queryRequest.process(solrCluster.getSolrClient(), COLLECTION);
assertNull(
Expand All @@ -87,8 +85,7 @@ public void distributedRerankCutoffScore_falseShouldNotBeReturnedPerShard() thro
final SolrQuery query = newBaseRerankQuery();
query.add("rq", "{!ltr model=powpularityS-model reRankDocs=3 echoReRankCutoff=false}");

final QueryRequest queryRequest = new QueryRequest(query);
queryRequest.setPath("/query");
final QueryRequest queryRequest = new QueryRequest("/query", query);
final QueryResponse queryResponse =
queryRequest.process(solrCluster.getSolrClient(), COLLECTION);
assertNull(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public void testTermsComponentRequest() throws Exception {
termsQuery.addTermsField("name");
termsQuery.setTermsMinCount(1);

final QueryRequest request = new QueryRequest(termsQuery);
request.setPath("/terms");
final QueryRequest request = new QueryRequest("/terms", termsQuery);
final List<Term> terms =
request
.process(cluster.getSolrClient(), COLLECTION_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.InputStreamResponseParser;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.noggit.JSONParser;
Expand All @@ -53,16 +52,8 @@ public JSONTupleStream(Reader reader) {
// temporary...
public static JSONTupleStream create(SolrClient server, SolrParams requestParams)
throws IOException, SolrServerException {
String p = requestParams.get("qt");
if (p != null) {
ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams;
modifiableSolrParams.remove("qt");
}

QueryRequest query = new QueryRequest(requestParams);
query.setPath(p);
QueryRequest query = new QueryRequest(requestParams, SolrRequest.METHOD.POST);
query.setResponseParser(new InputStreamResponseParser("json"));
query.setMethod(SolrRequest.METHOD.POST);
NamedList<Object> genericResponse = server.request(query);
InputStream stream = (InputStream) genericResponse.get(InputStreamResponseParser.STREAM_KEY);
InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,34 +270,19 @@ private <V> Map<String, V> mapFields(Map<String, V> fields, Map<String, String>

private TupleStreamParser constructParser(SolrParams requestParams)
throws IOException, SolrServerException {
String p = requestParams.get("qt");
if (p != null) {
ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams;
modifiableSolrParams.remove("qt");
// performance optimization - remove extra whitespace by default when streaming
modifiableSolrParams.set("indent", modifiableSolrParams.get("indent", "off"));
}
// performance optimization - remove extra whitespace when streaming
requestParams = SolrParams.wrapDefaults(requestParams, SolrParams.of("indent", "off"));

QueryRequest query = new QueryRequest(requestParams, SolrRequest.METHOD.POST);
String wt = requestParams.get(CommonParams.WT, "json");
QueryRequest query = new QueryRequest(requestParams);

// in order to reuse HttpSolrClient objects per node, we need to cache them without the core
// name in the URL
if (core != null) {
query.setPath("/" + core + (p != null ? p : "/select"));
} else {
query.setPath(p);
}

query.setResponseParser(new InputStreamResponseParser(wt));
query.setMethod(SolrRequest.METHOD.POST);

if (user != null && password != null) {
query.setBasicAuthCredentials(user, password);
}

var client = clientCache.getHttpSolrClient(baseUrl);
NamedList<Object> genericResponse = client.request(query);
NamedList<Object> genericResponse = client.request(query, core);
InputStream stream = (InputStream) genericResponse.get(InputStreamResponseParser.STREAM_KEY);
// since 9.4 the updated format has a dedicated status field
final Integer statusCode = (Integer) genericResponse.get("responseStatus");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1244,8 +1244,7 @@ public void testGraphHandler() throws Exception {
+ "gather=\"to_s\"))";

params.add("expr", expr);
QueryRequest query = new QueryRequest(params);
query.setPath("/collection1/graph");
QueryRequest query = new QueryRequest("/collection1/graph", params);

query.setResponseParser(new InputStreamResponseParser("xml"));
query.setMethod(SolrRequest.METHOD.POST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public UpdateRequest() {
super(METHOD.POST, "/update");
}

public UpdateRequest(String url) {
super(METHOD.POST, url);
public UpdateRequest(String path) {
super(METHOD.POST, path);
}

/** clear the pending documents and delete commands */
Expand Down Expand Up @@ -250,11 +250,10 @@ private Map<String, LBSolrClient.Req> getRoutes(
String leaderUrl = urls.get(0);
LBSolrClient.Req request = routes.get(leaderUrl);
if (request == null) {
UpdateRequest updateRequest = new UpdateRequest();
UpdateRequest updateRequest = new UpdateRequest(getPath());
updateRequest.setMethod(getMethod());
updateRequest.setCommitWithin(getCommitWithin());
updateRequest.setParams(params);
updateRequest.setPath(getPath());
updateRequest.setBasicAuthCredentials(getBasicAuthUser(), getBasicAuthPassword());
updateRequest.setResponseParser(getResponseParser());
updateRequest.addHeaders(getHeaders());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2337,8 +2337,7 @@ public void testRealtimeGet() throws Exception {
q.set("fl", "id,name,aaa:[value v=aaa]");

// First Try with the BinaryResponseParser
QueryRequest req = new QueryRequest(q);
req.setPath("/get");
QueryRequest req = new QueryRequest("/get", q);
req.setResponseParser(new JavaBinResponseParser());
QueryResponse rsp = req.process(client);
SolrDocument out = (SolrDocument) rsp.getResponse().get("doc");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.commons.io.file.PathUtils;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
import org.apache.solr.client.solrj.embedded.AbstractEmbeddedSolrServerTestCase;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Create;
import org.apache.solr.client.solrj.request.CoreAdminRequest.RequestRecovery;
Expand Down Expand Up @@ -110,8 +112,8 @@ public void testErrorCases() {
params.set("action", "BADACTION");
String collectionName = "badactioncollection";
params.set("name", collectionName);
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/cores");
var request =
new GenericSolrRequest(METHOD.POST, "/admin/cores", SolrRequestType.ADMIN, params);
expectThrows(SolrException.class, () -> getSolrAdmin().request(request));
}

Expand Down
Loading
Loading