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.
This commit is contained in:
Julie Tibshirani 2019-07-17 19:04:21 -07:00 committed by GitHub
parent 2a2686e6e7
commit 34c6067018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 202 additions and 212 deletions

View File

@ -22,7 +22,7 @@ import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse; 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.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.client.node.NodeClient; 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.ingest.common.IngestCommonPlugin.GROK_PATTERNS;
import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.GET;
public class GrokProcessorGetAction extends StreamableResponseActionType<GrokProcessorGetAction.Response> { public class GrokProcessorGetAction extends ActionType<GrokProcessorGetAction.Response> {
static final GrokProcessorGetAction INSTANCE = new GrokProcessorGetAction(); static final GrokProcessorGetAction INSTANCE = new GrokProcessorGetAction();
static final String NAME = "cluster:admin/ingest/processor/grok/get"; static final String NAME = "cluster:admin/ingest/processor/grok/get";
private GrokProcessorGetAction() { private GrokProcessorGetAction() {
super(NAME); super(NAME, Response::new);
}
@Override
public Response newResponse() {
return new Response(null);
} }
public static class Request extends ActionRequest { public static class Request extends ActionRequest {
@ -64,15 +59,26 @@ public class GrokProcessorGetAction extends StreamableResponseActionType<GrokPro
public ActionRequestValidationException validate() { public ActionRequestValidationException validate() {
return null; return null;
} }
Request() {}
Request(StreamInput in) throws IOException {
super(in);
}
} }
public static class Response extends ActionResponse implements ToXContentObject { public static class Response extends ActionResponse implements ToXContentObject {
private Map<String, String> grokPatterns; private final Map<String, String> grokPatterns;
Response(Map<String, String> grokPatterns) { Response(Map<String, String> grokPatterns) {
this.grokPatterns = grokPatterns; this.grokPatterns = grokPatterns;
} }
Response(StreamInput in) throws IOException {
super(in);
grokPatterns = in.readMap(StreamInput::readString, StreamInput::readString);
}
public Map<String, String> getGrokPatterns() { public Map<String, String> getGrokPatterns() {
return grokPatterns; return grokPatterns;
} }
@ -87,9 +93,8 @@ public class GrokProcessorGetAction extends StreamableResponseActionType<GrokPro
} }
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
grokPatterns = in.readMap(StreamInput::readString, StreamInput::readString);
} }
@Override @Override
@ -102,7 +107,7 @@ public class GrokProcessorGetAction extends StreamableResponseActionType<GrokPro
@Inject @Inject
public TransportAction(TransportService transportService, ActionFilters actionFilters) { public TransportAction(TransportService transportService, ActionFilters actionFilters) {
super(NAME, transportService, Request::new, actionFilters); super(NAME, transportService, actionFilters, Request::new);
} }
@Override @Override

View File

@ -34,7 +34,6 @@ import java.util.Map;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.IsNull.nullValue; import static org.hamcrest.core.IsNull.nullValue;
public class GrokProcessorGetActionTests extends ESTestCase { public class GrokProcessorGetActionTests extends ESTestCase {
private static final Map<String, String> TEST_PATTERNS = Collections.singletonMap("PATTERN", "foo"); private static final Map<String, String> TEST_PATTERNS = Collections.singletonMap("PATTERN", "foo");
@ -53,8 +52,7 @@ public class GrokProcessorGetActionTests extends ESTestCase {
BytesStreamOutput out = new BytesStreamOutput(); BytesStreamOutput out = new BytesStreamOutput();
response.writeTo(out); response.writeTo(out);
StreamInput streamInput = out.bytes().streamInput(); StreamInput streamInput = out.bytes().streamInput();
GrokProcessorGetAction.Response otherResponse = new GrokProcessorGetAction.Response(null); GrokProcessorGetAction.Response otherResponse = new GrokProcessorGetAction.Response(streamInput);
otherResponse.readFrom(streamInput);
assertThat(response.getGrokPatterns(), equalTo(TEST_PATTERNS)); assertThat(response.getGrokPatterns(), equalTo(TEST_PATTERNS));
assertThat(response.getGrokPatterns(), equalTo(otherResponse.getGrokPatterns())); assertThat(response.getGrokPatterns(), equalTo(otherResponse.getGrokPatterns()));
} }

View File

@ -47,6 +47,14 @@ public class MultiSearchTemplateRequest extends ActionRequest implements Composi
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled(); 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 * 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. * same order as the search requests.
@ -116,10 +124,8 @@ public class MultiSearchTemplateRequest extends ActionRequest implements Composi
} }
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
maxConcurrentSearchRequests = in.readVInt();
requests = in.readStreamableList(SearchTemplateRequest::new);
} }
@Override @Override

