Why not to get cluster state with ClusterStateRequest using RestClient #667
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.
DO NOT MERGE THIS PR.
This PR is a record of several wasted hours on a dead end to explain to future travelers to not go down this road.
Seriously. Don't go here.
This PR is for educational purposes only. Review to see how you can implement simpler requests, and why it's the wrong answer for complex requests. For the actual implementation, go review #668
Description
Some optimistic person with the GitHub handle @dbwiddis commented on #354:
They couldn't be more wrong.
Problem 1: Not part of Cluster APIs
opensearch-java
(and other clients) are built from spec, which means if a REST API exists, it should be in these clients. Unfortunately, a cluster state request is not one of the Cluster APIs.performRequest()
for exactly this use case!Problem 2: PerformRequest isn't meant for complex requests
Problem 3: The response needs to be parsed
Response
from a PerformRequest isn't aClusterStateRequest
object, it needs to be parsed into one. No problem, right? The neededClusterState
object has atoXContent()
method, we just need to reverse engineer it.ClusterState
is anXContentFragment
not a whole object, so it doesn't have thefromXContent(parser)
method. So I tried to write my own version of afromXContent(parser)
.Is it possible? Probably. But not for any sane person. I question my sanity, but even I have given up.
The sane person sends a transport request using our well known handlers, and the ClusterStateRequest and ClusterStateResponse objects are both writeable.
Issues NOT Resolved
Futile attempt to work on #354 without using the super-easy TransportAction on OpenSearch, which is what you should do instead of this fiasco.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.