This is an automated email from the ASF dual-hosted git repository. dsmiley pushed a commit to branch branch_9x in repository https://gitbox.apache.org/repos/asf/solr.git
commit af1c5bcbf3269cc6ab697234530e8ae9b9bfbb9c Author: Xinyao Zhang <[email protected]> AuthorDate: Thu Sep 3 20:16:18 2026 -0400 SOLR-18343: SolrJ now uses POST for suitable v1 admin requests (#4861) SolrJ v1 admin requests now use appropriate HTTP verbs -- mostly POST, some GET. Observability note: hurts since useful request params are no longer in the URL. Addressing separately. (cherry picked from commit 22620db37328e1f8794574daad661542ed0ab98d) --- .../solr-18343-explicit-admin-methods.yml | 8 + .../solr/util/tracing/TestDistributedTracing.java | 8 +- .../solrj/request/CollectionAdminRequest.java | 200 ++++++++++++++------- .../solrj/request/ConfigSetAdminRequest.java | 37 +++- .../client/solrj/request/CoreAdminRequest.java | 42 +++-- .../solrj/request/TestCollectionAdminRequest.java | 20 +++ .../solrj/request/TestConfigSetAdminRequest.java | 9 + .../solr/client/solrj/request/TestCoreAdmin.java | 9 + 8 files changed, 254 insertions(+), 79 deletions(-) diff --git a/changelog/unreleased/solr-18343-explicit-admin-methods.yml b/changelog/unreleased/solr-18343-explicit-admin-methods.yml new file mode 100644 index 00000000000..3f88523466e --- /dev/null +++ b/changelog/unreleased/solr-18343-explicit-admin-methods.yml @@ -0,0 +1,8 @@ +title: > + SolrJ v1 admin requests now use appropriate HTTP verbs -- mostly POST, some GET +type: changed +authors: + - name: Xinyao Zhang +links: + - name: SOLR-18343 + url: https://issues.apache.org/jira/browse/SOLR-18343 diff --git a/solr/core/src/test/org/apache/solr/util/tracing/TestDistributedTracing.java b/solr/core/src/test/org/apache/solr/util/tracing/TestDistributedTracing.java index a039511af63..6ddb021546c 100644 --- a/solr/core/src/test/org/apache/solr/util/tracing/TestDistributedTracing.java +++ b/solr/core/src/test/org/apache/solr/util/tracing/TestDistributedTracing.java @@ -203,7 +203,7 @@ public class TestDistributedTracing extends SolrCloudTestCase { assertEquals(0, r1.getStatus()); // Expecting 8 spans: - // 1. api call 'operationName:"create:/admin/collections"', + // 1. api call 'operationName:"post:/admin/collections"', // db.instance=testInternalCollectionApiCommands // - unique traceId unrelated to the internal trace id generated for the operation // 2. internal CollectionApiCommand 'operationName:"CreateCollectionCmd"' @@ -223,7 +223,7 @@ public class TestDistributedTracing extends SolrCloudTestCase { var finishedSpans = getAndClearSpans(); var s0 = finishedSpans.remove(0); assertDbInstanceColl(s0, collection); - assertEquals("create:/admin/collections", s0.operationName()); + assertEquals("post:/admin/collections", s0.operationName()); Map<String, Integer> ops = new HashMap<>(); assertEquals(7, finishedSpans.size()); @@ -251,7 +251,7 @@ public class TestDistributedTracing extends SolrCloudTestCase { assertEquals(0, r1.getStatus()); // Expecting 6 spans: - // 1. api call 'operationName:"delete:/admin/collections"', + // 1. api call 'operationName:"post:/admin/collections"', // db.instance=testInternalCollectionApiCommands // - unique traceId unrelated to the internal trace id generated for the operation // 2. internal CollectionApiCommand 'operationName:"DeleteCollectionCmd"' @@ -267,7 +267,7 @@ public class TestDistributedTracing extends SolrCloudTestCase { var finishedSpans = getAndClearSpans(); var s0 = finishedSpans.remove(0); assertDbInstanceColl(s0, collection); - assertEquals("delete:/admin/collections", s0.operationName()); + assertEquals("post:/admin/collections", s0.operationName()); Map<String, Integer> ops = new HashMap<>(); assertEquals(5, finishedSpans.size()); 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 9afdd3d579a..38d25dba71b 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 @@ -79,13 +79,29 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> @Deprecated public static String PROPERTY_PREFIX = CollectionAdminParams.PROPERTY_PREFIX; + public CollectionAdminRequest(METHOD method, CollectionAction action) { + this(method, "/admin/collections", action); + } + + public CollectionAdminRequest(METHOD method, String path, CollectionAction action) { + super(method, path); + this.action = checkNotNull(CoreAdminParams.ACTION, action); + } + + /** + * @deprecated Use {@link #CollectionAdminRequest(METHOD, CollectionAction)}. + */ + @Deprecated(since = "11.0") public CollectionAdminRequest(CollectionAction action) { - this("/admin/collections", action); + this(METHOD.POST, action); } + /** + * @deprecated Use {@link #CollectionAdminRequest(METHOD, String, CollectionAction)}. + */ + @Deprecated(since = "11.0") public CollectionAdminRequest(String path, CollectionAction action) { - super(METHOD.GET, path); - this.action = checkNotNull(CoreAdminParams.ACTION, action); + this(METHOD.POST, path, action); } @Override @@ -149,8 +165,16 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String asyncId = null; protected boolean waitForFinalState = false; + public AsyncCollectionAdminRequest(METHOD method, CollectionAction action) { + super(method, action); + } + + /** + * @deprecated Use {@link #AsyncCollectionAdminRequest(METHOD, CollectionAction)}. + */ + @Deprecated(since = "11.0") public AsyncCollectionAdminRequest(CollectionAction action) { - super(action); + this(METHOD.POST, action); } @Override @@ -251,11 +275,21 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String collection; protected Boolean followAliases; - public AsyncCollectionSpecificAdminRequest(CollectionAction action, String collection) { - super(action); + public AsyncCollectionSpecificAdminRequest( + METHOD method, CollectionAction action, String collection) { + super(method, action); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); } + /** + * @deprecated Use {@link #AsyncCollectionSpecificAdminRequest(METHOD, CollectionAction, + * String)}. + */ + @Deprecated(since = "11.0") + public AsyncCollectionSpecificAdminRequest(CollectionAction action, String collection) { + this(METHOD.POST, action, collection); + } + public String getCollectionName() { return collection; } @@ -280,12 +314,22 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String shard; public AsyncShardSpecificAdminRequest( - CollectionAction action, String collection, String shard) { - super(action); + METHOD method, CollectionAction action, String collection, String shard) { + super(method, action); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); this.shard = checkNotNull(CoreAdminParams.SHARD, shard); } + /** + * @deprecated Use {@link #AsyncShardSpecificAdminRequest(METHOD, CollectionAction, String, + * String)}. + */ + @Deprecated(since = "11.0") + public AsyncShardSpecificAdminRequest( + CollectionAction action, String collection, String shard) { + this(METHOD.POST, action, collection, shard); + } + @Override public SolrParams getParams() { ModifiableSolrParams params = new ModifiableSolrParams(super.getParams()); @@ -301,12 +345,21 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String collection; protected String shard; - public ShardSpecificAdminRequest(CollectionAction action, String collection, String shard) { - super(action); + public ShardSpecificAdminRequest( + METHOD method, CollectionAction action, String collection, String shard) { + super(method, action); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); this.shard = checkNotNull(CoreAdminParams.SHARD, shard); } + /** + * @deprecated Use {@link #ShardSpecificAdminRequest(METHOD, CollectionAction, String, String)}. + */ + @Deprecated(since = "11.0") + public ShardSpecificAdminRequest(CollectionAction action, String collection, String shard) { + this(METHOD.POST, action, collection, shard); + } + @Override public SolrParams getParams() { ModifiableSolrParams params = new ModifiableSolrParams(super.getParams()); @@ -330,12 +383,22 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String node; protected String role; - public CollectionAdminRoleRequest(CollectionAction action, String node, String role) { - super(action); + public CollectionAdminRoleRequest( + METHOD method, CollectionAction action, String node, String role) { + super(method, action); this.role = checkNotNull(CollectionAdminParams.ROLE, role); this.node = checkNotNull(CoreAdminParams.NODE, node); } + /** + * @deprecated Use {@link #CollectionAdminRoleRequest(METHOD, CollectionAction, String, + * String)}. + */ + @Deprecated(since = "11.0") + public CollectionAdminRoleRequest(CollectionAction action, String node, String role) { + this(METHOD.POST, action, node, role); + } + public String getNode() { return this.node; } @@ -524,7 +587,10 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> Integer numNrtReplicas, Integer numTlogReplicas, Integer numPullReplicas) { - super(CollectionAction.CREATE, SolrIdentifierValidator.validateCollectionName(collection)); + super( + METHOD.POST, + CollectionAction.CREATE, + SolrIdentifierValidator.validateCollectionName(collection)); // NOTE: there's very little we can assert about the args because nothing but "collection" is // required by the server if ((null != shards) && (null != numShards)) { @@ -721,7 +787,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> public static class Reload extends AsyncCollectionSpecificAdminRequest { private Reload(String collection) { - super(CollectionAction.RELOAD, collection); + super(METHOD.POST, CollectionAction.RELOAD, collection); } } @@ -733,7 +799,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> String target; public Rename(String collection, String target) { - super(CollectionAction.RENAME, collection); + super(METHOD.POST, CollectionAction.RENAME, collection); this.target = target; } @@ -757,7 +823,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> * @param node The node to be deleted */ public DeleteNode(String node) { - super(CollectionAction.DELETENODE); + super(METHOD.POST, CollectionAction.DELETENODE); this.node = checkNotNull("node", node); } @@ -778,7 +844,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> * @param target node where the new replicas are to be created */ public ReplaceNode(String source, String target) { - super(CollectionAction.REPLACENODE); + super(METHOD.POST, CollectionAction.REPLACENODE); this.sourceNode = checkNotNull(CollectionParams.SOURCE_NODE, source); this.targetNode = target; } @@ -812,7 +878,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected int timeout = -1; public MoveReplica(String collection, String replica, String targetNode) { - super(CollectionAction.MOVEREPLICA); + super(METHOD.POST, CollectionAction.MOVEREPLICA); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); this.replica = checkNotNull(CoreAdminParams.REPLICA, replica); this.targetNode = checkNotNull(CollectionParams.TARGET_NODE, targetNode); @@ -820,7 +886,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> } public MoveReplica(String collection, String shard, String sourceNode, String targetNode) { - super(CollectionAction.MOVEREPLICA); + super(METHOD.POST, CollectionAction.MOVEREPLICA); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); this.shard = checkNotNull(CoreAdminParams.SHARD, shard); this.sourceNode = checkNotNull(CollectionParams.SOURCE_NODE, sourceNode); @@ -887,7 +953,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> } public RebalanceLeaders(String collection) { - super(CollectionAction.REBALANCELEADERS); + super(METHOD.POST, CollectionAction.REBALANCELEADERS); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); } @@ -928,7 +994,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> Map<String, Object> collectionParams = new HashMap<>(); private ReindexCollection(String collection) { - super(CollectionAction.REINDEXCOLLECTION, collection); + super(METHOD.POST, CollectionAction.REINDEXCOLLECTION, collection); } /** Target collection name (null if the same). */ @@ -1021,12 +1087,12 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected Float rawSizeSamplingPercent = null; private ColStatus(String collection) { - super(CollectionAction.COLSTATUS); + super(METHOD.GET, CollectionAction.COLSTATUS); this.collection = collection; } private ColStatus() { - super(CollectionAction.COLSTATUS); + super(METHOD.GET, CollectionAction.COLSTATUS); } public ColStatus setWithSegments(boolean withSegments) { @@ -1094,7 +1160,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> public static class Delete extends AsyncCollectionSpecificAdminRequest { private Delete(String collection) { - super(CollectionAction.DELETE, collection); + super(METHOD.POST, CollectionAction.DELETE, collection); } } @@ -1115,7 +1181,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected Properties extraProperties; public Backup(String collection, String name) { - super(CollectionAction.BACKUP, collection); + super(METHOD.POST, CollectionAction.BACKUP, collection); this.name = name; this.repositoryName = Optional.empty(); } @@ -1261,7 +1327,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected Integer backupId; public Restore(String collection, String backupName) { - super(CollectionAction.RESTORE, collection); + super(METHOD.POST, CollectionAction.RESTORE, collection); this.backupName = backupName; } @@ -1449,7 +1515,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String location; public InstallShard(String collection, String shard, String location, String backupRepository) { - super(CollectionAction.INSTALLSHARDDATA, collection, shard); + super(METHOD.POST, CollectionAction.INSTALLSHARDDATA, collection, shard); this.repositoryName = backupRepository; this.location = location; @@ -1481,7 +1547,10 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected final String commitName; public CreateSnapshot(String collection, String commitName) { - super(CollectionAction.CREATESNAPSHOT, checkNotNull(CoreAdminParams.COLLECTION, collection)); + super( + METHOD.POST, + CollectionAction.CREATESNAPSHOT, + checkNotNull(CoreAdminParams.COLLECTION, collection)); this.commitName = checkNotNull(CoreAdminParams.COMMIT_NAME, commitName); } @@ -1508,7 +1577,10 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected final String commitName; public DeleteSnapshot(String collection, String commitName) { - super(CollectionAction.DELETESNAPSHOT, checkNotNull(CoreAdminParams.COLLECTION, collection)); + super( + METHOD.POST, + CollectionAction.DELETESNAPSHOT, + checkNotNull(CoreAdminParams.COLLECTION, collection)); this.commitName = checkNotNull(CoreAdminParams.COMMIT_NAME, commitName); } @@ -1533,7 +1605,10 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> @SuppressWarnings("serial") public static class ListSnapshots extends AsyncCollectionSpecificAdminRequest { public ListSnapshots(String collection) { - super(CollectionAction.LISTSNAPSHOTS, checkNotNull(CoreAdminParams.COLLECTION, collection)); + super( + METHOD.GET, + CollectionAction.LISTSNAPSHOTS, + checkNotNull(CoreAdminParams.COLLECTION, collection)); } @Override @@ -1580,6 +1655,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> private CreateShard(String collection, String shard) { super( + METHOD.POST, CollectionAction.CREATESHARD, collection, SolrIdentifierValidator.validateShardName(shard)); @@ -1609,7 +1685,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String sleep; private MockCollTask(String collection) { - super(CollectionAction.MOCK_COLL_TASK); + super(METHOD.POST, CollectionAction.MOCK_COLL_TASK); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); } @@ -1647,7 +1723,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String createNodeSet; private SplitShard(String collection) { - super(CollectionAction.SPLITSHARD); + super(METHOD.POST, CollectionAction.SPLITSHARD); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); } @@ -1771,7 +1847,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> private Boolean deleteDataDir; private DeleteShard(String collection, String shard) { - super(CollectionAction.DELETESHARD, collection, shard); + super(METHOD.POST, CollectionAction.DELETESHARD, collection, shard); } public Boolean getDeleteInstanceDir() { @@ -1818,7 +1894,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> // FORCELEADER request public static class ForceLeader extends ShardSpecificAdminRequest { private ForceLeader(String collection, String shard) { - super(CollectionAction.FORCELEADER, collection, shard); + super(METHOD.POST, CollectionAction.FORCELEADER, collection, shard); } } @@ -1851,7 +1927,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String requestId = null; private RequestStatus(String requestId) { - super(CollectionAction.REQUESTSTATUS); + super(METHOD.GET, CollectionAction.REQUESTSTATUS); this.requestId = checkNotNull("requestId", requestId); } @@ -1912,7 +1988,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected Boolean flush = null; private DeleteStatus(String requestId, Boolean flush) { - super(CollectionAction.DELETESTATUS); + super(METHOD.POST, CollectionAction.DELETESTATUS); if (requestId == null && flush == null) throw new IllegalArgumentException( "Either requestid or flush parameter must be specified."); @@ -1963,7 +2039,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> private Map<String, String> properties = new HashMap<>(); public SetAliasProperty(String aliasName) { - super(CollectionAction.ALIASPROP); + super(METHOD.POST, CollectionAction.ALIASPROP); this.aliasName = SolrIdentifierValidator.validateAliasName(aliasName); } @@ -2002,7 +2078,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String aliasedCollections; private CreateAlias(String aliasName, String aliasedCollections) { - super(CollectionAction.CREATEALIAS); + super(METHOD.POST, CollectionAction.CREATEALIAS); this.aliasName = SolrIdentifierValidator.validateAliasName(aliasName); this.aliasedCollections = checkNotNull("aliasedCollections", aliasedCollections); } @@ -2076,7 +2152,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> String start, String interval, Create createCollTemplate) { - super(CollectionAction.CREATEALIAS); + super(METHOD.POST, CollectionAction.CREATEALIAS); this.aliasName = aliasName; this.start = start; this.interval = interval; @@ -2202,7 +2278,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> public CreateCategoryRoutedAlias( String aliasName, String routerField, int maxCardinality, Create createCollTemplate) { - super(CollectionAction.CREATEALIAS); + super(METHOD.POST, CollectionAction.CREATEALIAS); this.aliasName = aliasName; this.routerField = routerField; this.maxCardinality = maxCardinality; @@ -2308,7 +2384,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> public DimensionalRoutedAlias( String aliasName, Create createCollTemplate, RoutedAliasAdminRequest... dims) { - super(CollectionAction.CREATEALIAS); + super(METHOD.POST, CollectionAction.CREATEALIAS); this.aliasName = aliasName; this.createCollTemplate = createCollTemplate; this.dims = dims; @@ -2392,7 +2468,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String aliasName; private DeleteAlias(String aliasName) { - super(CollectionAction.DELETEALIAS); + super(METHOD.POST, CollectionAction.DELETEALIAS); this.aliasName = checkNotNull("aliasName", aliasName); } @@ -2447,7 +2523,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String createNodeSet; private AddReplica(String collection, String shard, String routeKey, Replica.Type type) { - super(CollectionAction.ADDREPLICA); + super(METHOD.POST, CollectionAction.ADDREPLICA); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); this.shard = shard; this.routeKey = routeKey; @@ -2648,19 +2724,19 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> private Integer count; private DeleteReplica(String collection, String shard, String replica) { - super(CollectionAction.DELETEREPLICA, collection); + super(METHOD.POST, CollectionAction.DELETEREPLICA, collection); this.shard = shard; this.replica = replica; } private DeleteReplica(String collection, String shard, int count) { - super(CollectionAction.DELETEREPLICA, collection); + super(METHOD.POST, CollectionAction.DELETEREPLICA, collection); this.shard = shard; this.count = count; } private DeleteReplica(String collection, int count) { - super(CollectionAction.DELETEREPLICA, collection); + super(METHOD.POST, CollectionAction.DELETEREPLICA, collection); this.count = count; } @@ -2747,7 +2823,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> private String propertyValue; private ClusterProp(String propertyName, String propertyValue) { - super(CollectionAction.CLUSTERPROP); + super(METHOD.POST, CollectionAction.CLUSTERPROP); this.propertyName = checkNotNull("propertyName", propertyName); this.propertyValue = propertyValue; } @@ -2787,7 +2863,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> private String propertyValue; private CollectionProp(String collection, String propertyName, String propertyValue) { - super(CollectionAction.COLLECTIONPROP, collection); + super(METHOD.POST, CollectionAction.COLLECTIONPROP, collection); this.propertyName = checkNotNull("propertyName", propertyName); this.propertyValue = propertyValue; } @@ -2830,7 +2906,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> private Properties properties; private Migrate(String collection, String targetCollection, String splitKey) { - super(CollectionAction.MIGRATE); + super(METHOD.POST, CollectionAction.MIGRATE); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); this.targetCollection = checkNotNull("targetCollection", targetCollection); this.splitKey = checkNotNull("split.key", splitKey); @@ -2891,7 +2967,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> // ADDROLE request public static class AddRole extends CollectionAdminRoleRequest { private AddRole(String node, String role) { - super(CollectionAction.ADDROLE, node, role); + super(METHOD.POST, CollectionAction.ADDROLE, node, role); } } @@ -2903,7 +2979,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> // REMOVEROLE request public static class RemoveRole extends CollectionAdminRoleRequest { private RemoveRole(String node, String role) { - super(CollectionAction.REMOVEROLE, node, role); + super(METHOD.POST, CollectionAction.REMOVEROLE, node, role); } } @@ -2916,7 +2992,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> public static class OverseerStatus extends AsyncCollectionAdminRequest { public OverseerStatus() { - super(CollectionAction.OVERSEERSTATUS); + super(METHOD.GET, CollectionAction.OVERSEERSTATUS); } } @@ -2925,7 +3001,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> extends CollectionAdminRequest<RequestApiDistributedProcessingResponse> { public RequestApiDistributedProcessing() { - super(CollectionAction.DISTRIBUTEDAPIPROCESSING); + super(METHOD.GET, CollectionAction.DISTRIBUTEDAPIPROCESSING); } @Override @@ -2954,7 +3030,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected String routeKey = null; public ClusterStatus() { - super(CollectionAction.CLUSTERSTATUS); + super(METHOD.GET, CollectionAction.CLUSTERSTATUS); } public ClusterStatus setCollectionName(String collectionName) { @@ -3009,7 +3085,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> public static class ListAliases extends CollectionAdminRequest<CollectionAdminResponse> { public ListAliases() { - super(CollectionAction.LISTALIASES); + super(METHOD.GET, CollectionAction.LISTALIASES); } @Override @@ -3029,7 +3105,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> // LIST request public static class List extends CollectionAdminRequest<CollectionAdminResponse> { public List() { - super(CollectionAction.LIST); + super(METHOD.GET, CollectionAction.LIST); } @Override @@ -3102,7 +3178,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> private Boolean purgeUnused; private DeleteBackup(String backupName) { - super(CollectionAction.DELETEBACKUP); + super(METHOD.POST, CollectionAction.DELETEBACKUP); this.name = backupName; } @@ -3205,7 +3281,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> private String repositoryName; private ListBackup(String backupName) { - super(CollectionAction.LISTBACKUP); + super(METHOD.GET, CollectionAction.LISTBACKUP); this.backupName = backupName; } @@ -3267,7 +3343,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> String replica, String propertyName, String propertyValue) { - super(CollectionAction.ADDREPLICAPROP, collection, shard); + super(METHOD.POST, CollectionAction.ADDREPLICAPROP, collection, shard); this.replica = checkNotNull(CoreAdminParams.REPLICA, replica); this.propertyName = checkNotNull("propertyName", propertyName); this.propertyValue = checkNotNull("propertyValue", propertyValue); @@ -3323,7 +3399,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> private DeleteReplicaProp( String collection, String shard, String replica, String propertyName) { - super(CollectionAction.DELETEREPLICAPROP, collection, shard); + super(METHOD.POST, CollectionAction.DELETEREPLICAPROP, collection, shard); this.replica = checkNotNull(CoreAdminParams.REPLICA, replica); this.propertyName = checkNotNull("propertyName", propertyName); } @@ -3359,7 +3435,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected Boolean shardUnique; private BalanceShardUnique(String collection, String propertyName) { - super(CollectionAction.BALANCESHARDUNIQUE); + super(METHOD.POST, CollectionAction.BALANCESHARDUNIQUE); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); this.propertyName = checkNotNull("propertyName", propertyName); } @@ -3407,7 +3483,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse> protected Map<String, Object> attributes; private Modify(String collection, Map<String, Object> attributes) { - super(CollectionAction.MODIFYCOLLECTION, collection); + super(METHOD.POST, CollectionAction.MODIFYCOLLECTION, collection); this.attributes = attributes; } 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 4c21ce6c776..117265606f2 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 @@ -51,12 +51,28 @@ public abstract class ConfigSetAdminRequest< return this; } + public ConfigSetAdminRequest(METHOD method) { + this(method, "/admin/configs"); + } + + public ConfigSetAdminRequest(METHOD method, String path) { + super(method, path); + } + + /** + * @deprecated Use {@link #ConfigSetAdminRequest(METHOD)}. + */ + @Deprecated(since = "11.0") public ConfigSetAdminRequest() { - super(METHOD.GET, "/admin/configs"); + this(METHOD.POST); } + /** + * @deprecated Use {@link #ConfigSetAdminRequest(METHOD, String)}. + */ + @Deprecated(since = "11.0") public ConfigSetAdminRequest(String path) { - super(METHOD.GET, path); + this(METHOD.POST, path); } protected abstract Q getThis(); @@ -79,6 +95,18 @@ public abstract class ConfigSetAdminRequest< extends ConfigSetAdminRequest<T, ConfigSetAdminResponse> { protected String configSetName = null; + protected ConfigSetSpecificAdminRequest(METHOD method) { + super(method); + } + + /** + * @deprecated Use {@link #ConfigSetSpecificAdminRequest(METHOD)}. + */ + @Deprecated(since = "11.0") + protected ConfigSetSpecificAdminRequest() { + this(METHOD.POST); + } + public final T setConfigSetName(String configSetName) { this.configSetName = configSetName; return getThis(); @@ -127,8 +155,8 @@ public abstract class ConfigSetAdminRequest< protected Boolean cleanup; public Upload() { + super(METHOD.POST); action = ConfigSetAction.UPLOAD; - setMethod(SolrRequest.METHOD.POST); } @Override @@ -260,6 +288,7 @@ public abstract class ConfigSetAdminRequest< protected Properties properties; public Create() { + super(METHOD.POST); action = ConfigSetAction.CREATE; } @@ -305,6 +334,7 @@ public abstract class ConfigSetAdminRequest< // DELETE request public static class Delete extends ConfigSetSpecificAdminRequest<Delete> { public Delete() { + super(METHOD.POST); action = ConfigSetAction.DELETE; } @@ -317,6 +347,7 @@ public abstract class ConfigSetAdminRequest< // LIST request public static class List extends ConfigSetAdminRequest<List, ConfigSetAdminResponse.List> { public List() { + super(METHOD.GET); action = ConfigSetAction.LIST; } 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 d31b5651fbe..ecdb3ba5fb8 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 @@ -67,6 +67,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { private String collectionConfigName; public Create() { + super(METHOD.POST); action = CoreAdminAction.CREATE; } @@ -261,6 +262,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { protected Boolean onlyIfLeaderActive; public WaitForState() { + super(METHOD.POST); action = CoreAdminAction.PREPRECOVERY; } @@ -358,6 +360,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { public static class RequestRecovery extends CoreAdminRequest { public RequestRecovery() { + super(METHOD.POST); action = CoreAdminAction.REQUESTRECOVERY; } @@ -380,6 +383,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { private String collection; public RequestSyncShard() { + super(METHOD.POST); action = CoreAdminAction.REQUESTSYNCSHARD; } @@ -447,6 +451,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { protected List<String> srcCores; public MergeIndexes() { + super(METHOD.POST); action = CoreAdminAction.MERGEINDEXES; } @@ -494,6 +499,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { protected boolean deleteInstanceDir; public Unload(boolean deleteIndex) { + super(METHOD.POST); action = CoreAdminAction.UNLOAD; this.deleteIndex = deleteIndex; } @@ -536,7 +542,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { private String commitName; public CreateSnapshot(String commitName) { - super(); + super(METHOD.POST); this.action = CoreAdminAction.CREATESNAPSHOT; if (commitName == null) { throw new NullPointerException("Please specify non null value for commitName parameter."); @@ -560,7 +566,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { private String commitName; public DeleteSnapshot(String commitName) { - super(); + super(METHOD.POST); this.action = CoreAdminAction.DELETESNAPSHOT; if (commitName == null) { @@ -583,17 +589,33 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { public static class ListSnapshots extends CoreAdminRequest { public ListSnapshots() { - super(); + super(METHOD.GET); this.action = CoreAdminAction.LISTSNAPSHOTS; } } + public CoreAdminRequest(METHOD method) { + this(method, "/admin/cores"); + } + + public CoreAdminRequest(METHOD method, String path) { + super(method, path); + } + + /** + * @deprecated Use {@link #CoreAdminRequest(METHOD)}. + */ + @Deprecated(since = "11.0") public CoreAdminRequest() { - super(METHOD.GET, "/admin/cores"); + this(METHOD.POST); } + /** + * @deprecated Use {@link #CoreAdminRequest(METHOD, String)}. + */ + @Deprecated(since = "11.0") public CoreAdminRequest(String path) { - super(METHOD.GET, path); + this(METHOD.POST, path); } public void setCoreName(String coreName) { @@ -650,7 +672,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { public static CoreAdminResponse reloadCore(String name, SolrClient client) throws SolrServerException, IOException { - CoreAdminRequest req = new CoreAdminRequest(); + CoreAdminRequest req = new CoreAdminRequest(METHOD.POST); req.setCoreName(name); req.setAction(CoreAdminAction.RELOAD); return req.process(client); @@ -682,7 +704,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { */ public static CoreAdminResponse renameCore(String coreName, String newName, SolrClient client) throws SolrServerException, IOException { - CoreAdminRequest req = new CoreAdminRequest(); + CoreAdminRequest req = new CoreAdminRequest(METHOD.POST); req.setCoreName(coreName); req.setOtherCoreName(SolrIdentifierValidator.validateCoreName(newName)); req.setAction(CoreAdminAction.RENAME); @@ -701,7 +723,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { */ public static CoreAdminResponse swapCore(String core1, String core2, SolrClient client) throws SolrServerException, IOException { - CoreAdminRequest req = new CoreAdminRequest(); + CoreAdminRequest req = new CoreAdminRequest(METHOD.POST); req.setCoreName(core1); req.setOtherCoreName(core2); req.setAction(CoreAdminAction.SWAP); @@ -715,7 +737,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { public static CoreStatus getCoreStatus(String coreName, boolean getIndexInfo, SolrClient client) throws SolrServerException, IOException { - CoreAdminRequest req = new CoreAdminRequest(); + CoreAdminRequest req = new CoreAdminRequest(METHOD.GET); req.setAction(CoreAdminAction.STATUS); req.setIndexInfoNeeded(getIndexInfo); return new CoreStatus(req.process(client).getCoreStatus(coreName)); @@ -723,7 +745,7 @@ public class CoreAdminRequest extends SolrRequest<CoreAdminResponse> { public static CoreAdminResponse getStatus(String name, SolrClient client) throws SolrServerException, IOException { - CoreAdminRequest req = new CoreAdminRequest(); + CoreAdminRequest req = new CoreAdminRequest(METHOD.GET); req.setCoreName(name); req.setAction(CoreAdminAction.STATUS); return req.process(client); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java index 3963b5866a3..9f9ddade79f 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCollectionAdminRequest.java @@ -17,14 +17,34 @@ package org.apache.solr.client.solrj.request; import org.apache.solr.SolrTestCase; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrRequest.METHOD; import org.apache.solr.client.solrj.request.CollectionAdminRequest.CreateAlias; import org.apache.solr.client.solrj.request.CollectionAdminRequest.CreateShard; +import org.apache.solr.client.solrj.response.CollectionAdminResponse; import org.apache.solr.common.SolrException; +import org.apache.solr.common.params.CollectionParams.CollectionAction; import org.junit.Test; /** Unit tests for {@link CollectionAdminRequest}. */ public class TestCollectionAdminRequest extends SolrTestCase { + @Test + @SuppressWarnings("deprecation") + public void testAdminRequestsChooseExplicitHttpMethods() { + CollectionAdminRequest<CollectionAdminResponse> legacyRequest = + new CollectionAdminRequest<>(CollectionAction.CREATE) { + @Override + protected CollectionAdminResponse createResponse(SolrClient client) { + return new CollectionAdminResponse(); + } + }; + assertEquals(METHOD.POST, legacyRequest.getMethod()); + assertEquals( + METHOD.POST, CollectionAdminRequest.createCollection("collection", null, 1, 1).getMethod()); + assertEquals(METHOD.GET, new CollectionAdminRequest.List().getMethod()); + } + @Test public void testInvalidCollectionNameRejectedWhenCreatingCollection() { final SolrException e = diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestConfigSetAdminRequest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestConfigSetAdminRequest.java index 794129d34b4..f9b3fd33a7b 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestConfigSetAdminRequest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestConfigSetAdminRequest.java @@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.request; import java.io.File; 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.response.ConfigSetAdminResponse; import org.apache.solr.common.params.ConfigSetParams; import org.junit.Test; @@ -26,6 +27,14 @@ import org.junit.Test; /** Basic error checking of ConfigSetAdminRequests. */ public class TestConfigSetAdminRequest extends SolrTestCaseJ4 { + @Test + @SuppressWarnings("deprecation") + public void testAdminRequestsChooseExplicitHttpMethods() { + assertEquals(METHOD.POST, new MyConfigSetAdminRequest().getMethod()); + assertEquals(METHOD.POST, new ConfigSetAdminRequest.Create().getMethod()); + assertEquals(METHOD.GET, new ConfigSetAdminRequest.List().getMethod()); + } + @Test public void testNoAction() { MyConfigSetAdminRequest request = new MyConfigSetAdminRequest(); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java index d8630d016ff..d5a8c36b173 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java @@ -30,6 +30,7 @@ import org.apache.commons.io.FileUtils; import org.apache.lucene.tests.util.LuceneTestCase; 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.SolrServerException; import org.apache.solr.client.solrj.embedded.AbstractEmbeddedSolrServerTestCase; import org.apache.solr.client.solrj.request.CoreAdminRequest.Create; @@ -48,6 +49,14 @@ import org.junit.Test; public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase { + @Test + @SuppressWarnings("deprecation") + public void testAdminRequestsChooseExplicitHttpMethods() { + assertEquals(METHOD.POST, new CoreAdminRequest().getMethod()); + assertEquals(METHOD.POST, new CoreAdminRequest.Create().getMethod()); + assertEquals(METHOD.GET, new CoreAdminRequest.ListSnapshots().getMethod()); + } + @Test public void testConfigSet() throws Exception {
