From 11b11f6f4cbae65a76834d45b2697906ead4e003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Mon, 4 Jun 2018 15:10:02 +0200 Subject: [PATCH] Share common readFrom/writeTo code in AcknowledgeResponse (#30983) The majority of Responses inheriting from AcknowledgeResponse implement the readFrom and writeTo serialization method in the same way. Moving this as a default into AcknowledgeResponse and letting the few exceptions that need a slightly different implementation handle this themselves saves a lot of duplication. --- .../delete/DeleteRepositoryResponse.java | 17 ----- .../put/PutRepositoryResponse.java | 16 ----- .../reroute/ClusterRerouteResponse.java | 28 +++++--- .../ClusterUpdateSettingsResponse.java | 27 ++++--- .../delete/DeleteSnapshotResponse.java | 17 ----- .../DeleteStoredScriptResponse.java | 16 ----- .../PutStoredScriptResponse.java | 16 ----- .../indices/alias/IndicesAliasesResponse.java | 16 ----- .../indices/close/CloseIndexResponse.java | 16 ----- .../indices/create/CreateIndexResponse.java | 2 - .../indices/delete/DeleteIndexResponse.java | 17 ----- .../mapping/put/PutMappingResponse.java | 16 ----- .../admin/indices/open/OpenIndexResponse.java | 4 -- .../indices/rollover/RolloverResponse.java | 71 +++++++++++++------ .../settings/put/UpdateSettingsResponse.java | 16 ----- .../delete/DeleteIndexTemplateResponse.java | 16 ----- .../put/PutIndexTemplateResponse.java | 16 ----- .../upgrade/post/UpgradeSettingsResponse.java | 16 ----- .../action/ingest/WritePipelineResponse.java | 16 ----- .../support/master/AcknowledgedResponse.java | 16 ++--- .../ClusterUpdateSettingsResponseTests.java | 8 +++ .../rollover/RolloverResponseTests.java | 8 +++ .../license/DeleteLicenseResponse.java | 17 ----- .../license/PostStartBasicResponse.java | 2 - .../license/PutLicenseResponse.java | 2 - .../core/ml/action/DeleteCalendarAction.java | 12 ---- .../ml/action/DeleteCalendarEventAction.java | 12 ---- .../core/ml/action/DeleteDatafeedAction.java | 12 ---- .../core/ml/action/DeleteFilterAction.java | 12 ---- .../xpack/core/ml/action/DeleteJobAction.java | 12 ---- .../ml/action/DeleteModelSnapshotAction.java | 13 ---- .../ml/action/FinalizeJobExecutionAction.java | 12 ---- .../xpack/core/ml/action/OpenJobAction.java | 11 +-- .../xpack/core/ml/action/PutFilterAction.java | 13 ---- .../core/ml/action/StartDatafeedAction.java | 10 --- .../ml/action/ValidateDetectorAction.java | 12 ---- .../ml/action/ValidateJobConfigAction.java | 12 ---- .../rollup/action/DeleteRollupJobAction.java | 12 ---- .../rollup/action/PutRollupJobAction.java | 12 ---- .../service/WatcherServiceResponse.java | 16 ----- 40 files changed, 111 insertions(+), 484 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryResponse.java index 43036a2a697..1f1fe524c64 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryResponse.java @@ -20,14 +20,9 @@ package org.elasticsearch.action.admin.cluster.repositories.delete; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentParser; -import java.io.IOException; - /** * Unregister repository response */ @@ -47,18 +42,6 @@ public class DeleteRepositoryResponse extends AcknowledgedResponse { super(acknowledged); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - public static DeleteRepositoryResponse fromXContent(XContentParser parser) { return PARSER.apply(parser, null); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryResponse.java index e58a1d9d147..52a1a736ec7 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryResponse.java @@ -20,13 +20,9 @@ package org.elasticsearch.action.admin.cluster.repositories.put; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentParser; -import java.io.IOException; - /** * Register repository response */ @@ -46,18 +42,6 @@ public class PutRepositoryResponse extends AcknowledgedResponse { super(acknowledged); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - public static PutRepositoryResponse fromXContent(XContentParser parser) { return PARSER.apply(parser, null); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponse.java index caf9fa62d4c..792f2135e78 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponse.java @@ -63,22 +63,32 @@ public class ClusterRerouteResponse extends AcknowledgedResponse implements ToXC @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - state = ClusterState.readFrom(in, null); - readAcknowledged(in); - explanations = RoutingExplanations.readFrom(in); + if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { + super.readFrom(in); + state = ClusterState.readFrom(in, null); + explanations = RoutingExplanations.readFrom(in); + } else { + state = ClusterState.readFrom(in, null); + acknowledged = in.readBoolean(); + explanations = RoutingExplanations.readFrom(in); + } } @Override public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - if (out.getVersion().onOrAfter(Version.V_6_3_0)) { + if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { + super.writeTo(out); state.writeTo(out); + RoutingExplanations.writeTo(explanations, out); } else { - ClusterModule.filterCustomsForPre63Clients(state).writeTo(out); + if (out.getVersion().onOrAfter(Version.V_6_3_0)) { + state.writeTo(out); + } else { + ClusterModule.filterCustomsForPre63Clients(state).writeTo(out); + } + out.writeBoolean(acknowledged); + RoutingExplanations.writeTo(explanations, out); } - writeAcknowledged(out); - RoutingExplanations.writeTo(explanations, out); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsResponse.java index 9ce22268afd..2691d5b5b09 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsResponse.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.admin.cluster.settings; +import org.elasticsearch.Version; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; @@ -67,10 +68,15 @@ public class ClusterUpdateSettingsResponse extends AcknowledgedResponse { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - transientSettings = Settings.readSettingsFromStream(in); - persistentSettings = Settings.readSettingsFromStream(in); - readAcknowledged(in); + if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { + super.readFrom(in); + transientSettings = Settings.readSettingsFromStream(in); + persistentSettings = Settings.readSettingsFromStream(in); + } else { + transientSettings = Settings.readSettingsFromStream(in); + persistentSettings = Settings.readSettingsFromStream(in); + acknowledged = in.readBoolean(); + } } public Settings getTransientSettings() { @@ -83,10 +89,15 @@ public class ClusterUpdateSettingsResponse extends AcknowledgedResponse { @Override public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - Settings.writeSettingsToStream(transientSettings, out); - Settings.writeSettingsToStream(persistentSettings, out); - writeAcknowledged(out); + if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { + super.writeTo(out); + Settings.writeSettingsToStream(transientSettings, out); + Settings.writeSettingsToStream(persistentSettings, out); + } else { + Settings.writeSettingsToStream(transientSettings, out); + Settings.writeSettingsToStream(persistentSettings, out); + out.writeBoolean(acknowledged); + } } @Override diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotResponse.java index 0783f3061ef..d8de78c3e5b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotResponse.java @@ -20,10 +20,6 @@ package org.elasticsearch.action.admin.cluster.snapshots.delete; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; - -import java.io.IOException; /** * Delete snapshot response @@ -36,17 +32,4 @@ public class DeleteSnapshotResponse extends AcknowledgedResponse { DeleteSnapshotResponse(boolean acknowledged) { super(acknowledged); } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/DeleteStoredScriptResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/DeleteStoredScriptResponse.java index 4fbb50a34d9..42f08ae73e0 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/DeleteStoredScriptResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/DeleteStoredScriptResponse.java @@ -20,10 +20,6 @@ package org.elasticsearch.action.admin.cluster.storedscripts; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; - -import java.io.IOException; public class DeleteStoredScriptResponse extends AcknowledgedResponse { @@ -33,16 +29,4 @@ public class DeleteStoredScriptResponse extends AcknowledgedResponse { public DeleteStoredScriptResponse(boolean acknowledged) { super(acknowledged); } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptResponse.java index 44250f3809d..a511c7dd47e 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/storedscripts/PutStoredScriptResponse.java @@ -20,10 +20,6 @@ package org.elasticsearch.action.admin.cluster.storedscripts; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; - -import java.io.IOException; public class PutStoredScriptResponse extends AcknowledgedResponse { @@ -34,16 +30,4 @@ public class PutStoredScriptResponse extends AcknowledgedResponse { super(acknowledged); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesResponse.java index b6402d5139a..ebfc82fec74 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesResponse.java @@ -20,13 +20,9 @@ package org.elasticsearch.action.admin.indices.alias; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentParser; -import java.io.IOException; - /** * A response for a add/remove alias action. */ @@ -45,18 +41,6 @@ public class IndicesAliasesResponse extends AcknowledgedResponse { super(acknowledged); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - public static IndicesAliasesResponse fromXContent(XContentParser parser) { return PARSER.apply(parser, null); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponse.java index de56c52f9f6..bfebaee5e59 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponse.java @@ -20,13 +20,9 @@ package org.elasticsearch.action.admin.indices.close; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentParser; -import java.io.IOException; - /** * A response for a close index action. */ @@ -45,18 +41,6 @@ public class CloseIndexResponse extends AcknowledgedResponse { super(acknowledged); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - public static CloseIndexResponse fromXContent(XContentParser parser) { return PARSER.apply(parser, null); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexResponse.java index edc0852cb28..4e3a5685bda 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexResponse.java @@ -66,7 +66,6 @@ public class CreateIndexResponse extends ShardsAcknowledgedResponse { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - readAcknowledged(in); readShardsAcknowledged(in); if (in.getVersion().onOrAfter(Version.V_5_6_0)) { index = in.readString(); @@ -76,7 +75,6 @@ public class CreateIndexResponse extends ShardsAcknowledgedResponse { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - writeAcknowledged(out); writeShardsAcknowledged(out); if (out.getVersion().onOrAfter(Version.V_5_6_0)) { out.writeString(index); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexResponse.java index a788f272d18..3a04dc5b70b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexResponse.java @@ -20,14 +20,9 @@ package org.elasticsearch.action.admin.indices.delete; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import java.io.IOException; - /** * A response for a delete index action. */ @@ -47,18 +42,6 @@ public class DeleteIndexResponse extends AcknowledgedResponse { super(acknowledged); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - public static DeleteIndexResponse fromXContent(XContentParser parser) { return PARSER.apply(parser, null); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingResponse.java index 8ccc5c8006a..1e022474955 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingResponse.java @@ -20,13 +20,9 @@ package org.elasticsearch.action.admin.indices.mapping.put; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentParser; -import java.io.IOException; - /** * The response of put mapping operation. */ @@ -47,18 +43,6 @@ public class PutMappingResponse extends AcknowledgedResponse { super(acknowledged); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - public static PutMappingResponse fromXContent(XContentParser parser) { return PARSER.apply(parser, null); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexResponse.java index 3918273cec9..97db91f8973 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexResponse.java @@ -21,11 +21,9 @@ package org.elasticsearch.action.admin.indices.open; import org.elasticsearch.Version; import org.elasticsearch.action.support.master.ShardsAcknowledgedResponse; -import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; @@ -52,7 +50,6 @@ public class OpenIndexResponse extends ShardsAcknowledgedResponse { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - readAcknowledged(in); if (in.getVersion().onOrAfter(Version.V_6_1_0)) { readShardsAcknowledged(in); } @@ -61,7 +58,6 @@ public class OpenIndexResponse extends ShardsAcknowledgedResponse { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - writeAcknowledged(out); if (out.getVersion().onOrAfter(Version.V_6_1_0)) { writeShardsAcknowledged(out); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java index d3ba00cdfcf..1342e62c652 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.admin.indices.rollover; +import org.elasticsearch.Version; import org.elasticsearch.action.support.master.ShardsAcknowledgedResponse; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; @@ -114,34 +115,60 @@ public final class RolloverResponse extends ShardsAcknowledgedResponse implement @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - oldIndex = in.readString(); - newIndex = in.readString(); - int conditionSize = in.readVInt(); - conditionStatus = new HashMap<>(conditionSize); - for (int i = 0; i < conditionSize; i++) { - conditionStatus.put(in.readString(), in.readBoolean()); + if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { + super.readFrom(in); + oldIndex = in.readString(); + newIndex = in.readString(); + int conditionSize = in.readVInt(); + conditionStatus = new HashMap<>(conditionSize); + for (int i = 0; i < conditionSize; i++) { + conditionStatus.put(in.readString(), in.readBoolean()); + } + dryRun = in.readBoolean(); + rolledOver = in.readBoolean(); + readShardsAcknowledged(in); + } else { + oldIndex = in.readString(); + newIndex = in.readString(); + int conditionSize = in.readVInt(); + conditionStatus = new HashMap<>(conditionSize); + for (int i = 0; i < conditionSize; i++) { + conditionStatus.put(in.readString(), in.readBoolean()); + } + dryRun = in.readBoolean(); + rolledOver = in.readBoolean(); + acknowledged = in.readBoolean(); + readShardsAcknowledged(in); } - dryRun = in.readBoolean(); - rolledOver = in.readBoolean(); - readAcknowledged(in); - readShardsAcknowledged(in); } @Override public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeString(oldIndex); - out.writeString(newIndex); - out.writeVInt(conditionStatus.size()); - for (Map.Entry entry : conditionStatus.entrySet()) { - out.writeString(entry.getKey()); - out.writeBoolean(entry.getValue()); + if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { + super.writeTo(out); + out.writeString(oldIndex); + out.writeString(newIndex); + out.writeVInt(conditionStatus.size()); + for (Map.Entry entry : conditionStatus.entrySet()) { + out.writeString(entry.getKey()); + out.writeBoolean(entry.getValue()); + } + out.writeBoolean(dryRun); + out.writeBoolean(rolledOver); + writeShardsAcknowledged(out); + } else { + out.writeString(oldIndex); + out.writeString(newIndex); + out.writeVInt(conditionStatus.size()); + for (Map.Entry entry : conditionStatus.entrySet()) { + out.writeString(entry.getKey()); + out.writeBoolean(entry.getValue()); + } + out.writeBoolean(dryRun); + out.writeBoolean(rolledOver); + out.writeBoolean(acknowledged); + writeShardsAcknowledged(out); } - out.writeBoolean(dryRun); - out.writeBoolean(rolledOver); - writeAcknowledged(out); - writeShardsAcknowledged(out); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsResponse.java index 79116eb8cf5..022f575f1d0 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsResponse.java @@ -20,13 +20,9 @@ package org.elasticsearch.action.admin.indices.settings.put; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentParser; -import java.io.IOException; - /** * A response for an update index settings action */ @@ -46,18 +42,6 @@ public class UpdateSettingsResponse extends AcknowledgedResponse { super(acknowledged); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - public static UpdateSettingsResponse fromXContent(XContentParser parser) { return PARSER.apply(parser, null); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateResponse.java index 9519f0f9fcf..a95f18bf13d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateResponse.java @@ -19,10 +19,6 @@ package org.elasticsearch.action.admin.indices.template.delete; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; - -import java.io.IOException; /** * A response for a delete index template. @@ -35,16 +31,4 @@ public class DeleteIndexTemplateResponse extends AcknowledgedResponse { protected DeleteIndexTemplateResponse(boolean acknowledged) { super(acknowledged); } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateResponse.java index 6c8a5291b12..59b00bd719b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateResponse.java @@ -19,13 +19,9 @@ package org.elasticsearch.action.admin.indices.template.put; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentParser; -import java.io.IOException; - /** * A response for a put index template action. */ @@ -38,18 +34,6 @@ public class PutIndexTemplateResponse extends AcknowledgedResponse { super(acknowledged); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - private static final ConstructingObjectParser PARSER; static { PARSER = new ConstructingObjectParser<>("put_index_template", true, args -> new PutIndexTemplateResponse((boolean) args[0])); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/UpgradeSettingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/UpgradeSettingsResponse.java index 0918af6f418..0d3ac16a6fe 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/UpgradeSettingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/upgrade/post/UpgradeSettingsResponse.java @@ -20,10 +20,6 @@ package org.elasticsearch.action.admin.indices.upgrade.post; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; - -import java.io.IOException; /** * A response for an update index settings action @@ -36,16 +32,4 @@ public class UpgradeSettingsResponse extends AcknowledgedResponse { UpgradeSettingsResponse(boolean acknowledged) { super(acknowledged); } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } } diff --git a/server/src/main/java/org/elasticsearch/action/ingest/WritePipelineResponse.java b/server/src/main/java/org/elasticsearch/action/ingest/WritePipelineResponse.java index 36301d6735a..b3bda3f1521 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/WritePipelineResponse.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/WritePipelineResponse.java @@ -20,14 +20,10 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentParser; -import java.io.IOException; - public class WritePipelineResponse extends AcknowledgedResponse implements ToXContentObject { private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( @@ -45,18 +41,6 @@ public class WritePipelineResponse extends AcknowledgedResponse implements ToXCo super(acknowledged); } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - readAcknowledged(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - writeAcknowledged(out); - } - public static WritePipelineResponse fromXContent(XContentParser parser) { return PARSER.apply(parser, null); } diff --git a/server/src/main/java/org/elasticsearch/action/support/master/AcknowledgedResponse.java b/server/src/main/java/org/elasticsearch/action/support/master/AcknowledgedResponse.java index ea9a373efdd..41c806bc205 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/AcknowledgedResponse.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/AcknowledgedResponse.java @@ -45,7 +45,7 @@ public abstract class AcknowledgedResponse extends ActionResponse implements ToX ObjectParser.ValueType.BOOLEAN); } - private boolean acknowledged; + protected boolean acknowledged; protected AcknowledgedResponse() { @@ -63,17 +63,15 @@ public abstract class AcknowledgedResponse extends ActionResponse implements ToX return acknowledged; } - /** - * Reads the acknowledged value - */ - protected void readAcknowledged(StreamInput in) throws IOException { + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); acknowledged = in.readBoolean(); } - /** - * Writes the acknowledged value - */ - protected void writeAcknowledged(StreamOutput out) throws IOException { + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); out.writeBoolean(acknowledged); } diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsResponseTests.java index 5ea5fd5ac02..c15c0a1be7f 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsResponseTests.java @@ -19,13 +19,16 @@ package org.elasticsearch.action.admin.cluster.settings; +import org.elasticsearch.Version; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings.Builder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.test.VersionUtils; +import java.io.IOException; import java.util.List; import java.util.Set; import java.util.function.Predicate; @@ -96,4 +99,9 @@ public class ClusterUpdateSettingsResponseTests extends AbstractStreamableXConte protected ClusterUpdateSettingsResponse createBlankInstance() { return new ClusterUpdateSettingsResponse(); } + + public void testOldSerialisation() throws IOException { + ClusterUpdateSettingsResponse original = createTestInstance(); + assertSerialization(original, VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.V_7_0_0_alpha1)); + } } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponseTests.java index a50f06cc540..c3ff4511815 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponseTests.java @@ -19,10 +19,13 @@ package org.elasticsearch.action.admin.indices.rollover; +import org.elasticsearch.Version; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.test.VersionUtils; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -126,4 +129,9 @@ public class RolloverResponseTests extends AbstractStreamableXContentTestCase { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/FinalizeJobExecutionAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/FinalizeJobExecutionAction.java index 019a52d16b3..4532c422d25 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/FinalizeJobExecutionAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/FinalizeJobExecutionAction.java @@ -79,18 +79,6 @@ public class FinalizeJobExecutionAction extends Action