From c4b5733c61ce91c4eaca742d174e55ddfb28023b Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Fri, 8 Sep 2017 19:33:35 +0300 Subject: [PATCH] convert more admin requests to writeable --- .../get/GetRepositoriesRequest.java | 20 +++--- .../get/TransportGetRepositoriesAction.java | 2 +- .../shards/ClusterSearchShardsRequest.java | 72 ++++++++++--------- .../TransportClusterSearchShardsAction.java | 2 +- .../cluster/state/ClusterStateRequest.java | 44 ++++++------ .../state/TransportClusterStateAction.java | 2 +- .../storedscripts/GetStoredScriptRequest.java | 39 +++++----- .../TransportGetStoredScriptAction.java | 2 +- .../tasks/PendingClusterTasksRequest.java | 10 +++ .../TransportPendingClusterTasksAction.java | 2 +- .../exists/TransportAliasesExistAction.java | 2 +- .../indices/alias/get/GetAliasesRequest.java | 28 ++++---- .../alias/get/TransportGetAliasesAction.java | 2 +- .../exists/indices/IndicesExistsRequest.java | 24 ++++--- .../indices/TransportIndicesExistsAction.java | 2 +- .../types/TransportTypesExistsAction.java | 2 +- .../exists/types/TypesExistsRequest.java | 28 ++++---- .../admin/indices/get/GetIndexRequest.java | 22 ++++-- .../indices/get/TransportGetIndexAction.java | 2 +- .../mapping/get/GetMappingsRequest.java | 10 +++ .../get/TransportGetMappingsAction.java | 2 +- .../settings/get/GetSettingsRequest.java | 35 +++++---- .../get/TransportGetSettingsAction.java | 2 +- .../shards/IndicesShardStoresRequest.java | 42 ++++++----- .../TransportIndicesShardStoresAction.java | 2 +- .../get/GetIndexTemplatesRequest.java | 20 +++--- .../get/TransportGetIndexTemplatesAction.java | 2 +- .../action/ingest/GetPipelineRequest.java | 20 +++--- .../ingest/GetPipelineTransportAction.java | 2 +- .../support/master/MasterNodeReadRequest.java | 5 +- .../master/info/ClusterInfoRequest.java | 28 +++++--- .../info/TransportClusterInfoAction.java | 5 +- .../ClusterSearchShardsRequestTests.java | 3 +- .../state/ClusterStateRequestTests.java | 3 +- .../GetStoredScriptRequestTests.java | 3 +- .../TransportClientNodesServiceTests.java | 2 +- .../RemoteClusterConnectionTests.java | 4 +- 37 files changed, 288 insertions(+), 209 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesRequest.java index a0e6de916ff07..9c2e2b80a6d28 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesRequest.java @@ -51,6 +51,17 @@ public GetRepositoriesRequest(String[] repositories) { this.repositories = repositories; } + public GetRepositoriesRequest(StreamInput in) throws IOException { + super(in); + repositories = in.readStringArray(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeStringArray(repositories); + } + @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; @@ -85,13 +96,6 @@ public GetRepositoriesRequest repositories(String[] repositories) { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - repositories = in.readStringArray(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeStringArray(repositories); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/TransportGetRepositoriesAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/TransportGetRepositoriesAction.java index 490d20f086cc4..6e7a0ca5cf49c 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/TransportGetRepositoriesAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/TransportGetRepositoriesAction.java @@ -51,7 +51,7 @@ public class TransportGetRepositoriesAction extends TransportMasterNodeReadActio @Inject public TransportGetRepositoriesAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { - super(settings, GetRepositoriesAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, GetRepositoriesRequest::new); + super(settings, GetRepositoriesAction.NAME, transportService, clusterService, threadPool, actionFilters, GetRepositoriesRequest::new, indexNameExpressionResolver); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequest.java index df38690b790a4..d8dfd71530922 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequest.java @@ -49,6 +49,42 @@ public ClusterSearchShardsRequest(String... indices) { indices(indices); } + public ClusterSearchShardsRequest(StreamInput in) throws IOException { + super(in); + indices = new String[in.readVInt()]; + for (int i = 0; i < indices.length; i++) { + indices[i] = in.readString(); + } + + routing = in.readOptionalString(); + preference = in.readOptionalString(); + + if (in.getVersion().onOrBefore(Version.V_5_1_1)) { + //types + in.readStringArray(); + } + indicesOptions = IndicesOptions.readIndicesOptions(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + + out.writeVInt(indices.length); + for (String index : indices) { + out.writeString(index); + } + + out.writeOptionalString(routing); + out.writeOptionalString(preference); + + if (out.getVersion().onOrBefore(Version.V_5_1_1)) { + //types + out.writeStringArray(Strings.EMPTY_ARRAY); + } + indicesOptions.writeIndicesOptions(out); + } + @Override public ActionRequestValidationException validate() { return null; @@ -124,40 +160,6 @@ public String preference() { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - - indices = new String[in.readVInt()]; - for (int i = 0; i < indices.length; i++) { - indices[i] = in.readString(); - } - - routing = in.readOptionalString(); - preference = in.readOptionalString(); - - if (in.getVersion().onOrBefore(Version.V_5_1_1)) { - //types - in.readStringArray(); - } - indicesOptions = IndicesOptions.readIndicesOptions(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - - out.writeVInt(indices.length); - for (String index : indices) { - out.writeString(index); - } - - out.writeOptionalString(routing); - out.writeOptionalString(preference); - - if (out.getVersion().onOrBefore(Version.V_5_1_1)) { - //types - out.writeStringArray(Strings.EMPTY_ARRAY); - } - indicesOptions.writeIndicesOptions(out); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } - } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java index 20ed69ae5a92f..9774ecdffba17 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java @@ -54,7 +54,7 @@ public TransportClusterSearchShardsAction(Settings settings, TransportService tr IndicesService indicesService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { super(settings, ClusterSearchShardsAction.NAME, transportService, clusterService, threadPool, actionFilters, - indexNameExpressionResolver, ClusterSearchShardsRequest::new); + ClusterSearchShardsRequest::new, indexNameExpressionResolver); this.indicesService = indicesService; } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java index e6b468b804b0d..33a20332526bf 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java @@ -42,6 +42,29 @@ public class ClusterStateRequest extends MasterNodeReadRequest { + public PendingClusterTasksRequest() { + } + + public PendingClusterTasksRequest(StreamInput in) throws IOException { + super(in); + } + @Override public ActionRequestValidationException validate() { return null; diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/tasks/TransportPendingClusterTasksAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/tasks/TransportPendingClusterTasksAction.java index cd58bb8d6d43e..542b2dd8badc4 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/tasks/TransportPendingClusterTasksAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/tasks/TransportPendingClusterTasksAction.java @@ -42,7 +42,7 @@ public class TransportPendingClusterTasksAction extends TransportMasterNodeReadA @Inject public TransportPendingClusterTasksAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { - super(settings, PendingClusterTasksAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, PendingClusterTasksRequest::new); + super(settings, PendingClusterTasksAction.NAME, transportService, clusterService, threadPool, actionFilters, PendingClusterTasksRequest::new, indexNameExpressionResolver); this.clusterService = clusterService; } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/TransportAliasesExistAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/TransportAliasesExistAction.java index 9a104598e8af3..6b77b9a39e97e 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/TransportAliasesExistAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/TransportAliasesExistAction.java @@ -37,7 +37,7 @@ public class TransportAliasesExistAction extends TransportMasterNodeReadAction { + public GetMappingsRequest() { + } + + public GetMappingsRequest(StreamInput in) throws IOException { + super(in); + } + @Override public ActionRequestValidationException validate() { return null; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java index 363e935ca56f0..3189a5a15c24f 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java @@ -39,7 +39,7 @@ public class TransportGetMappingsAction extends TransportClusterInfoAction request) { - super(settings, actionName, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, request); + Writeable.Reader request, IndexNameExpressionResolver indexNameExpressionResolver) { + super(settings, actionName, transportService, clusterService, threadPool, actionFilters, request, indexNameExpressionResolver); } @Override diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequestTests.java index e21635596b9e7..d8b9e2f5b5e03 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsRequestTests.java @@ -60,8 +60,7 @@ public void testSerialization() throws Exception { request.writeTo(out); try (StreamInput in = out.bytes().streamInput()) { in.setVersion(version); - ClusterSearchShardsRequest deserialized = new ClusterSearchShardsRequest(); - deserialized.readFrom(in); + ClusterSearchShardsRequest deserialized = new ClusterSearchShardsRequest(in); assertArrayEquals(request.indices(), deserialized.indices()); assertSame(request.indicesOptions(), deserialized.indicesOptions()); assertEquals(request.routing(), deserialized.routing()); diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestTests.java index b515829b72ac5..8c77ccfef90ce 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestTests.java @@ -47,8 +47,7 @@ public void testSerialization() throws Exception { StreamInput streamInput = output.bytes().streamInput(); streamInput.setVersion(testVersion); - ClusterStateRequest deserializedCSRequest = new ClusterStateRequest(); - deserializedCSRequest.readFrom(streamInput); + ClusterStateRequest deserializedCSRequest = new ClusterStateRequest(streamInput); assertThat(deserializedCSRequest.routingTable(), equalTo(clusterStateRequest.routingTable())); assertThat(deserializedCSRequest.metaData(), equalTo(clusterStateRequest.metaData())); diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/storedscripts/GetStoredScriptRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/storedscripts/GetStoredScriptRequestTests.java index bd12d58b1cbcd..756b7f1e5f688 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/storedscripts/GetStoredScriptRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/storedscripts/GetStoredScriptRequestTests.java @@ -38,8 +38,7 @@ public void testGetIndexedScriptRequestSerialization() throws IOException { StreamInput in = out.bytes().streamInput(); in.setVersion(out.getVersion()); - GetStoredScriptRequest request2 = new GetStoredScriptRequest(); - request2.readFrom(in); + GetStoredScriptRequest request2 = new GetStoredScriptRequest(in); assertThat(request2.id(), equalTo(request.id())); } diff --git a/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java b/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java index 9ff6ae06d17e7..e63f9f04617fd 100644 --- a/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java +++ b/core/src/test/java/org/elasticsearch/client/transport/TransportClientNodesServiceTests.java @@ -340,7 +340,7 @@ public void testSniffNodesSamplerClosesConnections() throws Exception { Settings remoteSettings = Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "remote").build(); try (MockTransportService remoteService = createNewService(remoteSettings, Version.CURRENT, threadPool, null)) { final MockHandler handler = new MockHandler(remoteService); - remoteService.registerRequestHandler(ClusterStateAction.NAME, ClusterStateRequest::new, ThreadPool.Names.SAME, handler); + remoteService.registerRequestHandler(ClusterStateAction.NAME, ThreadPool.Names.SAME, ClusterStateRequest::new, handler); remoteService.start(); remoteService.acceptIncomingRequests(); diff --git a/core/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java b/core/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java index d70032ca065f7..856385531d7ec 100644 --- a/core/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java +++ b/core/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java @@ -110,12 +110,12 @@ public static MockTransportService startTransport( ClusterName clusterName = ClusterName.CLUSTER_NAME_SETTING.get(s); MockTransportService newService = MockTransportService.createNewService(s, version, threadPool, null); try { - newService.registerRequestHandler(ClusterSearchShardsAction.NAME, ClusterSearchShardsRequest::new, ThreadPool.Names.SAME, + newService.registerRequestHandler(ClusterSearchShardsAction.NAME,ThreadPool.Names.SAME, ClusterSearchShardsRequest::new, (request, channel) -> { channel.sendResponse(new ClusterSearchShardsResponse(new ClusterSearchShardsGroup[0], knownNodes.toArray(new DiscoveryNode[0]), Collections.emptyMap())); }); - newService.registerRequestHandler(ClusterStateAction.NAME, ClusterStateRequest::new, ThreadPool.Names.SAME, + newService.registerRequestHandler(ClusterStateAction.NAME, ThreadPool.Names.SAME, ClusterStateRequest::new, (request, channel) -> { DiscoveryNodes.Builder builder = DiscoveryNodes.builder(); for (DiscoveryNode node : knownNodes) {