Skip to content

Commit eb39c25

Browse files
committed
Spotless changes
Signed-off-by: Lakshya Taragi <[email protected]>
1 parent a38968e commit eb39c25

File tree

3 files changed

+63
-32
lines changed

3 files changed

+63
-32
lines changed

server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception {
808808
.execute()
809809
.actionGet()
810810
);
811-
String cause = "index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]";
811+
String cause =
812+
"index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]";
812813
assertTrue(ex.getMessage().contains(cause));
813814
});
814815

@@ -840,7 +841,8 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception {
840841
.execute()
841842
.actionGet()
842843
);
843-
String cause = "index list filter is supported only when a single 'snapshot' is passed, but found 'snapshot' param = [[test-snap-1, test-snap-2]]";
844+
String cause =
845+
"index list filter is supported only when a single 'snapshot' is passed, but found 'snapshot' param = [[test-snap-1, test-snap-2]]";
844846
assertTrue(ex.getMessage().contains(cause));
845847
});
846848

@@ -918,8 +920,6 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
918920
.put("wait_after_unblock", 200)
919921
);
920922

921-
922-
923923
logger.info("Create indices");
924924
String index1 = "test-idx-1";
925925
String index2 = "test-idx-2";
@@ -937,11 +937,7 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
937937
logger.info("Create completed snapshot");
938938
String completedSnapshot = "test-completed-snapshot";
939939
String blockedNode = blockNodeWithIndex(repositoryName, index1);
940-
client().admin()
941-
.cluster()
942-
.prepareCreateSnapshot(repositoryName, completedSnapshot)
943-
.setWaitForCompletion(false)
944-
.get();
940+
client().admin().cluster().prepareCreateSnapshot(repositoryName, completedSnapshot).setWaitForCompletion(false).get();
945941
waitForBlock(blockedNode, repositoryName, TimeValue.timeValueSeconds(60));
946942
unblockNode(repositoryName, blockedNode);
947943
waitForCompletion(repositoryName, completedSnapshot, TimeValue.timeValueSeconds(60));
@@ -955,11 +951,7 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
955951
logger.info("Create in-progress snapshot");
956952
String inProgressSnapshot = "test-in-progress-snapshot";
957953
blockedNode = blockNodeWithIndex(repositoryName, index1);
958-
client().admin()
959-
.cluster()
960-
.prepareCreateSnapshot(repositoryName, inProgressSnapshot)
961-
.setWaitForCompletion(false)
962-
.get();
954+
client().admin().cluster().prepareCreateSnapshot(repositoryName, inProgressSnapshot).setWaitForCompletion(false).get();
963955
waitForBlock(blockedNode, repositoryName, TimeValue.timeValueSeconds(60));
964956
List<SnapshotStatus> snapshotStatuses = client().admin()
965957
.cluster()
@@ -981,7 +973,12 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
981973
assertBusy(() -> {
982974
CircuitBreakingException exception = expectThrows(
983975
CircuitBreakingException.class,
984-
() -> client().admin().cluster().prepareSnapshotStatus(repositoryName).setSnapshots(inProgressSnapshot).execute().actionGet()
976+
() -> client().admin()
977+
.cluster()
978+
.prepareSnapshotStatus(repositoryName)
979+
.setSnapshots(inProgressSnapshot)
980+
.execute()
981+
.actionGet()
985982
);
986983
assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS);
987984
assertTrue(
@@ -993,7 +990,13 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
993990
assertBusy(() -> {
994991
CircuitBreakingException exception = expectThrows(
995992
CircuitBreakingException.class,
996-
() -> client().admin().cluster().prepareSnapshotStatus(repositoryName).setSnapshots(inProgressSnapshot).setIndices(index1, index2).execute().actionGet()
993+
() -> client().admin()
994+
.cluster()
995+
.prepareSnapshotStatus(repositoryName)
996+
.setSnapshots(inProgressSnapshot)
997+
.setIndices(index1, index2)
998+
.execute()
999+
.actionGet()
9971000
);
9981001
assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS);
9991002
assertTrue(
@@ -1013,12 +1016,18 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws
10131016
.prepareSnapshotStatus(repositoryName)
10141017
.setSnapshots(inProgressSnapshot)
10151018
.get()
1016-
.getSnapshots().get(0);
1019+
.getSnapshots()
1020+
.get(0);
10171021
assertEquals(3, inProgressSnapshotStatus.getShards().size());
10181022

10191023
CircuitBreakingException exception = expectThrows(
10201024
CircuitBreakingException.class,
1021-
() -> client().admin().cluster().prepareSnapshotStatus(repositoryName).setSnapshots(inProgressSnapshot, completedSnapshot).execute().actionGet()
1025+
() -> client().admin()
1026+
.cluster()
1027+
.prepareSnapshotStatus(repositoryName)
1028+
.setSnapshots(inProgressSnapshot, completedSnapshot)
1029+
.execute()
1030+
.actionGet()
10221031
);
10231032
assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS);
10241033
assertTrue(

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotsStatusRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ public ActionRequestValidationException validate() {
127127
}
128128
if (indices.length != 0) {
129129
if (repository.equals("_all")) {
130-
String error = "index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]";
130+
String error =
131+
"index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]";
131132
validationException = addValidationError(error, validationException);
132133
}
133134
if (snapshots.length != 1) {

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected void clusterManagerOperation(
151151
final ClusterState state,
152152
final ActionListener<SnapshotsStatusResponse> listener
153153
) throws Exception {
154-
requestSetup(request);
154+
setupForRequest(request);
155155

156156
final SnapshotsInProgress snapshotsInProgress = state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY);
157157
List<SnapshotsInProgress.Entry> currentSnapshots = SnapshotsService.currentSnapshots(
@@ -193,21 +193,21 @@ protected void clusterManagerOperation(
193193

194194
}
195195

196-
private void requestSetup(SnapshotsStatusRequest request) {
196+
private void setupForRequest(SnapshotsStatusRequest request) {
197197
requestedIndexNames = new HashSet<>(Arrays.asList(request.indices()));
198198
requestUsesIndexFilter = requestedIndexNames.isEmpty() == false;
199199
totalShardsRequiredInResponse = 0;
200200
maximumAllowedShardCount = clusterService.getClusterSettings().get(MAX_SHARDS_ALLOWED_IN_STATUS_API);
201201
}
202202

203-
204203
/*
205204
* To get the node IDs of the relevant (according to the index filter) shards which are part of current snapshots
206205
* It also deals with any missing indices (for index-filter case) and calculates the number of shards contributed by all
207206
* the current snapshots to the total count (irrespective of index-filter)
208207
* If this count exceeds the limit, CircuitBreakingException is thrown
209208
* */
210-
private Set<String> getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest request, List<SnapshotsInProgress.Entry> currentSnapshots) throws CircuitBreakingException {
209+
private Set<String> getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest request, List<SnapshotsInProgress.Entry> currentSnapshots)
210+
throws CircuitBreakingException {
211211
Set<String> nodesIdsOfCurrentSnapshotShards = new HashSet<>();
212212
int totalShardsAcrossCurrentSnapshots = 0;
213213

@@ -217,7 +217,8 @@ private Set<String> getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest re
217217
// index-filter is allowed only for a single snapshot, which has to be this one
218218
// first check if any requested indices are missing from this current snapshot
219219

220-
final Set<String> indicesInCurrentSnapshot = currentSnapshotEntry.indices().stream()
220+
final Set<String> indicesInCurrentSnapshot = currentSnapshotEntry.indices()
221+
.stream()
221222
.map(IndexId::getName)
222223
.collect(Collectors.toSet());
223224

@@ -226,15 +227,22 @@ private Set<String> getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest re
226227
.collect(Collectors.toSet());
227228

228229
if (indicesNotFound.isEmpty() == false) {
229-
handleIndexNotFound(requestedIndexNames, indicesNotFound, request, currentSnapshotEntry.snapshot().getSnapshotId().getName(), false);
230+
handleIndexNotFound(
231+
requestedIndexNames,
232+
indicesNotFound,
233+
request,
234+
currentSnapshotEntry.snapshot().getSnapshotId().getName(),
235+
false
236+
);
230237
}
231238
// the actual no. of shards contributed by this current snapshot will now be calculated
232239
} else {
233240
// all shards of this current snapshot are required in response
234241
totalShardsAcrossCurrentSnapshots = currentSnapshotEntry.shards().size();
235242
}
236243

237-
for (final Map.Entry<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shardStatusEntry : currentSnapshotEntry.shards().entrySet()) {
244+
for (final Map.Entry<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shardStatusEntry : currentSnapshotEntry.shards()
245+
.entrySet()) {
238246
SnapshotsInProgress.ShardSnapshotStatus shardStatus = shardStatusEntry.getValue();
239247
boolean indexPresentInFilter = requestedIndexNames.contains(shardStatusEntry.getKey().getIndexName());
240248

@@ -261,7 +269,8 @@ private Set<String> getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest re
261269
// index-filter is allowed only for a single snapshot. If index-filter is being used and limit got exceeded,
262270
// this snapshot is current and its relevant indices contribute more shards than the limit
263271

264-
// if index-filter is not being used and limit got exceed, there could be more shards required in response coming from completed snapshots
272+
// if index-filter is not being used and limit got exceed, there could be more shards required in response coming from completed
273+
// snapshots
265274
// but since the limit is already exceeded, we can fail request here
266275
boolean couldInvolveMoreShards = requestUsesIndexFilter == false;
267276
handleMaximumAllowedShardCountExceeded(request.repository(), totalShardsRequiredInResponse, couldInvolveMoreShards);
@@ -669,16 +678,28 @@ private void handleIndexNotFound(
669678
// remove unavailable indices from the set to be processed
670679
indicesToProcess.removeAll(indicesNotFound);
671680
} else {
672-
String cause = "indices [" + indices + "] missing in snapshot [" + snapshotName + "] of repository [" + request.repository() + "]";
681+
String cause = "indices ["
682+
+ indices
683+
+ "] missing in snapshot ["
684+
+ snapshotName
685+
+ "] of repository ["
686+
+ request.repository()
687+
+ "]";
673688
throw new IndexNotFoundException(indices, new IllegalArgumentException(cause));
674689
}
675690
}
676691

677-
private void handleMaximumAllowedShardCountExceeded(String repositoryName, int totalContributingShards, boolean couldInvolveMoreShards) throws CircuitBreakingException {
692+
private void handleMaximumAllowedShardCountExceeded(String repositoryName, int totalContributingShards, boolean couldInvolveMoreShards)
693+
throws CircuitBreakingException {
678694
String shardCount = "[" + totalContributingShards + (couldInvolveMoreShards ? "+" : "") + "]";
679-
String message = "[" + repositoryName + "] Total shard count " + shardCount + " is more than the maximum allowed value of shard count [" +
680-
maximumAllowedShardCount + "] for snapshot status request. Try narrowing down the request by using a snapshot list or " +
681-
"an index list for a singular snapshot.";
695+
String message = "["
696+
+ repositoryName
697+
+ "] Total shard count "
698+
+ shardCount
699+
+ " is more than the maximum allowed value of shard count ["
700+
+ maximumAllowedShardCount
701+
+ "] for snapshot status request. Try narrowing down the request by using a snapshot list or "
702+
+ "an index list for a singular snapshot.";
682703

683704
throw new CircuitBreakingException(message, CircuitBreaker.Durability.PERMANENT);
684705
}

0 commit comments

Comments
 (0)