SOLR-17044: Expose api "version" on SolrRequest objects #2456
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://issues.apache.org/jira/browse/SOLR-17044
Description
SolrJ often needs to know whether a given request is for a v1 or v2 API, but doesn't have an easy way to do so. The best it can do is one of two approximations: either check the path string for "____v2", or do an
instanceof V2Request
check. Both of these are exceedingly brittle.Solution
This PR introduces a new request on the SolrRequest class:
getApiVersion()
. It returns an ApiVersion enum value, which can either be "V1" or "V2". The method has a default implementation on SolrRequest which returns the enum value "V1", overriding this on a number of subclasses that represent v2 requests (V2Request, various generated SolrJ classes, etc.)As usual with these sort of changes,
GenericSolrRequest
introduces some complications. There's no great way to determine whether a given GSR represents a v1 or v2 API without resorting to the same brittle string inspection we're trying to avoid. This PR solves this by assuming that 'GenericSolrRequest' instances represent v1 API requests, and adds a trivial 'GenericV2SolrRequest' class to represent v2 requests. (Open to other ways of doing this if folks don't like this approach)Tests
Existing tests continue to pass.
Checklist
Please review the following and check all that apply:
main
branch../gradlew check
.