From 29ee20de3365b68a6705bcd017acfc880d7ee989 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 17 Jul 2019 18:01:05 -0700 Subject: [PATCH] Convert remaining request classes in xpack core to writeable.reader (#44524) This commit converts all remaining classes extending ActionRequest in xpack core to have a StreamInput constructor. relates #34389 --- .../index/rankeval/RankEvalAction.java | 11 +--- .../index/rankeval/RankEvalResponse.java | 34 +++++------ .../index/rankeval/RankEvalResponseTests.java | 3 +- .../bulk/BulkShardOperationsAction.java | 12 +--- .../PutCcrRestoreSessionAction.java | 10 +--- .../XPackUsageFeatureTransportAction.java | 2 +- .../privilege/DeletePrivilegesRequest.java | 12 ++-- .../GetBuiltinPrivilegesRequest.java | 7 +++ .../privilege/GetPrivilegesRequest.java | 10 +++- .../privilege/PutPrivilegesRequest.java | 10 +++- .../action/role/DeleteRoleRequest.java | 10 +++- .../security/action/role/GetRolesRequest.java | 8 ++- .../security/action/role/PutRoleRequest.java | 30 +++++----- .../rolemapping/DeleteRoleMappingRequest.java | 10 +++- .../rolemapping/GetRoleMappingsRequest.java | 8 ++- .../rolemapping/PutRoleMappingRequest.java | 24 ++++---- .../action/saml/SamlAuthenticateRequest.java | 10 +++- .../saml/SamlInvalidateSessionRequest.java | 7 +++ .../action/saml/SamlLogoutRequest.java | 7 +++ .../SamlPrepareAuthenticationRequest.java | 10 +++- .../action/token/CreateTokenRequest.java | 18 +++--- .../action/token/InvalidateTokenRequest.java | 16 ++++-- .../action/user/AuthenticateRequest.java | 8 ++- .../action/user/ChangePasswordRequest.java | 14 +++-- .../action/user/DeleteUserRequest.java | 10 +++- .../security/action/user/GetUsersRequest.java | 8 ++- .../action/user/HasPrivilegesRequest.java | 24 +++++--- .../security/action/user/PutUserRequest.java | 22 +++++--- .../action/user/SetEnabledRequest.java | 14 +++-- .../DeletePrivilegesRequestTests.java | 3 +- .../privilege/GetPrivilegesRequestTests.java | 3 +- .../privilege/PutPrivilegesRequestTests.java | 3 +- .../action/role/PutRoleRequestTests.java | 3 +- .../action/token/CreateTokenRequestTests.java | 3 +- .../user/HasPrivilegesRequestTests.java | 4 +- .../TransportDeletePrivilegesAction.java | 2 +- .../TransportGetBuiltinPrivilegesAction.java | 2 +- .../TransportGetPrivilegesAction.java | 2 +- .../TransportPutPrivilegesAction.java | 2 +- .../role/TransportDeleteRoleAction.java | 2 +- .../action/role/TransportGetRolesAction.java | 2 +- .../action/role/TransportPutRoleAction.java | 2 +- .../TransportDeleteRoleMappingAction.java | 2 +- .../TransportGetRoleMappingsAction.java | 2 +- .../TransportPutRoleMappingAction.java | 2 +- .../saml/TransportSamlAuthenticateAction.java | 2 +- .../TransportSamlInvalidateSessionAction.java | 2 +- .../saml/TransportSamlLogoutAction.java | 2 +- ...nsportSamlPrepareAuthenticationAction.java | 2 +- .../token/TransportCreateTokenAction.java | 2 +- .../token/TransportInvalidateTokenAction.java | 2 +- .../token/TransportRefreshTokenAction.java | 2 +- .../user/TransportAuthenticateAction.java | 2 +- .../user/TransportChangePasswordAction.java | 2 +- .../user/TransportDeleteUserAction.java | 2 +- .../action/user/TransportGetUsersAction.java | 2 +- .../user/TransportHasPrivilegesAction.java | 2 +- .../action/user/TransportPutUserAction.java | 2 +- .../user/TransportSetEnabledAction.java | 2 +- ...SamlPrepareAuthenticationRequestTests.java | 7 +-- .../sql/action/SqlClearCursorAction.java | 11 +--- .../sql/action/SqlClearCursorResponse.java | 7 ++- .../xpack/sql/action/SqlQueryAction.java | 11 +--- .../xpack/sql/action/SqlQueryResponse.java | 56 ++++++++++--------- .../xpack/sql/action/SqlTranslateAction.java | 11 +--- .../sql/action/SqlTranslateResponse.java | 6 +- .../action/SqlClearCursorResponseTests.java | 9 +-- .../sql/action/SqlQueryResponseTests.java | 17 +++--- .../sql/action/SqlTranslateResponseTests.java | 10 ++-- .../plugin/TransportSqlClearCursorAction.java | 3 +- .../sql/plugin/TransportSqlQueryAction.java | 3 +- .../plugin/TransportSqlTranslateAction.java | 3 +- 72 files changed, 332 insertions(+), 258 deletions(-) diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java index 07de8c8a22cad..68b0b414ee051 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalAction.java @@ -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 { +public class RankEvalAction extends ActionType { 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); } } diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResponse.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResponse.java index 60c2f474d7d5b..48bfaad51ae14 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResponse.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResponse.java @@ -61,8 +61,22 @@ public RankEvalResponse(double metricScore, Map 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() { @@ -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 diff --git a/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalResponseTests.java b/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalResponseTests.java index d92fc4504ffc8..649db936d4fbb 100644 --- a/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalResponseTests.java +++ b/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalResponseTests.java @@ -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()); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/bulk/BulkShardOperationsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/bulk/BulkShardOperationsAction.java index 02af69d9ac3ae..4da457bb8668a 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/bulk/BulkShardOperationsAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/bulk/BulkShardOperationsAction.java @@ -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 { +public class BulkShardOperationsAction extends ActionType { 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(); - } - } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/repositories/PutCcrRestoreSessionAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/repositories/PutCcrRestoreSessionAction.java index 96974542369ed..81dc927abb848 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/repositories/PutCcrRestoreSessionAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/repositories/PutCcrRestoreSessionAction.java @@ -36,7 +36,7 @@ public class PutCcrRestoreSessionAction extends ActionType 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(); } @@ -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 diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/DeleteRoleRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/DeleteRoleRequest.java index ff4d416e2002c..bd1c4bf4c46c7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/DeleteRoleRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/DeleteRoleRequest.java @@ -23,6 +23,12 @@ public class DeleteRoleRequest extends ActionRequest implements WriteRequest 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() { } @@ -159,19 +175,7 @@ public Map 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 diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/DeleteRoleMappingRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/DeleteRoleMappingRequest.java index 9d3e1758026ea..e2256042e3463 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/DeleteRoleMappingRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/DeleteRoleMappingRequest.java @@ -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() { } @@ -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 diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/GetRoleMappingsRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/GetRoleMappingsRequest.java index ff59aa8482d61..78ccc526cf80a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/GetRoleMappingsRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/GetRoleMappingsRequest.java @@ -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() { } @@ -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 diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingRequest.java index 43d005c5227a1..61cb21b5e350f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/rolemapping/PutRoleMappingRequest.java @@ -42,6 +42,19 @@ public class PutRoleMappingRequest extends ActionRequest private Map metadata = Collections.emptyMap(); private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE; + public PutRoleMappingRequest(StreamInput in) throws IOException { + super(in); + this.name = in.readString(); + this.enabled = in.readBoolean(); + this.roles = in.readStringList(); + if (in.getVersion().onOrAfter(Version.V_7_2_0)) { + this.roleTemplates = in.readList(TemplateRoleName::new); + } + this.rules = ExpressionParser.readExpression(in); + this.metadata = in.readMap(); + this.refreshPolicy = RefreshPolicy.readFrom(in); + } + public PutRoleMappingRequest() { } @@ -133,16 +146,7 @@ public Map getMetadata() { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - this.name = in.readString(); - this.enabled = in.readBoolean(); - this.roles = in.readStringList(); - if (in.getVersion().onOrAfter(Version.V_7_2_0)) { - this.roleTemplates = in.readList(TemplateRoleName::new); - } - this.rules = ExpressionParser.readExpression(in); - this.metadata = in.readMap(); - this.refreshPolicy = RefreshPolicy.readFrom(in); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateRequest.java index 0d6d0f44c7110..40fce11edbc08 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlAuthenticateRequest.java @@ -5,10 +5,12 @@ */ package org.elasticsearch.xpack.core.security.action.saml; -import java.util.List; - import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; +import java.util.List; /** * Represents a request to authenticate using SAML assertions. @@ -18,6 +20,10 @@ public final class SamlAuthenticateRequest extends ActionRequest { private byte[] saml; private List validRequestIds; + public SamlAuthenticateRequest(StreamInput in) throws IOException { + super(in); + } + public SamlAuthenticateRequest() { } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionRequest.java index b2b49db838f31..5d88e6e7dcac7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlInvalidateSessionRequest.java @@ -9,6 +9,9 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -25,6 +28,10 @@ public final class SamlInvalidateSessionRequest extends ActionRequest { private String queryString; + public SamlInvalidateSessionRequest(StreamInput in) throws IOException { + super(in); + } + public SamlInvalidateSessionRequest() { } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlLogoutRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlLogoutRequest.java index 45088fdd3d93a..0078cec9a7c87 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlLogoutRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlLogoutRequest.java @@ -9,6 +9,9 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -21,6 +24,10 @@ public final class SamlLogoutRequest extends ActionRequest { @Nullable private String refreshToken; + public SamlLogoutRequest(StreamInput in) throws IOException { + super(in); + } + public SamlLogoutRequest() { } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationRequest.java index bd1c59a48b42b..13a17752ddeb5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/saml/SamlPrepareAuthenticationRequest.java @@ -24,6 +24,12 @@ public final class SamlPrepareAuthenticationRequest extends ActionRequest { @Nullable private String assertionConsumerServiceURL; + public SamlPrepareAuthenticationRequest(StreamInput in) throws IOException { + super(in); + realmName = in.readOptionalString(); + assertionConsumerServiceURL = in.readOptionalString(); + } + public SamlPrepareAuthenticationRequest() { } @@ -58,9 +64,7 @@ public String toString() { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - realmName = in.readOptionalString(); - assertionConsumerServiceURL = in.readOptionalString(); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequest.java index aeae2d8590774..057401b5ebcc6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequest.java @@ -68,6 +68,16 @@ public static GrantType fromString(String grantType) { private String scope; private String refreshToken; + public CreateTokenRequest(StreamInput in) throws IOException { + super(in); + grantType = in.readString(); + username = in.readOptionalString(); + password = in.readOptionalSecureString(); + refreshToken = in.readOptionalString(); + scope = in.readOptionalString(); + kerberosTicket = in.readOptionalSecureString(); + } + public CreateTokenRequest() {} public CreateTokenRequest(String grantType, @Nullable String username, @Nullable SecureString password, @@ -215,13 +225,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - grantType = in.readString(); - username = in.readOptionalString(); - password = in.readOptionalSecureString(); - refreshToken = in.readOptionalString(); - scope = in.readOptionalString(); - kerberosTicket = in.readOptionalSecureString(); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/InvalidateTokenRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/InvalidateTokenRequest.java index 43348456d2306..c33c6c9d60681 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/InvalidateTokenRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/token/InvalidateTokenRequest.java @@ -52,6 +52,15 @@ public static Type fromString(String tokenType) { private String realmName; private String userName; + public InvalidateTokenRequest(StreamInput in) throws IOException { + super(in); + tokenString = in.readOptionalString(); + Integer type = in.readOptionalVInt(); + tokenType = type == null ? null : Type.values()[type]; + realmName = in.readOptionalString(); + userName = in.readOptionalString(); + } + public InvalidateTokenRequest() {} /** @@ -144,11 +153,6 @@ public void writeTo(StreamOutput out) throws IOException { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - tokenString = in.readOptionalString(); - Integer type = in.readOptionalVInt(); - tokenType = type == null ? null : Type.values()[type]; - realmName = in.readOptionalString(); - userName = in.readOptionalString(); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/AuthenticateRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/AuthenticateRequest.java index 1b1b5d8db6ca8..ccdf42d6c80b0 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/AuthenticateRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/AuthenticateRequest.java @@ -16,6 +16,11 @@ public class AuthenticateRequest extends ActionRequest implements UserRequest { private String username; + public AuthenticateRequest(StreamInput in) throws IOException { + super(in); + username = in.readString(); + } + public AuthenticateRequest() {} public AuthenticateRequest(String username) { @@ -43,8 +48,7 @@ public String[] usernames() { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - username = in.readString(); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/ChangePasswordRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/ChangePasswordRequest.java index b78b81c060080..d5b9cbc953cb3 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/ChangePasswordRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/ChangePasswordRequest.java @@ -28,6 +28,15 @@ public class ChangePasswordRequest extends ActionRequest private char[] passwordHash; private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE; + public ChangePasswordRequest() {} + + public ChangePasswordRequest(StreamInput in) throws IOException { + super(in); + username = in.readString(); + passwordHash = CharArrays.utf8BytesToChars(BytesReference.toBytes(in.readBytesReference())); + refreshPolicy = RefreshPolicy.readFrom(in); + } + @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; @@ -78,10 +87,7 @@ public String[] usernames() { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - username = in.readString(); - passwordHash = CharArrays.utf8BytesToChars(BytesReference.toBytes(in.readBytesReference())); - refreshPolicy = RefreshPolicy.readFrom(in); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/DeleteUserRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/DeleteUserRequest.java index 6587576b515b3..6046d6d878068 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/DeleteUserRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/DeleteUserRequest.java @@ -23,6 +23,12 @@ public class DeleteUserRequest extends ActionRequest implements UserRequest, Wri private String username; private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE; + public DeleteUserRequest(StreamInput in) throws IOException { + super(in); + username = in.readString(); + refreshPolicy = RefreshPolicy.readFrom(in); + } + public DeleteUserRequest() { } @@ -65,9 +71,7 @@ public String[] usernames() { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - username = in.readString(); - refreshPolicy = RefreshPolicy.readFrom(in); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUsersRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUsersRequest.java index 3ed0f798b371c..3a3d5b949c60f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUsersRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/GetUsersRequest.java @@ -22,6 +22,11 @@ public class GetUsersRequest extends ActionRequest implements UserRequest { private String[] usernames; + public GetUsersRequest(StreamInput in) throws IOException { + super(in); + usernames = in.readStringArray(); + } + public GetUsersRequest() { usernames = Strings.EMPTY_ARRAY; } @@ -46,8 +51,7 @@ public String[] usernames() { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - usernames = in.readStringArray(); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesRequest.java index 93ac7ff45dd66..9aee890e69e13 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesRequest.java @@ -27,6 +27,20 @@ public class HasPrivilegesRequest extends ActionRequest implements UserRequest { private RoleDescriptor.IndicesPrivileges[] indexPrivileges; private ApplicationResourcePrivileges[] applicationPrivileges; + public HasPrivilegesRequest() {} + + public HasPrivilegesRequest(StreamInput in) throws IOException { + super(in); + this.username = in.readString(); + this.clusterPrivileges = in.readStringArray(); + int indexSize = in.readVInt(); + indexPrivileges = new RoleDescriptor.IndicesPrivileges[indexSize]; + for (int i = 0; i < indexSize; i++) { + indexPrivileges[i] = new RoleDescriptor.IndicesPrivileges(in); + } + applicationPrivileges = in.readArray(ApplicationResourcePrivileges::new, ApplicationResourcePrivileges[]::new); + } + @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; @@ -100,15 +114,7 @@ public void applicationPrivileges(ApplicationResourcePrivileges... appPrivileges @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - this.username = in.readString(); - this.clusterPrivileges = in.readStringArray(); - int indexSize = in.readVInt(); - indexPrivileges = new RoleDescriptor.IndicesPrivileges[indexSize]; - for (int i = 0; i < indexSize; i++) { - indexPrivileges[i] = new RoleDescriptor.IndicesPrivileges(in); - } - applicationPrivileges = in.readArray(ApplicationResourcePrivileges::new, ApplicationResourcePrivileges[]::new); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserRequest.java index d09b168e9669b..d0bb99a46a21e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserRequest.java @@ -36,6 +36,18 @@ public class PutUserRequest extends ActionRequest implements UserRequest, WriteR private boolean enabled = true; private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE; + public PutUserRequest(StreamInput in) throws IOException { + super(in); + username = in.readString(); + passwordHash = readCharArrayFromStream(in); + roles = in.readStringArray(); + fullName = in.readOptionalString(); + email = in.readOptionalString(); + metadata = in.readBoolean() ? in.readMap() : null; + refreshPolicy = RefreshPolicy.readFrom(in); + enabled = in.readBoolean(); + } + public PutUserRequest() { } @@ -134,15 +146,7 @@ public String[] usernames() { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - username = in.readString(); - passwordHash = readCharArrayFromStream(in); - roles = in.readStringArray(); - fullName = in.readOptionalString(); - email = in.readOptionalString(); - metadata = in.readBoolean() ? in.readMap() : null; - refreshPolicy = RefreshPolicy.readFrom(in); - enabled = in.readBoolean(); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/SetEnabledRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/SetEnabledRequest.java index 664a46ae3e727..b352d1111b20f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/SetEnabledRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/SetEnabledRequest.java @@ -27,6 +27,15 @@ public class SetEnabledRequest extends ActionRequest implements UserRequest, Wri private String username; private RefreshPolicy refreshPolicy = RefreshPolicy.IMMEDIATE; + public SetEnabledRequest() {} + + public SetEnabledRequest(StreamInput in) throws IOException { + super(in); + this.enabled = in.readBoolean(); + this.username = in.readString(); + this.refreshPolicy = RefreshPolicy.readFrom(in); + } + @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; @@ -90,10 +99,7 @@ public SetEnabledRequest setRefreshPolicy(RefreshPolicy refreshPolicy) { @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - this.enabled = in.readBoolean(); - this.username = in.readString(); - this.refreshPolicy = RefreshPolicy.readFrom(in); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/DeletePrivilegesRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/DeletePrivilegesRequestTests.java index 03232181f930e..186f9dcfe0018 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/DeletePrivilegesRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/DeletePrivilegesRequestTests.java @@ -29,8 +29,7 @@ public void testSerialization() throws IOException { final BytesStreamOutput output = new BytesStreamOutput(); original.writeTo(output); output.flush(); - final DeletePrivilegesRequest copy = new DeletePrivilegesRequest(); - copy.readFrom(output.bytes().streamInput()); + final DeletePrivilegesRequest copy = new DeletePrivilegesRequest(output.bytes().streamInput()); assertThat(copy.application(), equalTo(original.application())); assertThat(copy.privileges(), equalTo(original.privileges())); assertThat(copy.getRefreshPolicy(), equalTo(original.getRefreshPolicy())); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/GetPrivilegesRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/GetPrivilegesRequestTests.java index db867f6775722..35a03d5882157 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/GetPrivilegesRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/GetPrivilegesRequestTests.java @@ -29,8 +29,7 @@ public void testSerialization() throws IOException { final BytesStreamOutput out = new BytesStreamOutput(); original.writeTo(out); - final GetPrivilegesRequest copy = new GetPrivilegesRequest(); - copy.readFrom(out.bytes().streamInput()); + final GetPrivilegesRequest copy = new GetPrivilegesRequest(out.bytes().streamInput()); assertThat(original.application(), Matchers.equalTo(copy.application())); assertThat(original.privileges(), Matchers.equalTo(copy.privileges())); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/PutPrivilegesRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/PutPrivilegesRequestTests.java index e1bdc7687e3e2..f67d62d3bf69b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/PutPrivilegesRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/privilege/PutPrivilegesRequestTests.java @@ -39,8 +39,7 @@ public void testSerialization() throws IOException { final BytesStreamOutput out = new BytesStreamOutput(); original.writeTo(out); - final PutPrivilegesRequest copy = new PutPrivilegesRequest(); - copy.readFrom(out.bytes().streamInput()); + final PutPrivilegesRequest copy = new PutPrivilegesRequest(out.bytes().streamInput()); assertThat(original.getPrivileges(), Matchers.equalTo(copy.getPrivileges())); assertThat(original.getRefreshPolicy(), Matchers.equalTo(copy.getRefreshPolicy())); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/role/PutRoleRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/role/PutRoleRequestTests.java index 7ca9f4da74ab3..742d8248bd10b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/role/PutRoleRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/role/PutRoleRequestTests.java @@ -63,11 +63,10 @@ public void testSerialization() throws IOException { } original.writeTo(out); - final PutRoleRequest copy = new PutRoleRequest(); final NamedWriteableRegistry registry = new NamedWriteableRegistry(new XPackClientPlugin(Settings.EMPTY).getNamedWriteables()); StreamInput in = new NamedWriteableAwareStreamInput(ByteBufferStreamInput.wrap(BytesReference.toBytes(out.bytes())), registry); in.setVersion(out.getVersion()); - copy.readFrom(in); + final PutRoleRequest copy = new PutRoleRequest(in); assertThat(copy.roleDescriptor(), equalTo(original.roleDescriptor())); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequestTests.java index 54681e97fc531..29611b1063de6 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/token/CreateTokenRequestTests.java @@ -126,8 +126,7 @@ public void testSerialization() throws IOException { try (BytesStreamOutput out = new BytesStreamOutput()) { request.writeTo(out); try (StreamInput in = out.bytes().streamInput()) { - final CreateTokenRequest serialized = new CreateTokenRequest(); - serialized.readFrom(in); + final CreateTokenRequest serialized = new CreateTokenRequest(in); assertEquals(grantType, serialized.getGrantType()); if (scope != null) { assertEquals(scope, serialized.getScope()); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesRequestTests.java index 6dd1d8a25f088..abf1505e38e2e 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/user/HasPrivilegesRequestTests.java @@ -75,10 +75,10 @@ private HasPrivilegesRequest serializeAndDeserialize(HasPrivilegesRequest origin out.setVersion(version); original.writeTo(out); - final HasPrivilegesRequest copy = new HasPrivilegesRequest(); + final StreamInput in = out.bytes().streamInput(); in.setVersion(version); - copy.readFrom(in); + final HasPrivilegesRequest copy = new HasPrivilegesRequest(in); assertThat(in.read(), equalTo(-1)); return copy; } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/privilege/TransportDeletePrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/privilege/TransportDeletePrivilegesAction.java index 57fbe5974f52a..502caf1c94be9 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/privilege/TransportDeletePrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/privilege/TransportDeletePrivilegesAction.java @@ -30,7 +30,7 @@ public class TransportDeletePrivilegesAction extends HandledTransportAction { +public class SqlClearCursorAction extends ActionType { public static final SqlClearCursorAction INSTANCE = new SqlClearCursorAction(); public static final String NAME = "indices:data/read/sql/close_cursor"; private SqlClearCursorAction() { - super(NAME); - } - - @Override - public SqlClearCursorResponse newResponse() { - return new SqlClearCursorResponse(); + super(NAME, SqlClearCursorResponse::new); } } diff --git a/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlClearCursorResponse.java b/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlClearCursorResponse.java index 1a677a713c8e2..3cdaf01b29b2f 100644 --- a/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlClearCursorResponse.java +++ b/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlClearCursorResponse.java @@ -30,7 +30,9 @@ public SqlClearCursorResponse(boolean succeeded) { this.succeeded = succeeded; } - SqlClearCursorResponse() { + SqlClearCursorResponse(StreamInput in) throws IOException { + super(in); + succeeded = in.readBoolean(); } /** @@ -60,8 +62,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - succeeded = in.readBoolean(); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlQueryAction.java b/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlQueryAction.java index 660d0ff19661b..cd1932d7fd18f 100644 --- a/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlQueryAction.java +++ b/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlQueryAction.java @@ -5,19 +5,14 @@ */ package org.elasticsearch.xpack.sql.action; -import org.elasticsearch.action.StreamableResponseActionType; +import org.elasticsearch.action.ActionType; -public class SqlQueryAction extends StreamableResponseActionType { +public class SqlQueryAction extends ActionType { public static final SqlQueryAction INSTANCE = new SqlQueryAction(); public static final String NAME = "indices:data/read/sql"; private SqlQueryAction() { - super(NAME); - } - - @Override - public SqlQueryResponse newResponse() { - return new SqlQueryResponse(); + super(NAME, SqlQueryResponse::new); } } diff --git a/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlQueryResponse.java b/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlQueryResponse.java index 5ba5ec3f232f5..95c79b10ff62b 100644 --- a/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlQueryResponse.java +++ b/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlQueryResponse.java @@ -40,7 +40,34 @@ public class SqlQueryResponse extends ActionResponse implements ToXContentObject private List> rows; private static final String INTERVAL_CLASS_NAME = "Interval"; - public SqlQueryResponse() { + public SqlQueryResponse(StreamInput in) throws IOException { + super(in); + cursor = in.readString(); + if (in.readBoolean()) { + // We might have rows without columns and we might have columns without rows + // So we send the column size twice, just to keep the protocol simple + int columnCount = in.readVInt(); + List columns = new ArrayList<>(columnCount); + for (int c = 0; c < columnCount; c++) { + columns.add(readColumnInfo(in)); + } + this.columns = unmodifiableList(columns); + } else { + this.columns = null; + } + int rowCount = in.readVInt(); + List> rows = new ArrayList<>(rowCount); + if (rowCount > 0) { + int columnCount = in.readVInt(); + for (int r = 0; r < rowCount; r++) { + List row = new ArrayList<>(columnCount); + for (int c = 0; c < columnCount; c++) { + row.add(in.readGenericValue()); + } + rows.add(unmodifiableList(row)); + } + } + this.rows = unmodifiableList(rows); } public SqlQueryResponse(String cursor, Mode mode, boolean columnar, @Nullable List columns, List> rows) { @@ -92,32 +119,7 @@ public SqlQueryResponse rows(List> rows) { @Override public void readFrom(StreamInput in) throws IOException { - cursor = in.readString(); - if (in.readBoolean()) { - // We might have rows without columns and we might have columns without rows - // So we send the column size twice, just to keep the protocol simple - int columnCount = in.readVInt(); - List columns = new ArrayList<>(columnCount); - for (int c = 0; c < columnCount; c++) { - columns.add(readColumnInfo(in)); - } - this.columns = unmodifiableList(columns); - } else { - this.columns = null; - } - int rowCount = in.readVInt(); - List> rows = new ArrayList<>(rowCount); - if (rowCount > 0) { - int columnCount = in.readVInt(); - for (int r = 0; r < rowCount; r++) { - List row = new ArrayList<>(columnCount); - for (int c = 0; c < columnCount; c++) { - row.add(in.readGenericValue()); - } - rows.add(unmodifiableList(row)); - } - } - this.rows = unmodifiableList(rows); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlTranslateAction.java b/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlTranslateAction.java index b858c7642d163..f12a1e58b9076 100644 --- a/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlTranslateAction.java +++ b/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlTranslateAction.java @@ -5,22 +5,17 @@ */ package org.elasticsearch.xpack.sql.action; -import org.elasticsearch.action.StreamableResponseActionType; +import org.elasticsearch.action.ActionType; /** * Sql action for translating SQL queries into ES requests */ -public class SqlTranslateAction extends StreamableResponseActionType { +public class SqlTranslateAction extends ActionType { public static final SqlTranslateAction INSTANCE = new SqlTranslateAction(); public static final String NAME = "indices:data/read/sql/translate"; private SqlTranslateAction() { - super(NAME); - } - - @Override - public SqlTranslateResponse newResponse() { - return new SqlTranslateResponse(); + super(NAME, SqlTranslateResponse::new); } } diff --git a/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlTranslateResponse.java b/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlTranslateResponse.java index e2efd4b46b674..478cef791be01 100644 --- a/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlTranslateResponse.java +++ b/x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlTranslateResponse.java @@ -21,7 +21,9 @@ public class SqlTranslateResponse extends ActionResponse implements ToXContentObject { private SearchSourceBuilder source; - public SqlTranslateResponse() { + public SqlTranslateResponse(StreamInput in) throws IOException { + super(in); + source = new SearchSourceBuilder(in); } public SqlTranslateResponse(SearchSourceBuilder source) { @@ -34,7 +36,7 @@ public SearchSourceBuilder source() { @Override public void readFrom(StreamInput in) throws IOException { - source = new SearchSourceBuilder(in); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorResponseTests.java b/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorResponseTests.java index 9e9f200abac52..1b4a71e097776 100644 --- a/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorResponseTests.java +++ b/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlClearCursorResponseTests.java @@ -5,10 +5,11 @@ */ package org.elasticsearch.xpack.sql.action; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.test.AbstractSerializingTestCase; -public class SqlClearCursorResponseTests extends AbstractStreamableXContentTestCase { +public class SqlClearCursorResponseTests extends AbstractSerializingTestCase { @Override protected SqlClearCursorResponse createTestInstance() { @@ -16,8 +17,8 @@ protected SqlClearCursorResponse createTestInstance() { } @Override - protected SqlClearCursorResponse createBlankInstance() { - return new SqlClearCursorResponse(); + protected Writeable.Reader instanceReader() { + return SqlClearCursorResponse::new; } @Override diff --git a/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlQueryResponseTests.java b/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlQueryResponseTests.java index 966e16e405731..7dd3f4aade637 100644 --- a/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlQueryResponseTests.java +++ b/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlQueryResponseTests.java @@ -7,11 +7,12 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.sql.proto.ColumnInfo; import org.elasticsearch.xpack.sql.proto.Mode; @@ -25,10 +26,10 @@ import java.util.function.Supplier; import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS; -import static org.hamcrest.Matchers.hasSize; import static org.elasticsearch.xpack.sql.action.AbstractSqlQueryRequest.CURSOR; +import static org.hamcrest.Matchers.hasSize; -public class SqlQueryResponseTests extends AbstractStreamableXContentTestCase { +public class SqlQueryResponseTests extends AbstractSerializingTestCase { static String randomStringCursor() { return randomBoolean() ? "" : randomAlphaOfLength(10); @@ -39,6 +40,11 @@ protected SqlQueryResponse createTestInstance() { return createRandomInstance(randomStringCursor(), randomFrom(Mode.values()), randomBoolean()); } + @Override + protected Writeable.Reader instanceReader() { + return SqlQueryResponse::new; + } + public static SqlQueryResponse createRandomInstance(String cursor, Mode mode, boolean columnar) { int columnCount = between(1, 10); @@ -78,11 +84,6 @@ public static SqlQueryResponse createRandomInstance(String cursor, Mode mode, bo return new SqlQueryResponse(cursor, mode, false, columns, rows); } - @Override - protected SqlQueryResponse createBlankInstance() { - return new SqlQueryResponse(); - } - public void testToXContent() throws IOException { SqlQueryResponse testInstance = createTestInstance(); diff --git a/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateResponseTests.java b/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateResponseTests.java index 76a04d03435e3..560db968a1177 100644 --- a/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateResponseTests.java +++ b/x-pack/plugin/sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlTranslateResponseTests.java @@ -5,13 +5,13 @@ */ package org.elasticsearch.xpack.sql.action; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.sql.action.SqlTranslateResponse; +import org.elasticsearch.test.AbstractWireSerializingTestCase; import java.io.IOException; -public class SqlTranslateResponseTests extends AbstractStreamableTestCase { +public class SqlTranslateResponseTests extends AbstractWireSerializingTestCase { @Override protected SqlTranslateResponse createTestInstance() { @@ -36,8 +36,8 @@ protected SqlTranslateResponse createTestInstance() { } @Override - protected SqlTranslateResponse createBlankInstance() { - return new SqlTranslateResponse(); + protected Writeable.Reader instanceReader() { + return SqlTranslateResponse::new; } @Override diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlClearCursorAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlClearCursorAction.java index 98bb25b8ebd81..6d3802c341f1d 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlClearCursorAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlClearCursorAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.sql.action.SqlClearCursorRequest; @@ -31,7 +30,7 @@ public class TransportSqlClearCursorAction extends HandledTransportAction) SqlClearCursorRequest::new); + super(NAME, transportService, actionFilters, SqlClearCursorRequest::new); this.planExecutor = planExecutor; this.sqlLicenseChecker = sqlLicenseChecker; } diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlQueryAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlQueryAction.java index 97fc583c3e886..3e9c30f49b453 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlQueryAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlQueryAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; @@ -49,7 +48,7 @@ public class TransportSqlQueryAction extends HandledTransportAction) SqlQueryRequest::new); + super(SqlQueryAction.NAME, transportService, actionFilters, SqlQueryRequest::new); this.securityContext = XPackSettings.SECURITY_ENABLED.get(settings) ? new SecurityContext(settings, threadPool.getThreadContext()) : null; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlTranslateAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlTranslateAction.java index 9101557d1cd1a..b37c25fcab933 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlTranslateAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlTranslateAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; @@ -40,7 +39,7 @@ public class TransportSqlTranslateAction extends HandledTransportAction) SqlTranslateRequest::new); + super(SqlTranslateAction.NAME, transportService, actionFilters, SqlTranslateRequest::new); this.securityContext = XPackSettings.SECURITY_ENABLED.get(settings) ? new SecurityContext(settings, threadPool.getThreadContext()) : null;