-
Notifications
You must be signed in to change notification settings - Fork 792
SOLR-17136: Replace most uses of GenericSolrRequest in Solr code #3955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
SOLR-17136: Replace most uses of GenericSolrRequest in Solr code #3955
Conversation
SystemInfoResponse
SystemInfoRequest/Response in CLI and package manager
Adjust the API model SystemInfoResponse and tie it into the SolrResponseBase. Remove commented code.
|
I approved the workflows to run. Ping us when you are ready for review! |
add MetricsRequest, more replacements of GenericSolrRequest, use the constants for "/admin/info/system" and "/admin/metrics"
…m:igiguere/solr.git into SOLR-17136-replace-GenericSolrRequest
solr/solrj/src/java/org/apache/solr/client/solrj/request/MetricsRequest.java
Outdated
Show resolved
Hide resolved
solr/solrj/src/java/org/apache/solr/client/solrj/response/SystemInfoResponse.java
Outdated
Show resolved
Hide resolved
|
Hemm. I wanted to run gradlew tidy with my corrections for the comments, but I get this error. My branch is up to date with main. $ ./gradlew tidy FAILURE: Build failed with an exception.
UPDATE: |
epugh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super exciting! I didn't quite realize how much duplicative boilerplate using GSR brought.
I think this is mostly in the right direction. A couple of comments and questions. I don't see explicit tests for these new classes, though I guess they are literally excercised everywhere and are just wrapper classes.
| String zkHost = (String) info.get("zkHost"); | ||
| status.put("cloud", getCloudStatus(solrClient, zkHost)); | ||
| if ("solrcloud".equals(sysResponse.getMode())) { | ||
| status.put("cloud", getCloudStatus(solrClient, sysResponse.getZkHost())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LIkewise in a future pr, would be nice to figure out is it cloud or solrcloud and use a single term everywhere ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely change!
| coreRootDirectory = (String) systemInfo.get("core_root"); | ||
| SystemInfoResponse sysResponse = (new SystemInfoRequest()).process(solrClient); | ||
| // usually same as solr home, but not always | ||
| String coreRootDirectory = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can core_root ever be null? do we know we need this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea. Just being cautious. Although, the original code did not check for null, so I guess the new code shouldn't need to.
|
|
||
| // convert raw JSON into user-friendly output | ||
| Map<String, Object> status = StatusTool.reportStatus(systemInfo, solrClient); | ||
| Map<String, Object> status = StatusTool.reportStatus(solrClient); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe for future, but is it odd a CLIUtils would call StatusTool for a method reportStatus? Should it be moved to CLIUtils instead and the StatusTool should call CLIUtils.reportStatus?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 17 calls to CLIUtils.getZkHost(CommandLine), where we find this call to StatusTool.reportStatus(SolrClient).
That's half the *Tool found in org.apache.solr.cli. That means CLIUtils serves as a "bridge" between tools (StatusTool and the rest of them).
Personally, I think it makes sense that the StatusTool would be the one reporting the status, rather than have it depend on the CLIUtils to essentially do the status reporting job (i.e.: CLIUtils.reportStatus).
Otherwise, if we don't want CLIUtils to call StatusTool, then, we have to add a call to StatusTool.reportStatus(SolrClient) in each of the 17 locations, and for each, find the ZK host currently provided by CLIUtils.getZkHost(CommandLine).
In a nutchell : I would not change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, thanks for digging into this.
| // This method is only called from PackageTool ("add-repo", or "add-key"), where the Solr URL is | ||
| // normalized to remove the /solr path part | ||
| // So might as well ping the V2 API "/node/system" instead. | ||
| // Otherwise, this SystemInfoRequest ctr would need to set the full /solr/admin/info/system path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"ctr"??? maybe spell it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;) it would have wrapped the line, but ok. I'll spell it out.
| // normalized to remove the /solr path part | ||
| // So might as well ping the V2 API "/node/system" instead. | ||
| // Otherwise, this SystemInfoRequest ctr would need to set the full /solr/admin/info/system path | ||
| SystemInfoResponse sysResponse = new SystemInfoRequest("/node/system").process(solrClient); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
humm.... In general we should just use V2 api's! Over time in Solr 10 x we will migrate internal tooling to using V2 apis, which will open the door to deprecate and remove V1 equivalents. If I am understanding here, you are choosing to use V2 in this one use case. Could we just use V2 everywhere....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SystemInfoRequest could set the V2 path by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to set the V2 path /node/system as default in SystemInfoRequest constructors, but, that would require some refactoring throughout the CLI tools, at least. The SolrClient used for the system info can be reused for other request that don't all support V2, so, having SystemInfoRequest default to V2 would mean managing the switch from V1 to V2 URLs.
Let's takle that in some other ticket. I'm leaving a "TODO" for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense.
| params); | ||
| SimpleSolrResponse rsp = null; | ||
| SystemInfoRequest req = new SystemInfoRequest(params); | ||
| SystemInfoResponse rsp = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check your ide, I think in geneal we don't do the = null pattern when declaring an empty variable as it is already null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was like that already, but for SimpleSolrResponse. I'll remove the = null.
Update: It was initialized to avoid compile error at line 91, after the try-catch, when rsp is used: "variable rsp might not have been initialized".
So I'll move the following asserts into the try-catch.
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private org.apache.solr.client.api.model.SystemInfoResponse fullResponse; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the import path being full here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import the API model SystemInfoResponse into the SolrJ client SystemInfoResponse. Maybe I should rename one of these classes, to avoid confusion ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gerlowskija any suggestions on what we should do here? Having the same name in two packages seems not good. SystemInfo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In org.apache.solr.client.api.*:
Most API model classes that represent responses have a name in *Reponse. There's also some *RequestBody. There seems to be some mapping between the class name and the exposed resource path (but not 100%)
So I think the system info response should have a name that ends in *Response. And I like the idea of keeping names aligned ("/whatever" resource = WhateverAPI returns WhateverResponse, and Whatever implements WhateverAPI)
The "home-grown" V2 NodeSystemInfoAPI exposes resource path "/node/system". Presumably, the JAX-RS V2 would still have a class name similar to it's resource path (i.e.: NodeSystemAPI ?) ... Which would make the API model response class NodeSystemResponse ?
That's my 2 cents. @epugh, @gerlowskija
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I can live with NodeSystemAPI and NodeSystemResponse. One thing I hate is having a PR sit forever ont he vine because we can't come up whti a name. We can always rename these thingsin future versions!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw that comment. Renamed.
Done. Unless checks fail.
| } | ||
|
|
||
| // ************************* | ||
| // Shortcuts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a pattern in other similar classes? Mostly my own curiosity!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen some similar "separator" comments in other classes, can't remember which right now. I can remove it.
OK, no, you meant the methods themselves. Ref. CoreAdminResponse providing similar methods : getStartTime, getUpTime. Also DocumentAnalysissResponse. If the response is complex enough, some parsing should be provided so the rest of the code doesn't need to know the inner structure of the response.
|
@gerlowskija can you review from the v2 api perspective? If @igiguere is intered, I'd love to take what she's learned on making V2 api for metrics and system request handler and look at osme of our other V2 api gaps! |
FYI : System Info already had a V2 implementation (/node/system), I didn't touch it. It just calls the SystemInfoHandler, same as V1. I didn't see a V2 resource for metrics. I suppose it could also call the same handler as V1. |
|
I just approved the workflows... Assuming the tests all pass, I'l leave it open till Monday to give folks a chance to review and then merge. This looks great... What's next? |
I'm running one more
What's next? For me, in the next few days: get over my cold that's dragging on, find a plumber to fix the clogged drain, Christmas... After that, more job hunting, and possibly tackle some of the missing V2 APIs. |
|
Pre commit failed. The crave tests have been failing |
|
Sigh. I ran |
|
update from |
|
actually, I just pushed up the updates from |
|
TEsts passed! I will leave this open for mOnday, and then will merge. Please tag me on your next PR, enjoyed working with you on this. |
https://issues.apache.org/jira/browse/SOLR-17136
Description
Replacing uses of GenericSolrRequest to call "/admin/info/system" and "admin/metrics" by classes SystemInfoRequest, and MetricsRequest.
Solution
Adding class SystemInfoRequest. SystemInfoRequest can toggle between the V1 and V2 APIs. The V2 API was already available at /api/node/system.
Adding API model class org.apache.solr.api.model.SystemInfoResponse to represent the system info response, and SorlJ response class org.apache.solr.client.solrj.response.SystemInfoResponse to map the NamedList response to the API model.
Adding class MetricsRequest. This one returns a generic SolrResponse, because there are so many variants of a metrics response.
Replacing hard-coded strings "/admin/info/system" and "admin/metrics" by the corresponding constants.
Tests
Unit tests pass. Existing unit tests already serve to test these modifications.
Functional tests using the CLI tool, where most of the functional changes occurred.
Multiple changes in unit tests, to use the new classes, or existing constants.
Checklist
Please review the following and check all that apply:
mainbranch../gradlew check.