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 000000000000..3f88523466e9 --- /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/modules/opentelemetry/src/test/org/apache/solr/opentelemetry/TestDistributedTracing.java b/solr/modules/opentelemetry/src/test/org/apache/solr/opentelemetry/TestDistributedTracing.java index f73d47060032..72f478590d28 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 @@ -195,7 +195,7 @@ private void verifyCollectionCreation(String collection) throws Exception { assertEquals(0, r1.getStatus()); // Expecting 8 spans: - // 1. api call "name=create:/admin/collections". db.instance=testInternalCollectionApiCommands + // 1. api call "name=post:/admin/collections". db.instance=testInternalCollectionApiCommands // - unique traceId unrelated to the internal trace id generated for the operation // 2. internal CollectionApiCommand "name=CreateCollectionCmd" // db.instance=testInternalCollectionApiCommands @@ -222,7 +222,7 @@ private void verifyCollectionCreation(String collection) throws Exception { var finishedSpans = getAndClearSpans(1); var s0 = finishedSpans.remove(0); assertCollectionName(s0, collection); - assertEquals("create:/admin/collections", s0.getName()); + assertEquals("post:/admin/collections", s0.getName()); Map ops = new HashMap<>(); assertEquals(11, finishedSpans.size()); @@ -248,7 +248,7 @@ private void verifyCollectionDeletion(String collection) throws Exception { assertEquals(0, r1.getStatus()); // Expecting 6 spans: - // 1. api call "name=delete:/admin/collections". db.instance=testInternalCollectionApiCommands + // 1. api call "name=post:/admin/collections". db.instance=testInternalCollectionApiCommands // - unique traceId unrelated to the internal trace id generated for the operation // 2. internal CollectionApiCommand "name=DeleteCollectionCmd" // db.instance=testInternalCollectionApiCommands @@ -263,7 +263,7 @@ private void verifyCollectionDeletion(String collection) throws Exception { var finishedSpans = getAndClearSpans(1); var s0 = finishedSpans.remove(0); assertCollectionName(s0, collection); - assertEquals("delete:/admin/collections", s0.getName()); + assertEquals("post:/admin/collections", s0.getName()); Map 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 ac7af67427c8..5197b4a2d341 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 @@ -78,13 +78,29 @@ public abstract class CollectionAdminRequest protected final CollectionAction action; + public CollectionAdminRequest(METHOD method, CollectionAction action) { + this(method, "/admin/collections", action); + } + + public CollectionAdminRequest(METHOD method, String path, CollectionAction action) { + super(method, path, SolrRequestType.ADMIN); + 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, SolrRequestType.ADMIN); - this.action = checkNotNull(CoreAdminParams.ACTION, action); + this(METHOD.POST, path, action); } @Override @@ -148,8 +164,16 @@ public abstract static class AsyncCollectionAdminRequest 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 @@ -255,11 +279,21 @@ protected abstract static class AsyncCollectionSpecificAdminRequest 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; } @@ -284,12 +318,22 @@ protected abstract static class AsyncShardSpecificAdminRequest 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()); @@ -305,12 +349,21 @@ protected abstract static class ShardSpecificAdminRequest 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()); @@ -334,12 +387,22 @@ protected abstract static class CollectionAdminRoleRequest extends AsyncCollecti 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; } @@ -518,7 +581,10 @@ private Create( Integer numShards, String shards, ReplicaCount numReplicas) { - 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)) { @@ -710,7 +776,7 @@ public static Reload reloadCollection(String collection) { public static class Reload extends AsyncCollectionSpecificAdminRequest { private Reload(String collection) { - super(CollectionAction.RELOAD, collection); + super(METHOD.POST, CollectionAction.RELOAD, collection); } } @@ -722,7 +788,7 @@ public static class Rename extends AsyncCollectionSpecificAdminRequest { String target; public Rename(String collection, String target) { - super(CollectionAction.RENAME, collection); + super(METHOD.POST, CollectionAction.RENAME, collection); this.target = target; } @@ -746,7 +812,7 @@ public static class DeleteNode extends AsyncCollectionAdminRequest { * @param node The node to be deleted */ public DeleteNode(String node) { - super(CollectionAction.DELETENODE); + super(METHOD.POST, CollectionAction.DELETENODE); this.node = checkNotNull("node", node); } @@ -767,7 +833,7 @@ public static class ReplaceNode extends AsyncCollectionAdminRequest { * @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; } @@ -801,7 +867,7 @@ public static class MoveReplica extends AsyncCollectionAdminRequest { 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); @@ -809,7 +875,7 @@ public MoveReplica(String collection, String replica, String targetNode) { } 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); @@ -876,7 +942,7 @@ public Integer getMaxWaitSeconds() { } public RebalanceLeaders(String collection) { - super(CollectionAction.REBALANCELEADERS); + super(METHOD.POST, CollectionAction.REBALANCELEADERS); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); } @@ -917,7 +983,7 @@ public static class ReindexCollection extends AsyncCollectionSpecificAdminReques Map collectionParams = new HashMap<>(); private ReindexCollection(String collection) { - super(CollectionAction.REINDEXCOLLECTION, collection); + super(METHOD.POST, CollectionAction.REINDEXCOLLECTION, collection); } /** Target collection name (null if the same). */ @@ -1010,12 +1076,12 @@ public static class ColStatus extends AsyncCollectionAdminRequest { 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) { @@ -1083,7 +1149,7 @@ public static Delete deleteCollection(String collection) { public static class Delete extends AsyncCollectionSpecificAdminRequest { private Delete(String collection) { - super(CollectionAction.DELETE, collection); + super(METHOD.POST, CollectionAction.DELETE, collection); } } @@ -1104,7 +1170,7 @@ public static class Backup extends AsyncCollectionSpecificAdminRequest { 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(); } @@ -1250,7 +1316,7 @@ public static class Restore extends AsyncCollectionSpecificAdminRequest { protected Integer backupId; public Restore(String collection, String backupName) { - super(CollectionAction.RESTORE, collection); + super(METHOD.POST, CollectionAction.RESTORE, collection); this.backupName = backupName; this.numReplicas = ReplicaCount.empty(); } @@ -1436,7 +1502,7 @@ public static class InstallShard extends AsyncShardSpecificAdminRequest { 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; @@ -1468,7 +1534,10 @@ public static class CreateSnapshot extends AsyncCollectionSpecificAdminRequest { 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); } @@ -1495,7 +1564,10 @@ public static class DeleteSnapshot extends AsyncCollectionSpecificAdminRequest { 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); } @@ -1520,7 +1592,10 @@ public SolrParams getParams() { @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 @@ -1567,6 +1642,7 @@ public CreateShard setProperties(Properties properties) { private CreateShard(String collection, String shard) { super( + METHOD.POST, CollectionAction.CREATESHARD, collection, SolrIdentifierValidator.validateShardName(shard)); @@ -1596,7 +1672,7 @@ public static class MockCollTask extends AsyncCollectionAdminRequest { 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); } @@ -1634,7 +1710,7 @@ public static class SplitShard extends AsyncCollectionAdminRequest { protected String createNodeSet; private SplitShard(String collection) { - super(CollectionAction.SPLITSHARD); + super(METHOD.POST, CollectionAction.SPLITSHARD); this.collection = checkNotNull(CoreAdminParams.COLLECTION, collection); } @@ -1758,7 +1834,7 @@ public static class DeleteShard extends AsyncShardSpecificAdminRequest { private Boolean deleteDataDir; private DeleteShard(String collection, String shard) { - super(CollectionAction.DELETESHARD, collection, shard); + super(METHOD.POST, CollectionAction.DELETESHARD, collection, shard); } public Boolean getDeleteInstanceDir() { @@ -1805,7 +1881,7 @@ public static ForceLeader forceLeaderElection(String collection, String shard) { // 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); } } @@ -1838,7 +1914,7 @@ public static class RequestStatus extends CollectionAdminRequest properties = new HashMap<>(); public SetAliasProperty(String aliasName) { - super(CollectionAction.ALIASPROP); + super(METHOD.POST, CollectionAction.ALIASPROP); this.aliasName = SolrIdentifierValidator.validateAliasName(aliasName); } @@ -1989,7 +2065,7 @@ public static class CreateAlias extends AsyncCollectionAdminRequest { 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); } @@ -2063,7 +2139,7 @@ public CreateTimeRoutedAlias( String start, String interval, Create createCollTemplate) { - super(CollectionAction.CREATEALIAS); + super(METHOD.POST, CollectionAction.CREATEALIAS); this.aliasName = aliasName; this.start = start; this.interval = interval; @@ -2178,7 +2254,7 @@ public static class CreateCategoryRoutedAlias extends AsyncCollectionAdminReques 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; @@ -2284,7 +2360,7 @@ public static class DimensionalRoutedAlias extends AsyncCollectionAdminRequest 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; @@ -2368,7 +2444,7 @@ public static class DeleteAlias extends AsyncCollectionAdminRequest { protected String aliasName; private DeleteAlias(String aliasName) { - super(CollectionAction.DELETEALIAS); + super(METHOD.POST, CollectionAction.DELETEALIAS); this.aliasName = checkNotNull("aliasName", aliasName); } @@ -2421,7 +2497,7 @@ public static class AddReplica extends AsyncCollectionAdminRequest { 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; @@ -2621,19 +2697,19 @@ public static class DeleteReplica extends AsyncCollectionSpecificAdminRequest { 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; } @@ -2720,7 +2796,7 @@ public static class ClusterProp extends CollectionAdminRequest { public RequestApiDistributedProcessing() { - super(CollectionAction.DISTRIBUTEDAPIPROCESSING); + super(METHOD.GET, CollectionAction.DISTRIBUTEDAPIPROCESSING); } @Override @@ -2937,7 +3013,7 @@ public static class ClusterStatus extends CollectionAdminRequest namedList) { public static class ListAliases extends CollectionAdminRequest { public ListAliases() { - super(CollectionAction.LISTALIASES); + super(METHOD.GET, CollectionAction.LISTALIASES); } @Override @@ -3012,7 +3088,7 @@ public static java.util.List listCollections(SolrClient client) // LIST request public static class List extends CollectionAdminRequest { public List() { - super(CollectionAction.LIST); + super(METHOD.GET, CollectionAction.LIST); } @Override @@ -3085,7 +3161,7 @@ public static class DeleteBackup extends CollectionAdminRequest attributes; private Modify(String collection, Map 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 e0b0a708e3fe..e0bb2cace5db 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 @@ -50,12 +50,28 @@ protected ConfigSetAdminRequest setAction(ConfigSetAction action) { return this; } + public ConfigSetAdminRequest(METHOD method) { + this(method, "/admin/configs"); + } + + public ConfigSetAdminRequest(METHOD method, String path) { + super(method, path, SolrRequestType.ADMIN); + } + + /** + * @deprecated Use {@link #ConfigSetAdminRequest(METHOD)}. + */ + @Deprecated(since = "11.0") public ConfigSetAdminRequest() { - super(METHOD.GET, "/admin/configs", SolrRequestType.ADMIN); + this(METHOD.POST); } + /** + * @deprecated Use {@link #ConfigSetAdminRequest(METHOD, String)}. + */ + @Deprecated(since = "11.0") public ConfigSetAdminRequest(String path) { - super(METHOD.GET, path, SolrRequestType.ADMIN); + this(METHOD.POST, path); } protected abstract Q getThis(); @@ -78,6 +94,18 @@ protected abstract static class ConfigSetSpecificAdminRequest< extends ConfigSetAdminRequest { 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(); @@ -121,8 +149,8 @@ public static class Upload extends ConfigSetSpecificAdminRequest { protected Boolean cleanup; public Upload() { + super(METHOD.POST); action = ConfigSetAction.UPLOAD; - setMethod(SolrRequest.METHOD.POST); } @Override @@ -255,6 +283,7 @@ public static class Create extends ConfigSetSpecificAdminRequest { protected Properties properties; public Create() { + super(METHOD.POST); action = ConfigSetAction.CREATE; } @@ -300,6 +329,7 @@ public SolrParams getParams() { // DELETE request public static class Delete extends ConfigSetSpecificAdminRequest { public Delete() { + super(METHOD.POST); action = ConfigSetAction.DELETE; } @@ -312,6 +342,7 @@ protected Delete getThis() { // LIST request public static class List extends ConfigSetAdminRequest { 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 3c4b5dae0a12..a31ce26d849b 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 @@ -62,6 +62,7 @@ public static class Create extends CoreAdminRequest { private String collectionConfigName; public Create() { + super(METHOD.POST); action = CoreAdminAction.CREATE; } @@ -233,6 +234,7 @@ public static class WaitForState extends CoreAdminRequest { protected Boolean onlyIfLeaderActive; public WaitForState() { + super(METHOD.POST); action = CoreAdminAction.PREPRECOVERY; } @@ -330,6 +332,7 @@ public String toString() { public static class RequestRecovery extends CoreAdminRequest { public RequestRecovery() { + super(METHOD.POST); action = CoreAdminAction.REQUESTRECOVERY; } @@ -352,6 +355,7 @@ public static class RequestSyncShard extends CoreAdminRequest { private String collection; public RequestSyncShard() { + super(METHOD.POST); action = CoreAdminAction.REQUESTSYNCSHARD; } @@ -391,6 +395,7 @@ public static class MergeIndexes extends CoreAdminRequest { protected List srcCores; public MergeIndexes() { + super(METHOD.POST); action = CoreAdminAction.MERGEINDEXES; } @@ -438,6 +443,7 @@ public static class Unload extends CoreAdminRequest { protected boolean deleteInstanceDir; public Unload(boolean deleteIndex) { + super(METHOD.POST); action = CoreAdminAction.UNLOAD; this.deleteIndex = deleteIndex; } @@ -480,7 +486,7 @@ public static class CreateSnapshot extends CoreAdminRequest { 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."); @@ -504,7 +510,7 @@ public static class DeleteSnapshot extends CoreAdminRequest { private String commitName; public DeleteSnapshot(String commitName) { - super(); + super(METHOD.POST); this.action = CoreAdminAction.DELETESNAPSHOT; if (commitName == null) { @@ -527,17 +533,33 @@ public SolrParams getParams() { 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, SolrRequestType.ADMIN); + } + + /** + * @deprecated Use {@link #CoreAdminRequest(METHOD)}. + */ + @Deprecated(since = "11.0") public CoreAdminRequest() { - super(METHOD.GET, "/admin/cores", SolrRequestType.ADMIN); + this(METHOD.POST); } + /** + * @deprecated Use {@link #CoreAdminRequest(METHOD, String)}. + */ + @Deprecated(since = "11.0") public CoreAdminRequest(String path) { - super(METHOD.GET, path, SolrRequestType.ADMIN); + this(METHOD.POST, path); } public void setCoreName(String coreName) { @@ -594,7 +616,7 @@ protected CoreAdminResponse createResponse(NamedList namedList) { 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); @@ -626,7 +648,7 @@ public static CoreAdminResponse unloadCore( */ 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); @@ -645,7 +667,7 @@ public static CoreAdminResponse renameCore(String coreName, String newName, Solr */ 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); @@ -660,7 +682,7 @@ public static CoreStatusResponse.SingleCoreData getCoreStatus(String coreName, S public static CoreStatusResponse.SingleCoreData 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 req.process(client).getCoreStatus(coreName); @@ -668,7 +690,7 @@ public static CoreStatusResponse.SingleCoreData getCoreStatus( 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 3963b5866a31..7cbab3936e62 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.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.apache.solr.common.util.NamedList; import org.junit.Test; /** Unit tests for {@link CollectionAdminRequest}. */ public class TestCollectionAdminRequest extends SolrTestCase { + @Test + @SuppressWarnings("deprecation") + public void testAdminRequestsChooseExplicitHttpMethods() { + CollectionAdminRequest legacyRequest = + new CollectionAdminRequest<>(CollectionAction.CREATE) { + @Override + protected CollectionAdminResponse createResponse(NamedList namedList) { + 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 39b22fed446f..357e061b17b7 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 @@ -18,6 +18,7 @@ import java.nio.file.Path; import org.apache.solr.SolrTestCaseJ4; +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.apache.solr.common.util.NamedList; @@ -26,6 +27,14 @@ /** 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 d4b7beece427..45198ba422c3 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 @@ -43,6 +43,14 @@ 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 {