Skip to content

Commit

Permalink
Remove unused arg from ActionType ctor (#104650)
Browse files Browse the repository at this point in the history
`ActionType` represents an action which runs on the local node, there's
no need for implementations to define a `Reader<Response>`. This commit
removes the unused constructor argument.
  • Loading branch information
DaveCTurner authored Jan 25, 2024
1 parent a7f2e2d commit 1116889
Show file tree
Hide file tree
Showing 538 changed files with 554 additions and 670 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

public class NoopPlugin extends Plugin implements ActionPlugin {

public static final ActionType<SearchResponse> NOOP_SEARCH_ACTION = new ActionType<>("mock:data/read/search", SearchResponse::new);
public static final ActionType<BulkResponse> NOOP_BULK_ACTION = new ActionType<>("mock:data/write/bulk", BulkResponse::new);
public static final ActionType<SearchResponse> NOOP_SEARCH_ACTION = new ActionType<>("mock:data/read/search");
public static final ActionType<BulkResponse> NOOP_BULK_ACTION = new ActionType<>("mock:data/write/bulk");

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public class DeleteDataStreamLifecycleAction {

public static final ActionType<AcknowledgedResponse> INSTANCE = ActionType.localOnly("indices:admin/data_stream/lifecycle/delete");
public static final ActionType<AcknowledgedResponse> INSTANCE = new ActionType<>("indices:admin/data_stream/lifecycle/delete");

private DeleteDataStreamLifecycleAction() {/* no instances */}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
public class ExplainDataStreamLifecycleAction {

public static final ActionType<ExplainDataStreamLifecycleAction.Response> INSTANCE = new ActionType<>(
"indices:admin/data_stream/lifecycle/explain",
Response::new
"indices:admin/data_stream/lifecycle/explain"
);

private ExplainDataStreamLifecycleAction() {/* no instances */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
public class GetDataStreamLifecycleAction {

public static final ActionType<GetDataStreamLifecycleAction.Response> INSTANCE = new ActionType<>(
"indices:admin/data_stream/lifecycle/get",
Response::new
"indices:admin/data_stream/lifecycle/get"
);

private GetDataStreamLifecycleAction() {/* no instances */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class GetDataStreamLifecycleStatsAction extends ActionType<GetDataStreamL
public static final String NAME = "cluster:monitor/data_stream/lifecycle/stats";

private GetDataStreamLifecycleStatsAction() {
super(NAME, Response::new);
super(NAME);
}

public static class Request extends MasterNodeReadRequest<Request> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
public class PutDataStreamLifecycleAction {

public static final ActionType<AcknowledgedResponse> INSTANCE = ActionType.localOnly("indices:admin/data_stream/lifecycle/put");
public static final ActionType<AcknowledgedResponse> INSTANCE = new ActionType<>("indices:admin/data_stream/lifecycle/put");

private PutDataStreamLifecycleAction() {/* no instances */}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@

public class GrokProcessorGetAction {

static final ActionType<GrokProcessorGetAction.Response> INSTANCE = new ActionType<>(
"cluster:admin/ingest/processor/grok/get",
Response::new
);
static final ActionType<GrokProcessorGetAction.Response> INSTANCE = new ActionType<>("cluster:admin/ingest/processor/grok/get");

private GrokProcessorGetAction() {/* no instances */}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class GeoIpDownloaderStatsAction {

public static final ActionType<Response> INSTANCE = new ActionType<>("cluster:monitor/ingest/geoip/stats", Response::new);
public static final ActionType<Response> INSTANCE = new ActionType<>("cluster:monitor/ingest/geoip/stats");

private GeoIpDownloaderStatsAction() {/* no instances */}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@

public class MustachePlugin extends Plugin implements ScriptPlugin, ActionPlugin, SearchPlugin {

public static final ActionType<SearchTemplateResponse> SEARCH_TEMPLATE_ACTION = new ActionType<>(
"indices:data/read/search/template",
SearchTemplateResponse::new
);
public static final ActionType<SearchTemplateResponse> SEARCH_TEMPLATE_ACTION = new ActionType<>("indices:data/read/search/template");
public static final ActionType<MultiSearchTemplateResponse> MULTI_SEARCH_TEMPLATE_ACTION = new ActionType<>(
"indices:data/read/msearch/template",
MultiSearchTemplateResponse::new
"indices:data/read/msearch/template"
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
*/
public class PainlessContextAction {

public static final ActionType<Response> INSTANCE = new ActionType<>("cluster:admin/scripts/painless/context", Response::new);
public static final ActionType<Response> INSTANCE = new ActionType<>("cluster:admin/scripts/painless/context");

private static final String SCRIPT_CONTEXT_NAME_PARAM = "context";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@

public class PainlessExecuteAction {

public static final ActionType<Response> INSTANCE = ActionType.localOnly("cluster:admin/scripts/painless/execute");
public static final ActionType<Response> INSTANCE = new ActionType<>("cluster:admin/scripts/painless/execute");
public static final RemoteClusterActionType<Response> REMOTE_TYPE = new RemoteClusterActionType<>(INSTANCE.name(), Response::new);

private PainlessExecuteAction() {/* no instances */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class RankEvalPlugin extends Plugin implements ActionPlugin {

public static final ActionType<RankEvalResponse> ACTION = new ActionType<>("indices:data/read/rank_eval", RankEvalResponse::new);
public static final ActionType<RankEvalResponse> ACTION = new ActionType<>("indices:data/read/rank_eval");

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
public class ReindexPlugin extends Plugin implements ActionPlugin {
public static final String NAME = "reindex";

public static final ActionType<ListTasksResponse> RETHROTTLE_ACTION = new ActionType<>(
"cluster:admin/reindex/rethrottle",
ListTasksResponse::new
);
public static final ActionType<ListTasksResponse> RETHROTTLE_ACTION = new ActionType<>("cluster:admin/reindex/rethrottle");

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class MainRestPlugin extends Plugin implements ActionPlugin {

public static final ActionType<MainResponse> MAIN_ACTION = ActionType.localOnly("cluster:monitor/main");
public static final ActionType<MainResponse> MAIN_ACTION = new ActionType<>("cluster:monitor/main");

@Override
public List<RestHandler> getRestHandlers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public void writeTo(StreamOutput out) throws IOException {

public static class TransportTestAction extends HandledTransportAction<TestRequest, TestResponse> {

public static ActionType<TestResponse> ACTION = new ActionType<>("internal::test_action", TestResponse::new);
public static ActionType<TestResponse> ACTION = new ActionType<>("internal::test_action");
private final TransportService transportService;
private final NodeClient client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
return List.of(TestPlugin.class);
}

private static final ActionType<ActionResponse.Empty> TEST_ACTION = ActionType.emptyResponse(TestTransportAction.NAME);
private static final ActionType<ActionResponse.Empty> TEST_ACTION = new ActionType<>(TestTransportAction.NAME);

public static class TestPlugin extends Plugin implements ActionPlugin {
volatile CyclicBarrier barrier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Response(StreamInput in) throws IOException {

public static class TestAction extends TransportReplicationAction<Request, Request, Response> {
private static final String ACTION_NAME = "internal:test-replication-action";
private static final ActionType<Response> TYPE = new ActionType<>(ACTION_NAME, Response::new);
private static final ActionType<Response> TYPE = new ActionType<>(ACTION_NAME);

@Inject
public TestAction(
Expand Down
26 changes: 3 additions & 23 deletions server/src/main/java/org/elasticsearch/action/ActionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
import org.elasticsearch.action.support.nodes.TransportNodesAction;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.transport.TransportService;

Expand All @@ -25,39 +23,21 @@
* TYPE}. Some legacy implementations create custom subclasses of {@link ActionType} but this is unnecessary and somewhat wasteful. Prefer
* to create instances of this class directly whenever possible.
*/
@SuppressWarnings("unused") // Response type arg is used to enable better type inference when calling Client#execute
public class ActionType<Response extends ActionResponse> {

private final String name;

/**
* Construct an {@link ActionType} which callers can execute on the local node (using {@link NodeClient}).
* Construct an {@link ActionType} with the given name.
* <p>
* There is no facility for directly executing an action on a different node in the local cluster. To achieve this, implement an action
* which runs on the local node and knows how to use the {@link TransportService} to forward the request to a different node. There are
* several utilities that help implement such an action, including {@link TransportNodesAction} or {@link TransportMasterNodeAction}.
*
* @param name The name of the action, which must be unique across actions.
* @return an {@link ActionType} which callers can execute on the local node.
*/
public static <T extends ActionResponse> ActionType<T> localOnly(String name) {
return new ActionType<>(name, Writeable.Reader.localOnly());
}

public static ActionType<ActionResponse.Empty> emptyResponse(String name) {
return new ActionType<>(name, in -> ActionResponse.Empty.INSTANCE);
}

/**
* Construct an {@link ActionType} and specify a method that can deserialize the response. This {@code responseReader} parameter is
* effectively unused. Use {@link #localOnly} instead.
* <p>
* There is no facility for directly executing an action on a different node in the local cluster. To achieve this, implement an action
* which runs on the local node and knows how to use the {@link TransportService} to forward the request to a different node. There are
* several utilities that help implement such an action, including {@link TransportNodesAction} or {@link TransportMasterNodeAction}.
*
* @param name The name of the action, which must be unique across actions.
*/
public ActionType(String name, Writeable.Reader<Response> ignored) {
public ActionType(String name) {
this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ public class TransportClusterAllocationExplainAction extends TransportMasterNode
ClusterAllocationExplainRequest,
ClusterAllocationExplainResponse> {

public static final ActionType<ClusterAllocationExplainResponse> TYPE = new ActionType<>(
"cluster:monitor/allocation/explain",
ClusterAllocationExplainResponse::new
);
public static final ActionType<ClusterAllocationExplainResponse> TYPE = new ActionType<>("cluster:monitor/allocation/explain");
private static final Logger logger = LogManager.getLogger(TransportClusterAllocationExplainAction.class);

private final ClusterInfoService clusterInfoService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class TransportDeleteDesiredBalanceAction extends TransportMasterNodeAction<DesiredBalanceRequest, ActionResponse.Empty> {

public static final ActionType<ActionResponse.Empty> TYPE = ActionType.emptyResponse("cluster:admin/desired_balance/reset");
public static final ActionType<ActionResponse.Empty> TYPE = new ActionType<>("cluster:admin/desired_balance/reset");
@Nullable
private final MasterServiceTaskQueue<ResetDesiredBalanceTask> resetDesiredBalanceTaskQueue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@

public class TransportGetDesiredBalanceAction extends TransportMasterNodeReadAction<DesiredBalanceRequest, DesiredBalanceResponse> {

public static final ActionType<DesiredBalanceResponse> TYPE = new ActionType<>(
"cluster:admin/desired_balance/get",
DesiredBalanceResponse::from
);
public static final ActionType<DesiredBalanceResponse> TYPE = new ActionType<>("cluster:admin/desired_balance/get");
@Nullable
private final DesiredBalanceShardsAllocator desiredBalanceShardsAllocator;
private final ClusterInfoService clusterInfoService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class TransportAddVotingConfigExclusionsAction extends TransportMasterNod
AddVotingConfigExclusionsRequest,
ActionResponse.Empty> {

public static final ActionType<ActionResponse.Empty> TYPE = ActionType.emptyResponse("cluster:admin/voting_config/add_exclusions");
public static final ActionType<ActionResponse.Empty> TYPE = new ActionType<>("cluster:admin/voting_config/add_exclusions");
private static final Logger logger = LogManager.getLogger(TransportAddVotingConfigExclusionsAction.class);

public static final Setting<Integer> MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING = Setting.intSetting(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class TransportClearVotingConfigExclusionsAction extends TransportMasterN
ClearVotingConfigExclusionsRequest,
ActionResponse.Empty> {

public static final ActionType<ActionResponse.Empty> TYPE = ActionType.emptyResponse("cluster:admin/voting_config/clear_exclusions");
public static final ActionType<ActionResponse.Empty> TYPE = new ActionType<>("cluster:admin/voting_config/clear_exclusions");
private static final Logger logger = LogManager.getLogger(TransportClearVotingConfigExclusionsAction.class);
private final Reconfigurator reconfigurator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ClusterFormationInfoAction extends ActionType<ClusterFormationInfoA
public static final String NAME = "internal:cluster/formation/info";

private ClusterFormationInfoAction() {
super(NAME, ClusterFormationInfoAction.Response::new);
super(NAME);
}

public static class Request extends ActionRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CoordinationDiagnosticsAction extends ActionType<CoordinationDiagno
public static final String NAME = "internal:cluster/coordination_diagnostics/info";

private CoordinationDiagnosticsAction() {
super(NAME, CoordinationDiagnosticsAction.Response::new);
super(NAME);
}

public static class Request extends ActionRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class MasterHistoryAction extends ActionType<MasterHistoryAction.Response
public static final String NAME = "internal:cluster/master_history/get";

private MasterHistoryAction() {
super(NAME, MasterHistoryAction.Response::new);
super(NAME);
}

public static class Request extends ActionRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class GetDesiredNodesAction extends ActionType<GetDesiredNodesAction.Resp
public static final String NAME = "cluster:admin/desired_nodes/get";

GetDesiredNodesAction() {
super(NAME, Response::new);
super(NAME);
}

public static class Request extends MasterNodeReadRequest<Request> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public class TransportDeleteDesiredNodesAction extends TransportMasterNodeAction<AcknowledgedRequest.Plain, ActionResponse.Empty> {

public static final ActionType<ActionResponse.Empty> TYPE = ActionType.emptyResponse("cluster:admin/desired_nodes/delete");
public static final ActionType<ActionResponse.Empty> TYPE = new ActionType<>("cluster:admin/desired_nodes/delete");
private final MasterServiceTaskQueue<DeleteDesiredNodesTask> taskQueue;

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class UpdateDesiredNodesAction extends ActionType<UpdateDesiredNodesRespo
public static final String NAME = "cluster:admin/desired_nodes/update";

UpdateDesiredNodesAction() {
super(NAME, UpdateDesiredNodesResponse::new);
super(NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
public class TransportClusterHealthAction extends TransportMasterNodeReadAction<ClusterHealthRequest, ClusterHealthResponse> {

public static final String NAME = "cluster:monitor/health";
public static final ActionType<ClusterHealthResponse> TYPE = new ActionType<ClusterHealthResponse>(NAME, ClusterHealthResponse::new);
public static final ActionType<ClusterHealthResponse> TYPE = new ActionType<ClusterHealthResponse>(NAME);
private static final Logger logger = LogManager.getLogger(TransportClusterHealthAction.class);

private final AllocationService allocationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public class GetFeatureUpgradeStatusAction extends ActionType<GetFeatureUpgradeS
public static final String NAME = "cluster:admin/migration/get_system_feature";

private GetFeatureUpgradeStatusAction() {
super(NAME, GetFeatureUpgradeStatusResponse::new);
super(NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public class PostFeatureUpgradeAction extends ActionType<PostFeatureUpgradeRespo
public static final String NAME = "cluster:admin/migration/post_system_feature";

private PostFeatureUpgradeAction() {
super(NAME, PostFeatureUpgradeResponse::new);
super(NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class TransportNodesHotThreadsAction extends TransportNodesAction<
TransportNodesHotThreadsAction.NodeRequest,
NodeHotThreads> {

public static final ActionType<NodesHotThreadsResponse> TYPE = ActionType.localOnly("cluster:monitor/nodes/hot_threads");
public static final ActionType<NodesHotThreadsResponse> TYPE = new ActionType<>("cluster:monitor/nodes/hot_threads");

@Inject
public TransportNodesHotThreadsAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class TransportNodesInfoAction extends TransportNodesAction<
TransportNodesInfoAction.NodeInfoRequest,
NodeInfo> {

public static final ActionType<NodesInfoResponse> TYPE = ActionType.localOnly("cluster:monitor/nodes/info");
public static final ActionType<NodesInfoResponse> TYPE = new ActionType<>("cluster:monitor/nodes/info");
private final NodeService nodeService;

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public class TransportNodesReloadSecureSettingsAction extends TransportNodesActi
NodesReloadSecureSettingsRequest.NodeRequest,
NodesReloadSecureSettingsResponse.NodeResponse> {

public static final ActionType<NodesReloadSecureSettingsResponse> TYPE = ActionType.localOnly(
"cluster:admin/nodes/reload_secure_settings"
);
public static final ActionType<NodesReloadSecureSettingsResponse> TYPE = new ActionType<>("cluster:admin/nodes/reload_secure_settings");

private static final Logger logger = LogManager.getLogger(TransportNodesReloadSecureSettingsAction.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PrevalidateNodeRemovalAction extends ActionType<PrevalidateNodeRemo
public static final String NAME = "cluster:admin/shutdown/prevalidate_removal";

private PrevalidateNodeRemovalAction() {
super(NAME, PrevalidateNodeRemovalResponse::new);
super(NAME);
}

}
Loading

0 comments on commit 1116889

Please sign in to comment.