From 17c4b2b839ef40dc269a015818b82ed76c44f7be Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 17 Jul 2019 18:01:29 -0700 Subject: [PATCH] Convert MasterNodeRequest to implement Writeable.Reader (#44452) (#44513) This commit converts all MasterNodeRequest subclasses to fullfill Writeable.Reader constructors. relates #34389 --- .../ClusterAllocationExplainRequest.java | 5 -- .../AddVotingConfigExclusionsRequest.java | 5 -- .../ClearVotingConfigExclusionsRequest.java | 5 -- .../cluster/health/ClusterHealthRequest.java | 5 -- .../get/GetRepositoriesRequest.java | 5 -- .../shards/ClusterSearchShardsRequest.java | 5 -- .../create/CreateSnapshotRequest.java | 5 -- .../delete/DeleteSnapshotRequest.java | 5 -- .../snapshots/get/GetSnapshotsRequest.java | 5 -- .../restore/RestoreSnapshotRequest.java | 5 -- .../status/SnapshotsStatusRequest.java | 5 -- .../cluster/state/ClusterStateRequest.java | 5 -- .../storedscripts/GetStoredScriptRequest.java | 5 -- .../indices/alias/get/GetAliasesRequest.java | 5 -- .../exists/indices/IndicesExistsRequest.java | 5 -- .../exists/types/TypesExistsRequest.java | 5 -- .../admin/indices/get/GetIndexRequest.java | 5 -- .../settings/get/GetSettingsRequest.java | 5 -- .../shards/IndicesShardStoresRequest.java | 5 -- .../delete/DeleteIndexTemplateRequest.java | 11 ++- .../TransportDeleteIndexTemplateAction.java | 2 +- .../get/GetIndexTemplatesRequest.java | 5 -- .../template/put/PutIndexTemplateRequest.java | 69 +++++++++---------- .../put/TransportPutIndexTemplateAction.java | 2 +- .../action/ingest/GetPipelineRequest.java | 5 -- .../support/master/AcknowledgedRequest.java | 5 -- .../support/master/MasterNodeReadRequest.java | 5 -- .../support/master/MasterNodeRequest.java | 7 +- .../master/info/ClusterInfoRequest.java | 10 --- .../CompletionPersistentTaskAction.java | 17 ++--- .../RemovePersistentTaskAction.java | 13 ++-- .../persistent/StartPersistentTaskAction.java | 23 +++---- .../UpdatePersistentTaskStatusAction.java | 18 +++-- .../snapshots/SnapshotShardsService.java | 17 ++--- .../InternalOrPrivateSettingsPlugin.java | 19 +++-- .../CancelPersistentTaskRequestTests.java | 9 +-- .../RestartPersistentTaskRequestTests.java | 9 +-- .../StartPersistentActionRequestTests.java | 9 +-- .../UpdatePersistentTaskRequestTests.java | 9 +-- .../license/PostStartTrialRequest.java | 25 +++---- .../TransportPostStartTrialAction.java | 2 +- .../protocol/xpack/XPackUsageRequest.java | 9 +++ .../migration/IndexUpgradeInfoRequest.java | 5 -- .../action/TransportXPackUsageAction.java | 4 +- .../deprecation/DeprecationInfoAction.java | 5 -- .../ml/action/FinalizeJobExecutionAction.java | 5 -- .../core/ml/action/GetDatafeedsAction.java | 5 -- .../ml/action/GetDatafeedsStatsAction.java | 5 -- .../xpack/core/ml/action/GetJobsAction.java | 5 -- .../xpack/core/ml/action/OpenJobAction.java | 9 +-- .../core/ml/action/StartDatafeedAction.java | 9 +-- .../upgrade/actions/IndexUpgradeAction.java | 5 -- .../service/WatcherServiceRequest.java | 11 ++- .../ml/action/OpenJobActionRequestTests.java | 15 ++-- .../StartDatafeedActionRequestTests.java | 13 ++-- .../TransportWatcherServiceAction.java | 2 +- 56 files changed, 158 insertions(+), 335 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java index b6959afba5d..0b0bb8c57a9 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java @@ -243,9 +243,4 @@ public class ClusterAllocationExplainRequest extends MasterNodeRequest public boolean verbose() { return verbose; } - - @Override - public void readFrom(StreamInput in) throws IOException { - throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); - } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java index 53aa522772a..0d2cac9b401 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java @@ -609,11 +609,6 @@ public class RestoreSnapshotRequest extends MasterNodeRequest public ActionRequestValidationException validate() { return null; } - - @Override - public void readFrom(StreamInput in) throws IOException { - throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); - } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java index 0c99175387d..8e6946e85eb 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsRequest.java @@ -94,9 +94,4 @@ public class IndicesExistsRequest extends MasterNodeReadRequest { return includeDefaults; } - @Override - public void readFrom(StreamInput in) throws IOException { - throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java index 1f4214dbdd7..e3fd95779cb 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsRequest.java @@ -129,11 +129,6 @@ public class GetSettingsRequest extends MasterNodeReadRequest 0) { + throw new IllegalStateException("unexpected custom metadata when none is supported"); + } + } + int aliasesSize = in.readVInt(); + for (int i = 0; i < aliasesSize; i++) { + aliases.add(Alias.read(in)); + } + version = in.readOptionalVInt(); + } + public PutIndexTemplateRequest() { } @@ -454,41 +488,6 @@ public class PutIndexTemplateRequest extends MasterNodeRequest 0) { - throw new IllegalStateException("unexpected custom metadata when none is supported"); - } - } - int aliasesSize = in.readVInt(); - for (int i = 0; i < aliasesSize; i++) { - aliases.add(Alias.read(in)); - } - version = in.readOptionalVInt(); - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java index 4a49820e60e..3584bd93d11 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/put/TransportPutIndexTemplateAction.java @@ -53,7 +53,7 @@ public class TransportPutIndexTemplateAction extends TransportMasterNodeAction

{ +public class CancelPersistentTaskRequestTests extends AbstractWireSerializingTestCase { @Override protected Request createTestInstance() { @@ -31,7 +32,7 @@ public class CancelPersistentTaskRequestTests extends AbstractStreamableTestCase } @Override - protected Request createBlankInstance() { - return new Request(); + protected Writeable.Reader instanceReader() { + return Request::new; } } diff --git a/server/src/test/java/org/elasticsearch/persistent/RestartPersistentTaskRequestTests.java b/server/src/test/java/org/elasticsearch/persistent/RestartPersistentTaskRequestTests.java index 3ce29d543d4..d0bbd4521f4 100644 --- a/server/src/test/java/org/elasticsearch/persistent/RestartPersistentTaskRequestTests.java +++ b/server/src/test/java/org/elasticsearch/persistent/RestartPersistentTaskRequestTests.java @@ -18,10 +18,11 @@ */ package org.elasticsearch.persistent; -import org.elasticsearch.test.AbstractStreamableTestCase; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.persistent.CompletionPersistentTaskAction.Request; +import org.elasticsearch.test.AbstractWireSerializingTestCase; -public class RestartPersistentTaskRequestTests extends AbstractStreamableTestCase { +public class RestartPersistentTaskRequestTests extends AbstractWireSerializingTestCase { @Override protected Request createTestInstance() { @@ -29,7 +30,7 @@ public class RestartPersistentTaskRequestTests extends AbstractStreamableTestCas } @Override - protected Request createBlankInstance() { - return new Request(); + protected Writeable.Reader instanceReader() { + return Request::new; } } diff --git a/server/src/test/java/org/elasticsearch/persistent/StartPersistentActionRequestTests.java b/server/src/test/java/org/elasticsearch/persistent/StartPersistentActionRequestTests.java index e4c5a26de9c..80155256d4f 100644 --- a/server/src/test/java/org/elasticsearch/persistent/StartPersistentActionRequestTests.java +++ b/server/src/test/java/org/elasticsearch/persistent/StartPersistentActionRequestTests.java @@ -21,14 +21,15 @@ package org.elasticsearch.persistent; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.persistent.StartPersistentTaskAction.Request; import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestParams; import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor; -import org.elasticsearch.test.AbstractStreamableTestCase; +import org.elasticsearch.test.AbstractWireSerializingTestCase; import java.util.Collections; -public class StartPersistentActionRequestTests extends AbstractStreamableTestCase { +public class StartPersistentActionRequestTests extends AbstractWireSerializingTestCase { @Override protected Request createTestInstance() { @@ -43,8 +44,8 @@ public class StartPersistentActionRequestTests extends AbstractStreamableTestCas } @Override - protected Request createBlankInstance() { - return new Request(); + protected Writeable.Reader instanceReader() { + return Request::new; } @Override diff --git a/server/src/test/java/org/elasticsearch/persistent/UpdatePersistentTaskRequestTests.java b/server/src/test/java/org/elasticsearch/persistent/UpdatePersistentTaskRequestTests.java index 5ae54640f8e..787b5ad5d89 100644 --- a/server/src/test/java/org/elasticsearch/persistent/UpdatePersistentTaskRequestTests.java +++ b/server/src/test/java/org/elasticsearch/persistent/UpdatePersistentTaskRequestTests.java @@ -20,14 +20,15 @@ package org.elasticsearch.persistent; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; -import org.elasticsearch.test.AbstractStreamableTestCase; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.persistent.TestPersistentTasksPlugin.State; import org.elasticsearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor; import org.elasticsearch.persistent.UpdatePersistentTaskStatusAction.Request; +import org.elasticsearch.test.AbstractWireSerializingTestCase; import java.util.Collections; -public class UpdatePersistentTaskRequestTests extends AbstractStreamableTestCase { +public class UpdatePersistentTaskRequestTests extends AbstractWireSerializingTestCase { @Override protected Request createTestInstance() { @@ -35,8 +36,8 @@ public class UpdatePersistentTaskRequestTests extends AbstractStreamableTestCase } @Override - protected Request createBlankInstance() { - return new Request(); + protected Writeable.Reader instanceReader() { + return Request::new; } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequest.java index cf94312b6a7..2de5a857878 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/PostStartTrialRequest.java @@ -18,6 +18,19 @@ public class PostStartTrialRequest extends MasterNodeRequest { + public XPackUsageRequest() {} + + public XPackUsageRequest(StreamInput in) throws IOException { + super(in); + } + @Override public ActionRequestValidationException validate() { return null; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoRequest.java index 17afee59fa1..d09b1344627 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/migration/IndexUpgradeInfoRequest.java @@ -64,11 +64,6 @@ public class IndexUpgradeInfoRequest extends MasterNodeReadRequest featureSets) { - super(XPackUsageAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, - XPackUsageRequest::new); + super(XPackUsageAction.NAME, transportService, clusterService, threadPool, actionFilters, XPackUsageRequest::new, + indexNameExpressionResolver); this.featureSets = Collections.unmodifiableList(new ArrayList<>(featureSets)); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoAction.java index 897690891b0..5c0589ddf44 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoAction.java @@ -270,11 +270,6 @@ public class DeprecationInfoAction extends StreamableResponseActionType return jobIds; } - @Override - public void readFrom(StreamInput in) throws IOException { - throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsAction.java index a107f8bef1e..0bc3a058053 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsAction.java @@ -84,11 +84,6 @@ public class GetDatafeedsAction extends ActionType return null; } - @Override - public void readFrom(StreamInput in) throws IOException { - throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); - } - @Override public int hashCode() { return Objects.hash(datafeedId, allowNoDatafeeds); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsStatsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsStatsAction.java index bdb5858f755..d08415ce412 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsStatsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedsStatsAction.java @@ -96,11 +96,6 @@ public class GetDatafeedsStatsAction extends ActionType { return null; } - @Override - public void readFrom(StreamInput in) throws IOException { - throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); - } - @Override public int hashCode() { return Objects.hash(jobId, allowNoJobs); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java index 1a0bd92eede..e146e39b638 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java @@ -74,7 +74,8 @@ public class OpenJobAction extends ActionType { } public Request(StreamInput in) throws IOException { - readFrom(in); + super(in); + jobParams = new JobParams(in); } public Request() { @@ -89,12 +90,6 @@ public class OpenJobAction extends ActionType { return null; } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - jobParams = new JobParams(in); - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java index 0240d8fb4ac..138915ca90e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java @@ -86,7 +86,8 @@ public class StartDatafeedAction extends ActionType { } public Request(StreamInput in) throws IOException { - readFrom(in); + super(in); + params = new DatafeedParams(in); } public Request() { @@ -107,12 +108,6 @@ public class StartDatafeedAction extends ActionType { return e; } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - params = new DatafeedParams(in); - } - @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeAction.java index 2cc6c9431d6..9398012662e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/upgrade/actions/IndexUpgradeAction.java @@ -113,11 +113,6 @@ public class IndexUpgradeAction extends StreamableResponseActionType { +public class OpenJobActionRequestTests extends AbstractSerializingTestCase { @Override protected Request createTestInstance() { return new Request(JobParamsTests.createJobParams()); } + @Override + protected Writeable.Reader instanceReader() { + return Request::new; + } + @Override protected boolean supportsUnknownFields() { return false; } - @Override - protected Request createBlankInstance() { - return new Request(); - } - @Override protected Request doParseInstance(XContentParser parser) { return Request.parseRequest(null, parser); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedActionRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedActionRequestTests.java index fe2bb5d6508..3b8eb0254ec 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedActionRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedActionRequestTests.java @@ -6,13 +6,14 @@ package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.xpack.core.ml.action.StartDatafeedAction.Request; import static org.hamcrest.Matchers.equalTo; -public class StartDatafeedActionRequestTests extends AbstractStreamableXContentTestCase { +public class StartDatafeedActionRequestTests extends AbstractSerializingTestCase { @Override protected Request createTestInstance() { @@ -20,13 +21,13 @@ public class StartDatafeedActionRequestTests extends AbstractStreamableXContentT } @Override - protected boolean supportsUnknownFields() { - return false; + protected Writeable.Reader instanceReader() { + return Request::new; } @Override - protected Request createBlankInstance() { - return new Request(); + protected boolean supportsUnknownFields() { + return false; } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/service/TransportWatcherServiceAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/service/TransportWatcherServiceAction.java index 8a2d52b8316..74c27c4edb5 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/service/TransportWatcherServiceAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/service/TransportWatcherServiceAction.java @@ -50,7 +50,7 @@ public class TransportWatcherServiceAction extends TransportMasterNodeAction