Skip to content

Commit

Permalink
Add StreamableResponseAction to aid in deprecation of Streamable (ela…
Browse files Browse the repository at this point in the history
…stic#43770)

The Action base class currently works for both Streamable and Writeable
response types. This commit intorduces StreamableResponseAction, for
which only the legacy Action implementions which provide newResponse()
will extend. This eliminates the need for overriding newResponse() with
an UnsupportedOperationException.

relates elastic#34389
  • Loading branch information
rjernst authored Jun 29, 2019
1 parent 7951c63 commit 28ab77a
Show file tree
Hide file tree
Showing 273 changed files with 378 additions and 908 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
package org.elasticsearch.plugin.noop.action.bulk;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;
import org.elasticsearch.action.bulk.BulkResponse;

public class NoopBulkAction extends Action<BulkResponse> {
public class NoopBulkAction extends StreamableResponseAction<BulkResponse> {
public static final String NAME = "mock:data/write/bulk";

public static final NoopBulkAction INSTANCE = new NoopBulkAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ private NoopSearchAction() {
super(NAME);
}

@Override
public SearchResponse newResponse() {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
public Writeable.Reader<SearchResponse> getResponseReader() {
return SearchResponse::new;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/
package org.elasticsearch.ingest.common;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.StreamableResponseAction;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.client.node.NodeClient;
Expand All @@ -45,7 +45,7 @@
import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS;
import static org.elasticsearch.rest.RestRequest.Method.GET;

public class GrokProcessorGetAction extends Action<GrokProcessorGetAction.Response> {
public class GrokProcessorGetAction extends StreamableResponseAction<GrokProcessorGetAction.Response> {

static final GrokProcessorGetAction INSTANCE = new GrokProcessorGetAction();
static final String NAME = "cluster:admin/ingest/processor/grok/get";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ private MultiSearchTemplateAction() {
super(NAME);
}

@Override
public MultiSearchTemplateResponse newResponse() {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
public Writeable.Reader<MultiSearchTemplateResponse> getResponseReader() {
return MultiSearchTemplateResponse::new;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ private SearchTemplateAction() {
super(NAME);
}

@Override
public SearchTemplateResponse newResponse() {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
public Writeable.Reader<SearchTemplateResponse> getResponseReader() {
return SearchTemplateResponse::new;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ private PainlessContextAction() {
super(NAME);
}

@Override
public Response newResponse() {
throw new UnsupportedOperationException();
}

@Override
public Writeable.Reader<Response> getResponseReader() {
return Response::new;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ private PainlessExecuteAction() {
}

@Override
public Response newResponse() {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
public Writeable.Reader<Response> getResponseReader() {
return Response::new;
}

public static class Request extends SingleShardRequest<Request> implements ToXContentObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

package org.elasticsearch.index.rankeval;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;

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

public static final RankEvalAction INSTANCE = new RankEvalAction();
public static final String NAME = "indices:data/read/rank_eval";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ private RethrottleAction() {
super(NAME);
}

@Override
public ListTasksResponse newResponse() {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
public Writeable.Reader<ListTasksResponse> getResponseReader() {
return ListTasksResponse::new;
Expand Down
28 changes: 14 additions & 14 deletions server/src/main/java/org/elasticsearch/action/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,27 @@
/**
* A generic action. Should strive to make it a singleton.
*/
public abstract class Action<Response extends ActionResponse> {
public class Action<Response extends ActionResponse> {

private final String name;
private final Writeable.Reader<Response> responseReader;

/**
* @param name The name of the action, must be unique across actions.
* @deprecated Pass a {@link Writeable.Reader} with {@link }
*/
@Deprecated
protected Action(String name) {
this(name, null);
}

/**
* @param name The name of the action, must be unique across actions.
* @param responseReader A reader for the response type
*/
public Action(String name, Writeable.Reader<Response> responseReader) {
this.name = name;
this.responseReader = responseReader;
}

/**
Expand All @@ -44,23 +56,11 @@ public String name() {
return this.name;
}

/**
* Creates a new response instance.
* @deprecated Implement {@link #getResponseReader()} instead and make this method throw an
* {@link UnsupportedOperationException}
*/
@Deprecated
public abstract Response newResponse();

/**
* Get a reader that can create a new instance of the class from a {@link org.elasticsearch.common.io.stream.StreamInput}
*/
public Writeable.Reader<Response> getResponseReader() {
return in -> {
Response response = newResponse();
response.readFrom(in);
return response;
};
return responseReader;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action;

import org.elasticsearch.common.io.stream.Writeable;

/**
* An action for with the response type implements {@link org.elasticsearch.common.io.stream.Streamable}.
* @deprecated Use {@link Action} directly and provide a {@link Writeable.Reader}
*/
@Deprecated
public abstract class StreamableResponseAction<Response extends ActionResponse> extends Action<Response> {

protected StreamableResponseAction(String name) {
super(name);
}

/**
* Creates a new response instance.
* @deprecated Implement {@link #getResponseReader()} instead and make this method throw an
* {@link UnsupportedOperationException}
*/
@Deprecated
public abstract Response newResponse();

@Override
public final Writeable.Reader<Response> getResponseReader() {
return in -> {
Response response = newResponse();
response.readFrom(in);
return response;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

package org.elasticsearch.action.admin.cluster.allocation;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;

/**
* Action for explaining shard allocation for a shard in the cluster
*/
public class ClusterAllocationExplainAction extends Action<ClusterAllocationExplainResponse> {
public class ClusterAllocationExplainAction extends StreamableResponseAction<ClusterAllocationExplainResponse> {

public static final ClusterAllocationExplainAction INSTANCE = new ClusterAllocationExplainAction();
public static final String NAME = "cluster:monitor/allocation/explain";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ private AddVotingConfigExclusionsAction() {
super(NAME);
}

@Override
public AddVotingConfigExclusionsResponse newResponse() {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
public Reader<AddVotingConfigExclusionsResponse> getResponseReader() {
return AddVotingConfigExclusionsResponse::new;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ private ClearVotingConfigExclusionsAction() {
super(NAME);
}

@Override
public ClearVotingConfigExclusionsResponse newResponse() {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
public Reader<ClearVotingConfigExclusionsResponse> getResponseReader() {
return ClearVotingConfigExclusionsResponse::new;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package org.elasticsearch.action.admin.cluster.health;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;

public class ClusterHealthAction extends Action<ClusterHealthResponse> {
public class ClusterHealthAction extends StreamableResponseAction<ClusterHealthResponse> {

public static final ClusterHealthAction INSTANCE = new ClusterHealthAction();
public static final String NAME = "cluster:monitor/health";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package org.elasticsearch.action.admin.cluster.node.hotthreads;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;

public class NodesHotThreadsAction extends Action<NodesHotThreadsResponse> {
public class NodesHotThreadsAction extends StreamableResponseAction<NodesHotThreadsResponse> {

public static final NodesHotThreadsAction INSTANCE = new NodesHotThreadsAction();
public static final String NAME = "cluster:monitor/nodes/hot_threads";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package org.elasticsearch.action.admin.cluster.node.info;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;

public class NodesInfoAction extends Action<NodesInfoResponse> {
public class NodesInfoAction extends StreamableResponseAction<NodesInfoResponse> {

public static final NodesInfoAction INSTANCE = new NodesInfoAction();
public static final String NAME = "cluster:monitor/nodes/info";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

package org.elasticsearch.action.admin.cluster.node.reload;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;

public class NodesReloadSecureSettingsAction
extends Action<NodesReloadSecureSettingsResponse> {
extends StreamableResponseAction<NodesReloadSecureSettingsResponse> {

public static final NodesReloadSecureSettingsAction INSTANCE = new NodesReloadSecureSettingsAction();
public static final String NAME = "cluster:admin/nodes/reload_secure_settings";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package org.elasticsearch.action.admin.cluster.node.stats;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;

public class NodesStatsAction extends Action<NodesStatsResponse> {
public class NodesStatsAction extends StreamableResponseAction<NodesStatsResponse> {

public static final NodesStatsAction INSTANCE = new NodesStatsAction();
public static final String NAME = "cluster:monitor/nodes/stats";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ private CancelTasksAction() {
super(NAME);
}

@Override
public CancelTasksResponse newResponse() {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
public Writeable.Reader<CancelTasksResponse> getResponseReader() {
return CancelTasksResponse::new;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

package org.elasticsearch.action.admin.cluster.node.tasks.get;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;

/**
* Action for retrieving a list of currently running tasks
*/
public class GetTaskAction extends Action<GetTaskResponse> {
public class GetTaskAction extends StreamableResponseAction<GetTaskResponse> {
public static final String TASKS_ORIGIN = "tasks";

public static final GetTaskAction INSTANCE = new GetTaskAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ private ListTasksAction() {
super(NAME);
}

@Override
public ListTasksResponse newResponse() {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}

@Override
public Writeable.Reader<ListTasksResponse> getResponseReader() {
return ListTasksResponse::new;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package org.elasticsearch.action.admin.cluster.node.usage;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;

public class NodesUsageAction extends Action<NodesUsageResponse> {
public class NodesUsageAction extends StreamableResponseAction<NodesUsageResponse> {

public static final NodesUsageAction INSTANCE = new NodesUsageAction();
public static final String NAME = "cluster:monitor/nodes/usage";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package org.elasticsearch.action.admin.cluster.remote;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.StreamableResponseAction;

public final class RemoteInfoAction extends Action<RemoteInfoResponse> {
public final class RemoteInfoAction extends StreamableResponseAction<RemoteInfoResponse> {

public static final String NAME = "cluster:monitor/remote/info";
public static final RemoteInfoAction INSTANCE = new RemoteInfoAction();
Expand Down
Loading

0 comments on commit 28ab77a

Please sign in to comment.