Skip to content

Commit

Permalink
Enforces extension action parsers have custom flag (#306)
Browse files Browse the repository at this point in the history
* Enforces extension action parsers have custom flag

Signed-off-by: Clay Downs <[email protected]>

* Updates release notes

Signed-off-by: Clay Downs <[email protected]>
  • Loading branch information
downsrob authored Mar 15, 2022
1 parent 4985a18 commit 6d93359
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ class ISMActionsParser private constructor() {

val customActionExtensionMap = mutableMapOf<String, String>()

/*
* 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IllegalArgumentException>("Expected IllegalArgumentException for duplicate action names") {
Expand All @@ -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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6d93359

Please sign in to comment.