Skip to content

Commit

Permalink
stopping replication before clean up of indices (#635)
Browse files Browse the repository at this point in the history
Signed-off-by: sricharanvuppu <[email protected]>
  • Loading branch information
sricharanvuppu authored Dec 27, 2022
1 parent e3d0868 commit 93fe3fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class BasicReplicationIT : MultiClusterRestTestCase() {
// Create an empty index on the leader and trigger replication on it
val createIndexResponse = leader.indices().create(CreateIndexRequest(leaderIndex), RequestOptions.DEFAULT)
assertThat(createIndexResponse.isAcknowledged).isTrue()

follower.startReplication(StartReplicationRequest("source", leaderIndex, followerIndex), waitForRestore=true)
val source = mapOf("name" to randomAlphaOfLength(20), "age" to randomInt().toString())
var response = leader.index(IndexRequest(leaderIndex).id("1").source(source), RequestOptions.DEFAULT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import org.junit.After
import org.junit.AfterClass
import org.junit.Before
import org.junit.BeforeClass
import org.opensearch.index.mapper.ObjectMapper
import java.nio.file.Files
import java.security.KeyManagementException
import java.security.KeyStore
Expand Down Expand Up @@ -420,9 +421,7 @@ abstract class MultiClusterRestTestCase : OpenSearchTestCase() {
testCluster.lowLevelClient.performRequest(request)
}
}

protected fun wipeIndicesFromCluster(testCluster: TestCluster) {

private fun stopAllReplicationJobs(testCluster: TestCluster) {
val indicesResponse = testCluster.lowLevelClient.performRequest((Request("GET","/_cat/indices/*,-.*?format=json&pretty")))
val indicesResponseEntity = EntityUtils.toString(indicesResponse.entity)
var parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, indicesResponseEntity)
Expand All @@ -433,18 +432,21 @@ abstract class MultiClusterRestTestCase : OpenSearchTestCase() {
key to value
}
val ind = map.get("index")
try {
try {
val stopRequest = Request("POST","/_plugins/_replication/" + ind.toString() + "/_stop")
stopRequest.setJsonEntity("{}")
stopRequest.setOptions(RequestOptions.DEFAULT)
val response=testCluster.lowLevelClient.performRequest(stopRequest)
}
}
catch (e:ResponseException){
if(e.response.statusLine.statusCode!=400) {
throw e
}
}
}
}
protected fun wipeIndicesFromCluster(testCluster: TestCluster) {
stopAllReplicationJobs(testCluster)
try {
val deleteRequest = Request("DELETE", "*,-.*") // All except system indices
val response = testCluster.lowLevelClient.performRequest(deleteRequest)
Expand Down

0 comments on commit 93fe3fc

Please sign in to comment.