Skip to content

Commit

Permalink
Convert remaining request classes in xpack core to writeable.reader (e…
Browse files Browse the repository at this point in the history
…lastic#44524)

This commit converts all remaining classes extending ActionRequest
in xpack core to have a StreamInput constructor.

relates elastic#34389
  • Loading branch information
rjernst authored Jul 18, 2019
1 parent c9fa03d commit 29ee20d
Show file tree
Hide file tree
Showing 72 changed files with 332 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@

package org.elasticsearch.index.rankeval;

import org.elasticsearch.action.StreamableResponseActionType;
import org.elasticsearch.action.ActionType;

/**
* ActionType for explaining evaluating search ranking results.
*/
public class RankEvalAction extends StreamableResponseActionType<RankEvalResponse> {
public class RankEvalAction extends ActionType<RankEvalResponse> {

public static final RankEvalAction INSTANCE = new RankEvalAction();
public static final String NAME = "indices:data/read/rank_eval";

private RankEvalAction() {
super(NAME);
}

@Override
public RankEvalResponse newResponse() {
return new RankEvalResponse();
super(NAME, RankEvalResponse::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,22 @@ public RankEvalResponse(double metricScore, Map<String, EvalQueryQuality> partia
this.failures = new HashMap<>(failures);
}

RankEvalResponse() {
// only used in RankEvalAction#newResponse()
RankEvalResponse(StreamInput in) throws IOException {
super(in);
this.metricScore = in.readDouble();
int partialResultSize = in.readVInt();
this.details = new HashMap<>(partialResultSize);
for (int i = 0; i < partialResultSize; i++) {
String queryId = in.readString();
EvalQueryQuality partial = new EvalQueryQuality(in);
this.details.put(queryId, partial);
}
int failuresSize = in.readVInt();
this.failures = new HashMap<>(failuresSize);
for (int i = 0; i < failuresSize; i++) {
String queryId = in.readString();
this.failures.put(queryId, in.readException());
}
}

public double getMetricScore() {
Expand Down Expand Up @@ -99,21 +113,7 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
this.metricScore = in.readDouble();
int partialResultSize = in.readVInt();
this.details = new HashMap<>(partialResultSize);
for (int i = 0; i < partialResultSize; i++) {
String queryId = in.readString();
EvalQueryQuality partial = new EvalQueryQuality(in);
this.details.put(queryId, partial);
}
int failuresSize = in.readVInt();
this.failures = new HashMap<>(failuresSize);
for (int i = 0; i < failuresSize; i++) {
String queryId = in.readString();
this.failures.put(queryId, in.readException());
}
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public void testSerialization() throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
randomResponse.writeTo(output);
try (StreamInput in = output.bytes().streamInput()) {
RankEvalResponse deserializedResponse = new RankEvalResponse();
deserializedResponse.readFrom(in);
RankEvalResponse deserializedResponse = new RankEvalResponse(in);
assertEquals(randomResponse.getMetricScore(), deserializedResponse.getMetricScore(), Double.MIN_VALUE);
assertEquals(randomResponse.getPartialResults(), deserializedResponse.getPartialResults());
assertEquals(randomResponse.getFailures().keySet(), deserializedResponse.getFailures().keySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
*/
package org.elasticsearch.xpack.ccr.action.bulk;

import org.elasticsearch.action.StreamableResponseActionType;
import org.elasticsearch.action.ActionType;

public class BulkShardOperationsAction extends StreamableResponseActionType<BulkShardOperationsResponse> {
public class BulkShardOperationsAction extends ActionType<BulkShardOperationsResponse> {

public static final BulkShardOperationsAction INSTANCE = new BulkShardOperationsAction();
public static final String NAME = "indices:data/write/bulk_shard_operations[s]";

private BulkShardOperationsAction() {
super(NAME);
super(NAME, BulkShardOperationsResponse::new);
}

@Override
public BulkShardOperationsResponse newResponse() {
return new BulkShardOperationsResponse();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class PutCcrRestoreSessionAction extends ActionType<PutCcrRestoreSessionA
public static final String NAME = "internal:admin/ccr/restore/session/put";

private PutCcrRestoreSessionAction() {
super(NAME, PutCcrRestoreSessionAction.PutCcrRestoreSessionResponse::new);
super(NAME, PutCcrRestoreSessionResponse::new);
}

public static class TransportPutCcrRestoreSessionAction
Expand Down Expand Up @@ -90,9 +90,6 @@ public static class PutCcrRestoreSessionResponse extends ActionResponse {
private Store.MetadataSnapshot storeFileMetaData;
private long mappingVersion;

PutCcrRestoreSessionResponse() {
}

PutCcrRestoreSessionResponse(DiscoveryNode node, Store.MetadataSnapshot storeFileMetaData, long mappingVersion) {
this.node = node;
this.storeFileMetaData = storeFileMetaData;
Expand All @@ -108,10 +105,7 @@ public static class PutCcrRestoreSessionResponse extends ActionResponse {

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
node = new DiscoveryNode(in);
storeFileMetaData = new Store.MetadataSnapshot(in);
mappingVersion = in.readVLong();
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public XPackUsageFeatureTransportAction(String name, TransportService transportS
ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver) {
super(name, transportService, clusterService, threadPool,
actionFilters, indexNameExpressionResolver, XPackUsageRequest::new);
actionFilters, XPackUsageRequest::new, indexNameExpressionResolver);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public final class DeletePrivilegesRequest extends ActionRequest
private String[] privileges;
private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;

public DeletePrivilegesRequest(StreamInput in) throws IOException {
super(in);
application = in.readString();
privileges = in.readStringArray();
refreshPolicy = RefreshPolicy.readFrom(in);
}

public DeletePrivilegesRequest() {
this(null, Strings.EMPTY_ARRAY);
}
Expand Down Expand Up @@ -84,10 +91,7 @@ public void privileges(String[] privileges) {

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
application = in.readString();
privileges = in.readStringArray();
refreshPolicy = RefreshPolicy.readFrom(in);
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@

import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.common.io.stream.StreamInput;

import java.io.IOException;

/**
* Request to retrieve built-in (cluster/index) privileges.
*/
public final class GetBuiltinPrivilegesRequest extends ActionRequest {

public GetBuiltinPrivilegesRequest(StreamInput in) throws IOException {
super(in);
}

public GetBuiltinPrivilegesRequest() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public final class GetPrivilegesRequest extends ActionRequest implements Applica
private String application;
private String[] privileges;

public GetPrivilegesRequest(StreamInput in) throws IOException {
super(in);
application = in.readOptionalString();
privileges = in.readStringArray();
}

public GetPrivilegesRequest() {
privileges = Strings.EMPTY_ARRAY;
}
Expand Down Expand Up @@ -63,9 +69,7 @@ public String[] privileges() {

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
application = in.readOptionalString();
privileges = in.readStringArray();
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public final class PutPrivilegesRequest extends ActionRequest implements Applica
private List<ApplicationPrivilegeDescriptor> privileges;
private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;

public PutPrivilegesRequest(StreamInput in) throws IOException {
super(in);
privileges = Collections.unmodifiableList(in.readList(ApplicationPrivilegeDescriptor::new));
refreshPolicy = RefreshPolicy.readFrom(in);
}

public PutPrivilegesRequest() {
privileges = Collections.emptyList();
}
Expand Down Expand Up @@ -113,9 +119,7 @@ public String toString() {

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
privileges = Collections.unmodifiableList(in.readList(ApplicationPrivilegeDescriptor::new));
refreshPolicy = RefreshPolicy.readFrom(in);
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class DeleteRoleRequest extends ActionRequest implements WriteRequest<Del
private String name;
private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;

public DeleteRoleRequest(StreamInput in) throws IOException {
super(in);
name = in.readString();
refreshPolicy = RefreshPolicy.readFrom(in);
}

public DeleteRoleRequest() {
}

Expand Down Expand Up @@ -56,9 +62,7 @@ public String name() {

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
name = in.readString();
refreshPolicy = RefreshPolicy.readFrom(in);
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public class GetRolesRequest extends ActionRequest {

private String[] names = Strings.EMPTY_ARRAY;

public GetRolesRequest(StreamInput in) throws IOException {
super(in);
names = in.readStringArray();
}

public GetRolesRequest() {
}

Expand All @@ -44,8 +49,7 @@ public String[] names() {

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
names = in.readStringArray();
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ public class PutRoleRequest extends ActionRequest implements WriteRequest<PutRol
private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;
private Map<String, Object> metadata;

public PutRoleRequest(StreamInput in) throws IOException {
super(in);
name = in.readString();
clusterPrivileges = in.readStringArray();
int indicesSize = in.readVInt();
indicesPrivileges = new ArrayList<>(indicesSize);
for (int i = 0; i < indicesSize; i++) {
indicesPrivileges.add(new RoleDescriptor.IndicesPrivileges(in));
}
applicationPrivileges = in.readList(RoleDescriptor.ApplicationResourcePrivileges::new);
conditionalClusterPrivileges = ConditionalClusterPrivileges.readArray(in);
runAs = in.readStringArray();
refreshPolicy = RefreshPolicy.readFrom(in);
metadata = in.readMap();
}

public PutRoleRequest() {
}

Expand Down Expand Up @@ -159,19 +175,7 @@ public Map<String, Object> metadata() {

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
name = in.readString();
clusterPrivileges = in.readStringArray();
int indicesSize = in.readVInt();
indicesPrivileges = new ArrayList<>(indicesSize);
for (int i = 0; i < indicesSize; i++) {
indicesPrivileges.add(new RoleDescriptor.IndicesPrivileges(in));
}
applicationPrivileges = in.readList(RoleDescriptor.ApplicationResourcePrivileges::new);
conditionalClusterPrivileges = ConditionalClusterPrivileges.readArray(in);
runAs = in.readStringArray();
refreshPolicy = RefreshPolicy.readFrom(in);
metadata = in.readMap();
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class DeleteRoleMappingRequest extends ActionRequest implements WriteRequ
private String name;
private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE;

public DeleteRoleMappingRequest(StreamInput in) throws IOException {
super(in);
name = in.readString();
refreshPolicy = RefreshPolicy.readFrom(in);
}

public DeleteRoleMappingRequest() {
}

Expand Down Expand Up @@ -56,9 +62,7 @@ public String getName() {

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
name = in.readString();
refreshPolicy = RefreshPolicy.readFrom(in);
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class GetRoleMappingsRequest extends ActionRequest {

private String[] names = Strings.EMPTY_ARRAY;

public GetRoleMappingsRequest(StreamInput in) throws IOException {
super(in);
names = in.readStringArray();
}

public GetRoleMappingsRequest() {
}

Expand Down Expand Up @@ -55,8 +60,7 @@ public String[] getNames() {

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
names = in.readStringArray();
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
Expand Down
Loading

0 comments on commit 29ee20d

Please sign in to comment.