From eb39c25bb6ffb803e09adbb5a248aaec11d7994c Mon Sep 17 00:00:00 2001 From: Lakshya Taragi Date: Mon, 21 Oct 2024 01:56:18 +0530 Subject: [PATCH] Spotless changes Signed-off-by: Lakshya Taragi --- .../snapshots/SnapshotStatusApisIT.java | 45 +++++++++++------- .../status/SnapshotsStatusRequest.java | 3 +- .../TransportSnapshotsStatusAction.java | 47 ++++++++++++++----- 3 files changed, 63 insertions(+), 32 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java index 83fa07032ca4e..123277a3780a2 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java @@ -808,7 +808,8 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception { .execute() .actionGet() ); - String cause = "index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]"; + String cause = + "index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]"; assertTrue(ex.getMessage().contains(cause)); }); @@ -840,7 +841,8 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception { .execute() .actionGet() ); - String cause = "index list filter is supported only when a single 'snapshot' is passed, but found 'snapshot' param = [[test-snap-1, test-snap-2]]"; + String cause = + "index list filter is supported only when a single 'snapshot' is passed, but found 'snapshot' param = [[test-snap-1, test-snap-2]]"; assertTrue(ex.getMessage().contains(cause)); }); @@ -918,8 +920,6 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws .put("wait_after_unblock", 200) ); - - logger.info("Create indices"); String index1 = "test-idx-1"; String index2 = "test-idx-2"; @@ -937,11 +937,7 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws logger.info("Create completed snapshot"); String completedSnapshot = "test-completed-snapshot"; String blockedNode = blockNodeWithIndex(repositoryName, index1); - client().admin() - .cluster() - .prepareCreateSnapshot(repositoryName, completedSnapshot) - .setWaitForCompletion(false) - .get(); + client().admin().cluster().prepareCreateSnapshot(repositoryName, completedSnapshot).setWaitForCompletion(false).get(); waitForBlock(blockedNode, repositoryName, TimeValue.timeValueSeconds(60)); unblockNode(repositoryName, blockedNode); waitForCompletion(repositoryName, completedSnapshot, TimeValue.timeValueSeconds(60)); @@ -955,11 +951,7 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws logger.info("Create in-progress snapshot"); String inProgressSnapshot = "test-in-progress-snapshot"; blockedNode = blockNodeWithIndex(repositoryName, index1); - client().admin() - .cluster() - .prepareCreateSnapshot(repositoryName, inProgressSnapshot) - .setWaitForCompletion(false) - .get(); + client().admin().cluster().prepareCreateSnapshot(repositoryName, inProgressSnapshot).setWaitForCompletion(false).get(); waitForBlock(blockedNode, repositoryName, TimeValue.timeValueSeconds(60)); List snapshotStatuses = client().admin() .cluster() @@ -981,7 +973,12 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws assertBusy(() -> { CircuitBreakingException exception = expectThrows( CircuitBreakingException.class, - () -> client().admin().cluster().prepareSnapshotStatus(repositoryName).setSnapshots(inProgressSnapshot).execute().actionGet() + () -> client().admin() + .cluster() + .prepareSnapshotStatus(repositoryName) + .setSnapshots(inProgressSnapshot) + .execute() + .actionGet() ); assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS); assertTrue( @@ -993,7 +990,13 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws assertBusy(() -> { CircuitBreakingException exception = expectThrows( CircuitBreakingException.class, - () -> client().admin().cluster().prepareSnapshotStatus(repositoryName).setSnapshots(inProgressSnapshot).setIndices(index1, index2).execute().actionGet() + () -> client().admin() + .cluster() + .prepareSnapshotStatus(repositoryName) + .setSnapshots(inProgressSnapshot) + .setIndices(index1, index2) + .execute() + .actionGet() ); assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS); assertTrue( @@ -1013,12 +1016,18 @@ public void testSnapshotStatusShardLimitOfResponseForInProgressSnapshot() throws .prepareSnapshotStatus(repositoryName) .setSnapshots(inProgressSnapshot) .get() - .getSnapshots().get(0); + .getSnapshots() + .get(0); assertEquals(3, inProgressSnapshotStatus.getShards().size()); CircuitBreakingException exception = expectThrows( CircuitBreakingException.class, - () -> client().admin().cluster().prepareSnapshotStatus(repositoryName).setSnapshots(inProgressSnapshot, completedSnapshot).execute().actionGet() + () -> client().admin() + .cluster() + .prepareSnapshotStatus(repositoryName) + .setSnapshots(inProgressSnapshot, completedSnapshot) + .execute() + .actionGet() ); assertEquals(exception.status(), RestStatus.TOO_MANY_REQUESTS); assertTrue( diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotsStatusRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotsStatusRequest.java index 221a4d5db1a38..a270dcfa53474 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotsStatusRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/SnapshotsStatusRequest.java @@ -127,7 +127,8 @@ public ActionRequestValidationException validate() { } if (indices.length != 0) { if (repository.equals("_all")) { - String error = "index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]"; + String error = + "index list filter is supported only when a single 'repository' is passed, but found 'repository' param = [_all]"; validationException = addValidationError(error, validationException); } if (snapshots.length != 1) { diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java index d90b2bd299b0e..d0df56b0c71ed 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java @@ -151,7 +151,7 @@ protected void clusterManagerOperation( final ClusterState state, final ActionListener listener ) throws Exception { - requestSetup(request); + setupForRequest(request); final SnapshotsInProgress snapshotsInProgress = state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY); List currentSnapshots = SnapshotsService.currentSnapshots( @@ -193,21 +193,21 @@ protected void clusterManagerOperation( } - private void requestSetup(SnapshotsStatusRequest request) { + private void setupForRequest(SnapshotsStatusRequest request) { requestedIndexNames = new HashSet<>(Arrays.asList(request.indices())); requestUsesIndexFilter = requestedIndexNames.isEmpty() == false; totalShardsRequiredInResponse = 0; maximumAllowedShardCount = clusterService.getClusterSettings().get(MAX_SHARDS_ALLOWED_IN_STATUS_API); } - /* * To get the node IDs of the relevant (according to the index filter) shards which are part of current snapshots * It also deals with any missing indices (for index-filter case) and calculates the number of shards contributed by all * the current snapshots to the total count (irrespective of index-filter) * If this count exceeds the limit, CircuitBreakingException is thrown * */ - private Set getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest request, List currentSnapshots) throws CircuitBreakingException { + private Set getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest request, List currentSnapshots) + throws CircuitBreakingException { Set nodesIdsOfCurrentSnapshotShards = new HashSet<>(); int totalShardsAcrossCurrentSnapshots = 0; @@ -217,7 +217,8 @@ private Set getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest re // index-filter is allowed only for a single snapshot, which has to be this one // first check if any requested indices are missing from this current snapshot - final Set indicesInCurrentSnapshot = currentSnapshotEntry.indices().stream() + final Set indicesInCurrentSnapshot = currentSnapshotEntry.indices() + .stream() .map(IndexId::getName) .collect(Collectors.toSet()); @@ -226,7 +227,13 @@ private Set getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest re .collect(Collectors.toSet()); if (indicesNotFound.isEmpty() == false) { - handleIndexNotFound(requestedIndexNames, indicesNotFound, request, currentSnapshotEntry.snapshot().getSnapshotId().getName(), false); + handleIndexNotFound( + requestedIndexNames, + indicesNotFound, + request, + currentSnapshotEntry.snapshot().getSnapshotId().getName(), + false + ); } // the actual no. of shards contributed by this current snapshot will now be calculated } else { @@ -234,7 +241,8 @@ private Set getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest re totalShardsAcrossCurrentSnapshots = currentSnapshotEntry.shards().size(); } - for (final Map.Entry shardStatusEntry : currentSnapshotEntry.shards().entrySet()) { + for (final Map.Entry shardStatusEntry : currentSnapshotEntry.shards() + .entrySet()) { SnapshotsInProgress.ShardSnapshotStatus shardStatus = shardStatusEntry.getValue(); boolean indexPresentInFilter = requestedIndexNames.contains(shardStatusEntry.getKey().getIndexName()); @@ -261,7 +269,8 @@ private Set getNodeIdsOfCurrentSnapshots(final SnapshotsStatusRequest re // index-filter is allowed only for a single snapshot. If index-filter is being used and limit got exceeded, // this snapshot is current and its relevant indices contribute more shards than the limit - // if index-filter is not being used and limit got exceed, there could be more shards required in response coming from completed snapshots + // if index-filter is not being used and limit got exceed, there could be more shards required in response coming from completed + // snapshots // but since the limit is already exceeded, we can fail request here boolean couldInvolveMoreShards = requestUsesIndexFilter == false; handleMaximumAllowedShardCountExceeded(request.repository(), totalShardsRequiredInResponse, couldInvolveMoreShards); @@ -669,16 +678,28 @@ private void handleIndexNotFound( // remove unavailable indices from the set to be processed indicesToProcess.removeAll(indicesNotFound); } else { - String cause = "indices [" + indices + "] missing in snapshot [" + snapshotName + "] of repository [" + request.repository() + "]"; + String cause = "indices [" + + indices + + "] missing in snapshot [" + + snapshotName + + "] of repository [" + + request.repository() + + "]"; throw new IndexNotFoundException(indices, new IllegalArgumentException(cause)); } } - private void handleMaximumAllowedShardCountExceeded(String repositoryName, int totalContributingShards, boolean couldInvolveMoreShards) throws CircuitBreakingException { + private void handleMaximumAllowedShardCountExceeded(String repositoryName, int totalContributingShards, boolean couldInvolveMoreShards) + throws CircuitBreakingException { String shardCount = "[" + totalContributingShards + (couldInvolveMoreShards ? "+" : "") + "]"; - String message = "[" + repositoryName + "] Total shard count " + shardCount + " is more than the maximum allowed value of shard count [" + - maximumAllowedShardCount + "] for snapshot status request. Try narrowing down the request by using a snapshot list or " + - "an index list for a singular snapshot."; + String message = "[" + + repositoryName + + "] Total shard count " + + shardCount + + " is more than the maximum allowed value of shard count [" + + maximumAllowedShardCount + + "] for snapshot status request. Try narrowing down the request by using a snapshot list or " + + "an index list for a singular snapshot."; throw new CircuitBreakingException(message, CircuitBreaker.Durability.PERMANENT); }