From 34c60670188577239b188c054508b52f3cd76463 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Wed, 17 Jul 2019 19:04:21 -0700 Subject: [PATCH] Convert several classes in 'server' to Writeable. (#44527) * Convert FieldCapabilities*. * Convert MultiTermVectors*. * Convert SyncedFlush*. * Convert SearchTemplateRequest. * Convert MultiSearchTemplateRequest. * Convert GrokProcessorGet*. * Remove a stray reference to SearchTemplateRequest#readFrom. Relates to #34389. --- .../ingest/common/GrokProcessorGetAction.java | 31 +++++---- .../common/GrokProcessorGetActionTests.java | 4 +- .../mustache/MultiSearchTemplateRequest.java | 14 ++-- .../mustache/SearchTemplateRequest.java | 29 +++++---- .../TransportMultiSearchTemplateAction.java | 2 +- .../TransportSearchTemplateAction.java | 2 +- .../mustache/SearchTemplateRequestTests.java | 15 +++-- .../indices/flush/SyncedFlushAction.java | 11 +--- .../indices/flush/SyncedFlushResponse.java | 64 +++++++++---------- .../fieldcaps/FieldCapabilitiesAction.java | 10 +-- .../fieldcaps/FieldCapabilitiesRequest.java | 26 ++++---- .../fieldcaps/FieldCapabilitiesResponse.java | 28 ++++---- .../TransportFieldCapabilitiesAction.java | 2 +- .../support/broadcast/BroadcastRequest.java | 4 +- .../termvectors/MultiTermVectorsAction.java | 11 +--- .../MultiTermVectorsItemResponse.java | 37 ++++------- .../termvectors/MultiTermVectorsRequest.java | 20 ++++-- .../termvectors/MultiTermVectorsResponse.java | 56 +++++++--------- .../MultiTermVectorsShardResponse.java | 2 +- .../TransportMultiTermVectorsAction.java | 2 +- .../indices/flush/SyncedFlushUnitTests.java | 5 +- .../FieldCapabilitiesRequestTests.java | 9 +-- .../FieldCapabilitiesResponseTests.java | 15 +++-- .../MergedFieldCapabilitiesResponseTests.java | 15 +++-- 24 files changed, 202 insertions(+), 212 deletions(-) diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java index 2129c0c9828..dd7e73d96c8 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java @@ -22,7 +22,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.action.StreamableResponseActionType; +import org.elasticsearch.action.ActionType; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.client.node.NodeClient; @@ -45,18 +45,13 @@ import java.util.Map; import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS; import static org.elasticsearch.rest.RestRequest.Method.GET; -public class GrokProcessorGetAction extends StreamableResponseActionType { +public class GrokProcessorGetAction extends ActionType { static final GrokProcessorGetAction INSTANCE = new GrokProcessorGetAction(); static final String NAME = "cluster:admin/ingest/processor/grok/get"; private GrokProcessorGetAction() { - super(NAME); - } - - @Override - public Response newResponse() { - return new Response(null); + super(NAME, Response::new); } public static class Request extends ActionRequest { @@ -64,15 +59,26 @@ public class GrokProcessorGetAction extends StreamableResponseActionType grokPatterns; + private final Map grokPatterns; Response(Map grokPatterns) { this.grokPatterns = grokPatterns; } + Response(StreamInput in) throws IOException { + super(in); + grokPatterns = in.readMap(StreamInput::readString, StreamInput::readString); + } + public Map getGrokPatterns() { return grokPatterns; } @@ -87,9 +93,8 @@ public class GrokProcessorGetAction extends StreamableResponseActionType TEST_PATTERNS = Collections.singletonMap("PATTERN", "foo"); @@ -53,8 +52,7 @@ public class GrokProcessorGetActionTests extends ESTestCase { BytesStreamOutput out = new BytesStreamOutput(); response.writeTo(out); StreamInput streamInput = out.bytes().streamInput(); - GrokProcessorGetAction.Response otherResponse = new GrokProcessorGetAction.Response(null); - otherResponse.readFrom(streamInput); + GrokProcessorGetAction.Response otherResponse = new GrokProcessorGetAction.Response(streamInput); assertThat(response.getGrokPatterns(), equalTo(TEST_PATTERNS)); assertThat(response.getGrokPatterns(), equalTo(otherResponse.getGrokPatterns())); } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java index c80f99484a9..327726dc576 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequest.java @@ -47,6 +47,14 @@ public class MultiSearchTemplateRequest extends ActionRequest implements Composi private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled(); + public MultiSearchTemplateRequest() {} + + public MultiSearchTemplateRequest(StreamInput in) throws IOException { + super(in); + maxConcurrentSearchRequests = in.readVInt(); + requests = in.readList(SearchTemplateRequest::new); + } + /** * Add a search template request to execute. Note, the order is important, the search response will be returned in the * same order as the search requests. @@ -116,10 +124,8 @@ public class MultiSearchTemplateRequest extends ActionRequest implements Composi } @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - maxConcurrentSearchRequests = in.readVInt(); - requests = in.readStreamableList(SearchTemplateRequest::new); + public void readFrom(StreamInput in) { + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequest.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequest.java index da3cc368814..96de9022c97 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequest.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequest.java @@ -54,13 +54,25 @@ public class SearchTemplateRequest extends ActionRequest implements CompositeInd private String script; private Map scriptParams; - public SearchTemplateRequest() { - } + public SearchTemplateRequest() {} public SearchTemplateRequest(SearchRequest searchRequest) { this.request = searchRequest; } + public SearchTemplateRequest(StreamInput in) throws IOException { + super(in); + request = in.readOptionalWriteable(SearchRequest::new); + simulate = in.readBoolean(); + explain = in.readBoolean(); + profile = in.readBoolean(); + scriptType = ScriptType.readFrom(in); + script = in.readOptionalString(); + if (in.readBoolean()) { + scriptParams = in.readMap(); + } + } + public void setRequest(SearchRequest request) { this.request = request; } @@ -218,17 +230,8 @@ public class SearchTemplateRequest extends ActionRequest implements CompositeInd } @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - request = in.readOptionalWriteable(SearchRequest::new); - simulate = in.readBoolean(); - explain = in.readBoolean(); - profile = in.readBoolean(); - scriptType = ScriptType.readFrom(in); - script = in.readOptionalString(); - if (in.readBoolean()) { - scriptParams = in.readMap(); - } + public void readFrom(StreamInput in) { + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportMultiSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportMultiSearchTemplateAction.java index e50eaf73481..7da78a449d7 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportMultiSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportMultiSearchTemplateAction.java @@ -46,7 +46,7 @@ public class TransportMultiSearchTemplateAction extends HandledTransportAction { - - @Override - protected SearchTemplateRequest createBlankInstance() { - return new SearchTemplateRequest(); - } +public class SearchTemplateRequestTests extends AbstractWireSerializingTestCase { @Override protected SearchTemplateRequest createTestInstance() { return createRandomRequest(); } + @Override + protected Writeable.Reader instanceReader() { + return SearchTemplateRequest::new; + } + @Override protected SearchTemplateRequest mutateInstance(SearchTemplateRequest instance) throws IOException { List> mutators = new ArrayList<>(); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushAction.java index 70153b767ee..d5180c799ad 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushAction.java @@ -19,20 +19,15 @@ package org.elasticsearch.action.admin.indices.flush; -import org.elasticsearch.action.StreamableResponseActionType; +import org.elasticsearch.action.ActionType; -public class SyncedFlushAction extends StreamableResponseActionType { +public class SyncedFlushAction extends ActionType { public static final SyncedFlushAction INSTANCE = new SyncedFlushAction(); public static final String NAME = "indices:admin/synced_flush"; private SyncedFlushAction() { - super(NAME); - } - - @Override - public SyncedFlushResponse newResponse() { - return new SyncedFlushResponse(); + super(NAME, SyncedFlushResponse::new); } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushResponse.java index ed05ec096df..77bedae5319 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushResponse.java @@ -22,7 +22,7 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.util.iterable.Iterables; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -44,12 +44,8 @@ import static java.util.Collections.unmodifiableMap; */ public class SyncedFlushResponse extends ActionResponse implements ToXContentFragment { - Map> shardsResultPerIndex; - ShardCounts shardCounts; - - SyncedFlushResponse() { - - } + private final Map> shardsResultPerIndex; + private final ShardCounts shardCounts; public SyncedFlushResponse(Map> shardsResultPerIndex) { // shardsResultPerIndex is never modified after it is passed to this @@ -59,6 +55,23 @@ public class SyncedFlushResponse extends ActionResponse implements ToXContentFra this.shardCounts = calculateShardCounts(Iterables.flatten(shardsResultPerIndex.values())); } + public SyncedFlushResponse(StreamInput in) throws IOException { + super(in); + shardCounts = new ShardCounts(in); + Map> tmpShardsResultPerIndex = new HashMap<>(); + int numShardsResults = in.readInt(); + for (int i =0 ; i< numShardsResults; i++) { + String index = in.readString(); + List shardsSyncedFlushResults = new ArrayList<>(); + int numShards = in.readInt(); + for (int j =0; j< numShards; j++) { + shardsSyncedFlushResults.add(ShardsSyncedFlushResult.readShardsSyncedFlushResult(in)); + } + tmpShardsResultPerIndex.put(index, shardsSyncedFlushResults); + } + shardsResultPerIndex = Collections.unmodifiableMap(tmpShardsResultPerIndex); + } + /** * total number shards, including replicas, both assigned and unassigned */ @@ -140,11 +153,11 @@ public class SyncedFlushResponse extends ActionResponse implements ToXContentFra return new ShardCounts(total, successful, failed); } - static final class ShardCounts implements ToXContentFragment, Streamable { + static final class ShardCounts implements ToXContentFragment, Writeable { - public int total; - public int successful; - public int failed; + public final int total; + public final int successful; + public final int failed; ShardCounts(int total, int successful, int failed) { this.total = total; @@ -152,8 +165,10 @@ public class SyncedFlushResponse extends ActionResponse implements ToXContentFra this.failed = failed; } - ShardCounts() { - + ShardCounts(StreamInput in) throws IOException { + total = in.readInt(); + successful = in.readInt(); + failed = in.readInt(); } @Override @@ -164,13 +179,6 @@ public class SyncedFlushResponse extends ActionResponse implements ToXContentFra return builder; } - @Override - public void readFrom(StreamInput in) throws IOException { - total = in.readInt(); - successful = in.readInt(); - failed = in.readInt(); - } - @Override public void writeTo(StreamOutput out) throws IOException { out.writeInt(total); @@ -192,21 +200,7 @@ public class SyncedFlushResponse extends ActionResponse implements ToXContentFra @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - shardCounts = new ShardCounts(); - shardCounts.readFrom(in); - Map> tmpShardsResultPerIndex = new HashMap<>(); - int numShardsResults = in.readInt(); - for (int i =0 ; i< numShardsResults; i++) { - String index = in.readString(); - List shardsSyncedFlushResults = new ArrayList<>(); - int numShards = in.readInt(); - for (int j =0; j< numShards; j++) { - shardsSyncedFlushResults.add(ShardsSyncedFlushResult.readShardsSyncedFlushResult(in)); - } - tmpShardsResultPerIndex.put(index, shardsSyncedFlushResults); - } - shardsResultPerIndex = Collections.unmodifiableMap(tmpShardsResultPerIndex); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesAction.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesAction.java index e64a3b67c10..30bceef47e7 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesAction.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesAction.java @@ -19,19 +19,15 @@ package org.elasticsearch.action.fieldcaps; -import org.elasticsearch.action.StreamableResponseActionType; +import org.elasticsearch.action.ActionType; -public class FieldCapabilitiesAction extends StreamableResponseActionType { +public class FieldCapabilitiesAction extends ActionType { public static final FieldCapabilitiesAction INSTANCE = new FieldCapabilitiesAction(); public static final String NAME = "indices:data/read/field_caps"; private FieldCapabilitiesAction() { - super(NAME); + super(NAME, FieldCapabilitiesResponse::new); } - @Override - public FieldCapabilitiesResponse newResponse() { - return new FieldCapabilitiesResponse(); - } } diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java index 75686cc6b0e..437889c6c3e 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java @@ -56,6 +56,19 @@ public final class FieldCapabilitiesRequest extends ActionRequest implements Ind PARSER.declareStringArray(fromList(String.class, FieldCapabilitiesRequest::fields), FIELDS_FIELD); } + public FieldCapabilitiesRequest(StreamInput in) throws IOException { + super(in); + fields = in.readStringArray(); + indices = in.readStringArray(); + indicesOptions = IndicesOptions.readIndicesOptions(in); + mergeResults = in.readBoolean(); + if (in.getVersion().onOrAfter(Version.V_7_2_0)) { + includeUnmapped = in.readBoolean(); + } else { + includeUnmapped = false; + } + } + public FieldCapabilitiesRequest() {} /** @@ -78,17 +91,8 @@ public final class FieldCapabilitiesRequest extends ActionRequest implements Ind } @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - fields = in.readStringArray(); - indices = in.readStringArray(); - indicesOptions = IndicesOptions.readIndicesOptions(in); - mergeResults = in.readBoolean(); - if (in.getVersion().onOrAfter(Version.V_7_2_0)) { - includeUnmapped = in.readBoolean(); - } else { - includeUnmapped = false; - } + public void readFrom(StreamInput in) { + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponse.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponse.java index 1d04d07da29..22695d53928 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponse.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponse.java @@ -48,9 +48,9 @@ public class FieldCapabilitiesResponse extends ActionResponse implements ToXCont private static final ParseField INDICES_FIELD = new ParseField("indices"); private static final ParseField FIELDS_FIELD = new ParseField("fields"); - private String[] indices; - private Map> responseMap; - private List indexResponses; + private final String[] indices; + private final Map> responseMap; + private final List indexResponses; FieldCapabilitiesResponse(String[] indices, Map> responseMap) { this(indices, responseMap, Collections.emptyList()); @@ -67,6 +67,17 @@ public class FieldCapabilitiesResponse extends ActionResponse implements ToXCont this.indices = indices; } + public FieldCapabilitiesResponse(StreamInput in) throws IOException { + super(in); + if (in.getVersion().onOrAfter(Version.V_7_2_0)) { + indices = in.readStringArray(); + } else { + indices = Strings.EMPTY_ARRAY; + } + this.responseMap = in.readMap(StreamInput::readString, FieldCapabilitiesResponse::readField); + indexResponses = in.readList(FieldCapabilitiesIndexResponse::new); + } + /** * Used for serialization */ @@ -106,15 +117,8 @@ public class FieldCapabilitiesResponse extends ActionResponse implements ToXCont } @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - if (in.getVersion().onOrAfter(Version.V_7_2_0)) { - indices = in.readStringArray(); - } else { - indices = Strings.EMPTY_ARRAY; - } - this.responseMap = in.readMap(StreamInput::readString, FieldCapabilitiesResponse::readField); - indexResponses = in.readList(FieldCapabilitiesIndexResponse::new); + public void readFrom(StreamInput in) { + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } private static Map readField(StreamInput in) throws IOException { diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java index 6d77376745d..dcd52094ff6 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java @@ -57,7 +57,7 @@ public class TransportFieldCapabilitiesAction extends HandledTransportAction> extends } @Override - public final void readFrom(StreamInput in) throws IOException { - throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable " + getClass().getName()); + public final void readFrom(StreamInput in) { + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } } diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java index e02969856e9..6b4014ed77b 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java @@ -19,19 +19,14 @@ package org.elasticsearch.action.termvectors; -import org.elasticsearch.action.StreamableResponseActionType; +import org.elasticsearch.action.ActionType; -public class MultiTermVectorsAction extends StreamableResponseActionType { +public class MultiTermVectorsAction extends ActionType { public static final MultiTermVectorsAction INSTANCE = new MultiTermVectorsAction(); public static final String NAME = "indices:data/read/mtv"; private MultiTermVectorsAction() { - super(NAME); - } - - @Override - public MultiTermVectorsResponse newResponse() { - return new MultiTermVectorsResponse(); + super(NAME, MultiTermVectorsResponse::new); } } diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsItemResponse.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsItemResponse.java index 14ac59cb132..38cf039f330 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsItemResponse.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsItemResponse.java @@ -21,21 +21,17 @@ package org.elasticsearch.action.termvectors; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.common.io.stream.Writeable; import java.io.IOException; /** * A single multi get response. */ -public class MultiTermVectorsItemResponse implements Streamable { +public class MultiTermVectorsItemResponse implements Writeable { - private TermVectorsResponse response; - private MultiTermVectorsResponse.Failure failure; - - MultiTermVectorsItemResponse() { - - } + private final TermVectorsResponse response; + private final MultiTermVectorsResponse.Failure failure; public MultiTermVectorsItemResponse(TermVectorsResponse response, MultiTermVectorsResponse.Failure failure) { assert (((response == null) && (failure != null)) || ((response != null) && (failure == null))); @@ -43,6 +39,16 @@ public class MultiTermVectorsItemResponse implements Streamable { this.failure = failure; } + MultiTermVectorsItemResponse(StreamInput in) throws IOException { + if (in.readBoolean()) { + failure = new MultiTermVectorsResponse.Failure(in); + response = null; + } else { + response = new TermVectorsResponse(in); + failure = null; + } + } + /** * The index name of the document. */ @@ -94,21 +100,6 @@ public class MultiTermVectorsItemResponse implements Streamable { return this.failure; } - public static MultiTermVectorsItemResponse readItemResponse(StreamInput in) throws IOException { - MultiTermVectorsItemResponse response = new MultiTermVectorsItemResponse(); - response.readFrom(in); - return response; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - if (in.readBoolean()) { - failure = MultiTermVectorsResponse.Failure.readFailure(in); - } else { - response = new TermVectorsResponse(in); - } - } - @Override public void writeTo(StreamOutput out) throws IOException { if (failure != null) { diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java index efc940ac3de..9eb6f04f5ae 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java @@ -47,6 +47,18 @@ public class MultiTermVectorsRequest extends ActionRequest final Set ids = new HashSet<>(); + public MultiTermVectorsRequest(StreamInput in) throws IOException { + super(in); + preference = in.readOptionalString(); + int size = in.readVInt(); + requests = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + requests.add(new TermVectorsRequest(in)); + } + } + + public MultiTermVectorsRequest() {} + public MultiTermVectorsRequest add(TermVectorsRequest termVectorsRequest) { requests.add(termVectorsRequest); return this; @@ -138,13 +150,7 @@ public class MultiTermVectorsRequest extends ActionRequest @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - preference = in.readOptionalString(); - int size = in.readVInt(); - requests = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - requests.add(new TermVectorsRequest(in)); - } + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java index 8aac77d4f3d..a079a2f759d 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java @@ -23,7 +23,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -36,15 +36,11 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable /** * Represents a failure. */ - public static class Failure implements Streamable { - private String index; - private String type; - private String id; - private Exception cause; - - Failure() { - - } + public static class Failure implements Writeable { + private final String index; + private final String type; + private final String id; + private final Exception cause; public Failure(String index, String type, String id, Exception cause) { this.index = index; @@ -53,6 +49,13 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable this.cause = cause; } + public Failure(StreamInput in) throws IOException { + index = in.readString(); + type = in.readOptionalString(); + id = in.readString(); + cause = in.readException(); + } + /** * The index name of the action. */ @@ -84,20 +87,6 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable return this.cause; } - public static Failure readFailure(StreamInput in) throws IOException { - Failure failure = new Failure(); - failure.readFrom(in); - return failure; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - index = in.readString(); - type = in.readOptionalString(); - id = in.readString(); - cause = in.readException(); - } - @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(index); @@ -107,15 +96,20 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable } } - private MultiTermVectorsItemResponse[] responses; - - MultiTermVectorsResponse() { - } + private final MultiTermVectorsItemResponse[] responses; public MultiTermVectorsResponse(MultiTermVectorsItemResponse[] responses) { this.responses = responses; } + public MultiTermVectorsResponse(StreamInput in) throws IOException { + super(in); + responses = new MultiTermVectorsItemResponse[in.readVInt()]; + for (int i = 0; i < responses.length; i++) { + responses[i] = new MultiTermVectorsItemResponse(in); + } + } + public MultiTermVectorsItemResponse[] getResponses() { return this.responses; } @@ -157,11 +151,7 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - responses = new MultiTermVectorsItemResponse[in.readVInt()]; - for (int i = 0; i < responses.length; i++) { - responses[i] = MultiTermVectorsItemResponse.readItemResponse(in); - } + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsShardResponse.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsShardResponse.java index d319e23cf51..4a4026a9fd6 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsShardResponse.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsShardResponse.java @@ -54,7 +54,7 @@ public class MultiTermVectorsShardResponse extends ActionResponse { responses.add(null); } if (in.readBoolean()) { - failures.add(MultiTermVectorsResponse.Failure.readFailure(in)); + failures.add(new MultiTermVectorsResponse.Failure(in)); } else { failures.add(null); } diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsAction.java b/server/src/main/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsAction.java index d9a05403343..20514733aff 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsAction.java @@ -48,7 +48,7 @@ public class TransportMultiTermVectorsAction extends HandledTransportAction 0 ? RestStatus.CONFLICT : RestStatus.OK)); - assertThat(readResponse.shardsResultPerIndex.size(), equalTo(testPlan.result.getShardsResultPerIndex().size())); + assertThat(readResponse.getShardsResultPerIndex().size(), equalTo(testPlan.result.getShardsResultPerIndex().size())); for (Map.Entry> entry : readResponse.getShardsResultPerIndex().entrySet()) { List originalShardsResults = testPlan.result.getShardsResultPerIndex().get(entry.getKey()); assertNotNull(originalShardsResults); diff --git a/server/src/test/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequestTests.java b/server/src/test/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequestTests.java index dbab3104d44..18c09e75b35 100644 --- a/server/src/test/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequestTests.java @@ -21,15 +21,16 @@ package org.elasticsearch.action.fieldcaps; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.util.ArrayUtils; -import org.elasticsearch.test.AbstractStreamableTestCase; +import org.elasticsearch.test.AbstractWireSerializingTestCase; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -public class FieldCapabilitiesRequestTests extends AbstractStreamableTestCase { +public class FieldCapabilitiesRequestTests extends AbstractWireSerializingTestCase { @Override protected FieldCapabilitiesRequest createTestInstance() { @@ -55,8 +56,8 @@ public class FieldCapabilitiesRequestTests extends AbstractStreamableTestCase instanceReader() { + return FieldCapabilitiesRequest::new; } @Override diff --git a/server/src/test/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponseTests.java b/server/src/test/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponseTests.java index e75dede451b..0c329bee819 100644 --- a/server/src/test/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponseTests.java @@ -19,7 +19,8 @@ package org.elasticsearch.action.fieldcaps; -import org.elasticsearch.test.AbstractStreamableTestCase; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractWireSerializingTestCase; import java.util.ArrayList; import java.util.Collections; @@ -29,12 +30,7 @@ import java.util.Map; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiLettersOfLength; - -public class FieldCapabilitiesResponseTests extends AbstractStreamableTestCase { - @Override - protected FieldCapabilitiesResponse createBlankInstance() { - return new FieldCapabilitiesResponse(); - } +public class FieldCapabilitiesResponseTests extends AbstractWireSerializingTestCase { @Override protected FieldCapabilitiesResponse createTestInstance() { @@ -47,6 +43,11 @@ public class FieldCapabilitiesResponseTests extends AbstractStreamableTestCase instanceReader() { + return FieldCapabilitiesResponse::new; + } + private FieldCapabilitiesIndexResponse createRandomIndexResponse() { Map responses = new HashMap<>(); diff --git a/server/src/test/java/org/elasticsearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java b/server/src/test/java/org/elasticsearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java index 45097af07ea..656dd5458e8 100644 --- a/server/src/test/java/org/elasticsearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/fieldcaps/MergedFieldCapabilitiesResponseTests.java @@ -20,12 +20,13 @@ package org.elasticsearch.action.fieldcaps; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.test.AbstractSerializingTestCase; import java.io.IOException; import java.util.Collections; @@ -33,18 +34,13 @@ import java.util.HashMap; import java.util.Map; import java.util.function.Predicate; -public class MergedFieldCapabilitiesResponseTests extends AbstractStreamableXContentTestCase { +public class MergedFieldCapabilitiesResponseTests extends AbstractSerializingTestCase { @Override protected FieldCapabilitiesResponse doParseInstance(XContentParser parser) throws IOException { return FieldCapabilitiesResponse.fromXContent(parser); } - @Override - protected FieldCapabilitiesResponse createBlankInstance() { - return new FieldCapabilitiesResponse(); - } - @Override protected FieldCapabilitiesResponse createTestInstance() { // merged responses @@ -71,6 +67,11 @@ public class MergedFieldCapabilitiesResponseTests extends AbstractStreamableXCon return new FieldCapabilitiesResponse(indices, responses); } + @Override + protected Writeable.Reader instanceReader() { + return FieldCapabilitiesResponse::new; + } + @Override protected FieldCapabilitiesResponse mutateInstance(FieldCapabilitiesResponse response) { Map> mutatedResponses = new HashMap<>(response.get());