Skip to content

Introduce GenericCollectionRequest #3423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions solr/core/src/java/org/apache/solr/cli/ExportTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import org.apache.solr.client.solrj.impl.ClusterStateProvider;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.impl.StreamingJavaBinResponseParser;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.GenericCollectionRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
Expand Down Expand Up @@ -253,11 +253,12 @@ void fetchUniqueKey() throws SolrServerException, IOException {
.build();
NamedList<Object> response =
solrClient.request(
new GenericSolrRequest(
SolrRequest.METHOD.GET,
"/schema/uniquekey",
SolrParams.of("collection", coll))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't love that collection param; moved to the request path

.setRequiresCollection(true));
new GenericCollectionRequest(
SolrRequest.METHOD.GET,
"/schema/uniquekey",
SolrRequest.SolrRequestType.ADMIN,
SolrParams.of()),
coll);
uniqueKey = (String) response.get("uniqueKey");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import org.apache.solr.client.solrj.impl.JavaBinResponseParser;
import org.apache.solr.client.solrj.impl.JsonMapResponseParser;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.GenericCollectionRequest;
import org.apache.solr.client.solrj.request.schema.FieldTypeDefinition;
import org.apache.solr.client.solrj.request.schema.SchemaRequest;
import org.apache.solr.client.solrj.response.schema.SchemaResponse;
Expand All @@ -78,6 +78,7 @@
import org.apache.solr.common.cloud.ZkMaintenanceUtils;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.IOUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
Expand Down Expand Up @@ -126,9 +127,13 @@ Map<String, Object> analyzeField(String configSet, String fieldName, String fiel
solrParams.set("analysis.showmatch", true);
solrParams.set("analysis.fieldname", fieldName);
solrParams.set("analysis.fieldvalue", "POST");
var request = new GenericSolrRequest(SolrRequest.METHOD.POST, "/analysis/field", solrParams);
var request =
new GenericCollectionRequest(
SolrRequest.METHOD.POST,
"/analysis/field",
SolrRequest.SolrRequestType.ADMIN,
solrParams);
request.withContent(fieldText.getBytes(StandardCharsets.UTF_8), "text/plain");
request.setRequiresCollection(true);
request.setResponseParser(new JsonMapResponseParser());
try {
var resp = request.process(cloudClient(), mutableId).getResponse();
Expand Down Expand Up @@ -483,8 +488,12 @@ void deleteStoredSampleDocs(String configSet) {

@SuppressWarnings("unchecked")
List<SolrInputDocument> getStoredSampleDocs(final String configSet) throws IOException {
var request = new GenericSolrRequest(SolrRequest.METHOD.GET, "/blob/" + configSet + "_sample");
request.setRequiresCollection(true);
var request =
new GenericCollectionRequest(
SolrRequest.METHOD.GET,
"/blob/" + configSet + "_sample",
SolrRequest.SolrRequestType.ADMIN,
SolrParams.of());
request.setResponseParser(new InputStreamResponseParser("filestream"));
InputStream inputStream = null;
try {
Expand Down Expand Up @@ -515,9 +524,13 @@ static byte[] readAllBytes(IOSupplier<InputStream> hasStream) throws IOException

protected void postDataToBlobStore(CloudSolrClient cloudClient, String blobName, byte[] bytes)
throws IOException {
var request = new GenericSolrRequest(SolrRequest.METHOD.POST, "/blob/" + blobName);
var request =
new GenericCollectionRequest(
SolrRequest.METHOD.POST,
"/blob/" + blobName,
SolrRequest.SolrRequestType.ADMIN,
SolrParams.of());
request.withContent(bytes, JavaBinResponseParser.JAVABIN_CONTENT_TYPE);
request.setRequiresCollection(true);
try {
request.process(cloudClient, BLOB_STORE_ID);
} catch (SolrServerException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.response.SimpleSolrResponse;
import org.apache.solr.client.solrj.request.GenericCollectionRequest;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.SolrInputDocument;
Expand Down Expand Up @@ -681,8 +680,8 @@ private UpdateCommand fetchFullUpdateFromLeader(AddUpdateCommand inplaceAdd, lon
params.set(DISTRIB, false);
params.set("getInputDocument", id);
params.set("onlyIfActive", true);
SolrRequest<SimpleSolrResponse> ur =
new GenericSolrRequest(METHOD.GET, "/get", params).setRequiresCollection(true);
var ur =
new GenericCollectionRequest(METHOD.GET, "/get", SolrRequest.SolrRequestType.ADMIN, params);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

making the request type mandatory; force you to think about it. RTG is used for internal purposes; maybe QUERY would get throttled? Or maybe not; I recall the rate limiter would ignore internal requests. LBSolrClient should retry a QUERY but not ADMIN; maybe this should be QUERY.


String leaderUrl = getLeaderUrl(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,6 @@ private void clusterStatusAliasTest() throws Exception {
params.set("collection", "notAnAliasOrCollection");
request =
new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params);
request.setPath("/admin/collections");

// SOLR-12938 - this should still cause an exception
try {
Expand Down Expand Up @@ -1258,11 +1257,10 @@ private Map<String, String> getProps(
private void missingParamsError(CloudSolrClient client, ModifiableSolrParams origParams)
throws IOException, SolrServerException {

GenericSolrRequest request;
try {
request =
var request =
new GenericSolrRequest(
METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, origParams);
METHOD.POST, "/admin/collections", SolrRequestType.ADMIN, origParams);
client.request(request);
fail("Should have thrown a SolrException due to lack of a required parameter.");
} catch (SolrException se) {
Expand Down Expand Up @@ -1352,7 +1350,7 @@ public void testCreateCollectionBooleanValues() throws Exception {
params.set("numShards", "1");
params.set(CollectionAdminParams.PER_REPLICA_STATE, "False");
var request =
new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params);
new GenericSolrRequest(METHOD.POST, "/admin/collections", SolrRequestType.ADMIN, params);

try {
client.request(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.CoresApi;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.GenericCollectionRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
Expand Down Expand Up @@ -1556,12 +1556,12 @@ public void testEmptyBackups() throws Exception {

{ // initial request w/o any committed docs
final String backupName = "empty_backup1";
final GenericSolrRequest req =
new GenericSolrRequest(
SolrRequest.METHOD.GET,
"/replication",
params("command", "backup", "location", backupDir.toString(), "name", backupName))
.setRequiresCollection(true);
final GenericCollectionRequest req =
new GenericCollectionRequest(
SolrRequest.METHOD.POST,
"/replication",
SolrRequest.SolrRequestType.ADMIN,
params("command", "backup", "location", backupDir.toString(), "name", backupName));
final TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME);
final SimpleSolrResponse rsp = req.process(leaderClient);

Expand All @@ -1579,12 +1579,12 @@ public void testEmptyBackups() throws Exception {

{ // second backup w/uncommitted doc
final String backupName = "empty_backup2";
final GenericSolrRequest req =
new GenericSolrRequest(
SolrRequest.METHOD.GET,
"/replication",
params("command", "backup", "location", backupDir.toString(), "name", backupName))
.setRequiresCollection(true);
final GenericCollectionRequest req =
new GenericCollectionRequest(
SolrRequest.METHOD.POST,
"/replication",
SolrRequest.SolrRequestType.ADMIN,
params("command", "backup", "location", backupDir.toString(), "name", backupName));
final TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME);
final SimpleSolrResponse rsp = req.process(leaderClient);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
import org.apache.lucene.tests.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.GenericCollectionRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.UpdateResponse;
Expand Down Expand Up @@ -133,9 +135,12 @@ public void testReplicationHandler() throws Exception {
final BackupStatusChecker backupStatus = new BackupStatusChecker(coreClient);

/** no solrj API for ReplicationHandler */
private GenericSolrRequest makeReplicationReq(SolrParams p) {
return new GenericSolrRequest(GenericSolrRequest.METHOD.GET, "/replication", p)
.setRequiresCollection(true);
private SolrRequest<?> makeReplicationReq(SolrParams p) {
return new GenericCollectionRequest(
GenericSolrRequest.METHOD.POST,
"/replication",
SolrRequest.SolrRequestType.ADMIN,
p);
}

/**
Expand Down
22 changes: 12 additions & 10 deletions solr/core/src/test/org/apache/solr/pkg/TestPackages.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.solr.client.solrj.impl.BaseHttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.GenericCollectionRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.RequestWriter;
import org.apache.solr.client.solrj.request.UpdateRequest;
Expand Down Expand Up @@ -292,12 +293,12 @@ public void testPluginLoading() throws Exception {
TestDistribFileStore.assertResponseValues(
10,
cluster.getSolrClient(),
new GenericSolrRequest(
SolrRequest.METHOD.GET,
"/stream",
new MapSolrParams(
Map.of("collection", COLLECTION_NAME, WT, JAVABIN, "action", "plugins")))
.setRequiresCollection(true),
new GenericCollectionRequest(
SolrRequest.METHOD.GET,
"/stream",
SolrRequest.SolrRequestType.ADMIN,
new MapSolrParams(
Map.of("collection", COLLECTION_NAME, WT, JAVABIN, "action", "plugins"))),
Map.of(":plugins:mincopy", "org.apache.solr.client.solrj.io.stream.metrics.MinCopyMetric"));

UpdateRequest ur = new UpdateRequest();
Expand Down Expand Up @@ -567,13 +568,14 @@ private void verifyComponent(
"meta",
"true"));

GenericSolrRequest req1 =
new GenericSolrRequest(SolrRequest.METHOD.GET, "/config/" + componentType, params)
.setRequiresCollection(true);
TestDistribFileStore.assertResponseValues(
10,
client,
req1,
new GenericCollectionRequest(
SolrRequest.METHOD.GET,
"/config/" + componentType,
SolrRequest.SolrRequestType.ADMIN,
params),
Map.of(
":config:" + componentType + ":" + componentName + ":_packageinfo_:package", pkg,
":config:" + componentType + ":" + componentName + ":_packageinfo_:version", version));
Expand Down
21 changes: 12 additions & 9 deletions solr/core/src/test/org/apache/solr/search/TestTaskManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.GenericCollectionRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.SolrInputDocument;
Expand Down Expand Up @@ -106,9 +106,9 @@ public void testNonExistentQuery() throws Exception {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("queryUUID", "foobar");

GenericSolrRequest request =
new GenericSolrRequest(SolrRequest.METHOD.GET, "/tasks/cancel", params)
.setRequiresCollection(true);
var request =
new GenericCollectionRequest(
SolrRequest.METHOD.GET, "/tasks/cancel", SolrRequest.SolrRequestType.ADMIN, params);
NamedList<Object> queryResponse = cluster.getSolrClient(COLLECTION_NAME).request(request);

assertEquals("Query with queryID foobar not found", queryResponse.get("status"));
Expand Down Expand Up @@ -185,8 +185,11 @@ private NamedList<String> listTasks() throws SolrServerException, IOException {
cluster
.getSolrClient(COLLECTION_NAME)
.request(
new GenericSolrRequest(SolrRequest.METHOD.GET, "/tasks/list")
.setRequiresCollection(true));
new GenericCollectionRequest(
SolrRequest.METHOD.GET,
"/tasks/list",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was a little eye-opening to see we have a handler that doesn't "look" like an admin handler but is one

SolrRequest.SolrRequestType.ADMIN,
new ModifiableSolrParams()));
return (NamedList<String>) response.get("taskList");
}

Expand All @@ -195,9 +198,9 @@ public void testCheckSpecificQueryStatus() throws Exception {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("taskUUID", "25");

GenericSolrRequest request =
new GenericSolrRequest(SolrRequest.METHOD.GET, "/tasks/list", params)
.setRequiresCollection(true);
var request =
new GenericCollectionRequest(
SolrRequest.METHOD.GET, "/tasks/list", SolrRequest.SolrRequestType.ADMIN, params);
NamedList<Object> queryResponse = cluster.getSolrClient(COLLECTION_NAME).request(request);

String result = (String) queryResponse.get("taskStatus");
Expand Down
Loading
Loading