Skip to content

Commit 66b164c

Browse files
authored
[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 5330067 commit 66b164c

File tree

3 files changed

+60
-46
lines changed

3 files changed

+60
-46
lines changed

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

+43-26
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
import java.util.concurrent.atomic.AtomicReferenceArray;
6363
import java.util.stream.Collectors;
6464

65-
public class FollowIndexAction extends Action<FollowIndexAction.Response> {
65+
public class FollowIndexAction extends Action<AcknowledgedResponse> {
6666

6767
public static final FollowIndexAction INSTANCE = new FollowIndexAction();
6868
public static final String NAME = "cluster:admin/xpack/ccr/follow_index";
@@ -72,8 +72,8 @@ private FollowIndexAction() {
7272
}
7373

7474
@Override
75-
public Response newResponse() {
76-
return new Response();
75+
public AcknowledgedResponse newResponse() {
76+
return new AcknowledgedResponse();
7777
}
7878

7979
public static class Request extends ActionRequest implements ToXContentObject {
@@ -129,9 +129,17 @@ public static Request fromXContent(XContentParser parser, String followerIndex)
129129
private TimeValue retryTimeout;
130130
private TimeValue idleShardRetryDelay;
131131

132-
public Request(String leaderIndex, String followerIndex, Integer maxBatchOperationCount, Integer maxConcurrentReadBatches,
133-
Long maxOperationSizeInBytes, Integer maxConcurrentWriteBatches, Integer maxWriteBufferSize,
134-
TimeValue retryTimeout, TimeValue idleShardRetryDelay) {
132+
public Request(
133+
String leaderIndex,
134+
String followerIndex,
135+
Integer maxBatchOperationCount,
136+
Integer maxConcurrentReadBatches,
137+
Long maxOperationSizeInBytes,
138+
Integer maxConcurrentWriteBatches,
139+
Integer maxWriteBufferSize,
140+
TimeValue retryTimeout,
141+
TimeValue idleShardRetryDelay) {
142+
135143
if (leaderIndex == null) {
136144
throw new IllegalArgumentException("leader_index is missing");
137145
}
@@ -271,22 +279,21 @@ public boolean equals(Object o) {
271279

272280
@Override
273281
public int hashCode() {
274-
return Objects.hash(leaderIndex, followerIndex, maxBatchOperationCount, maxConcurrentReadBatches, maxOperationSizeInBytes,
275-
maxConcurrentWriteBatches, maxWriteBufferSize, retryTimeout, idleShardRetryDelay);
276-
}
277-
}
278-
279-
public static class Response extends AcknowledgedResponse {
280-
281-
Response() {
282-
}
283-
284-
Response(boolean acknowledged) {
285-
super(acknowledged);
282+
return Objects.hash(
283+
leaderIndex,
284+
followerIndex,
285+
maxBatchOperationCount,
286+
maxConcurrentReadBatches,
287+
maxOperationSizeInBytes,
288+
maxConcurrentWriteBatches,
289+
maxWriteBufferSize,
290+
retryTimeout,
291+
idleShardRetryDelay
292+
);
286293
}
287294
}
288295

289-
public static class TransportAction extends HandledTransportAction<Request, Response> {
296+
public static class TransportAction extends HandledTransportAction<Request, AcknowledgedResponse> {
290297

291298
private final Client client;
292299
private final ThreadPool threadPool;
@@ -318,7 +325,9 @@ public TransportAction(
318325
}
319326

320327
@Override
321-
protected void doExecute(final Task task, final Request request, final ActionListener<Response> listener) {
328+
protected void doExecute(final Task task,
329+
final Request request,
330+
final ActionListener<AcknowledgedResponse> listener) {
322331
if (ccrLicenseChecker.isCcrAllowed()) {
323332
final String[] indices = new String[]{request.leaderIndex};
324333
final Map<String, List<String>> remoteClusterIndices = remoteClusterService.groupClusterIndices(indices, s -> false);
@@ -337,7 +346,8 @@ protected void doExecute(final Task task, final Request request, final ActionLis
337346
}
338347
}
339348

340-
private void followLocalIndex(final Request request, final ActionListener<Response> listener) {
349+
private void followLocalIndex(final Request request,
350+
final ActionListener<AcknowledgedResponse> listener) {
341351
final ClusterState state = clusterService.state();
342352
final IndexMetaData followerIndexMetadata = state.getMetaData().index(request.getFollowerIndex());
343353
// following an index in local cluster, so use local cluster state to fetch leader index metadata
@@ -353,7 +363,7 @@ private void followRemoteIndex(
353363
final Request request,
354364
final String clusterAlias,
355365
final String leaderIndex,
356-
final ActionListener<Response> listener) {
366+
final ActionListener<AcknowledgedResponse> listener) {
357367
final ClusterState state = clusterService.state();
358368
final IndexMetaData followerIndexMetadata = state.getMetaData().index(request.getFollowerIndex());
359369
ccrLicenseChecker.checkRemoteClusterLicenseAndFetchLeaderIndexMetadata(
@@ -380,8 +390,13 @@ private void followRemoteIndex(
380390
* <li>The leader index and follow index need to have the same number of primary shards</li>
381391
* </ul>
382392
*/
383-
void start(Request request, String clusterNameAlias, IndexMetaData leaderIndexMetadata, IndexMetaData followIndexMetadata,
384-
ActionListener<Response> handler) throws IOException {
393+
void start(
394+
Request request,
395+
String clusterNameAlias,
396+
IndexMetaData leaderIndexMetadata,
397+
IndexMetaData followIndexMetadata,
398+
ActionListener<AcknowledgedResponse> handler) throws IOException {
399+
385400
MapperService mapperService = followIndexMetadata != null ? indicesService.createIndexMapperService(followIndexMetadata) : null;
386401
validate(request, leaderIndexMetadata, followIndexMetadata, mapperService);
387402
final int numShards = followIndexMetadata.getNumberOfShards();
@@ -429,7 +444,7 @@ void finalizeResponse() {
429444

430445
if (error == null) {
431446
// include task ids?
432-
handler.onResponse(new Response(true));
447+
handler.onResponse(new AcknowledgedResponse(true));
433448
} else {
434449
// TODO: cancel all started tasks
435450
handler.onFailure(error);
@@ -493,7 +508,9 @@ void finalizeResponse() {
493508
WHITELISTED_SETTINGS = Collections.unmodifiableSet(whiteListedSettings);
494509
}
495510

496-
static void validate(Request request, IndexMetaData leaderIndex, IndexMetaData followIndex, MapperService followerMapperService) {
511+
static void validate(Request request,
512+
IndexMetaData leaderIndex,
513+
IndexMetaData followIndex, MapperService followerMapperService) {
497514
if (leaderIndex == null) {
498515
throw new IllegalArgumentException("leader index [" + request.leaderIndex + "] does not exist");
499516
}

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

+14-18
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.concurrent.atomic.AtomicInteger;
2929
import java.util.concurrent.atomic.AtomicReferenceArray;
3030

31-
public class UnfollowIndexAction extends Action<UnfollowIndexAction.Response> {
31+
public class UnfollowIndexAction extends Action<AcknowledgedResponse> {
3232

3333
public static final UnfollowIndexAction INSTANCE = new UnfollowIndexAction();
3434
public static final String NAME = "cluster:admin/xpack/ccr/unfollow_index";
@@ -38,8 +38,8 @@ private UnfollowIndexAction() {
3838
}
3939

4040
@Override
41-
public Response newResponse() {
42-
return new Response();
41+
public AcknowledgedResponse newResponse() {
42+
return new AcknowledgedResponse();
4343
}
4444

4545
public static class Request extends ActionRequest {
@@ -72,31 +72,27 @@ public void writeTo(StreamOutput out) throws IOException {
7272
}
7373
}
7474

75-
public static class Response extends AcknowledgedResponse {
76-
77-
Response(boolean acknowledged) {
78-
super(acknowledged);
79-
}
80-
81-
Response() {
82-
}
83-
}
84-
85-
public static class TransportAction extends HandledTransportAction<Request, Response> {
75+
public static class TransportAction extends HandledTransportAction<Request, AcknowledgedResponse> {
8676

8777
private final Client client;
8878
private final PersistentTasksService persistentTasksService;
8979

9080
@Inject
91-
public TransportAction(Settings settings, TransportService transportService,
92-
ActionFilters actionFilters, Client client, PersistentTasksService persistentTasksService) {
81+
public TransportAction(Settings settings,
82+
TransportService transportService,
83+
ActionFilters actionFilters,
84+
Client client,
85+
PersistentTasksService persistentTasksService) {
9386
super(settings, NAME, transportService, actionFilters, Request::new);
9487
this.client = client;
9588
this.persistentTasksService = persistentTasksService;
9689
}
9790

9891
@Override
99-
protected void doExecute(Task task, Request request, ActionListener<Response> listener) {
92+
protected void doExecute(Task task,
93+
Request request,
94+
ActionListener<AcknowledgedResponse> listener) {
95+
10096
client.admin().cluster().state(new ClusterStateRequest(), ActionListener.wrap(r -> {
10197
IndexMetaData followIndexMetadata = r.getState().getMetaData().index(request.followIndex);
10298
if (followIndexMetadata == null) {
@@ -140,7 +136,7 @@ void finalizeResponse() {
140136

141137
if (error == null) {
142138
// include task ids?
143-
listener.onResponse(new Response(true));
139+
listener.onResponse(new AcknowledgedResponse(true));
144140
} else {
145141
// TODO: cancel all started tasks
146142
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)