View File

@ -54,13 +54,25 @@ public class SearchTemplateRequest extends ActionRequest implements CompositeInd
private String script; private String script;
private Map<String, Object> scriptParams; private Map<String, Object> scriptParams;
public SearchTemplateRequest() { public SearchTemplateRequest() {}
}
public SearchTemplateRequest(SearchRequest searchRequest) { public SearchTemplateRequest(SearchRequest searchRequest) {
this.request = 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) { public void setRequest(SearchRequest request) {
this.request = request; this.request = request;
} }
@ -218,17 +230,8 @@ public class SearchTemplateRequest extends ActionRequest implements CompositeInd
} }
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
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();
}
} }
@Override @Override

View File

@ -46,7 +46,7 @@ public class TransportMultiSearchTemplateAction extends HandledTransportAction<M
@Inject @Inject
public TransportMultiSearchTemplateAction(TransportService transportService, ActionFilters actionFilters, ScriptService scriptService, public TransportMultiSearchTemplateAction(TransportService transportService, ActionFilters actionFilters, ScriptService scriptService,
NamedXContentRegistry xContentRegistry, NodeClient client) { NamedXContentRegistry xContentRegistry, NodeClient client) {
super(MultiSearchTemplateAction.NAME, transportService, MultiSearchTemplateRequest::new, actionFilters); super(MultiSearchTemplateAction.NAME, transportService, actionFilters, MultiSearchTemplateRequest::new);
this.scriptService = scriptService; this.scriptService = scriptService;
this.xContentRegistry = xContentRegistry; this.xContentRegistry = xContentRegistry;
this.client = client; this.client = client;

View File

@ -54,7 +54,7 @@ public class TransportSearchTemplateAction extends HandledTransportAction<Search
@Inject @Inject
public TransportSearchTemplateAction(TransportService transportService, ActionFilters actionFilters, public TransportSearchTemplateAction(TransportService transportService, ActionFilters actionFilters,
ScriptService scriptService, NamedXContentRegistry xContentRegistry, NodeClient client) { ScriptService scriptService, NamedXContentRegistry xContentRegistry, NodeClient client) {
super(SearchTemplateAction.NAME, transportService, SearchTemplateRequest::new, actionFilters); super(SearchTemplateAction.NAME, transportService, actionFilters, SearchTemplateRequest::new);
this.scriptService = scriptService; this.scriptService = scriptService;
this.xContentRegistry = xContentRegistry; this.xContentRegistry = xContentRegistry;
this.client = client; this.client = client;

View File

@ -19,10 +19,11 @@
package org.elasticsearch.script.mustache; package org.elasticsearch.script.mustache;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.RandomSearchRequestGenerator; import org.elasticsearch.search.RandomSearchRequestGenerator;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.test.AbstractWireSerializingTestCase;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -31,18 +32,18 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
public class SearchTemplateRequestTests extends AbstractStreamableTestCase<SearchTemplateRequest> { public class SearchTemplateRequestTests extends AbstractWireSerializingTestCase<SearchTemplateRequest> {
@Override
protected SearchTemplateRequest createBlankInstance() {
return new SearchTemplateRequest();
}
@Override @Override
protected SearchTemplateRequest createTestInstance() { protected SearchTemplateRequest createTestInstance() {
return createRandomRequest(); return createRandomRequest();
} }
@Override
protected Writeable.Reader<SearchTemplateRequest> instanceReader() {
return SearchTemplateRequest::new;
}
@Override @Override
protected SearchTemplateRequest mutateInstance(SearchTemplateRequest instance) throws IOException { protected SearchTemplateRequest mutateInstance(SearchTemplateRequest instance) throws IOException {
List<Consumer<SearchTemplateRequest>> mutators = new ArrayList<>(); List<Consumer<SearchTemplateRequest>> mutators = new ArrayList<>();

View File

@ -19,20 +19,15 @@
package org.elasticsearch.action.admin.indices.flush; package org.elasticsearch.action.admin.indices.flush;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
public class SyncedFlushAction extends StreamableResponseActionType<SyncedFlushResponse> { public class SyncedFlushAction extends ActionType<SyncedFlushResponse> {
public static final SyncedFlushAction INSTANCE = new SyncedFlushAction(); public static final SyncedFlushAction INSTANCE = new SyncedFlushAction();
public static final String NAME = "indices:admin/synced_flush"; public static final String NAME = "indices:admin/synced_flush";
private SyncedFlushAction() { private SyncedFlushAction() {
super(NAME); super(NAME, SyncedFlushResponse::new);
}
@Override
public SyncedFlushResponse newResponse() {
return new SyncedFlushResponse();
} }
} }

View File

@ -22,7 +22,7 @@ import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; 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.util.iterable.Iterables;
import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -44,12 +44,8 @@ import static java.util.Collections.unmodifiableMap;
*/ */
public class SyncedFlushResponse extends ActionResponse implements ToXContentFragment { public class SyncedFlushResponse extends ActionResponse implements ToXContentFragment {
Map<String, List<ShardsSyncedFlushResult>> shardsResultPerIndex; private final Map<String, List<ShardsSyncedFlushResult>> shardsResultPerIndex;
ShardCounts shardCounts; private final ShardCounts shardCounts;
SyncedFlushResponse() {
}
public SyncedFlushResponse(Map<String, List<ShardsSyncedFlushResult>> shardsResultPerIndex) { public SyncedFlushResponse(Map<String, List<ShardsSyncedFlushResult>> shardsResultPerIndex) {
// shardsResultPerIndex is never modified after it is passed to this // 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())); this.shardCounts = calculateShardCounts(Iterables.flatten(shardsResultPerIndex.values()));
} }
public SyncedFlushResponse(StreamInput in) throws IOException {
super(in);
shardCounts = new ShardCounts(in);
Map<String, List<ShardsSyncedFlushResult>> tmpShardsResultPerIndex = new HashMap<>();
int numShardsResults = in.readInt();
for (int i =0 ; i< numShardsResults; i++) {
String index = in.readString();
List<ShardsSyncedFlushResult> 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 * 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); return new ShardCounts(total, successful, failed);
} }
static final class ShardCounts implements ToXContentFragment, Streamable { static final class ShardCounts implements ToXContentFragment, Writeable {
public int total; public final int total;
public int successful; public final int successful;
public int failed; public final int failed;
ShardCounts(int total, int successful, int failed) { ShardCounts(int total, int successful, int failed) {
this.total = total; this.total = total;
@ -152,8 +165,10 @@ public class SyncedFlushResponse extends ActionResponse implements ToXContentFra
this.failed = failed; this.failed = failed;
} }
ShardCounts() { ShardCounts(StreamInput in) throws IOException {
total = in.readInt();
successful = in.readInt();
failed = in.readInt();
} }
@Override @Override
@ -164,13 +179,6 @@ public class SyncedFlushResponse extends ActionResponse implements ToXContentFra
return builder; return builder;
} }
@Override
public void readFrom(StreamInput in) throws IOException {
total = in.readInt();
successful = in.readInt();
failed = in.readInt();
}
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
out.writeInt(total); out.writeInt(total);
@ -192,21 +200,7 @@ public class SyncedFlushResponse extends ActionResponse implements ToXContentFra
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
shardCounts = new ShardCounts();
shardCounts.readFrom(in);
Map<String, List<ShardsSyncedFlushResult>> tmpShardsResultPerIndex = new HashMap<>();
int numShardsResults = in.readInt();
for (int i =0 ; i< numShardsResults; i++) {
String index = in.readString();
List<ShardsSyncedFlushResult> 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);
} }
@Override @Override

View File

@ -19,19 +19,15 @@
package org.elasticsearch.action.fieldcaps; package org.elasticsearch.action.fieldcaps;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
public class FieldCapabilitiesAction extends StreamableResponseActionType<FieldCapabilitiesResponse> { public class FieldCapabilitiesAction extends ActionType<FieldCapabilitiesResponse> {
public static final FieldCapabilitiesAction INSTANCE = new FieldCapabilitiesAction(); public static final FieldCapabilitiesAction INSTANCE = new FieldCapabilitiesAction();
public static final String NAME = "indices:data/read/field_caps"; public static final String NAME = "indices:data/read/field_caps";
private FieldCapabilitiesAction() { private FieldCapabilitiesAction() {
super(NAME); super(NAME, FieldCapabilitiesResponse::new);
} }
@Override
public FieldCapabilitiesResponse newResponse() {
return new FieldCapabilitiesResponse();
}
} }

View File

@ -56,6 +56,19 @@ public final class FieldCapabilitiesRequest extends ActionRequest implements Ind
PARSER.declareStringArray(fromList(String.class, FieldCapabilitiesRequest::fields), FIELDS_FIELD); 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() {} public FieldCapabilitiesRequest() {}
/** /**
@ -78,17 +91,8 @@ public final class FieldCapabilitiesRequest extends ActionRequest implements Ind
} }
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
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;
}
} }
@Override @Override

View File

@ -48,9 +48,9 @@ public class FieldCapabilitiesResponse extends ActionResponse implements ToXCont
private static final ParseField INDICES_FIELD = new ParseField("indices"); private static final ParseField INDICES_FIELD = new ParseField("indices");
private static final ParseField FIELDS_FIELD = new ParseField("fields"); private static final ParseField FIELDS_FIELD = new ParseField("fields");
private String[] indices; private final String[] indices;
private Map<String, Map<String, FieldCapabilities>> responseMap; private final Map<String, Map<String, FieldCapabilities>> responseMap;
private List<FieldCapabilitiesIndexResponse> indexResponses; private final List<FieldCapabilitiesIndexResponse> indexResponses;
FieldCapabilitiesResponse(String[] indices, Map<String, Map<String, FieldCapabilities>> responseMap) { FieldCapabilitiesResponse(String[] indices, Map<String, Map<String, FieldCapabilities>> responseMap) {
this(indices, responseMap, Collections.emptyList()); this(indices, responseMap, Collections.emptyList());
@ -67,6 +67,17 @@ public class FieldCapabilitiesResponse extends ActionResponse implements ToXCont
this.indices = indices; 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 * Used for serialization
*/ */
@ -106,15 +117,8 @@ public class FieldCapabilitiesResponse extends ActionResponse implements ToXCont
} }
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
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);
} }
private static Map<String, FieldCapabilities> readField(StreamInput in) throws IOException { private static Map<String, FieldCapabilities> readField(StreamInput in) throws IOException {

View File

@ -57,7 +57,7 @@ public class TransportFieldCapabilitiesAction extends HandledTransportAction<Fie
ClusterService clusterService, ThreadPool threadPool, ClusterService clusterService, ThreadPool threadPool,
TransportFieldCapabilitiesIndexAction shardAction, TransportFieldCapabilitiesIndexAction shardAction,
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
super(FieldCapabilitiesAction.NAME, transportService, FieldCapabilitiesRequest::new, actionFilters); super(FieldCapabilitiesAction.NAME, transportService, actionFilters, FieldCapabilitiesRequest::new);
this.threadPool = threadPool; this.threadPool = threadPool;
this.clusterService = clusterService; this.clusterService = clusterService;
this.remoteClusterService = transportService.getRemoteClusterService(); this.remoteClusterService = transportService.getRemoteClusterService();

View File

@ -84,7 +84,7 @@ public class BroadcastRequest<Request extends BroadcastRequest<Request>> extends
} }
@Override @Override
public final void readFrom(StreamInput in) throws IOException { public final void readFrom(StreamInput in) {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable " + getClass().getName()); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
} }
} }

