Skip to content

Commit 2f0a3bb

Browse files
committed
[CCR] Removed custom follow and unfollow api's reponse classes with AcknowledgedResponse (#33260)
These response classes did not add any value and in that case just AcknowledgedResponse should be used. I also changed the formatting of methods to take one line per parameter in FollowIndexAction.java and UnfollowIndexAction.java files to make reviewing diffs in the future easier.
1 parent 04d443b commit 2f0a3bb

File tree

3 files changed

+58
-47
lines changed

3 files changed

+58
-47
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/FollowIndexAction.java

+41-26
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
import java.util.stream.Collectors;
6666

6767
public class FollowIndexAction extends Action<FollowIndexAction.Request,
68-
FollowIndexAction.Response, FollowIndexAction.RequestBuilder> {
68+
AcknowledgedResponse, FollowIndexAction.RequestBuilder> {
6969

7070
public static final FollowIndexAction INSTANCE = new FollowIndexAction();
7171
public static final String NAME = "cluster:admin/xpack/ccr/follow_index";
@@ -80,8 +80,8 @@ public RequestBuilder newRequestBuilder(ElasticsearchClient client) {
8080
}
8181

8282
@Override
83-
public Response newResponse() {
84-
return new Response();
83+
public AcknowledgedResponse newResponse() {
84+
return new AcknowledgedResponse();
8585
}
8686

8787
public static class Request extends ActionRequest implements ToXContentObject {
@@ -137,9 +137,17 @@ public static Request fromXContent(XContentParser parser, String followerIndex)
137137
private TimeValue retryTimeout;
138138
private TimeValue idleShardRetryDelay;
139139

140-
public Request(String leaderIndex, String followerIndex, Integer maxBatchOperationCount, Integer maxConcurrentReadBatches,
141-
Long maxOperationSizeInBytes, Integer maxConcurrentWriteBatches, Integer maxWriteBufferSize,
142-
TimeValue retryTimeout, TimeValue idleShardRetryDelay) {
140+
public Request(
141+
String leaderIndex,
142+
String followerIndex,
143+
Integer maxBatchOperationCount,
144+
Integer maxConcurrentReadBatches,
145+
Long maxOperationSizeInBytes,
146+
Integer maxConcurrentWriteBatches,
147+
Integer maxWriteBufferSize,
148+
TimeValue retryTimeout,
149+
TimeValue idleShardRetryDelay) {
150+
143151
if (leaderIndex == null) {
144152
throw new IllegalArgumentException("leader_index is missing");
145153
}
@@ -279,8 +287,17 @@ public boolean equals(Object o) {
279287

280288
@Override
281289
public int hashCode() {
282-
return Objects.hash(leaderIndex, followerIndex, maxBatchOperationCount, maxConcurrentReadBatches, maxOperationSizeInBytes,
283-
maxConcurrentWriteBatches, maxWriteBufferSize, retryTimeout, idleShardRetryDelay);
290+
return Objects.hash(
291+
leaderIndex,
292+
followerIndex,
293+
maxBatchOperationCount,
294+
maxConcurrentReadBatches,
295+
maxOperationSizeInBytes,
296+
maxConcurrentWriteBatches,
297+
maxWriteBufferSize,
298+
retryTimeout,
299+
idleShardRetryDelay
300+
);
284301
}
285302
}
286303

@@ -291,17 +308,7 @@ public static class RequestBuilder extends ActionRequestBuilder<Request, Respons
291308
}
292309
}
293310

294-
public static class Response extends AcknowledgedResponse {
295-
296-
Response() {
297-
}
298-
299-
Response(boolean acknowledged) {
300-
super(acknowledged);
301-
}
302-
}
303-
304-
public static class TransportAction extends HandledTransportAction<Request, Response> {
311+
public static class TransportAction extends HandledTransportAction<Request, AcknowledgedResponse> {
305312

306313
private final Client client;
307314
private final ClusterService clusterService;
@@ -332,7 +339,7 @@ public TransportAction(
332339
}
333340

334341
@Override
335-
protected void doExecute(final Request request, final ActionListener<Response> listener) {
342+
protected void doExecute(final Request request, final ActionListener<AcknowledgedResponse> listener) {
336343
if (ccrLicenseChecker.isCcrAllowed()) {
337344
final String[] indices = new String[]{request.leaderIndex};
338345
final Map<String, List<String>> remoteClusterIndices = remoteClusterService.groupClusterIndices(indices, s -> false);
@@ -351,7 +358,8 @@ protected void doExecute(final Request request, final ActionListener<Response> l
351358
}
352359
}
353360

354-
private void followLocalIndex(final Request request, final ActionListener<Response> listener) {
361+
private void followLocalIndex(final Request request,
362+
final ActionListener<AcknowledgedResponse> listener) {
355363
final ClusterState state = clusterService.state();
356364
final IndexMetaData followerIndexMetadata = state.getMetaData().index(request.getFollowerIndex());
357365
// following an index in local cluster, so use local cluster state to fetch leader index metadata
@@ -367,7 +375,7 @@ private void followRemoteIndex(
367375
final Request request,
368376
final String clusterAlias,
369377
final String leaderIndex,
370-
final ActionListener<Response> listener) {
378+
final ActionListener<AcknowledgedResponse> listener) {
371379
final ClusterState state = clusterService.state();
372380
final IndexMetaData followerIndexMetadata = state.getMetaData().index(request.getFollowerIndex());
373381
ccrLicenseChecker.checkRemoteClusterLicenseAndFetchLeaderIndexMetadata(
@@ -394,8 +402,13 @@ private void followRemoteIndex(
394402
* <li>The leader index and follow index need to have the same number of primary shards</li>
395403
* </ul>
396404
*/
397-
void start(Request request, String clusterNameAlias, IndexMetaData leaderIndexMetadata, IndexMetaData followIndexMetadata,
398-
ActionListener<Response> handler) throws IOException {
405+
void start(
406+
Request request,
407+
String clusterNameAlias,
408+
IndexMetaData leaderIndexMetadata,
409+
IndexMetaData followIndexMetadata,
410+
ActionListener<AcknowledgedResponse> handler) throws IOException {
411+
399412
MapperService mapperService = followIndexMetadata != null ? indicesService.createIndexMapperService(followIndexMetadata) : null;
400413
validate(request, leaderIndexMetadata, followIndexMetadata, mapperService);
401414
final int numShards = followIndexMetadata.getNumberOfShards();
@@ -443,7 +456,7 @@ void finalizeResponse() {
443456

444457
if (error == null) {
445458
// include task ids?
446-
handler.onResponse(new Response(true));
459+
handler.onResponse(new AcknowledgedResponse(true));
447460
} else {
448461
// TODO: cancel all started tasks
449462
handler.onFailure(error);
@@ -506,7 +519,9 @@ void finalizeResponse() {
506519
WHITELISTED_SETTINGS = Collections.unmodifiableSet(whiteListedSettings);
507520
}
508521

509-
static void validate(Request request, IndexMetaData leaderIndex, IndexMetaData followIndex, MapperService followerMapperService) {
522+
static void validate(Request request,
523+
IndexMetaData leaderIndex,
524+
IndexMetaData followIndex, MapperService followerMapperService) {
510525
if (leaderIndex == null) {
511526
throw new IllegalArgumentException("leader index [" + request.leaderIndex + "] does not exist");
512527
}

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/UnfollowIndexAction.java

+14-19
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.concurrent.atomic.AtomicInteger;
3232
import java.util.concurrent.atomic.AtomicReferenceArray;
3333

34-
public class UnfollowIndexAction extends Action<UnfollowIndexAction.Request, UnfollowIndexAction.Response,
34+
public class UnfollowIndexAction extends Action<UnfollowIndexAction.Request, AcknowledgedResponse,
3535
UnfollowIndexAction.RequestBuilder> {
3636

3737
public static final UnfollowIndexAction INSTANCE = new UnfollowIndexAction();
@@ -47,8 +47,8 @@ public RequestBuilder newRequestBuilder(ElasticsearchClient client) {
4747
}
4848

4949
@Override
50-
public Response newResponse() {
51-
return new Response();
50+
public AcknowledgedResponse newResponse() {
51+
return new AcknowledgedResponse();
5252
}
5353

5454
public static class Request extends ActionRequest {
@@ -81,16 +81,6 @@ public void writeTo(StreamOutput out) throws IOException {
8181
}
8282
}
8383

84-
public static class Response extends AcknowledgedResponse {
85-
86-
Response(boolean acknowledged) {
87-
super(acknowledged);
88-
}
89-
90-
Response() {
91-
}
92-
}
93-
9484
public static class RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder> {
9585

9686
RequestBuilder(ElasticsearchClient client) {
@@ -99,22 +89,27 @@ public static class RequestBuilder extends ActionRequestBuilder<Request, Respons
9989
}
10090

10191

102-
public static class TransportAction extends HandledTransportAction<Request, Response> {
92+
public static class TransportAction extends HandledTransportAction<Request, AcknowledgedResponse> {
10393

10494
private final Client client;
10595
private final PersistentTasksService persistentTasksService;
10696

10797
@Inject
108-
public TransportAction(Settings settings, ThreadPool threadPool, TransportService transportService, ActionFilters actionFilters,
109-
IndexNameExpressionResolver indexNameExpressionResolver, Client client,
98+
public TransportAction(Settings settings,
99+
ThreadPool threadPool,
100+
TransportService transportService,
101+
ActionFilters actionFilters,
102+
IndexNameExpressionResolver indexNameExpressionResolver,
103+
Client client,
110104
PersistentTasksService persistentTasksService) {
111-
super(settings, NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, Request::new);
105+
super(settings, NAME, threadPool,transportService, actionFilters, indexNameExpressionResolver,Request::new);
112106
this.client = client;
113107
this.persistentTasksService = persistentTasksService;
114108
}
115109

116110
@Override
117-
protected void doExecute(Request request, ActionListener<Response> listener) {
111+
protected void doExecute(Request request,
112+
ActionListener<AcknowledgedResponse> listener) {
118113
client.admin().cluster().state(new ClusterStateRequest(), ActionListener.wrap(r -> {
119114
IndexMetaData followIndexMetadata = r.getState().getMetaData().index(request.followIndex);
120115
if (followIndexMetadata == null) {
@@ -158,7 +153,7 @@ void finalizeResponse() {
158153

159154
if (error == null) {
160155
// include task ids?
161-
listener.onResponse(new Response(true));
156+
listener.onResponse(new AcknowledgedResponse(true));
162157
} else {
163158
// TODO: cancel all started tasks
164159
listener.onFailure(error);

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrLicenseIT.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import org.elasticsearch.ElasticsearchSecurityException;
1010
import org.elasticsearch.action.ActionListener;
11+
import org.elasticsearch.action.support.master.AcknowledgedResponse;
1112
import org.elasticsearch.common.unit.TimeValue;
1213
import org.elasticsearch.plugins.Plugin;
1314
import org.elasticsearch.test.ESSingleNodeTestCase;
@@ -36,9 +37,9 @@ public void testThatFollowingIndexIsUnavailableWithIncompatibleLicense() throws
3637
client().execute(
3738
FollowIndexAction.INSTANCE,
3839
followRequest,
39-
new ActionListener<FollowIndexAction.Response>() {
40+
new ActionListener<AcknowledgedResponse>() {
4041
@Override
41-
public void onResponse(final FollowIndexAction.Response response) {
42+
public void onResponse(final AcknowledgedResponse response) {
4243
fail();
4344
}
4445

0 commit comments

Comments
 (0)