diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java index 60f25c324b2..662221cca7f 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java @@ -858,7 +858,8 @@ public static void checkDiskSpace( .add("key", indexSizeMetricName) .add("key", freeDiskSpaceMetricName); SolrResponse rsp = - new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/metrics", params) + new GenericSolrRequest( + SolrRequest.METHOD.GET, "/admin/metrics", SolrRequest.SolrRequestType.ADMIN, params) .process(cloudManager.getSolrClient()); Number size = (Number) rsp.getResponse().findRecursive("metrics", indexSizeMetricName); diff --git a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java index 4842534259d..e1edb227856 100644 --- a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java @@ -55,7 +55,6 @@ import org.apache.solr.api.Api; import org.apache.solr.api.ApiBag; import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.SolrResponse; import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.io.stream.expr.Expressible; @@ -968,7 +967,7 @@ private static class PerReplicaCallable extends CollectionRequiringSolrRequest { public SystemInfoRequest() { - super(METHOD.GET, "/admin/info/system"); + super(METHOD.GET, "/admin/info/system", SolrRequest.SolrRequestType.ADMIN); } @Override @@ -60,10 +60,5 @@ public SolrParams getParams() { protected QueryResponse createResponse(final SolrClient client) { return new QueryResponse(); } - - @Override - public String getRequestType() { - return SolrRequest.SolrRequestType.ADMIN.toString(); - } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java index 64c858ac4ea..1ed5c1568bb 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java @@ -67,6 +67,8 @@ import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.api.AnnotatedApi; 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.CloudLegacySolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; @@ -74,7 +76,7 @@ import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Delete; import org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Upload; -import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.schema.SchemaRequest; import org.apache.solr.client.solrj.response.CollectionAdminResponse; import org.apache.solr.client.solrj.response.ConfigSetAdminResponse; @@ -1487,8 +1489,8 @@ protected CollectionAdminResponse createCollection( params.set("name", collectionName); params.set("numShards", numShards); params.set("replicationFactor", replicationFactor); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); CollectionAdminResponse res = new CollectionAdminResponse(); res.setResponse(client.request(request)); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java b/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java index b7a15aea1b6..a5070fa7566 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java @@ -29,17 +29,20 @@ import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; +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.QueryRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.response.CollectionAdminResponse; -import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.client.solrj.response.SimpleSolrResponse; import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; import org.apache.solr.common.params.CollectionParams; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.util.ExecutorUtil; +import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.TimeSource; import org.apache.solr.embedded.JettySolrRunner; import org.apache.solr.util.TimeOut; @@ -408,13 +411,14 @@ private void rebalanceLeaderUsingStandardRequest() throws IOException, SolrServe ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.REBALANCELEADERS.toString()); params.set("collection", COLLECTION_NAME); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); - QueryResponse resp = request.process(cluster.getSolrClient()); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); + SimpleSolrResponse resp = request.process(cluster.getSolrClient()); assertTrue( "All leaders should have been verified", resp.getResponse().get("Summary").toString().contains("Success")); - assertEquals("Call to rebalanceLeaders failed ", 0, resp.getStatus()); + NamedList header = (NamedList) resp.getResponse().get("responseHeader"); + assertEquals("Call to rebalanceLeaders failed ", 0, header.get("status")); } private void rebalancePropUsingSolrJAPI(String prop) throws IOException, SolrServerException { @@ -445,10 +449,12 @@ private void rebalancePropUsingStandardRequest(String prop) if (prop.toLowerCase(Locale.ROOT).contains("preferredleader") == false) { params.set("shardUnique", true); } - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); - QueryResponse resp = request.process(cluster.getSolrClient()); - assertEquals("Call to rebalanceLeaders failed ", 0, resp.getStatus()); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); + request.setRequiresCollection(false); + SimpleSolrResponse resp = request.process(cluster.getSolrClient()); + NamedList header = (NamedList) resp.getResponse().get("responseHeader"); + assertEquals("Call to rebalanceLeaders failed ", 0, header.get("status")); } // This important. I've (Erick Erickson) run across a situation where the "standard request" @@ -479,8 +485,9 @@ void setPropWithStandardRequest(Slice slice, Replica rep, String prop) params.set("shardUnique", "true"); } - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); + request.setRequiresCollection(false); cluster.getSolrClient().request(request); String propLC = prop.toLowerCase(Locale.ROOT); waitForState( diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/ReplicaPropertiesBase.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/ReplicaPropertiesBase.java index 6e81a24c1ec..8d9949ce1b3 100644 --- a/solr/core/src/test/org/apache/solr/cloud/api/collections/ReplicaPropertiesBase.java +++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/ReplicaPropertiesBase.java @@ -22,9 +22,11 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +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.QueryRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.cloud.AbstractFullDistribZkTestBase; import org.apache.solr.common.cloud.ClusterState; import org.apache.solr.common.cloud.DocCollection; @@ -47,8 +49,8 @@ public static NamedList doPropertyAction(CloudSolrClient client, String. for (int idx = 0; idx < paramsIn.length; idx += 2) { params.set(paramsIn[idx], paramsIn[idx + 1]); } - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); return client.request(request); } diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java index ce605c70271..26d6528881f 100644 --- a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java @@ -27,11 +27,13 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.LongAdder; 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.impl.NoOpResponseParser; 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.response.CollectionAdminResponse; import org.apache.solr.cloud.MiniSolrCloudCluster; import org.apache.solr.cloud.ZkConfigSetService; @@ -120,8 +122,8 @@ private void testModifyCollection() throws Exception { params.set("action", CollectionParams.CollectionAction.MODIFYCOLLECTION.toString()); params.set("collection", COLLECTION_NAME); params.set("replicationFactor", 25); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); client.request(request); NamedList rsp = @@ -141,9 +143,8 @@ private void testModifyCollection() throws Exception { params.set("action", CollectionParams.CollectionAction.MODIFYCOLLECTION.toString()); params.set("collection", COLLECTION_NAME); params.set("replicationFactor", ""); - request = new QueryRequest(params); - request.setPath("/admin/collections"); - + request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); client.request(request); rsp = @@ -164,8 +165,8 @@ private void testModifyCollection() throws Exception { params.set("action", CollectionParams.CollectionAction.MODIFYCOLLECTION.toString()); params.set("collection", COLLECTION_NAME); params.set("non_existent_property", ""); - request = new QueryRequest(params); - request.setPath("/admin/collections"); + request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); try { client.request(request); @@ -186,8 +187,8 @@ private void testReplicationFactorValidaton() throws Exception { params.set("numShards", "1"); params.set("replicationFactor", "1"); params.set("nrtReplicas", "2"); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); try { client.request(request); @@ -214,8 +215,8 @@ private void testReplicationFactorValidaton() throws Exception { params.set("action", CollectionParams.CollectionAction.MODIFYCOLLECTION.toString()); params.set("collection", "test_repFactorColl"); params.set("replicationFactor", "4"); - request = new QueryRequest(params); - request.setPath("/admin/collections"); + request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); client.request(request); assertCountsForRepFactorAndNrtReplicas(client, "test_repFactorColl"); @@ -240,9 +241,8 @@ private void testNoConfigset() throws Exception { params.set("numShards", "1"); params.set("replicationFactor", "1"); params.set("collection.configName", configSet); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); - + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); client.request(request); waitForCollection(ZkStateReader.from(client), collection, 1); @@ -278,8 +278,8 @@ private void assertCountsForRepFactorAndNrtReplicas(CloudSolrClient client, Stri ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", collectionName); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); NamedList rsp = client.request(request); NamedList cluster = (NamedList) rsp.get("cluster"); @@ -300,8 +300,8 @@ private void clusterStatusWithCollectionAndShard() throws IOException, SolrServe params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", COLLECTION_NAME); params.set("shard", SHARD1); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); NamedList rsp = client.request(request); NamedList cluster = (NamedList) rsp.get("cluster"); @@ -441,8 +441,8 @@ private void listCollection() throws IOException, SolrServerException { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.LIST.toString()); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); NamedList rsp = client.request(request); List collections = (List) rsp.get("collections"); @@ -461,8 +461,8 @@ private void clusterStatusNoCollection() throws Exception { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); NamedList rsp = client.request(request); NamedList cluster = (NamedList) rsp.get("cluster"); @@ -483,8 +483,8 @@ private void clusterStatusWithCollection() throws IOException, SolrServerExcepti ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", COLLECTION_NAME); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); NamedList rsp = client.request(request); NamedList cluster = (NamedList) rsp.get("cluster"); @@ -513,8 +513,8 @@ private void clusterStatusZNodeVersion() throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", cname); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); NamedList rsp = client.request(request); NamedList cluster = (NamedList) rsp.get("cluster"); @@ -554,8 +554,8 @@ private void clusterStatusWithRouteKey() throws IOException, SolrServerException params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", DEFAULT_COLLECTION); params.set(ShardParams._ROUTE_, "a!"); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); NamedList rsp = client.request(request); @SuppressWarnings({"unchecked"}) @@ -586,8 +586,8 @@ private void clusterStatusAliasTest() throws Exception { params.set("action", CollectionParams.CollectionAction.CREATEALIAS.toString()); params.set("name", "myalias"); params.set("collections", DEFAULT_COLLECTION + "," + COLLECTION_NAME); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); client.request(request); @@ -595,8 +595,8 @@ private void clusterStatusAliasTest() throws Exception { params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", DEFAULT_COLLECTION); - request = new QueryRequest(params); - request.setPath("/admin/collections"); + request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); NamedList rsp = client.request(request); @@ -621,8 +621,8 @@ private void clusterStatusAliasTest() throws Exception { params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", "myalias"); - request = new QueryRequest(params); - request.setPath("/admin/collections"); + request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); // SOLR-12938 - this should NOT cause an exception rsp = client.request(request); @@ -638,7 +638,8 @@ private void clusterStatusAliasTest() throws Exception { params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", "notAnAliasOrCollection"); - request = new QueryRequest(params); + request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); request.setPath("/admin/collections"); // SOLR-12938 - this should still cause an exception @@ -663,9 +664,9 @@ private void clusterStatusWithCollectionAndShardJSON() throws IOException, SolrS params.set("collection", COLLECTION_NAME); params.set("shard", SHARD1); params.set("wt", "json"); - QueryRequest request = new QueryRequest(params); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); request.setResponseParser(new NoOpResponseParser("json")); - request.setPath("/admin/collections"); NamedList rsp = client.request(request); String actualResponse = (String) rsp.get("response"); @@ -694,15 +695,15 @@ private void clusterStatusRolesTest() throws Exception { params.set("action", CollectionParams.CollectionAction.ADDROLE.toString()); params.set("node", replica.getNodeName()); params.set("role", "overseer"); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); client.request(request); params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", DEFAULT_COLLECTION); - request = new QueryRequest(params); - request.setPath("/admin/collections"); + request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); NamedList rsp = client.request(request); NamedList cluster = (NamedList) rsp.get("cluster"); @@ -722,8 +723,8 @@ private void clusterStatusBadCollectionTest() throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString()); params.set("collection", "bad_collection_name"); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); try { client.request(request); @@ -772,8 +773,8 @@ private void replicaPropTest() throws Exception { missingParamsError(client, params); params.set("property.value", "true"); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); client.request(request); // The above should have set exactly one preferredleader... @@ -1143,8 +1144,8 @@ private void testCollectionCreationCollectionNameValidation() throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.CREATE.toString()); params.set("name", "invalid@name#with$weird%characters"); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); try { client.request(request); @@ -1166,8 +1167,8 @@ private void testCollectionCreationShardNameValidation() throws Exception { params.set("router.name", "implicit"); params.set("numShards", "1"); params.set("shards", "invalid@name#with$weird%characters"); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); try { client.request(request); @@ -1187,8 +1188,8 @@ private void testAliasCreationNameValidation() throws Exception { params.set("action", CollectionParams.CollectionAction.CREATEALIAS.toString()); params.set("name", "invalid@name#with$weird%characters"); params.set("collections", COLLECTION_NAME); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); try { client.request(request); @@ -1211,8 +1212,8 @@ private void testShardCreationNameValidation() throws Exception { params.set("name", "valid_collection_name"); params.set("shards", "a"); params.set("router.name", "implicit"); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); client.request(request); params = new ModifiableSolrParams(); @@ -1220,8 +1221,8 @@ private void testShardCreationNameValidation() throws Exception { params.set("collection", "valid_collection_name"); params.set("shard", "invalid@name#with$weird%characters"); - request = new QueryRequest(params); - request.setPath("/admin/collections"); + request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); try { client.request(request); @@ -1257,10 +1258,11 @@ private Map getProps( private void missingParamsError(CloudSolrClient client, ModifiableSolrParams origParams) throws IOException, SolrServerException { - QueryRequest request; + GenericSolrRequest request; try { - request = new QueryRequest(origParams); - request.setPath("/admin/collections"); + request = + new GenericSolrRequest( + METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, origParams); client.request(request); fail("Should have thrown a SolrException due to lack of a required parameter."); } catch (SolrException se) { @@ -1349,8 +1351,8 @@ public void testCreateCollectionBooleanValues() throws Exception { params.set("collection.configName", "conf1"); params.set("numShards", "1"); params.set(CollectionAdminParams.PER_REPLICA_STATE, "False"); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); try { client.request(request); diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestReplicaProperties.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestReplicaProperties.java index 11a5dde4612..ca2d3f3c8d7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestReplicaProperties.java +++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestReplicaProperties.java @@ -20,9 +20,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +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.QueryRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.common.SolrException; import org.apache.solr.common.cloud.ClusterState; import org.apache.solr.common.cloud.Replica; @@ -67,8 +69,8 @@ private void listCollection() throws IOException, SolrServerException { try (CloudSolrClient client = createCloudClient(null)) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.LIST.toString()); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); NamedList rsp = client.request(request); @SuppressWarnings({"unchecked"}) diff --git a/solr/core/src/test/org/apache/solr/handler/RequestHandlerMetricsTest.java b/solr/core/src/test/org/apache/solr/handler/RequestHandlerMetricsTest.java index b5b73de2597..96a038f7bc4 100644 --- a/solr/core/src/test/org/apache/solr/handler/RequestHandlerMetricsTest.java +++ b/solr/core/src/test/org/apache/solr/handler/RequestHandlerMetricsTest.java @@ -81,7 +81,9 @@ public void testAggregateNodeLevelMetrics() throws SolrServerException, IOExcept cloudClient.query(collection2, solrQuery); NamedList response = - cloudClient.request(new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/metrics")); + cloudClient.request( + new GenericSolrRequest( + SolrRequest.METHOD.GET, "/admin/metrics", SolrRequest.SolrRequestType.ADMIN)); NamedList metrics = (NamedList) response.get("metrics"); diff --git a/solr/core/src/test/org/apache/solr/handler/admin/AdminHandlersProxyTest.java b/solr/core/src/test/org/apache/solr/handler/admin/AdminHandlersProxyTest.java index b6f74ddfba6..cdc9ca26494 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/AdminHandlersProxyTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/AdminHandlersProxyTest.java @@ -57,7 +57,11 @@ public void setUp() throws Exception { public void proxySystemInfoHandlerAllNodes() throws IOException, SolrServerException { MapSolrParams params = new MapSolrParams(Collections.singletonMap("nodes", "all")); GenericSolrRequest req = - new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/info/system", params); + new GenericSolrRequest( + SolrRequest.METHOD.GET, + "/admin/info/system", + SolrRequest.SolrRequestType.ADMIN, + params); SimpleSolrResponse rsp = req.process(solrClient, null); NamedList nl = rsp.getResponse(); assertEquals(3, nl.size()); @@ -71,7 +75,8 @@ public void proxySystemInfoHandlerAllNodes() throws IOException, SolrServerExcep public void proxyMetricsHandlerAllNodes() throws IOException, SolrServerException { MapSolrParams params = new MapSolrParams(Collections.singletonMap("nodes", "all")); GenericSolrRequest req = - new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/metrics", params); + new GenericSolrRequest( + SolrRequest.METHOD.GET, "/admin/metrics", SolrRequest.SolrRequestType.ADMIN, params); SimpleSolrResponse rsp = req.process(solrClient, null); NamedList nl = rsp.getResponse(); assertEquals(3, nl.size()); @@ -85,7 +90,11 @@ public void proxySystemInfoHandlerNonExistingNode() throws IOException, SolrServ MapSolrParams params = new MapSolrParams(Collections.singletonMap("nodes", "example.com:1234_solr")); GenericSolrRequest req = - new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/info/system", params); + new GenericSolrRequest( + SolrRequest.METHOD.GET, + "/admin/info/system", + SolrRequest.SolrRequestType.ADMIN, + params); SimpleSolrResponse rsp = req.process(solrClient, null); } @@ -97,7 +106,11 @@ public void proxySystemInfoHandlerOneNode() { node -> { MapSolrParams params = new MapSolrParams(Collections.singletonMap("nodes", node)); GenericSolrRequest req = - new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/info/system", params); + new GenericSolrRequest( + SolrRequest.METHOD.GET, + "/admin/info/system", + SolrRequest.SolrRequestType.ADMIN, + params); SimpleSolrResponse rsp = null; try { rsp = req.process(solrClient, null); diff --git a/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java index 6955b994f7a..38c99b87bd1 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java @@ -64,7 +64,8 @@ public void testHealthCheckHandler() throws Exception { // as compared with testHealthCheckHandlerWithCloudClient // (Not sure if that's actually a good thing -- but it's how the existing test worked) final var genericHealthcheck = - new GenericSolrRequest(SolrRequest.METHOD.GET, HEALTH_CHECK_HANDLER_PATH); + new GenericSolrRequest( + SolrRequest.METHOD.GET, HEALTH_CHECK_HANDLER_PATH, SolrRequest.SolrRequestType.ADMIN); assertEquals( CommonParams.OK, genericHealthcheck.process(cluster.getSolrClient()).getResponse().get(CommonParams.STATUS)); diff --git a/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java index a4d38ccf68d..f52b76d5706 100644 --- a/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestPrometheusResponseWriter.java @@ -30,8 +30,10 @@ import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.solr.SolrTestCaseJ4; 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.impl.NoOpResponseParser; -import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.metrics.SolrMetricManager; @@ -79,9 +81,8 @@ public static void clearMetricsRegistries() { @Test public void testPrometheusStructureOutput() throws Exception { ModifiableSolrParams params = new ModifiableSolrParams(); - params.set("qt", "/admin/metrics"); params.set("wt", "prometheus"); - QueryRequest req = new QueryRequest(params); + var req = new GenericSolrRequest(METHOD.GET, "/admin/metrics", SolrRequestType.ADMIN, params); req.setResponseParser(new NoOpResponseParser("prometheus")); try (SolrClient adminClient = getHttpSolrClient(solrClientTestRule.getBaseUrl())) { @@ -135,9 +136,8 @@ public void testPrometheusDummyOutput() throws Exception { String expectedJvm = "solr_metrics_jvm_gc{item=\"dummyMetrics\"} 0.0"; ModifiableSolrParams params = new ModifiableSolrParams(); - params.set("qt", "/admin/metrics"); params.set("wt", "prometheus"); - QueryRequest req = new QueryRequest(params); + var req = new GenericSolrRequest(METHOD.GET, "/admin/metrics", SolrRequestType.ADMIN, params); req.setResponseParser(new NoOpResponseParser("prometheus")); try (SolrClient adminClient = getHttpSolrClient(solrClientTestRule.getBaseUrl())) { diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java index 77ee3536959..22f5f4a6857 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java @@ -142,7 +142,8 @@ public void testBasicAuth() throws Exception { .build(); } else { GenericSolrRequest genericSolrRequest = - new GenericSolrRequest(SolrRequest.METHOD.POST, authcPrefix); + new GenericSolrRequest( + SolrRequest.METHOD.POST, authcPrefix, SolrRequest.SolrRequestType.ADMIN); genericSolrRequest.setContentWriter( new StringPayloadContentWriter(command, CommonParams.JSON_MIME)); genericReq = genericSolrRequest; diff --git a/solr/modules/opentelemetry/src/test/org/apache/solr/opentelemetry/TestDistributedTracing.java b/solr/modules/opentelemetry/src/test/org/apache/solr/opentelemetry/TestDistributedTracing.java index d16e60bcf17..711c1039a6d 100644 --- a/solr/modules/opentelemetry/src/test/org/apache/solr/opentelemetry/TestDistributedTracing.java +++ b/solr/modules/opentelemetry/src/test/org/apache/solr/opentelemetry/TestDistributedTracing.java @@ -29,6 +29,7 @@ import java.util.Map; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrRequest; +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; @@ -129,7 +130,8 @@ public void test() throws IOException, SolrServerException { public void testAdminApi() throws Exception { CloudSolrClient cloudClient = cluster.getSolrClient(); - cloudClient.request(new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/metrics")); + cloudClient.request( + new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/metrics", SolrRequestType.ADMIN)); var finishedSpans = getAndClearSpans(); assertEquals("get:/admin/metrics", finishedSpans.get(0).getName()); diff --git a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrScraper.java b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrScraper.java index 5bc4d720b1b..4e9f4ce0fd3 100644 --- a/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrScraper.java +++ b/solr/prometheus-exporter/src/java/org/apache/solr/prometheus/scraper/SolrScraper.java @@ -16,6 +16,8 @@ */ package org.apache.solr.prometheus.scraper; +import static org.apache.solr.common.params.CommonParams.ADMIN_PATHS; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.prometheus.client.Collector; @@ -35,10 +37,12 @@ import net.thisptr.jackson.jq.JsonQuery; import net.thisptr.jackson.jq.exception.JsonQueryException; 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.impl.Http2SolrClient; -import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.common.util.NamedList; import org.apache.solr.prometheus.collector.MetricSamples; import org.apache.solr.prometheus.exporter.MetricsQuery; @@ -130,29 +134,35 @@ protected MetricSamples request(SolrClient client, MetricsQuery query) throws IO zkHostLabelValue = ((CloudSolrClient) client).getClusterStateProvider().getQuorumHosts(); } - QueryRequest queryRequest = new QueryRequest(query.getParameters()); - queryRequest.setPath(query.getPath()); - - NamedList queryResponse; + SolrRequestType requestType = SolrRequestType.QUERY; + boolean requiresCollection = true; + if (ADMIN_PATHS.contains(query.getPath())) { + requestType = SolrRequestType.ADMIN; + requiresCollection = false; + } + var request = + new GenericSolrRequest(METHOD.GET, query.getPath(), requestType, query.getParameters()); + request.setRequiresCollection(requiresCollection); + NamedList response; try { if (query.getCollection().isEmpty() && query.getCore().isEmpty()) { - queryResponse = client.request(queryRequest); + response = client.request(request); } else if (query.getCore().isPresent()) { - queryResponse = client.request(queryRequest, query.getCore().get()); + response = client.request(request, query.getCore().get()); } else if (query.getCollection().isPresent()) { - queryResponse = client.request(queryRequest, query.getCollection().get()); + response = client.request(request, query.getCollection().get()); } else { throw new AssertionError("Invalid configuration"); } - if (queryResponse == null) { // ideally we'd make this impossible + if (response == null) { // ideally we'd make this impossible throw new RuntimeException("no response from server"); } } catch (SolrServerException | IOException e) { - log.error("failed to request: {}", queryRequest.getPath(), e); + log.error("failed to request: {}", request.getPath(), e); return samples; } - JsonNode jsonNode = OBJECT_MAPPER.readTree((String) queryResponse.get("response")); + JsonNode jsonNode = OBJECT_MAPPER.readTree((String) response.get("response")); for (JsonQuery jsonQuery : query.getJsonQueries()) { try { diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java index 4e06f697f88..eda6b663d8c 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.request.RequestWriter; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.ContentStream; @@ -90,6 +91,7 @@ public enum SolrClientContext { private METHOD method = METHOD.GET; private String path = null; + private SolrRequestType requestType = SolrRequestType.UNSPECIFIED; private Map headers; private List preferredNodes; @@ -127,9 +129,10 @@ public String getBasicAuthPassword() { // --------------------------------------------------------- // --------------------------------------------------------- - public SolrRequest(METHOD m, String path) { + public SolrRequest(METHOD m, String path, SolrRequestType requestType) { this.method = m; this.path = path; + this.requestType = requestType; } // --------------------------------------------------------- @@ -185,8 +188,20 @@ public void setQueryParams(Set queryParams) { this.queryParams = queryParams; } - /** This method defines the type of this Solr request. */ - public abstract String getRequestType(); + /** + * The type of this Solr request. + * + *

