diff --git a/src/main/kotlin/org/opensearch/replication/action/status/ShardInfoRequest.kt b/src/main/kotlin/org/opensearch/replication/action/status/ShardInfoRequest.kt index 40c0d560..23549470 100644 --- a/src/main/kotlin/org/opensearch/replication/action/status/ShardInfoRequest.kt +++ b/src/main/kotlin/org/opensearch/replication/action/status/ShardInfoRequest.kt @@ -39,7 +39,11 @@ class ShardInfoRequest : BroadcastRequest , 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 { diff --git a/src/main/kotlin/org/opensearch/replication/rest/ReplicationStatusHandler.kt b/src/main/kotlin/org/opensearch/replication/rest/ReplicationStatusHandler.kt index 7e1d926e..50f6f388 100644 --- a/src/main/kotlin/org/opensearch/replication/rest/ReplicationStatusHandler.kt +++ b/src/main/kotlin/org/opensearch/replication/rest/ReplicationStatusHandler.kt @@ -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 { diff --git a/src/test/kotlin/org/opensearch/replication/integ/rest/ReplicationStatusIT.kt b/src/test/kotlin/org/opensearch/replication/integ/rest/ReplicationStatusIT.kt new file mode 100644 index 00000000..4b4e3762 --- /dev/null +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/ReplicationStatusIT.kt @@ -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")) + } + } +}