Skip to content

Dry up Empty ActionResponse Implementations (#65035) #65179

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

Merged
merged 1 commit into from
Nov 18, 2020
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
20 changes: 20 additions & 0 deletions server/src/main/java/org/elasticsearch/action/ActionResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
package org.elasticsearch.action;

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.transport.TransportResponse;

import java.io.IOException;
Expand All @@ -35,4 +38,21 @@ public ActionResponse() {
public ActionResponse(StreamInput in) throws IOException {
super(in);
}

public static final class Empty extends ActionResponse implements ToXContentObject {
public static final ActionResponse.Empty INSTANCE = new ActionResponse.Empty();

@Override
public String toString() {
return "EmptyActionResponse{}";
}

@Override
public void writeTo(StreamOutput out) {}

@Override
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) {
return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
*/
package org.elasticsearch.action.admin.cluster.configuration;

import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;

public class AddVotingConfigExclusionsAction extends ActionType<AddVotingConfigExclusionsResponse> {
public class AddVotingConfigExclusionsAction extends ActionType<ActionResponse.Empty> {
public static final AddVotingConfigExclusionsAction INSTANCE = new AddVotingConfigExclusionsAction();
public static final String NAME = "cluster:admin/voting_config/add_exclusions";

private AddVotingConfigExclusionsAction() {
super(NAME, AddVotingConfigExclusionsResponse::new);
super(NAME, in -> ActionResponse.Empty.INSTANCE);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
*/
package org.elasticsearch.action.admin.cluster.configuration;

import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;

public class ClearVotingConfigExclusionsAction extends ActionType<ClearVotingConfigExclusionsResponse> {
public class ClearVotingConfigExclusionsAction extends ActionType<ActionResponse.Empty> {
public static final ClearVotingConfigExclusionsAction INSTANCE = new ClearVotingConfigExclusionsAction();
public static final String NAME = "cluster:admin/voting_config/clear_exclusions";

private ClearVotingConfigExclusionsAction() {
super(NAME, ClearVotingConfigExclusionsResponse::new);
super(NAME, in -> ActionResponse.Empty.INSTANCE);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
import org.elasticsearch.cluster.ClusterState;
Expand Down Expand Up @@ -51,7 +52,7 @@
import java.util.stream.Collectors;

public class TransportAddVotingConfigExclusionsAction extends TransportMasterNodeAction<AddVotingConfigExclusionsRequest,
AddVotingConfigExclusionsResponse> {
ActionResponse.Empty> {

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

Expand All @@ -65,7 +66,7 @@ public TransportAddVotingConfigExclusionsAction(Settings settings, ClusterSettin
ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver) {
super(AddVotingConfigExclusionsAction.NAME, transportService, clusterService, threadPool, actionFilters,
AddVotingConfigExclusionsRequest::new, indexNameExpressionResolver, AddVotingConfigExclusionsResponse::new,
AddVotingConfigExclusionsRequest::new, indexNameExpressionResolver, in -> ActionResponse.Empty.INSTANCE,
ThreadPool.Names.SAME);

maxVotingConfigExclusions = MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.get(settings);
Expand All @@ -78,7 +79,7 @@ private void setMaxVotingConfigExclusions(int maxVotingConfigExclusions) {

@Override
protected void masterOperation(AddVotingConfigExclusionsRequest request, ClusterState state,
ActionListener<AddVotingConfigExclusionsResponse> listener) throws Exception {
ActionListener<ActionResponse.Empty> listener) throws Exception {

resolveVotingConfigExclusionsAndCheckMaximum(request, state, maxVotingConfigExclusions);
// throws IAE if no nodes matched or maximum exceeded
Expand Down Expand Up @@ -123,7 +124,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
final Listener clusterStateListener = new Listener() {
@Override
public void onNewClusterState(ClusterState state) {
listener.onResponse(new AddVotingConfigExclusionsResponse());
listener.onResponse(ActionResponse.Empty.INSTANCE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
import org.elasticsearch.cluster.ClusterState;
Expand All @@ -45,7 +46,7 @@
import java.util.function.Predicate;

public class TransportClearVotingConfigExclusionsAction
extends TransportMasterNodeAction<ClearVotingConfigExclusionsRequest, ClearVotingConfigExclusionsResponse> {
extends TransportMasterNodeAction<ClearVotingConfigExclusionsRequest, ActionResponse.Empty> {

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

Expand All @@ -54,13 +55,13 @@ public TransportClearVotingConfigExclusionsAction(TransportService transportServ
ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver) {
super(ClearVotingConfigExclusionsAction.NAME, transportService, clusterService, threadPool, actionFilters,
ClearVotingConfigExclusionsRequest::new, indexNameExpressionResolver, ClearVotingConfigExclusionsResponse::new,
ClearVotingConfigExclusionsRequest::new, indexNameExpressionResolver, in -> ActionResponse.Empty.INSTANCE,
ThreadPool.Names.SAME);
}

@Override
protected void masterOperation(ClearVotingConfigExclusionsRequest request, ClusterState initialState,
ActionListener<ClearVotingConfigExclusionsResponse> listener) throws Exception {
ActionListener<ActionResponse.Empty> listener) throws Exception {

final long startTimeMillis = threadPool.relativeTimeInMillis();

Expand Down Expand Up @@ -103,7 +104,7 @@ public void onTimeout(TimeValue timeout) {
}

private void submitClearVotingConfigExclusionsTask(ClearVotingConfigExclusionsRequest request, long startTimeMillis,
ActionListener<ClearVotingConfigExclusionsResponse> listener) {
ActionListener<ActionResponse.Empty> listener) {
clusterService.submitStateUpdateTask("clear-voting-config-exclusions", new ClusterStateUpdateTask(Priority.URGENT,
TimeValue.timeValueMillis(
Math.max(0, request.getTimeout().millis() + startTimeMillis - threadPool.relativeTimeInMillis()))) {
Expand All @@ -123,7 +124,7 @@ public void onFailure(String source, Exception e) {

@Override
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
listener.onResponse(new ClearVotingConfigExclusionsResponse());
listener.onResponse(ActionResponse.Empty.INSTANCE);
}
});
}
Expand Down
Loading