Skip to content

Commit

Permalink
Moving empty IndicesStats creation to Response class
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Garg <[email protected]>
  • Loading branch information
Harsh Garg committed Oct 23, 2024
1 parent 016fcaf commit 2099d92
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void onResponse(ClusterStateResponse clusterStateResponse) {
catShardsResponse.setPageToken(Objects.isNull(paginationStrategy) ? null : paginationStrategy.getResponseToken());
// For paginated queries, if strategy outputs no shards to be returned, avoid fetching IndicesStats.
if (shouldSkipIndicesStatsRequest(paginationStrategy)) {
catShardsResponse.setIndicesStatsResponse(EMPTY_INDICES_STATS_RESPONSE);
catShardsResponse.setIndicesStatsResponse(IndicesStatsResponse.getEmptyResponse());
cancellableListener.onResponse(catShardsResponse);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.opensearch.core.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -230,4 +231,8 @@ static final class Fields {
public String toString() {
return Strings.toString(MediaTypeRegistry.JSON, this, true, false);
}

public static IndicesStatsResponse getEmptyResponse() {
return new IndicesStatsResponse(new ShardStats[0], 0, 0, 0, Collections.emptyList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void onResponse(ClusterStateResponse clusterStateResponse) {
// For paginated queries, if strategy outputs no indices to be returned,
// avoid fetching indices stats.
if (shouldSkipIndicesStatsRequest(paginationStrategy)) {
groupedListener.onResponse(EMPTY_INDICES_STATS_RESPONSE);
groupedListener.onResponse(IndicesStatsResponse.getEmptyResponse());
} else {
sendIndicesStatsRequest(
indicesToBeQueried,
Expand Down

0 comments on commit 2099d92

Please sign in to comment.