Pattern matches {@link SolrRequest#getPath} to identify ADMIN requests and other special + * cases. Overriding this method may affect request routing within various clients (i.e. {@link + * CloudSolrClient}). + */ + public SolrRequestType getRequestType() { + return requestType; + } + + public void setRequestType(SolrRequestType requestType) { + this.requestType = requestType; + } /** * The parameters for this request; never null. The runtime type may be mutable but modifications diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java index a0dc29f7196..f2f04dc277c 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java @@ -17,7 +17,6 @@ package org.apache.solr.client.solrj.impl; -import static org.apache.solr.common.params.CommonParams.ADMIN_PATHS; import static org.apache.solr.common.params.CommonParams.ID; import java.io.IOException; @@ -51,9 +50,8 @@ import org.apache.solr.client.solrj.ResponseParser; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.request.AbstractUpdateRequest; -import org.apache.solr.client.solrj.request.IsUpdateRequest; import org.apache.solr.client.solrj.request.RequestWriter; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.request.V2Request; @@ -356,9 +354,8 @@ public void connect(long duration, TimeUnit timeUnit) } @SuppressWarnings({"unchecked"}) - private NamedList directUpdate(AbstractUpdateRequest request, String collection) + private NamedList directUpdate(UpdateRequest request, String collection) throws SolrServerException { - UpdateRequest updateRequest = (UpdateRequest) request; SolrParams params = request.getParams(); ModifiableSolrParams routableParams = new ModifiableSolrParams(); ModifiableSolrParams nonRoutableParams = new ModifiableSolrParams(); @@ -412,9 +409,9 @@ private NamedList directUpdate(AbstractUpdateRequest request, String col String routeField = (col.getRouter().getRouteField(col) == null) ? ID : col.getRouter().getRouteField(col); final Map routes = - createRoutes(updateRequest, routableParams, col, router, urlMap, routeField); + createRoutes(request, routableParams, col, router, urlMap, routeField); if (routes == null) { - if (directUpdatesToLeadersOnly && hasInfoToFindLeaders(updateRequest, routeField)) { + if (directUpdatesToLeadersOnly && hasInfoToFindLeaders(request, routeField)) { // we have info (documents with ids and/or ids to delete) with // which to find the leaders, but we could not find (all of) them throw new SolrException( @@ -491,7 +488,7 @@ private NamedList directUpdate(AbstractUpdateRequest request, String col } UpdateRequest nonRoutableRequest = null; - List deleteQuery = updateRequest.getDeleteQuery(); + List deleteQuery = request.getDeleteQuery(); if (deleteQuery != null && deleteQuery.size() > 0) { UpdateRequest deleteQueryRequest = new UpdateRequest(); deleteQueryRequest.setDeleteQuery(deleteQuery); @@ -800,7 +797,8 @@ protected NamedList requestWithRetryOnStaleState( if (request instanceof V2Request) { isCollectionRequestOfV2 = ((V2Request) request).isPerCollectionRequest(); } - boolean isAdmin = ADMIN_PATHS.contains(request.getPath()); + boolean isAdmin = + request.getRequestType() == SolrRequestType.ADMIN && !request.requiresCollection(); if (!inputCollections.isEmpty() && !isAdmin && !isCollectionRequestOfV2) { // don't do _stateVer_ checking for admin, v2 api requests @@ -1001,25 +999,30 @@ protected NamedList sendRequest(SolrRequest request, List inp boolean sendToLeaders = false; - if (request instanceof IsUpdateRequest) { - sendToLeaders = ((IsUpdateRequest) request).isSendToLeaders() && this.isUpdatesToLeaders(); + if (request.getRequestType() == SolrRequestType.UPDATE) { + sendToLeaders = this.isUpdatesToLeaders(); - // Check if we can do a "directUpdate" ... if (sendToLeaders && request instanceof UpdateRequest) { - if (inputCollections.size() > 1) { - throw new SolrException( - SolrException.ErrorCode.BAD_REQUEST, - "Update request must be sent to a single collection " - + "or an alias: " - + inputCollections); - } - String collection = - inputCollections.isEmpty() - ? null - : inputCollections.get(0); // getting first mimics HttpSolrCall - NamedList response = directUpdate((AbstractUpdateRequest) request, collection); - if (response != null) { - return response; + var updateRequest = (UpdateRequest) request; + sendToLeaders = sendToLeaders && updateRequest.isSendToLeaders(); + + // Check if we can do a "directUpdate" ... + if (sendToLeaders) { + if (inputCollections.size() > 1) { + throw new SolrException( + SolrException.ErrorCode.BAD_REQUEST, + "Update request must be sent to a single collection " + + "or an alias: " + + inputCollections); + } + String collection = + inputCollections.isEmpty() + ? null + : inputCollections.get(0); // getting first mimics HttpSolrCall + NamedList response = directUpdate(updateRequest, collection); + if (response != null) { + return response; + } } } } @@ -1045,12 +1048,11 @@ protected NamedList sendRequest(SolrRequest request, List inp requestEndpoints.add(new LBSolrClient.Endpoint(chosenNodeUrl)); } - } else if (ADMIN_PATHS.contains(request.getPath())) { + } else if (request.getRequestType() == SolrRequestType.ADMIN && !request.requiresCollection()) { for (String liveNode : liveNodes) { final var nodeBaseUrl = Utils.getBaseUrlForNodeName(liveNode, urlScheme); requestEndpoints.add(new LBSolrClient.Endpoint(nodeBaseUrl)); } - } else { // Typical... Set collectionNames = resolveAliases(inputCollections); if (collectionNames.isEmpty()) { @@ -1173,9 +1175,9 @@ private Set resolveAliases(List inputCollections) { /** * If true, this client has been configured such that it will generally prefer to send {@link - * IsUpdateRequest} requests to a shard leader, if and only if {@link - * IsUpdateRequest#isSendToLeaders} is also true. If false, then this client has been configured - * to obey normal routing preferences when dealing with {@link IsUpdateRequest} requests. + * SolrRequestType#UPDATE} requests to a shard leader, if and only if {@link + * UpdateRequest#isSendToLeaders} is also true. If false, then this client has been configured to + * obey normal routing preferences when dealing with {@link SolrRequestType#UPDATE} requests. * * @see #isDirectUpdatesToLeadersOnly */ @@ -1187,7 +1189,7 @@ public boolean isUpdatesToLeaders() { * If true, this client has been configured such that "direct updates" will only be sent * to the current leader of the corresponding shard, and will not be retried with other replicas. * This method has no effect if {@link #isUpdatesToLeaders()} or {@link - * IsUpdateRequest#isSendToLeaders} returns false. + * UpdateRequest#isSendToLeaders} returns false. * *

A "direct update" is any update that can be sent directly to a single shard, and does not * need to be broadcast to every shard. (Example: document updates or "delete by id" when using diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java index e1de05d97da..1bea292b042 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java @@ -752,7 +752,7 @@ private Header[] buildRequestSpecificHeaders(final SolrRequest request) { new BasicHeader(CommonParams.SOLR_REQUEST_CONTEXT_PARAM, getContext().toString()); contextHeaders[1] = - new BasicHeader(CommonParams.SOLR_REQUEST_TYPE_PARAM, request.getRequestType()); + new BasicHeader(CommonParams.SOLR_REQUEST_TYPE_PARAM, request.getRequestType().toString()); return contextHeaders; } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java index 33488a83d30..e7aee581a38 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttp2SolrClient.java @@ -16,8 +16,6 @@ */ package org.apache.solr.client.solrj.impl; -import static org.apache.solr.common.params.CommonParams.ADMIN_PATHS; - import java.io.IOException; import java.net.ConnectException; import java.net.SocketException; @@ -29,8 +27,8 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.solr.client.solrj.ResponseParser; import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.request.IsUpdateRequest; import org.apache.solr.client.solrj.request.RequestWriter; import org.apache.solr.common.SolrException; import org.apache.solr.common.util.NamedList; @@ -139,7 +137,8 @@ public CompletableFuture requestAsync(Req req) { CompletableFuture apiFuture = new CompletableFuture<>(); Rsp rsp = new Rsp(); boolean isNonRetryable = - req.request instanceof IsUpdateRequest || ADMIN_PATHS.contains(req.request.getPath()); + req.request.getRequestType() == SolrRequestType.UPDATE + || req.request.getRequestType() == SolrRequestType.ADMIN; EndpointIterator it = new EndpointIterator(req, zombieServers); AtomicReference>> currentFuture = new AtomicReference<>(); RetryListener retryListener = diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java index 0d0d539d97c..3cd9e2e09d1 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBSolrClient.java @@ -17,8 +17,6 @@ package org.apache.solr.client.solrj.impl; -import static org.apache.solr.common.params.CommonParams.ADMIN_PATHS; - import java.io.IOException; import java.lang.invoke.MethodHandles; import java.lang.ref.WeakReference; @@ -46,8 +44,8 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.request.IsUpdateRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.RequestWriter; import org.apache.solr.client.solrj.response.QueryResponse; @@ -457,7 +455,8 @@ public Rsp request(Req req) throws SolrServerException, IOException { Rsp rsp = new Rsp(); Exception ex = null; boolean isNonRetryable = - req.request instanceof IsUpdateRequest || ADMIN_PATHS.contains(req.request.getPath()); + req.request.getRequestType() == SolrRequestType.UPDATE + || req.request.getRequestType() == SolrRequestType.ADMIN; EndpointIterator endpointIterator = new EndpointIterator(req, zombieServers); Endpoint serverStr; while ((serverStr = endpointIterator.nextOrError(ex)) != null) { diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/AbstractUpdateRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/AbstractUpdateRequest.java index 81c555d8d1a..b26a2dcc4fb 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/AbstractUpdateRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/AbstractUpdateRequest.java @@ -22,8 +22,7 @@ import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.UpdateParams; -public abstract class AbstractUpdateRequest extends CollectionRequiringSolrRequest - implements IsUpdateRequest { +public abstract class AbstractUpdateRequest extends CollectionRequiringSolrRequest { protected ModifiableSolrParams params = new ModifiableSolrParams(); // maybe make final; no setter protected int commitWithin = -1; @@ -33,7 +32,7 @@ public enum ACTION { } public AbstractUpdateRequest(METHOD m, String path) { - super(m, path); + super(m, path, SolrRequestType.UPDATE); } /** Sets appropriate parameters for the given ACTION */ @@ -125,11 +124,6 @@ protected UpdateResponse createResponse(SolrClient client) { return new UpdateResponse(); } - @Override - public String getRequestType() { - return SolrRequestType.UPDATE.toString(); - } - public boolean isWaitSearcher() { return params.getBool(UpdateParams.WAIT_SEARCHER, false); } @@ -152,16 +146,4 @@ public AbstractUpdateRequest setCommitWithin(int commitWithin) { this.commitWithin = commitWithin; return this; } - - private boolean sendToLeaders = true; - - @Override - public boolean isSendToLeaders() { - return sendToLeaders; - } - - public AbstractUpdateRequest setSendToLeaders(final boolean sendToLeaders) { - this.sendToLeaders = sendToLeaders; - return this; - } } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java index 54a03cd7031..36954bfdb63 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java @@ -85,7 +85,7 @@ public CollectionAdminRequest(CollectionAction action) { } public CollectionAdminRequest(String path, CollectionAction action) { - super(METHOD.GET, path); + super(METHOD.GET, path, SolrRequestType.ADMIN); this.action = checkNotNull(CoreAdminParams.ACTION, action); } @@ -124,8 +124,8 @@ public String toString() { } @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); + public boolean requiresCollection() { + return false; } /** diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionRequiringSolrRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionRequiringSolrRequest.java index d5ebff84821..ea0d61ba1e5 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionRequiringSolrRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionRequiringSolrRequest.java @@ -22,8 +22,8 @@ /** Parent {@link SolrRequest} class that requires a target collection or core. */ public abstract class CollectionRequiringSolrRequest extends SolrRequest { - public CollectionRequiringSolrRequest(METHOD m, String path) { - super(m, path); + public CollectionRequiringSolrRequest(METHOD m, String path, SolrRequestType requestType) { + super(m, path, requestType); } @Override diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/ConfigSetAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/ConfigSetAdminRequest.java index 6743cc09711..99b99d9f1c3 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/ConfigSetAdminRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/ConfigSetAdminRequest.java @@ -52,11 +52,11 @@ protected ConfigSetAdminRequest setAction(ConfigSetAction action) { } public ConfigSetAdminRequest() { - super(METHOD.GET, "/admin/configs"); + super(METHOD.GET, "/admin/configs", SolrRequestType.ADMIN); } public ConfigSetAdminRequest(String path) { - super(METHOD.GET, path); + super(METHOD.GET, path, SolrRequestType.ADMIN); } protected abstract Q getThis(); @@ -104,11 +104,6 @@ protected ConfigSetAdminResponse createResponse(SolrClient client) { } } - @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); - } - /** * Uploads files to create a new configset, or modify an existing config set. * diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java index db078ca2ebc..e82d5f19ecb 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java @@ -44,11 +44,6 @@ public class CoreAdminRequest extends SolrRequest { protected boolean isIndexInfoNeeded = true; protected CoreAdminParams.CoreAdminAction action = null; - @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); - } - // a create core request public static class Create extends CoreAdminRequest { @@ -590,11 +585,11 @@ public ListSnapshots() { } public CoreAdminRequest() { - super(METHOD.GET, "/admin/cores"); + super(METHOD.GET, "/admin/cores", SolrRequestType.ADMIN); } public CoreAdminRequest(String path) { - super(METHOD.GET, path); + super(METHOD.GET, path, SolrRequestType.ADMIN); } public void setCoreName(String coreName) { diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/DelegationTokenRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/DelegationTokenRequest.java index 6f19620142a..6eadd244dce 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/DelegationTokenRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/DelegationTokenRequest.java @@ -43,7 +43,7 @@ public DelegationTokenRequest(METHOD m) { // path doesn't really matter -- the filter will respond to any path. // setting the path to admin/collections lets us pass through CloudSolrServer // without having to specify a collection (that may not even exist yet). - super(m, "/admin/collections"); + super(m, "/admin/collections", SolrRequestType.ADMIN); } protected abstract Q getThis(); @@ -82,11 +82,6 @@ public SolrParams getParams() { public DelegationTokenResponse.Get createResponse(SolrClient client) { return new DelegationTokenResponse.Get(); } - - @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); - } } public static class Renew extends DelegationTokenRequest { @@ -116,11 +111,6 @@ public SolrParams getParams() { public DelegationTokenResponse.Renew createResponse(SolrClient client) { return new DelegationTokenResponse.Renew(); } - - @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); - } } public static class Cancel @@ -151,10 +141,5 @@ public SolrParams getParams() { public DelegationTokenResponse.Cancel createResponse(SolrClient client) { return new DelegationTokenResponse.Cancel(); } - - @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); - } } } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/DirectXmlRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/DirectXmlRequest.java index cca187dd4d6..d00efb9ee02 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/DirectXmlRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/DirectXmlRequest.java @@ -37,7 +37,7 @@ public class DirectXmlRequest extends CollectionRequiringSolrRequest { private Boolean includeIndexFieldFlags = null; public LukeRequest() { - super(METHOD.GET, "/admin/luke"); + // this request is not processed as an ADMIN request + super(METHOD.GET, "/admin/luke", SolrRequestType.ADMIN); } public LukeRequest(String path) { - super(METHOD.GET, path); + super(METHOD.GET, path, SolrRequestType.ADMIN); } // --------------------------------------------------------------------------------- @@ -124,9 +125,4 @@ public SolrParams getParams() { return params; } - - @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); - } } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/QueryRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/QueryRequest.java index 2c26b2ac81d..a7d12f32915 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/QueryRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/QueryRequest.java @@ -30,17 +30,17 @@ public class QueryRequest extends CollectionRequiringSolrRequest private final SolrParams query; public QueryRequest() { - super(METHOD.GET, null); + super(METHOD.GET, null, SolrRequestType.QUERY); query = SolrParams.of(); } public QueryRequest(SolrParams q) { - super(METHOD.GET, null); + super(METHOD.GET, null, SolrRequestType.QUERY); query = Objects.requireNonNull(q); } public QueryRequest(SolrParams q, METHOD method) { - super(method, null); + super(method, null, SolrRequestType.QUERY); query = Objects.requireNonNull(q); } @@ -69,9 +69,4 @@ protected QueryResponse createResponse(SolrClient client) { public SolrParams getParams() { return query; } - - @Override - public String getRequestType() { - return SolrRequestType.QUERY.toString(); - } } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java index 1fa5634d637..73aca921a34 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java @@ -38,7 +38,7 @@ public class SolrPing extends CollectionRequiringSolrRequest { /** Create a new SolrPing object. */ public SolrPing() { - super(METHOD.GET, CommonParams.PING_HANDLER); + super(METHOD.GET, CommonParams.PING_HANDLER, SolrRequestType.ADMIN); params = new ModifiableSolrParams(); } @@ -52,11 +52,6 @@ public ModifiableSolrParams getParams() { return params; } - @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); - } - /** * Remove the action parameter from this request. This will result in the same behavior as {@code * SolrPing#setActionPing()}. For Solr server version 4.0 and later. diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java index 21c72fd7348..2d4e4e011d4 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java @@ -55,6 +55,7 @@ public class UpdateRequest extends AbstractUpdateRequest { private Iterator docIterator = null; private Map> deleteById = null; private List deleteQuery = null; + private boolean sendToLeaders = true; private boolean isLastDocInBatch = false; @@ -390,4 +391,13 @@ public boolean isLastDocInBatch() { public void lastDocInBatch() { isLastDocInBatch = true; } + + public boolean isSendToLeaders() { + return sendToLeaders; + } + + public UpdateRequest setSendToLeaders(final boolean sendToLeaders) { + this.sendToLeaders = sendToLeaders; + return this; + } } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java index a64a927e38e..1e6b3deb5c0 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java @@ -50,7 +50,7 @@ public class V2Request extends SolrRequest implements MapWriter { private ResponseParser parser; private V2Request(METHOD m, String resource, boolean useBinary) { - super(m, resource); + super(m, resource, SolrRequestType.ADMIN); Matcher matcher = COLL_REQ_PATTERN.matcher(getPath()); if (matcher.find()) { this.collection = matcher.group(2); @@ -105,6 +105,11 @@ public boolean isPerCollectionRequest() { return isPerCollectionRequest; } + @Override + public boolean requiresCollection() { + return isPerCollectionRequest; + } + @Override public String getCollection() { return collection; @@ -134,11 +139,6 @@ public ResponseParser getResponseParser() { return super.getResponseParser(); } - @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); - } - public static class Builder { private String resource; private METHOD method = METHOD.GET; diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/schema/AbstractSchemaRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/schema/AbstractSchemaRequest.java index 1547e13d1a1..ea32f148b22 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/schema/AbstractSchemaRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/schema/AbstractSchemaRequest.java @@ -30,7 +30,7 @@ public AbstractSchemaRequest(METHOD m, String path) { } public AbstractSchemaRequest(METHOD m, String path, SolrParams params) { - super(m, path); + super(m, path, SolrRequestType.ADMIN); this.params = params != null ? params : new ModifiableSolrParams(); } @@ -38,9 +38,4 @@ public AbstractSchemaRequest(METHOD m, String path, SolrParams params) { public SolrParams getParams() { return params; } - - @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); - } } diff --git a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java index 3055708d29e..32687789a69 100644 --- a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java +++ b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java @@ -224,6 +224,7 @@ public interface CommonParams { String OK = "OK"; String FAILURE = "FAILURE"; + /** /admin paths which don't require a target collection */ Set ADMIN_PATHS = Set.of( CORES_HANDLER_PATH, @@ -236,6 +237,7 @@ public interface CommonParams { AUTHC_PATH, AUTHZ_PATH, METRICS_PATH); + String APISPEC_LOCATION = "apispec/"; String INTROSPECT = "/_introspect"; diff --git a/solr/solrj/src/resources/java-template/api.mustache b/solr/solrj/src/resources/java-template/api.mustache index 0ed28650056..f2eac4544c2 100644 --- a/solr/solrj/src/resources/java-template/api.mustache +++ b/solr/solrj/src/resources/java-template/api.mustache @@ -122,10 +122,12 @@ public class {{classname}} { {{/requiredParams}} */ public {{operationIdCamelCase}}({{#allParams}}{{#required}}{{^isBodyParam}}{{^-first}}, {{/-first}}{{{dataType}}} {{paramName}}{{/isBodyParam}}{{#isBodyParam}}{{#vendorExtensions.x-genericEntity}}{{^-first}}, {{/-first}}{{{dataType}}} requestBody{{/vendorExtensions.x-genericEntity}}{{/isBodyParam}}{{/required}}{{/allParams}}) { + // TODO Hardcode request type for now, but in reality we'll want to parse this out of the Operation data somehow super( SolrRequest.METHOD.valueOf("{{httpMethod}}"), "{{{path}}}"{{#pathParams}} - .replace("{" + "{{baseName}}" + "}", {{paramName}}{{^isString}}.toString(){{/isString}}){{/pathParams}} + .replace("{" + "{{baseName}}" + "}", {{paramName}}{{^isString}}.toString(){{/isString}}){{/pathParams}}, + SolrRequestType.ADMIN ); {{#requiredParams}} @@ -218,12 +220,6 @@ public class {{classname}} { } {{/bodyParam}} - // TODO Hardcode this for now, but in reality we'll want to parse this out of the Operation data somehow - @Override - public String getRequestType() { - return SolrRequestType.ADMIN.toString(); - } - @Override public ApiVersion getApiVersion() { return ApiVersion.V2; diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java index 0b610339687..2fc66ad7913 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java @@ -439,6 +439,7 @@ public void testExampleConfig() throws Exception { try (SolrClient adminClient = getHttpSolrClient(url)) { SolrQuery q = new SolrQuery(); q.set("qt", "/admin/info/system"); + QueryResponse rsp = adminClient.query(q); assertNotNull(rsp.getResponse().get("mode")); assertNotNull(rsp.getResponse().get("lucene")); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientRetryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientRetryTest.java index 505210c94df..61287300d2e 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientRetryTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientRetryTest.java @@ -19,9 +19,10 @@ import java.util.Collections; import java.util.Optional; -import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.SolrRequest.METHOD; +import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.cloud.SolrCloudTestCase; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.params.CommonParams; @@ -60,14 +61,17 @@ public void testRetry() throws Exception { solrClient.add(collectionName, new SolrInputDocument("id", "1")); ModifiableSolrParams params = new ModifiableSolrParams(); - params.set(CommonParams.QT, "/admin/metrics"); String updateRequestCountKey = "solr.core.testRetry.shard1.replica_n1:UPDATE./update.requestTimes:count"; params.set("key", updateRequestCountKey); params.set("indent", "true"); + params.set(CommonParams.WT, "xml"); - QueryResponse response = solrClient.query(collectionName, params, SolrRequest.METHOD.GET); - NamedList namedList = response.getResponse(); + var metricsRequest = + new GenericSolrRequest(METHOD.GET, "/admin/metrics", SolrRequestType.ADMIN, params); + metricsRequest.setRequiresCollection(false); + + NamedList namedList = solrClient.request(metricsRequest); System.out.println(namedList); NamedList metrics = (NamedList) namedList.get("metrics"); assertEquals(1L, metrics.get(updateRequestCountKey)); @@ -84,8 +88,7 @@ public void testRetry() throws Exception { TestInjection.reset(); } - response = solrClient.query(collectionName, params, SolrRequest.METHOD.GET); - namedList = response.getResponse(); + namedList = solrClient.request(metricsRequest); System.out.println(namedList); metrics = (NamedList) namedList.get("metrics"); assertEquals(2L, metrics.get(updateRequestCountKey)); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java index e8233413be1..7c36d4aef0e 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java @@ -39,9 +39,12 @@ import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrQuery; +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.AbstractUpdateRequest; import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -730,11 +733,14 @@ public void testNonRetryableRequests() throws Exception { } ModifiableSolrParams params = new ModifiableSolrParams(); - params.set("qt", adminPath); params.set("action", "foobar"); // this should cause an error - QueryRequest req = new QueryRequest(params); + params.set("qt", adminPath); + + var request = + new GenericSolrRequest(METHOD.GET, adminPath, SolrRequestType.ADMIN, params); + request.setRequiresCollection(false); try { - NamedList resp = client.request(req); + NamedList resp = client.request(request); fail("call to foo for admin path " + adminPath + " should have failed"); } catch (Exception e) { // expected diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java index 9f4fbb85b61..59ef3f1d661 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java @@ -17,9 +17,10 @@ package org.apache.solr.client.solrj.impl; -import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.SolrRequest.METHOD; +import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.cloud.SolrCloudTestCase; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.params.CommonParams; @@ -55,14 +56,17 @@ public void testRetry() throws Exception { solrClient.add(collectionName, new SolrInputDocument("id", "1")); ModifiableSolrParams params = new ModifiableSolrParams(); - params.set(CommonParams.QT, "/admin/metrics"); String updateRequestCountKey = "solr.core.testRetry.shard1.replica_n1:UPDATE./update.requestTimes:count"; params.set("key", updateRequestCountKey); params.set("indent", "true"); + params.set(CommonParams.WT, "xml"); - QueryResponse response = solrClient.query(collectionName, params, SolrRequest.METHOD.GET); - NamedList namedList = response.getResponse(); + var metricsRequest = + new GenericSolrRequest(METHOD.GET, "/admin/metrics", SolrRequestType.ADMIN, params); + metricsRequest.setRequiresCollection(false); + + NamedList namedList = solrClient.request(metricsRequest); System.out.println(namedList); @SuppressWarnings({"rawtypes"}) NamedList metrics = (NamedList) namedList.get("metrics"); @@ -80,8 +84,7 @@ public void testRetry() throws Exception { TestInjection.reset(); } - response = solrClient.query(collectionName, params, SolrRequest.METHOD.GET); - namedList = response.getResponse(); + namedList = solrClient.request(metricsRequest); System.out.println(namedList); metrics = (NamedList) namedList.get("metrics"); assertEquals(2L, metrics.get(updateRequestCountKey)); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java index cb1b015d7e9..13195846baa 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java @@ -39,9 +39,12 @@ import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrQuery; +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.AbstractUpdateRequest; import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.request.V2Request; @@ -666,11 +669,13 @@ public void testNonRetryableRequests() throws Exception { } ModifiableSolrParams params = new ModifiableSolrParams(); - params.set("qt", adminPath); params.set("action", "foobar"); // this should cause an error - QueryRequest req = new QueryRequest(params); + + var request = + new GenericSolrRequest(METHOD.GET, adminPath, SolrRequestType.ADMIN, params); + request.setRequiresCollection(false); try { - NamedList resp = client.request(req); + NamedList resp = client.request(request); fail("call to foo for admin path " + adminPath + " should have failed"); } catch (Exception e) { // expected diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/SendUpdatesToLeadersOverrideTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/SendUpdatesToLeadersOverrideTest.java index 91ad98170f1..89c674b01ee 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/SendUpdatesToLeadersOverrideTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/SendUpdatesToLeadersOverrideTest.java @@ -34,7 +34,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.request.AbstractUpdateRequest; import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.request.IsUpdateRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.cloud.SolrCloudTestCase; import org.apache.solr.common.cloud.Replica; @@ -48,7 +47,7 @@ /** * Test the behavior of {@link CloudSolrClient#isUpdatesToLeaders} and {@link - * IsUpdateRequest#isSendToLeaders}. + * UpdateRequest#isSendToLeaders}. * *

This class uses {@link TrackingUpdateProcessorFactory} instances (configured both before, and * after the distrib processor) to inspect which replicas receive various {@link @@ -202,7 +201,7 @@ private static RecordingResults assertUpdateWithRecording( * setting shards.preference=replica.type:PULL on the input req, and then returning * that req */ - private static AbstractUpdateRequest prefPull(final AbstractUpdateRequest req) { + private static UpdateRequest prefPull(final UpdateRequest req) { req.setParam("shards.preference", "replica.type:PULL"); return req; } @@ -481,7 +480,7 @@ private void checkUpdatesWithShardsPrefPull(final CloudSolrClient client) throws } /** - * Given a SolrClient, sends various updates were {@link IsUpdateRequest#isSendToLeaders} returns + * Given a SolrClient, sends various updates were {@link UpdateRequest#isSendToLeaders} returns * false, and asserts expectations that requests using {@link #prefPull} are all sent to PULL * replicas, regardless of how the client is configured. */ diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java index 4fcd1b1279f..234031ee860 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java @@ -41,12 +41,15 @@ import org.apache.solr.JSONTestUtil; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrQuery; +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.QueryRequest; import org.apache.solr.client.solrj.request.StreamingUpdateRequest; import org.apache.solr.client.solrj.request.UpdateRequest; @@ -1284,11 +1287,10 @@ private Long getNumCommits(HttpSolrClient sourceClient) throws SolrServerExcepti ModifiableSolrParams params = new ModifiableSolrParams(); // params.set("qt", "/admin/metrics?prefix=UPDATE.updateHandler®istry=solr.core." + // collection); - params.set("qt", "/admin/metrics"); params.set("prefix", "UPDATE.updateHandler"); params.set("registry", "solr.core." + collection); // use generic request to avoid extra processing of queries - QueryRequest req = new QueryRequest(params); + var req = new GenericSolrRequest(METHOD.GET, "/admin/metrics", SolrRequestType.ADMIN, params); NamedList resp = client.request(req); NamedList metrics = (NamedList) resp.get("metrics"); NamedList uhandlerCat = (NamedList) metrics.getVal(0); diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java index 681bf7152e5..5f8e5c4cff6 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java @@ -49,13 +49,15 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrRequest; +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.cloud.SocketProxy; import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.CoreAdminRequest; -import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.CollectionAdminResponse; import org.apache.solr.client.solrj.response.CoreAdminResponse; @@ -2077,8 +2079,8 @@ protected CollectionAdminResponse createCollection( } params.set("name", collectionName); @SuppressWarnings({"rawtypes"}) - SolrRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + SolrRequest request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); CollectionAdminResponse res = new CollectionAdminResponse(); if (client == null) { @@ -2554,7 +2556,8 @@ protected boolean reloadCollection(Replica replica, String testCollectionName) t ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.RELOAD.toString()); params.set("name", testCollectionName); - QueryRequest request = new QueryRequest(params); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); request.setPath("/admin/collections"); client.request(request); Thread.sleep(2000); // reload can take a short while diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/ConfigRequest.java b/solr/test-framework/src/java/org/apache/solr/cloud/ConfigRequest.java index 2ddf05aeb44..3ab86e3c430 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/ConfigRequest.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/ConfigRequest.java @@ -36,7 +36,7 @@ public class ConfigRequest extends CollectionRequiringSolrRequest { protected final String message; public ConfigRequest(String message) { - super(SolrRequest.METHOD.POST, "/config"); + super(SolrRequest.METHOD.POST, "/config", SolrRequestType.ADMIN); this.message = message; } @@ -56,9 +56,4 @@ public RequestWriter.ContentWriter getContentWriter(String expectedType) { public SolrResponse createResponse(SolrClient client) { return new SolrResponseBase(); } - - @Override - public String getRequestType() { - return SolrRequest.SolrRequestType.ADMIN.toString(); - } } diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java index 0a2a7ae6099..89571dfe646 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java @@ -42,10 +42,12 @@ import org.apache.solr.client.api.model.CoreStatusResponse; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrQuery; +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.CoreAdminRequest; -import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.GenericSolrRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.CollectionAdminResponse; import org.apache.solr.client.solrj.response.CoreAdminResponse; @@ -192,8 +194,8 @@ public void testBadActionNames() { String collectionName = "badactioncollection"; params.set("name", collectionName); params.set("numShards", 2); - final QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); expectThrows( Exception.class, @@ -208,8 +210,8 @@ public void testMissingRequiredParameters() { params.set("action", CollectionAction.CREATE.toString()); params.set("numShards", 2); // missing required collection parameter - final QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); expectThrows( Exception.class, @@ -227,8 +229,8 @@ public void testMissingNumShards() { params.set(REPLICATION_FACTOR, 10); params.set("collection.configName", "conf"); - final QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); expectThrows( Exception.class, @@ -246,8 +248,8 @@ public void testZeroNumShards() { params.set("numShards", 0); params.set("collection.configName", "conf"); - final QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest(METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); expectThrows( Exception.class, () -> { @@ -675,8 +677,9 @@ public void addReplicaTest() throws Exception { params.set("collection", collectionName); params.set("shard", "shard1"); params.set("name", coreName); - QueryRequest request = new QueryRequest(params); - request.setPath("/admin/collections"); + var request = + new GenericSolrRequest( + METHOD.GET, "/admin/collections", SolrRequestType.ADMIN, params); cluster.getSolrClient().request(request); });