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`() {