From 619f10d837bbf1e74afca926779a9dabd50b51bb Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:18:19 +0530 Subject: [PATCH] Handle respone for deletion of non-existing autofollow replication rule (#1371) (#1372) Signed-off-by: Sanjay Kumar (cherry picked from commit d4047421120b0f24a12fd67eded3e698b25d05f8) Co-authored-by: Sanjay Kumar <93825455+skumarp7@users.noreply.github.com> --- ...ransportAutoFollowClusterManagerNodeAction.kt | 1 + .../integ/rest/UpdateAutoFollowPatternIT.kt | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/kotlin/org/opensearch/replication/action/autofollow/TransportAutoFollowClusterManagerNodeAction.kt b/src/main/kotlin/org/opensearch/replication/action/autofollow/TransportAutoFollowClusterManagerNodeAction.kt index 140a708d..51a0bd06 100644 --- a/src/main/kotlin/org/opensearch/replication/action/autofollow/TransportAutoFollowClusterManagerNodeAction.kt +++ b/src/main/kotlin/org/opensearch/replication/action/autofollow/TransportAutoFollowClusterManagerNodeAction.kt @@ -123,6 +123,7 @@ class TransportAutoFollowClusterManagerNodeAction @Inject constructor(transportS } catch(e: ResourceNotFoundException) { // Log warn as the task is already removed log.warn("Task already stopped for '$clusterAlias:$patternName'", e) + throw OpenSearchException("Autofollow replication rule $clusterAlias:$patternName does not exist") } catch (e: Exception) { log.error("Failed to stop auto follow task for cluster '$clusterAlias:$patternName'", e) throw OpenSearchException(AUTOFOLLOW_EXCEPTION_GENERIC_STRING) diff --git a/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt b/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt index 2234bd86..bdf51acf 100644 --- a/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt @@ -295,6 +295,22 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() { .hasMessageContaining(errorMsg) } + fun `test deletion of auto follow pattern`() { + val followerClient = getClientForCluster(FOLLOWER) + createConnectionBetweenClusters(FOLLOWER, LEADER, connectionAlias) + followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern) + //Delete a replication rule which does not exist + Assertions.assertThatThrownBy { + followerClient.deleteAutoFollowPattern(connectionAlias, "dummy_conn") + }.isInstanceOf(ResponseException::class.java) + .hasMessageContaining("does not exist") + //Delete a replication rule which exists + Assertions.assertThatCode { + followerClient.deleteAutoFollowPattern(connectionAlias, indexPatternName) + }.doesNotThrowAnyException() + + } + fun `test removing autofollow pattern stop autofollow task`() { val followerClient = getClientForCluster(FOLLOWER) val leaderClient = getClientForCluster(LEADER)