-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 2.x] [Point in time] Backport point in time changes (#4616)
* Adding create pit service layer changes Signed-off-by: Bharathwaj G <[email protected]> * Adding delete pit service layer changes Signed-off-by: Bharathwaj G <[email protected]> * Add service layer changes for list all PITs Signed-off-by: Bharathwaj G <[email protected]> * Add Point In Time Node Stats API ServiceLayer Changes Signed-off-by: Bharathwaj G <[email protected]> * Add changes to Point in time segments API service layer Signed-off-by: Bharathwaj G <[email protected]> * Add changes for Create PIT and Delete PIT rest layer and rest high level client Signed-off-by: Bharathwaj G <[email protected]> * Added restlayer changes for pit stats Signed-off-by: Bharathwaj G <[email protected]> * 2.4 specific fixes Signed-off-by: Bharathwaj G <[email protected]> * Modified cat shards test for pit stats Signed-off-by: Bharathwaj G <[email protected]> * Added rest layer changes for List all PITs and PIT segments Signed-off-by: Bharathwaj G <[email protected]>
- Loading branch information
1 parent
a12feea
commit 2c0b4e7
Showing
79 changed files
with
8,097 additions
and
31 deletions.
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
131 changes: 131 additions & 0 deletions
131
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,131 @@ | ||
/* | ||
* 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.action.search.GetAllPitNodesResponse; | ||
import org.opensearch.common.unit.TimeValue; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* 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 createPitResponse = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync); | ||
assertTrue(createPitResponse.getId() != null); | ||
assertEquals(1, createPitResponse.getTotalShards()); | ||
assertEquals(1, createPitResponse.getSuccessfulShards()); | ||
assertEquals(0, createPitResponse.getFailedShards()); | ||
assertEquals(0, createPitResponse.getSkippedShards()); | ||
GetAllPitNodesResponse getAllPitResponse = highLevelClient().getAllPits(RequestOptions.DEFAULT); | ||
List<String> pits = getAllPitResponse.getPitInfos().stream().map(r -> r.getPitId()).collect(Collectors.toList()); | ||
assertTrue(pits.contains(createPitResponse.getId())); | ||
List<String> pitIds = new ArrayList<>(); | ||
pitIds.add(createPitResponse.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(createPitResponse.getId())); | ||
} | ||
|
||
public void testDeleteAllAndListAllPits() 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); | ||
GetAllPitNodesResponse getAllPitResponse = highLevelClient().getAllPits(RequestOptions.DEFAULT); | ||
|
||
List<String> pits = getAllPitResponse.getPitInfos().stream().map(r -> r.getPitId()).collect(Collectors.toList()); | ||
assertTrue(pits.contains(pitResponse.getId())); | ||
assertTrue(pits.contains(pitResponse1.getId())); | ||
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"); | ||
} | ||
} | ||
}; | ||
final CreatePitResponse pitResponse3 = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync); | ||
|
||
ActionListener<GetAllPitNodesResponse> getPitsListener = new ActionListener<GetAllPitNodesResponse>() { | ||
@Override | ||
public void onResponse(GetAllPitNodesResponse response) { | ||
List<String> pits = response.getPitInfos().stream().map(r -> r.getPitId()).collect(Collectors.toList()); | ||
assertTrue(pits.contains(pitResponse3.getId())); | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
if (!(e instanceof OpenSearchStatusException)) { | ||
throw new AssertionError("List all PITs failed", e); | ||
} | ||
} | ||
}; | ||
highLevelClient().getAllPitsAsync(RequestOptions.DEFAULT, getPitsListener); | ||
highLevelClient().deleteAllPitsAsync(RequestOptions.DEFAULT, deletePitListener); | ||
// validate no pits case | ||
getAllPitResponse = highLevelClient().getAllPits(RequestOptions.DEFAULT); | ||
assertTrue(getAllPitResponse.getPitInfos().size() == 0); | ||
highLevelClient().deleteAllPitsAsync(RequestOptions.DEFAULT, deletePitListener); | ||
} | ||
} |
Oops, something went wrong.