From a045b2f9064142b1041b9d3d7fa8312d35faa0aa Mon Sep 17 00:00:00 2001 From: Harsh Jain Date: Thu, 9 Mar 2023 18:30:20 +0530 Subject: [PATCH] Removed NOT_FOUND for empty results. (#6544) * Removed NOT_FOUND for empty results. Signed-off-by: Harsh Jain * Fixed failing tests. Signed-off-by: Harsh Jain * Removed unnecessary semi-colon. Signed-off-by: Harsh Jain Signed-off-by: Harsh Jain * Added change log. Signed-off-by: Harsh Jain * Fixed formatting issues Signed-off-by: Harsh Jain * Backported to 2.x branch Signed-off-by: Harsh Jain * Removed duplicate entry as this entry is present under [Unrelease 2.x]. Signed-off-by: Harsh Jain * Updated changelog to make it more meaningful. Signed-off-by: Harsh Jain --------- Signed-off-by: Harsh Jain Co-authored-by: Harsh Jain (cherry picked from commit 67a9b439db79f2782a3fd071004e3ff02c59ba13) --- CHANGELOG.md | 1 + .../src/main/resources/rest-api-spec/test/pit/10_basic.yml | 6 ++++-- .../org/opensearch/action/search/DeletePitResponse.java | 2 -- .../java/org/opensearch/search/DeletePitResponseTests.java | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b40b9d39496e..bf1617949d835 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - [Segment Replication] Allocation and rebalancing based on average primary shard count per index ([#6422](https://github.com/opensearch-project/OpenSearch/pull/6422)) - The truncation limit of the OpenSearchJsonLayout logger is now configurable ([#6569](https://github.com/opensearch-project/OpenSearch/pull/6569)) - Add 'base_path' setting to File System Repository ([#6558](https://github.com/opensearch-project/OpenSearch/pull/6558)) +- Return success on DeletePits when no PITs exist. ([#6544](https://github.com/opensearch-project/OpenSearch/pull/6544)) ### Dependencies - Bump `org.apache.logging.log4j:log4j-core` from 2.18.0 to 2.20.0 ([#6490](https://github.com/opensearch-project/OpenSearch/pull/6490)) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/pit/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/pit/10_basic.yml index 84ff85f465f8b..9d1ee7571f2e2 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/pit/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/pit/10_basic.yml @@ -138,5 +138,7 @@ - match: {pits.0.successful: true } - do: - catch: missing - delete_all_pits: { } + delete_all_pits: {} + + - match: {pits: []} + - length: {pits: 0} diff --git a/server/src/main/java/org/opensearch/action/search/DeletePitResponse.java b/server/src/main/java/org/opensearch/action/search/DeletePitResponse.java index cdbeb3dc2b749..5ea959bc9acf9 100644 --- a/server/src/main/java/org/opensearch/action/search/DeletePitResponse.java +++ b/server/src/main/java/org/opensearch/action/search/DeletePitResponse.java @@ -24,7 +24,6 @@ import java.util.List; import static org.opensearch.common.xcontent.ConstructingObjectParser.constructorArg; -import static org.opensearch.rest.RestStatus.NOT_FOUND; import static org.opensearch.rest.RestStatus.OK; /** @@ -57,7 +56,6 @@ public List getDeletePitResults() { */ @Override public RestStatus status() { - if (deletePitResults.isEmpty()) return NOT_FOUND; return OK; } diff --git a/server/src/test/java/org/opensearch/search/DeletePitResponseTests.java b/server/src/test/java/org/opensearch/search/DeletePitResponseTests.java index 5944e2a35b14a..60330f189362e 100644 --- a/server/src/test/java/org/opensearch/search/DeletePitResponseTests.java +++ b/server/src/test/java/org/opensearch/search/DeletePitResponseTests.java @@ -43,7 +43,7 @@ public void testDeletePitResponseToXContent() throws IOException { public void testDeletePitResponseToAndFromXContent() throws IOException { XContentType xContentType = randomFrom(XContentType.values()); DeletePitResponse originalResponse = createDeletePitResponseTestItem(); - ; + BytesReference originalBytes = toShuffledXContent(originalResponse, xContentType, ToXContent.EMPTY_PARAMS, randomBoolean()); DeletePitResponse parsedResponse; try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {