From bdeeee981f83c814e387733115eb56c0285eec94 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 14 Mar 2022 18:30:17 -0700 Subject: [PATCH] Enforces extension action parsers have custom flag (#306) (#308) * Enforces extension action parsers have custom flag Signed-off-by: Clay Downs * Updates release notes Signed-off-by: Clay Downs (cherry picked from commit 6d933594f86645f3a41b845ed4bf45ac26be9a7f) Co-authored-by: Clay Downs --- .../opensearch-index-management.release-notes-1.3.0.0.md | 1 + .../org/opensearch/indexmanagement/IndexManagementPlugin.kt | 2 +- .../indexstatemanagement/ISMActionsParser.kt | 6 ++++++ .../indexstatemanagement/extension/ISMActionsParserTests.kt | 3 --- .../transport/action/getpolicy/GetPolicyResponseTests.kt | 1 - .../transport/action/indexpolicy/IndexPolicyRequestTests.kt | 1 - .../action/indexpolicy/IndexPolicyResponseTests.kt | 1 - 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/release-notes/opensearch-index-management.release-notes-1.3.0.0.md b/release-notes/opensearch-index-management.release-notes-1.3.0.0.md index db800f9c4..dab63a5d6 100644 --- a/release-notes/opensearch-index-management.release-notes-1.3.0.0.md +++ b/release-notes/opensearch-index-management.release-notes-1.3.0.0.md @@ -24,6 +24,7 @@ Compatible with OpenSearch 1.3.0 * Fixes flaky continuous transforms test ([#276](https://github.com/opensearch-project/index-management/pull/276)) * Porting additional missing logic ([#275](https://github.com/opensearch-project/index-management/pull/275)) * Fixes test failures with security enabled ([#292](https://github.com/opensearch-project/index-management/pull/292)) +* Enforces extension action parsers have custom flag ([#306](https://github.com/opensearch-project/index-management/pull/306)) ### Infrastructure * Add support for codeowners to repo ([#195](https://github.com/opensearch-project/index-management/pull/195)) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt index 4b506f588..609f87330 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt @@ -251,7 +251,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin indexManagementExtensions.forEach { extension -> val extensionName = extension.getExtensionName() if (extensionName in extensions) { - throw IllegalStateException("Mutliple extensions of IndexManagement have same name $extensionName - not supported") + throw IllegalStateException("Multiple extensions of IndexManagement have same name $extensionName - not supported") } extension.getISMActionParsers().forEach { parser -> ISMActionsParser.instance.addParser(parser, extensionName) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMActionsParser.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMActionsParser.kt index 197b218fc..e520c58ff 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMActionsParser.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ISMActionsParser.kt @@ -50,10 +50,16 @@ class ISMActionsParser private constructor() { val customActionExtensionMap = mutableMapOf() + /* + * This method is used for adding custom action parsers. Action parsers from ISM should be added directly + * to the parsers list. + */ fun addParser(parser: ActionParser, extensionName: String) { if (parsers.map { it.getActionType() }.contains(parser.getActionType())) { throw IllegalArgumentException(getDuplicateActionTypesMessage(parser.getActionType())) } + // Set the parser as custom to make sure that the custom actions are written with the "custom" wrapper + parser.customAction = true parsers.add(parser) customActionExtensionMap[parser.getActionType()] = extensionName } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt index 3e50097c6..69d238aa5 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/ISMActionsParserTests.kt @@ -31,7 +31,6 @@ class ISMActionsParserTests : OpenSearchTestCase() { fun `test duplicate action names fail`() { val customActionParser = SampleCustomActionParser() - customActionParser.customAction = true // Duplicate custom parser names should fail ISMActionsParser.instance.addParser(customActionParser, extensionName) assertFailsWith("Expected IllegalArgumentException for duplicate action names") { @@ -46,7 +45,6 @@ class ISMActionsParserTests : OpenSearchTestCase() { fun `test custom action parsing`() { val customActionParser = SampleCustomActionParser() - customActionParser.customAction = true ISMActionsParser.instance.addParser(customActionParser, extensionName) val customAction = SampleCustomActionParser.SampleCustomAction(randomInt(), 0) val builder = XContentFactory.jsonBuilder() @@ -62,7 +60,6 @@ class ISMActionsParserTests : OpenSearchTestCase() { fun `test parsing custom action without custom flag`() { val customActionParser = SampleCustomActionParser() - customActionParser.customAction = true ISMActionsParser.instance.addParser(customActionParser, extensionName) val customAction = SampleCustomActionParser.SampleCustomAction(randomInt(), 0) customAction.customAction = true diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponseTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponseTests.kt index 75e264cb3..9f4de9857 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponseTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/GetPolicyResponseTests.kt @@ -57,7 +57,6 @@ class GetPolicyResponseTests : OpenSearchTestCase() { @Suppress("UNCHECKED_CAST") fun `test get policy response custom action`() { val customActionParser = SampleCustomActionParser() - customActionParser.customAction = true val extensionName = "testExtension" ISMActionsParser.instance.addParser(customActionParser, extensionName) val id = "id" diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequestTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequestTests.kt index 8d9f13e62..5ec01105e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequestTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyRequestTests.kt @@ -111,7 +111,6 @@ class IndexPolicyRequestTests : OpenSearchTestCase() { fun `test index policy request custom action`() { val customActionParser = SampleCustomActionParser() - customActionParser.customAction = true val extensionName = "testExtension" ISMActionsParser.instance.addParser(customActionParser, extensionName) val policyID = "policyID" diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponseTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponseTests.kt index 5f90d8bba..a20c9e415 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponseTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/indexpolicy/IndexPolicyResponseTests.kt @@ -62,7 +62,6 @@ class IndexPolicyResponseTests : OpenSearchTestCase() { @Suppress("UNCHECKED_CAST") fun `test index policy response custom action`() { val customActionParser = SampleCustomActionParser() - customActionParser.customAction = true val extensionName = "testExtension" ISMActionsParser.instance.addParser(customActionParser, extensionName) val id = "id"