diff --git a/CHANGELOG.md b/CHANGELOG.md index feffc1ba..2e4b67e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Removed ### Fixed +- Fix ISM Transition to omitempty Conditions field ([#609](https://github.com/opensearch-project/opensearch-go/pull/609)) +- Fix ISM Allocation field types ([#609](https://github.com/opensearch-project/opensearch-go/pull/609)) ### Security diff --git a/plugins/ism/api_policies.go b/plugins/ism/api_policies.go index 523cc1e6..0b7787dd 100644 --- a/plugins/ism/api_policies.go +++ b/plugins/ism/api_policies.go @@ -226,10 +226,10 @@ type PolicyStateIndexPriority struct { // PolicyStateAllocation represents the allocation action type PolicyStateAllocation struct { - Require string `json:"require,omitempty"` - Include string `json:"include,omitempty"` - Exclude string `json:"exclude,omitempty"` - WaitFor string `json:"wait_for,omitempty"` + Require map[string]string `json:"require,omitempty"` + Include map[string]string `json:"include,omitempty"` + Exclude map[string]string `json:"exclude,omitempty"` + WaitFor *bool `json:"wait_for,omitempty"` } // PolicyStateRollup represents the rollup action @@ -264,5 +264,5 @@ type PolicyStateTransitionConditionCron struct { // PolicyStateTransition is a sub type of PolicyState containing information about transition to other states type PolicyStateTransition struct { StateName string `json:"state_name"` - Conditions *PolicyStateTransitionCondition `json:"conditions"` + Conditions *PolicyStateTransitionCondition `json:"conditions,omitempty"` } diff --git a/plugins/ism/api_policies_test.go b/plugins/ism/api_policies_test.go index a315f771..2de7ffb2 100644 --- a/plugins/ism/api_policies_test.go +++ b/plugins/ism/api_policies_test.go @@ -69,10 +69,41 @@ func TestPoliciesClient(t *testing.T) { Source: "The index {{ctx.index}} failed during policy execution.", }, }, - DefaultState: "test", + DefaultState: "transition", States: []ism.PolicyState{ ism.PolicyState{ - Name: "test", + Name: "allocation", + Actions: []ism.PolicyStateAction{ + ism.PolicyStateAction{ + Allocation: &ism.PolicyStateAllocation{ + Require: map[string]string{"temp": "warm"}, + Include: map[string]string{"test": "warm"}, + Exclude: map[string]string{"test2": "warm"}, + WaitFor: opensearch.ToPointer(true), + }, + }, + }, + Transitions: &[]ism.PolicyStateTransition{ + ism.PolicyStateTransition{ + StateName: "transition", + }, + }, + }, + ism.PolicyState{ + Name: "transition", + Actions: []ism.PolicyStateAction{ + ism.PolicyStateAction{ + Close: &ism.PolicyStateClose{}, + }, + }, + Transitions: &[]ism.PolicyStateTransition{ + ism.PolicyStateTransition{ + StateName: "delete", + }, + }, + }, + ism.PolicyState{ + Name: "delete", Actions: []ism.PolicyStateAction{ ism.PolicyStateAction{ Delete: &ism.PolicyStateDelete{},