From 74013ded4f12cdabd9dce47fefa35dd29bade11f Mon Sep 17 00:00:00 2001 From: Sanjay Kumar <93825455+skumarp7@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:17:39 +0530 Subject: [PATCH] backport 1405 to 2.x (#1415) Signed-off-by: Sanjay Kumar --- ...sportAutoFollowClusterManagerNodeAction.kt | 1 + .../integ/rest/UpdateAutoFollowPatternIT.kt | 26 +++++++++++++++++++ 2 files changed, 27 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 51a0bd06..b0f85838 100644 --- a/src/main/kotlin/org/opensearch/replication/action/autofollow/TransportAutoFollowClusterManagerNodeAction.kt +++ b/src/main/kotlin/org/opensearch/replication/action/autofollow/TransportAutoFollowClusterManagerNodeAction.kt @@ -111,6 +111,7 @@ class TransportAutoFollowClusterManagerNodeAction @Inject constructor(transportS } catch(e: ResourceAlreadyExistsException) { // Log and bail as task is already running log.warn("Task already started for '$clusterAlias:$patternName'", e) + throw OpenSearchException("Exisiting autofollow replication rule cannot be recreated/updated", e) } catch (e: Exception) { log.error("Failed to start 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 bdf51acf..c3c996f4 100644 --- a/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt +++ b/src/test/kotlin/org/opensearch/replication/integ/rest/UpdateAutoFollowPatternIT.kt @@ -309,6 +309,32 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() { followerClient.deleteAutoFollowPattern(connectionAlias, indexPatternName) }.doesNotThrowAnyException() + } + fun `test updation of auto follow pattern`() { + val followerClient = getClientForCluster(FOLLOWER) + createConnectionBetweenClusters(FOLLOWER, LEADER, connectionAlias) + followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern) + val indexPattern1 = "log*" + //Re-create the same replication rule + Assertions.assertThatThrownBy { + followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern) + }.isInstanceOf(ResponseException::class.java) + .hasMessageContaining("autofollow replication rule cannot be recreated/updated") + + //Update the replication rule with different indexpattern + Assertions.assertThatThrownBy { + followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern1) + }.isInstanceOf(ResponseException::class.java) + .hasMessageContaining("autofollow replication rule cannot be recreated/updated") + + //Create a new replication rule with same indexpattern but unique rule name + Assertions.assertThatCode { + followerClient.updateAutoFollowPattern(connectionAlias, "unique-rule", indexPattern1) + }.doesNotThrowAnyException() + + followerClient.deleteAutoFollowPattern(connectionAlias, indexPatternName) + followerClient.deleteAutoFollowPattern(connectionAlias, "unique-rule") + } fun `test removing autofollow pattern stop autofollow task`() {