-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add changes for Create PIT and Delete PIT rest layer and rest high level client #4064
Merged
Bukhtawar
merged 23 commits into
opensearch-project:main
from
bharath-techie:createpitrest
Sep 1, 2022
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
49b3f01
Create and delete pit rest layer changes
bharath-techie 6746775
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 1626cfb
addressing review comments
bharath-techie 3bdf1cc
Marking APIs stable
bharath-techie 6ce972e
Addressing comments
bharath-techie 03785b9
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 60b5552
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie dce02c2
changing action name for delete
bharath-techie ce306c1
addressing comments
bharath-techie 94b8a6a
Changing client due to change in security action and also fixing conc…
bharath-techie 5203a3c
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 90bdb5f
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 1be4e8b
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 611a43b
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie f1b408c
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 4ec23ca
Fixing rest client tests
bharath-techie 66b0ca7
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 2e97a58
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 7796ace
Changes to make security granular for PIT Ids for delete and get pits…
bharath-techie 40ac831
Fixing build
bharath-techie fab586c
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 1c714c7
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
bharath-techie 6412c08
addressing review comment
bharath-techie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
client/rest-high-level/src/test/java/org/opensearch/client/PitIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.client; | ||
|
||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.client.methods.HttpPut; | ||
import org.junit.Before; | ||
import org.opensearch.OpenSearchStatusException; | ||
import org.opensearch.action.ActionListener; | ||
import org.opensearch.action.search.CreatePitRequest; | ||
import org.opensearch.action.search.CreatePitResponse; | ||
import org.opensearch.action.search.DeletePitInfo; | ||
import org.opensearch.action.search.DeletePitRequest; | ||
import org.opensearch.action.search.DeletePitResponse; | ||
import org.opensearch.common.unit.TimeValue; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Tests point in time API with rest high level client | ||
*/ | ||
public class PitIT extends OpenSearchRestHighLevelClientTestCase { | ||
|
||
@Before | ||
public void indexDocuments() throws IOException { | ||
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index/_doc/1"); | ||
doc1.setJsonEntity("{\"type\":\"type1\", \"id\":1, \"num\":10, \"num2\":50}"); | ||
client().performRequest(doc1); | ||
Request doc2 = new Request(HttpPut.METHOD_NAME, "/index/_doc/2"); | ||
doc2.setJsonEntity("{\"type\":\"type1\", \"id\":2, \"num\":20, \"num2\":40}"); | ||
client().performRequest(doc2); | ||
Request doc3 = new Request(HttpPut.METHOD_NAME, "/index/_doc/3"); | ||
doc3.setJsonEntity("{\"type\":\"type1\", \"id\":3, \"num\":50, \"num2\":35}"); | ||
client().performRequest(doc3); | ||
Request doc4 = new Request(HttpPut.METHOD_NAME, "/index/_doc/4"); | ||
doc4.setJsonEntity("{\"type\":\"type2\", \"id\":4, \"num\":100, \"num2\":10}"); | ||
client().performRequest(doc4); | ||
Request doc5 = new Request(HttpPut.METHOD_NAME, "/index/_doc/5"); | ||
doc5.setJsonEntity("{\"type\":\"type2\", \"id\":5, \"num\":100, \"num2\":10}"); | ||
client().performRequest(doc5); | ||
client().performRequest(new Request(HttpPost.METHOD_NAME, "/_refresh")); | ||
} | ||
|
||
public void testCreateAndDeletePit() throws IOException { | ||
CreatePitRequest pitRequest = new CreatePitRequest(new TimeValue(1, TimeUnit.DAYS), true, "index"); | ||
CreatePitResponse pitResponse = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync); | ||
assertTrue(pitResponse.getId() != null); | ||
assertEquals(1, pitResponse.getTotalShards()); | ||
assertEquals(1, pitResponse.getSuccessfulShards()); | ||
assertEquals(0, pitResponse.getFailedShards()); | ||
assertEquals(0, pitResponse.getSkippedShards()); | ||
List<String> pitIds = new ArrayList<>(); | ||
pitIds.add(pitResponse.getId()); | ||
DeletePitRequest deletePitRequest = new DeletePitRequest(pitIds); | ||
DeletePitResponse deletePitResponse = execute(deletePitRequest, highLevelClient()::deletePit, highLevelClient()::deletePitAsync); | ||
assertTrue(deletePitResponse.getDeletePitResults().get(0).isSuccessful()); | ||
assertTrue(deletePitResponse.getDeletePitResults().get(0).getPitId().equals(pitResponse.getId())); | ||
} | ||
|
||
public void testDeleteAllPits() throws IOException { | ||
CreatePitRequest pitRequest = new CreatePitRequest(new TimeValue(1, TimeUnit.DAYS), true, "index"); | ||
CreatePitResponse pitResponse = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync); | ||
CreatePitResponse pitResponse1 = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync); | ||
assertTrue(pitResponse.getId() != null); | ||
assertTrue(pitResponse1.getId() != null); | ||
DeletePitResponse deletePitResponse = highLevelClient().deleteAllPits(RequestOptions.DEFAULT); | ||
for (DeletePitInfo deletePitInfo : deletePitResponse.getDeletePitResults()) { | ||
assertTrue(deletePitInfo.isSuccessful()); | ||
} | ||
pitResponse = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync); | ||
pitResponse1 = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync); | ||
assertTrue(pitResponse.getId() != null); | ||
assertTrue(pitResponse1.getId() != null); | ||
ActionListener<DeletePitResponse> deletePitListener = new ActionListener<>() { | ||
@Override | ||
public void onResponse(DeletePitResponse response) { | ||
for (DeletePitInfo deletePitInfo : response.getDeletePitResults()) { | ||
assertTrue(deletePitInfo.isSuccessful()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
if (!(e instanceof OpenSearchStatusException)) { | ||
throw new AssertionError("Delete all failed"); | ||
} | ||
} | ||
}; | ||
highLevelClient().deleteAllPitsAsync(RequestOptions.DEFAULT, deletePitListener); | ||
// validate no pits case | ||
highLevelClient().deleteAllPitsAsync(RequestOptions.DEFAULT, deletePitListener); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be not needed, the next line does
params.withIndicesOptions(searchRequest.indicesOptions());
unconditionally