Skip to content

Commit

Permalink
Enhanced status API validations to check for index name (#317)
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Kumar <[email protected]>
  • Loading branch information
saikaranam-amazon authored Mar 8, 2022
1 parent c068e26 commit 67afce7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class ShardInfoRequest : BroadcastRequest<ShardInfoRequest> , ToXContentObject {
}

override fun validate(): ActionRequestValidationException? {
return null
var validationException = ActionRequestValidationException()
if(indexName.isEmpty()) {
validationException.addValidationError("Index name must be specified to obtain replication status")
}
return if(validationException.validationErrors().isEmpty()) return null else validationException
}

override fun indices(): Array<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ReplicationStatusHandler : BaseRestHandler() {

@Throws(IOException::class)
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
val index = request.param("index")
val index = request.param("index", "")
var isVerbose = (request.paramAsBoolean("verbose", false))
val indexReplicationStatusRequest = ShardInfoRequest(index,isVerbose)
return RestChannelConsumer {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.replication.integ.rest

import org.assertj.core.api.Assertions
import org.junit.Assert
import org.opensearch.client.RequestOptions
import org.opensearch.client.ResponseException
import org.opensearch.client.indices.CreateIndexRequest
import org.opensearch.replication.MultiClusterAnnotations
import org.opensearch.replication.MultiClusterRestTestCase
import org.opensearch.replication.startReplication
import org.opensearch.replication.stopReplication
import org.opensearch.replication.StartReplicationRequest
import org.opensearch.replication.replicationStatus
import org.opensearch.replication.`validate status syncing response`
import java.util.concurrent.TimeUnit

@MultiClusterAnnotations.ClusterConfigurations(
MultiClusterAnnotations.ClusterConfiguration(clusterName = LEADER),
MultiClusterAnnotations.ClusterConfiguration(clusterName = FOLLOWER)
)
class ReplicationStatusIT: MultiClusterRestTestCase() {

fun `test replication status with valid params`() {
val followerClient = getClientForCluster(FOLLOWER)
val leaderClient = getClientForCluster(LEADER)
val indexName = "test-status-valid-param"
createConnectionBetweenClusters(FOLLOWER, LEADER)
val createIndexResponse = leaderClient.indices().create(CreateIndexRequest(indexName), RequestOptions.DEFAULT)
Assertions.assertThat(createIndexResponse.isAcknowledged).isTrue()
try {
followerClient.startReplication(StartReplicationRequest("source", indexName, indexName), waitForRestore = true)
assertBusy({
var statusResp = followerClient.replicationStatus(indexName)
`validate status syncing response`(statusResp)
}, 30, TimeUnit.SECONDS)
} finally {
followerClient.stopReplication(indexName)
}
}

fun `test replication status without valid params`() {
val followerClient = getClientForCluster(FOLLOWER)
createConnectionBetweenClusters(FOLLOWER, LEADER)
try {
followerClient.replicationStatus("")
Assert.fail("Status API shouldn't succeed in this case")
} catch (e: ResponseException) {
Assert.assertEquals(e.response.statusLine.statusCode, 400)
Assert.assertTrue(e.message != null)
Assert.assertTrue(e.message!!.contains("Index name must be specified to obtain replication status"))
}
}
}

0 comments on commit 67afce7

Please sign in to comment.