Skip to content

Commit 6eca627

Browse files
authored
Reverse logic for CCR license checks (#33549)
This commit reverses the logic for CCR license checks in a few actions. This is done so that the successful case, which tends to be a larger block of code, does not require indentation.
1 parent edc4924 commit 6eca627

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,21 @@ protected Response newResponse() {
221221
@Override
222222
protected void masterOperation(
223223
final Request request, final ClusterState state, final ActionListener<Response> listener) throws Exception {
224-
if (ccrLicenseChecker.isCcrAllowed()) {
225-
final String[] indices = new String[]{request.getFollowRequest().getLeaderIndex()};
226-
final Map<String, List<String>> remoteClusterIndices = remoteClusterService.groupClusterIndices(indices, s -> false);
227-
if (remoteClusterIndices.containsKey(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY)) {
228-
createFollowerIndexAndFollowLocalIndex(request, state, listener);
229-
} else {
230-
assert remoteClusterIndices.size() == 1;
231-
final Map.Entry<String, List<String>> entry = remoteClusterIndices.entrySet().iterator().next();
232-
assert entry.getValue().size() == 1;
233-
final String clusterAlias = entry.getKey();
234-
final String leaderIndex = entry.getValue().get(0);
235-
createFollowerIndexAndFollowRemoteIndex(request, clusterAlias, leaderIndex, listener);
236-
}
237-
} else {
224+
if (ccrLicenseChecker.isCcrAllowed() == false) {
238225
listener.onFailure(LicenseUtils.newComplianceException("ccr"));
226+
return;
227+
}
228+
final String[] indices = new String[]{request.getFollowRequest().getLeaderIndex()};
229+
final Map<String, List<String>> remoteClusterIndices = remoteClusterService.groupClusterIndices(indices, s -> false);
230+
if (remoteClusterIndices.containsKey(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY)) {
231+
createFollowerIndexAndFollowLocalIndex(request, state, listener);
232+
} else {
233+
assert remoteClusterIndices.size() == 1;
234+
final Map.Entry<String, List<String>> entry = remoteClusterIndices.entrySet().iterator().next();
235+
assert entry.getValue().size() == 1;
236+
final String clusterAlias = entry.getKey();
237+
final String leaderIndex = entry.getValue().get(0);
238+
createFollowerIndexAndFollowRemoteIndex(request, clusterAlias, leaderIndex, listener);
239239
}
240240
}
241241

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,21 @@ public TransportAction(
328328
protected void doExecute(final Task task,
329329
final Request request,
330330
final ActionListener<AcknowledgedResponse> listener) {
331-
if (ccrLicenseChecker.isCcrAllowed()) {
332-
final String[] indices = new String[]{request.leaderIndex};
333-
final Map<String, List<String>> remoteClusterIndices = remoteClusterService.groupClusterIndices(indices, s -> false);
334-
if (remoteClusterIndices.containsKey(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY)) {
335-
followLocalIndex(request, listener);
336-
} else {
337-
assert remoteClusterIndices.size() == 1;
338-
final Map.Entry<String, List<String>> entry = remoteClusterIndices.entrySet().iterator().next();
339-
assert entry.getValue().size() == 1;
340-
final String clusterAlias = entry.getKey();
341-
final String leaderIndex = entry.getValue().get(0);
342-
followRemoteIndex(request, clusterAlias, leaderIndex, listener);
343-
}
344-
} else {
331+
if (ccrLicenseChecker.isCcrAllowed() == false) {
345332
listener.onFailure(LicenseUtils.newComplianceException("ccr"));
333+
return;
334+
}
335+
final String[] indices = new String[]{request.leaderIndex};
336+
final Map<String, List<String>> remoteClusterIndices = remoteClusterService.groupClusterIndices(indices, s -> false);
337+
if (remoteClusterIndices.containsKey(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY)) {
338+
followLocalIndex(request, listener);
339+
} else {
340+
assert remoteClusterIndices.size() == 1;
341+
final Map.Entry<String, List<String>> entry = remoteClusterIndices.entrySet().iterator().next();
342+
assert entry.getValue().size() == 1;
343+
final String clusterAlias = entry.getKey();
344+
final String leaderIndex = entry.getValue().get(0);
345+
followRemoteIndex(request, clusterAlias, leaderIndex, listener);
346346
}
347347
}
348348

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ protected void doExecute(
6565
final Task task,
6666
final CcrStatsAction.TasksRequest request,
6767
final ActionListener<CcrStatsAction.TasksResponse> listener) {
68-
if (ccrLicenseChecker.isCcrAllowed()) {
69-
super.doExecute(task, request, listener);
70-
} else {
68+
if (ccrLicenseChecker.isCcrAllowed() == false) {
7169
listener.onFailure(LicenseUtils.newComplianceException("ccr"));
70+
return;
7271
}
72+
super.doExecute(task, request, listener);
7373
}
7474

7575
@Override

0 commit comments

Comments
 (0)