Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Combine Action and GenericAction #31405

Merged
merged 1 commit into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
package org.elasticsearch.plugin.noop.action.bulk;

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

public class NoopBulkAction extends Action<BulkRequest, BulkResponse> {
public class NoopBulkAction extends Action<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 @@ -19,10 +19,9 @@
package org.elasticsearch.plugin.noop.action.search;

import org.elasticsearch.action.Action;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;

public class NoopSearchAction extends Action<SearchRequest, SearchResponse> {
public class NoopSearchAction extends Action<SearchResponse> {
public static final NoopSearchAction INSTANCE = new NoopSearchAction();
public static final String NAME = "mock:data/read/search";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestStatus.OK;

public class GrokProcessorGetAction extends Action<GrokProcessorGetAction.Request, GrokProcessorGetAction.Response> {
public class GrokProcessorGetAction extends Action<GrokProcessorGetAction.Response> {

public static final GrokProcessorGetAction INSTANCE = new GrokProcessorGetAction();
public static final String NAME = "cluster:admin/ingest/processor/grok/get";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.elasticsearch.action.Action;

public class MultiSearchTemplateAction extends Action<MultiSearchTemplateRequest, MultiSearchTemplateResponse> {
public class MultiSearchTemplateAction extends Action<MultiSearchTemplateResponse> {

public static final MultiSearchTemplateAction INSTANCE = new MultiSearchTemplateAction();
public static final String NAME = "indices:data/read/msearch/template";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.elasticsearch.action.Action;

public class SearchTemplateAction extends Action<SearchTemplateRequest, SearchTemplateResponse> {
public class SearchTemplateAction extends Action<SearchTemplateResponse> {

public static final SearchTemplateAction INSTANCE = new SearchTemplateAction();
public static final String NAME = "indices:data/read/search/template";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestStatus.OK;

public class PainlessExecuteAction extends Action<PainlessExecuteAction.Request, PainlessExecuteAction.Response> {
public class PainlessExecuteAction extends Action<PainlessExecuteAction.Response> {

static final PainlessExecuteAction INSTANCE = new PainlessExecuteAction();
private static final String NAME = "cluster:admin/scripts/painless/execute";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* Action for explaining evaluating search ranking results.
*/
public class RankEvalAction extends Action<RankEvalRequest, RankEvalResponse> {
public class RankEvalAction extends Action<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 @@ -25,7 +25,7 @@

public class RankEvalRequestBuilder extends ActionRequestBuilder<RankEvalRequest, RankEvalResponse> {

public RankEvalRequestBuilder(ElasticsearchClient client, Action<RankEvalRequest, RankEvalResponse> action,
public RankEvalRequestBuilder(ElasticsearchClient client, Action<RankEvalResponse> action,
RankEvalRequest request) {
super(client, action, request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.elasticsearch.index.reindex;

import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.GenericAction;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -38,7 +38,7 @@

public abstract class AbstractBaseReindexRestHandler<
Request extends AbstractBulkByScrollRequest<Request>,
A extends GenericAction<Request, BulkByScrollResponse>
A extends Action<BulkByScrollResponse>
> extends BaseRestHandler {

private final A action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.index.reindex;

import org.elasticsearch.action.GenericAction;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -38,7 +38,7 @@
*/
public abstract class AbstractBulkByQueryRestHandler<
Request extends AbstractBulkByScrollRequest<Request>,
A extends GenericAction<Request, BulkByScrollResponse>> extends AbstractBaseReindexRestHandler<Request, A> {
A extends Action<BulkByScrollResponse>> extends AbstractBaseReindexRestHandler<Request, A> {

protected AbstractBulkByQueryRestHandler(Settings settings, A action) {
super(settings, action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private BulkByScrollParallelizationHelper() {}
static <Request extends AbstractBulkByScrollRequest<Request>> void startSlicedAction(
Request request,
BulkByScrollTask task,
Action<Request, BulkByScrollResponse> action,
Action<BulkByScrollResponse> action,
ActionListener<BulkByScrollResponse> listener,
Client client,
DiscoveryNode node,
Expand All @@ -85,7 +85,7 @@ static <Request extends AbstractBulkByScrollRequest<Request>> void startSlicedAc
private static <Request extends AbstractBulkByScrollRequest<Request>> void sliceConditionally(
Request request,
BulkByScrollTask task,
Action<Request, BulkByScrollResponse> action,
Action<BulkByScrollResponse> action,
ActionListener<BulkByScrollResponse> listener,
Client client,
DiscoveryNode node,
Expand Down Expand Up @@ -118,7 +118,7 @@ private static int countSlicesBasedOnShards(ClusterSearchShardsResponse response

private static <Request extends AbstractBulkByScrollRequest<Request>> void sendSubRequests(
Client client,
Action<Request, BulkByScrollResponse> action,
Action<BulkByScrollResponse> action,
String localNodeId,
BulkByScrollTask task,
Request request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.elasticsearch.action.Action;
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;

public class RethrottleAction extends Action<RethrottleRequest, ListTasksResponse> {
public class RethrottleAction extends Action<ListTasksResponse> {
public static final RethrottleAction INSTANCE = new RethrottleAction();
public static final String NAME = "cluster:admin/reindex/rethrottle";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
public class RethrottleRequestBuilder extends TasksRequestBuilder<RethrottleRequest, ListTasksResponse, RethrottleRequestBuilder> {
public RethrottleRequestBuilder(ElasticsearchClient client,
Action<RethrottleRequest, ListTasksResponse> action) {
Action<ListTasksResponse> action) {
super(client, action, new RethrottleRequest());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ private class MyMockClient extends FilterClient {
@SuppressWarnings("unchecked")
protected <Request extends ActionRequest, Response extends ActionResponse,
RequestBuilder extends ActionRequestBuilder<Request, Response>> void doExecute(
Action<Request, Response> action, Request request, ActionListener<Response> listener) {
Action<Response> action, Request request, ActionListener<Response> listener) {
if (false == expectedHeaders.equals(threadPool().getThreadContext().getHeaders())) {
listener.onFailure(
new RuntimeException("Expected " + expectedHeaders + " but got " + threadPool().getThreadContext().getHeaders()));
Expand Down
44 changes: 40 additions & 4 deletions server/src/main/java/org/elasticsearch/action/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,49 @@

package org.elasticsearch.action;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.transport.TransportRequestOptions;

/**
* Base action. Supports building the <code>Request</code> through a <code>RequestBuilder</code>.
* A generic action. Should strive to make it a singleton.
*/
public abstract class Action<Request extends ActionRequest, Response extends ActionResponse>
extends GenericAction<Request, Response> {
public abstract class Action<Response extends ActionResponse> {

private final String name;

/**
* @param name The name of the action, must be unique across actions.
*/
protected Action(String name) {
super(name);
this.name = name;
}

/**
* The name of the action. Must be unique across actions.
*/
public String name() {
return this.name;
}

/**
* Creates a new response instance.
*/
public abstract Response newResponse();

/**
* Optional request options for the action.
*/
public TransportRequestOptions transportOptions(Settings settings) {
return TransportRequestOptions.EMPTY;
}

@Override
public boolean equals(Object o) {
return o instanceof Action && name.equals(((Action) o).name());
}

@Override
public int hashCode() {
return name.hashCode();
}
}
10 changes: 5 additions & 5 deletions server/src/main/java/org/elasticsearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ public void register(ActionHandler<?, ?> handler) {
}

public <Request extends ActionRequest, Response extends ActionResponse> void register(
GenericAction<Request, Response> action, Class<? extends TransportAction<Request, Response>> transportAction,
Class<?>... supportTransportActions) {
Action<Response> action, Class<? extends TransportAction<Request, Response>> transportAction,
Class<?>... supportTransportActions) {
register(new ActionHandler<>(action, transportAction, supportTransportActions));
}
}
Expand Down Expand Up @@ -675,10 +675,10 @@ protected void configure() {
bind(AutoCreateIndex.class).toInstance(autoCreateIndex);
bind(TransportLivenessAction.class).asEagerSingleton();

// register GenericAction -> transportAction Map used by NodeClient
// register Action -> transportAction Map used by NodeClient
@SuppressWarnings("rawtypes")
MapBinder<GenericAction, TransportAction> transportActionsBinder
= MapBinder.newMapBinder(binder(), GenericAction.class, TransportAction.class);
MapBinder<Action, TransportAction> transportActionsBinder
= MapBinder.newMapBinder(binder(), Action.class, TransportAction.class);
for (ActionHandler<?, ?> action : actions.values()) {
// bind the action as eager singleton, so the map binder one will reuse it
bind(action.getTransportAction()).asEagerSingleton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

public abstract class ActionRequestBuilder<Request extends ActionRequest, Response extends ActionResponse> {

protected final Action<Request, Response> action;
protected final Action<Response> action;
protected final Request request;
protected final ElasticsearchClient client;

protected ActionRequestBuilder(ElasticsearchClient client, Action<Request, Response> action, Request request) {
protected ActionRequestBuilder(ElasticsearchClient client, Action<Response> action, Request request) {
Objects.requireNonNull(action, "action must not be null");
this.action = action;
this.request = request;
Expand Down
67 changes: 0 additions & 67 deletions server/src/main/java/org/elasticsearch/action/GenericAction.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
public class TransportActionNodeProxy<Request extends ActionRequest, Response extends ActionResponse> extends AbstractComponent {

private final TransportService transportService;
private final GenericAction<Request, Response> action;
private final Action<Response> action;
private final TransportRequestOptions transportOptions;

public TransportActionNodeProxy(Settings settings, GenericAction<Request, Response> action, TransportService transportService) {
public TransportActionNodeProxy(Settings settings, Action<Response> action, TransportService transportService) {
super(settings);
this.action = action;
this.transportService = transportService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* Action for explaining shard allocation for a shard in the cluster
*/
public class ClusterAllocationExplainAction extends Action<ClusterAllocationExplainRequest, ClusterAllocationExplainResponse> {
public class ClusterAllocationExplainAction extends Action<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 @@ -21,7 +21,7 @@

import org.elasticsearch.action.Action;

public class ClusterHealthAction extends Action<ClusterHealthRequest, ClusterHealthResponse> {
public class ClusterHealthAction extends Action<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 @@ -21,7 +21,7 @@

import org.elasticsearch.action.Action;

public class NodesHotThreadsAction extends Action<NodesHotThreadsRequest, NodesHotThreadsResponse> {
public class NodesHotThreadsAction extends Action<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 @@ -21,7 +21,7 @@

import org.elasticsearch.action.Action;

public class NodesInfoAction extends Action<NodesInfoRequest, NodesInfoResponse> {
public class NodesInfoAction extends Action<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 @@ -22,7 +22,7 @@
import org.elasticsearch.action.Action;

public class NodesReloadSecureSettingsAction
extends Action<NodesReloadSecureSettingsRequest, NodesReloadSecureSettingsResponse> {
extends Action<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 @@ -21,7 +21,7 @@

import org.elasticsearch.action.Action;

public class NodesStatsAction extends Action<NodesStatsRequest, NodesStatsResponse> {
public class NodesStatsAction extends Action<NodesStatsResponse> {

public static final NodesStatsAction INSTANCE = new NodesStatsAction();
public static final String NAME = "cluster:monitor/nodes/stats";
Expand Down
Loading