View File

@ -19,19 +19,14 @@
package org.elasticsearch.action.termvectors; package org.elasticsearch.action.termvectors;
import org.elasticsearch.action.StreamableResponseActionType; import org.elasticsearch.action.ActionType;
public class MultiTermVectorsAction extends StreamableResponseActionType<MultiTermVectorsResponse> { public class MultiTermVectorsAction extends ActionType<MultiTermVectorsResponse> {
public static final MultiTermVectorsAction INSTANCE = new MultiTermVectorsAction(); public static final MultiTermVectorsAction INSTANCE = new MultiTermVectorsAction();
public static final String NAME = "indices:data/read/mtv"; public static final String NAME = "indices:data/read/mtv";
private MultiTermVectorsAction() { private MultiTermVectorsAction() {
super(NAME); super(NAME, MultiTermVectorsResponse::new);
}
@Override
public MultiTermVectorsResponse newResponse() {
return new MultiTermVectorsResponse();
} }
} }

View File

@ -21,21 +21,17 @@ package org.elasticsearch.action.termvectors;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; 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; import java.io.IOException;
/** /**
* A single multi get response. * A single multi get response.
*/ */
public class MultiTermVectorsItemResponse implements Streamable { public class MultiTermVectorsItemResponse implements Writeable {
private TermVectorsResponse response; private final TermVectorsResponse response;
private MultiTermVectorsResponse.Failure failure; private final MultiTermVectorsResponse.Failure failure;
MultiTermVectorsItemResponse() {
}
public MultiTermVectorsItemResponse(TermVectorsResponse response, MultiTermVectorsResponse.Failure failure) { public MultiTermVectorsItemResponse(TermVectorsResponse response, MultiTermVectorsResponse.Failure failure) {
assert (((response == null) && (failure != null)) || ((response != null) && (failure == null))); assert (((response == null) && (failure != null)) || ((response != null) && (failure == null)));
@ -43,6 +39,16 @@ public class MultiTermVectorsItemResponse implements Streamable {
this.failure = failure; 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. * The index name of the document.
*/ */
@ -94,21 +100,6 @@ public class MultiTermVectorsItemResponse implements Streamable {
return this.failure; 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 @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
if (failure != null) { if (failure != null) {

View File

@ -47,6 +47,18 @@ public class MultiTermVectorsRequest extends ActionRequest
final Set<String> ids = new HashSet<>(); final Set<String> 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) { public MultiTermVectorsRequest add(TermVectorsRequest termVectorsRequest) {
requests.add(termVectorsRequest); requests.add(termVectorsRequest);
return this; return this;
@ -138,13 +150,7 @@ public class MultiTermVectorsRequest extends ActionRequest
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
preference = in.readOptionalString();
int size = in.readVInt();
requests = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
requests.add(new TermVectorsRequest(in));
}
} }
@Override @Override

View File

@ -23,7 +23,7 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; 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.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -36,15 +36,11 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable
/** /**
* Represents a failure. * Represents a failure.
*/ */
public static class Failure implements Streamable { public static class Failure implements Writeable {
private String index; private final String index;
private String type; private final String type;
private String id; private final String id;
private Exception cause; private final Exception cause;
Failure() {
}
public Failure(String index, String type, String id, Exception cause) { public Failure(String index, String type, String id, Exception cause) {
this.index = index; this.index = index;
@ -53,6 +49,13 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable
this.cause = cause; 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. * The index name of the action.
*/ */
@ -84,20 +87,6 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable
return this.cause; 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 @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
out.writeString(index); out.writeString(index);
@ -107,15 +96,20 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable
} }
} }
private MultiTermVectorsItemResponse[] responses; private final MultiTermVectorsItemResponse[] responses;
MultiTermVectorsResponse() {
}
public MultiTermVectorsResponse(MultiTermVectorsItemResponse[] responses) { public MultiTermVectorsResponse(MultiTermVectorsItemResponse[] responses) {
this.responses = 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() { public MultiTermVectorsItemResponse[] getResponses() {
return this.responses; return this.responses;
} }
@ -157,11 +151,7 @@ public class MultiTermVectorsResponse extends ActionResponse implements Iterable
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
responses = new MultiTermVectorsItemResponse[in.readVInt()];
for (int i = 0; i < responses.length; i++) {
responses[i] = MultiTermVectorsItemResponse.readItemResponse(in);
}
} }
@Override @Override

View File

@ -54,7 +54,7 @@ public class MultiTermVectorsShardResponse extends ActionResponse {
responses.add(null); responses.add(null);
} }
if (in.readBoolean()) { if (in.readBoolean()) {
failures.add(MultiTermVectorsResponse.Failure.readFailure(in)); failures.add(new MultiTermVectorsResponse.Failure(in));
} else { } else {
failures.add(null); failures.add(null);
} }

View File

@ -48,7 +48,7 @@ public class TransportMultiTermVectorsAction extends HandledTransportAction<Mult
public TransportMultiTermVectorsAction(TransportService transportService, ClusterService clusterService, public TransportMultiTermVectorsAction(TransportService transportService, ClusterService clusterService,
TransportShardMultiTermsVectorAction shardAction, ActionFilters actionFilters, TransportShardMultiTermsVectorAction shardAction, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver) { IndexNameExpressionResolver indexNameExpressionResolver) {
super(MultiTermVectorsAction.NAME, transportService, MultiTermVectorsRequest::new, actionFilters); super(MultiTermVectorsAction.NAME, transportService, actionFilters, MultiTermVectorsRequest::new);
this.clusterService = clusterService; this.clusterService = clusterService;
this.shardAction = shardAction; this.shardAction = shardAction;
this.indexNameExpressionResolver = indexNameExpressionResolver; this.indexNameExpressionResolver = indexNameExpressionResolver;

View File

@ -85,13 +85,12 @@ public class SyncedFlushUnitTests extends ESTestCase {
BytesStreamOutput out = new BytesStreamOutput(); BytesStreamOutput out = new BytesStreamOutput();
testPlan.result.writeTo(out); testPlan.result.writeTo(out);
StreamInput in = out.bytes().streamInput(); StreamInput in = out.bytes().streamInput();
SyncedFlushResponse readResponse = new SyncedFlushResponse(); SyncedFlushResponse readResponse = new SyncedFlushResponse(in);
readResponse.readFrom(in);
assertThat(readResponse.totalShards(), equalTo(testPlan.totalCounts.total)); assertThat(readResponse.totalShards(), equalTo(testPlan.totalCounts.total));
assertThat(readResponse.successfulShards(), equalTo(testPlan.totalCounts.successful)); assertThat(readResponse.successfulShards(), equalTo(testPlan.totalCounts.successful));
assertThat(readResponse.failedShards(), equalTo(testPlan.totalCounts.failed)); assertThat(readResponse.failedShards(), equalTo(testPlan.totalCounts.failed));
assertThat(readResponse.restStatus(), equalTo(testPlan.totalCounts.failed > 0 ? RestStatus.CONFLICT : RestStatus.OK)); assertThat(readResponse.restStatus(), equalTo(testPlan.totalCounts.failed > 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<String, List<ShardsSyncedFlushResult>> entry : readResponse.getShardsResultPerIndex().entrySet()) { for (Map.Entry<String, List<ShardsSyncedFlushResult>> entry : readResponse.getShardsResultPerIndex().entrySet()) {
List<ShardsSyncedFlushResult> originalShardsResults = testPlan.result.getShardsResultPerIndex().get(entry.getKey()); List<ShardsSyncedFlushResult> originalShardsResults = testPlan.result.getShardsResultPerIndex().get(entry.getKey());
assertNotNull(originalShardsResults); assertNotNull(originalShardsResults);

View File

@ -21,15 +21,16 @@ package org.elasticsearch.action.fieldcaps;
import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.util.ArrayUtils; import org.elasticsearch.common.util.ArrayUtils;
import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.test.AbstractWireSerializingTestCase;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
public class FieldCapabilitiesRequestTests extends AbstractStreamableTestCase<FieldCapabilitiesRequest> { public class FieldCapabilitiesRequestTests extends AbstractWireSerializingTestCase<FieldCapabilitiesRequest> {
@Override @Override
protected FieldCapabilitiesRequest createTestInstance() { protected FieldCapabilitiesRequest createTestInstance() {
@ -55,8 +56,8 @@ public class FieldCapabilitiesRequestTests extends AbstractStreamableTestCase<Fi
} }
@Override @Override
protected FieldCapabilitiesRequest createBlankInstance() { protected Writeable.Reader<FieldCapabilitiesRequest> instanceReader() {
return new FieldCapabilitiesRequest(); return FieldCapabilitiesRequest::new;
} }
@Override @Override

View File

@ -19,7 +19,8 @@
package org.elasticsearch.action.fieldcaps; 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.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -29,12 +30,7 @@ import java.util.Map;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiLettersOfLength; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiLettersOfLength;
public class FieldCapabilitiesResponseTests extends AbstractWireSerializingTestCase<FieldCapabilitiesResponse> {
public class FieldCapabilitiesResponseTests extends AbstractStreamableTestCase<FieldCapabilitiesResponse> {
@Override
protected FieldCapabilitiesResponse createBlankInstance() {
return new FieldCapabilitiesResponse();
}
@Override @Override
protected FieldCapabilitiesResponse createTestInstance() { protected FieldCapabilitiesResponse createTestInstance() {
@ -47,6 +43,11 @@ public class FieldCapabilitiesResponseTests extends AbstractStreamableTestCase<F
return new FieldCapabilitiesResponse(responses); return new FieldCapabilitiesResponse(responses);
} }
@Override
protected Writeable.Reader<FieldCapabilitiesResponse> instanceReader() {
return FieldCapabilitiesResponse::new;
}
private FieldCapabilitiesIndexResponse createRandomIndexResponse() { private FieldCapabilitiesIndexResponse createRandomIndexResponse() {
Map<String, FieldCapabilities> responses = new HashMap<>(); Map<String, FieldCapabilities> responses = new HashMap<>();

View File

@ -20,12 +20,13 @@
package org.elasticsearch.action.fieldcaps; package org.elasticsearch.action.fieldcaps;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.AbstractStreamableXContentTestCase; import org.elasticsearch.test.AbstractSerializingTestCase;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
@ -33,18 +34,13 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;
public class MergedFieldCapabilitiesResponseTests extends AbstractStreamableXContentTestCase<FieldCapabilitiesResponse> { public class MergedFieldCapabilitiesResponseTests extends AbstractSerializingTestCase<FieldCapabilitiesResponse> {
@Override @Override
protected FieldCapabilitiesResponse doParseInstance(XContentParser parser) throws IOException { protected FieldCapabilitiesResponse doParseInstance(XContentParser parser) throws IOException {
return FieldCapabilitiesResponse.fromXContent(parser); return FieldCapabilitiesResponse.fromXContent(parser);
} }
@Override
protected FieldCapabilitiesResponse createBlankInstance() {
return new FieldCapabilitiesResponse();
}
@Override @Override
protected FieldCapabilitiesResponse createTestInstance() { protected FieldCapabilitiesResponse createTestInstance() {
// merged responses // merged responses
@ -71,6 +67,11 @@ public class MergedFieldCapabilitiesResponseTests extends AbstractStreamableXCon
return new FieldCapabilitiesResponse(indices, responses); return new FieldCapabilitiesResponse(indices, responses);
} }
@Override
protected Writeable.Reader<FieldCapabilitiesResponse> instanceReader() {
return FieldCapabilitiesResponse::new;
}
@Override @Override
protected FieldCapabilitiesResponse mutateInstance(FieldCapabilitiesResponse response) { protected FieldCapabilitiesResponse mutateInstance(FieldCapabilitiesResponse response) {
Map<String, Map<String, FieldCapabilities>> mutatedResponses = new HashMap<>(response.get()); Map<String, Map<String, FieldCapabilities>> mutatedResponses = new HashMap<>(response.get());