-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Remove AcknowledgedRestListener in favour of RestToXContentListener #28724
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
Changes from all commits
ccfd123
7c89a40
718ceb4
94724b1
c899ee0
4fc3f8b
6ad82d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,13 +24,16 @@ | |
| import org.elasticsearch.cluster.routing.allocation.RoutingExplanations; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.xcontent.ToXContent; | ||
| import org.elasticsearch.common.xcontent.ToXContentObject; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Response returned after a cluster reroute request | ||
| */ | ||
| public class ClusterRerouteResponse extends AcknowledgedResponse { | ||
| public class ClusterRerouteResponse extends AcknowledgedResponse implements ToXContentObject { | ||
|
|
||
| private ClusterState state; | ||
| private RoutingExplanations explanations; | ||
|
|
@@ -71,4 +74,14 @@ public void writeTo(StreamOutput out) throws IOException { | |
| writeAcknowledged(out); | ||
| RoutingExplanations.writeTo(explanations, out); | ||
| } | ||
|
|
||
| @Override | ||
| protected void addCustomFields(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject("state"); | ||
| state.toXContent(builder, params); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I see this was previously done in the RestClusterRerouteAction. |
||
| builder.endObject(); | ||
| if (params.paramAsBoolean("explain", false)) { | ||
| explanations.toXContent(builder, ToXContent.EMPTY_PARAMS); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
| import org.elasticsearch.common.xcontent.ObjectParser; | ||
| import org.elasticsearch.common.xcontent.ToXContentObject; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
|
|
@@ -35,7 +36,7 @@ | |
| * Abstract class that allows to mark action responses that support acknowledgements. | ||
| * Facilitates consistency across different api. | ||
| */ | ||
| public abstract class AcknowledgedResponse extends ActionResponse { | ||
| public abstract class AcknowledgedResponse extends ActionResponse implements ToXContentObject { | ||
|
|
||
| private static final ParseField ACKNOWLEDGED = new ParseField("acknowledged"); | ||
|
|
||
|
|
@@ -76,8 +77,17 @@ protected void writeAcknowledged(StreamOutput out) throws IOException { | |
| out.writeBoolean(acknowledged); | ||
| } | ||
|
|
||
| protected void addAcknowledgedField(XContentBuilder builder) throws IOException { | ||
| @Override | ||
| public final XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| builder.startObject(); | ||
| builder.field(ACKNOWLEDGED.getPreferredName(), isAcknowledged()); | ||
| addCustomFields(builder, params); | ||
| builder.endObject(); | ||
| return builder; | ||
| } | ||
|
|
||
| protected void addCustomFields(XContentBuilder builder, Params params) throws IOException { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if this could be abstract, so subclasses don't forget to implement it. Looks like many would have an empty implementation though, so just a thought.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it could be, but the classes that have a non-empty impl for it are more of an exception, so maybe it's ok like this? |
||
|
|
||
| } | ||
|
|
||
| @Override | ||
|
|
||
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'm curious why this class didn't implement toXContent before. Was it not client-facing, that is not used in the rest API?
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.
because the API is not supported yet by the high-level REST client