Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins/ism: add alias action #614

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased]

### Added
- Adds ISM Alias action ([#614](https://github.com/opensearch-project/opensearch-go/pull/614))

### Changed

Expand Down
19 changes: 18 additions & 1 deletion plugins/ism/api_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type PolicyBody struct {
Description string `json:"description,omitempty"`
LastUpdatedTime int64 `json:"last_updated_time,omitempty"`
SchemaVersion int `json:"schema_version,omitempty"`
ErrorNotification *PolicyErrorNotification `json:"error_notification,omitempty"`
ErrorNotification *PolicyErrorNotification `json:"error_notification"`
DefaultState string `json:"default_state"`
States []PolicyState `json:"states"`
Template []Template `json:"ism_template,omitempty"`
Expand Down Expand Up @@ -146,6 +146,7 @@ type PolicyStateAction struct {
IndexPriority *PolicyStateIndexPriority `json:"index_priority,omitempty"`
Allocation *PolicyStateAllocation `json:"allocation,omitempty"`
Rollup *PolicyStateRollup `json:"rollup,omitempty"`
Alias *PolicyStateAlias `json:"alias,omitempty"`
}

// Template is a sub type of PolicyBody containing information about the ims template
Expand Down Expand Up @@ -271,3 +272,19 @@ type PolicyStateTransition struct {
StateName string `json:"state_name"`
Conditions *PolicyStateTransitionCondition `json:"conditions,omitempty"`
}

// PolicyStateAlias represents the Alias action
type PolicyStateAlias struct {
Actions []PolicyStateAliasAction `json:"actions"`
}

// PolicyStateAliasAction is a sub type of PolicyStateAlias defining to add or remove aliases
type PolicyStateAliasAction struct {
Add *PolicyStateAliasName `json:"add,omitempty"`
Remove *PolicyStateAliasName `json:"remove,omitempty"`
}

// PolicyStateAliasName is a sub type of PolicyStateAliasAction defining the list of aliases
type PolicyStateAliasName struct {
Aliases []string `json:"aliases"`
}
65 changes: 56 additions & 9 deletions plugins/ism/api_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ func TestPoliciesClient(t *testing.T) {
failingClient, err := osismtest.CreateFailingClient()
require.Nil(t, err)

testPolicy1 := "test"
testPolicy2 := "test2"
t.Cleanup(func() { client.Policies.Delete(nil, ism.PoliciesDeleteReq{Policy: testPolicy2}) })
testPolicy := "test"
testPolicyChannel := "test_channel"
testPolicyAlias := "test_alias"
t.Cleanup(func() {
client.Policies.Delete(nil, ism.PoliciesDeleteReq{Policy: testPolicyChannel})
client.Policies.Delete(nil, ism.PoliciesDeleteReq{Policy: testPolicyAlias})
})

var putResp ism.PoliciesPutResp

Expand All @@ -54,7 +58,7 @@ func TestPoliciesClient(t *testing.T) {
putResp, err = client.Policies.Put(
nil,
ism.PoliciesPutReq{
Policy: testPolicy1,
Policy: testPolicy,
Body: ism.PoliciesPutBody{
Policy: ism.PolicyBody{
Description: "test",
Expand Down Expand Up @@ -138,7 +142,7 @@ func TestPoliciesClient(t *testing.T) {
return client.Policies.Put(
nil,
ism.PoliciesPutReq{
Policy: testPolicy2,
Policy: testPolicyChannel,
Body: ism.PoliciesPutBody{
Policy: ism.PolicyBody{
Description: "test",
Expand All @@ -163,7 +167,50 @@ func TestPoliciesClient(t *testing.T) {
},
Template: []ism.Template{
ism.Template{
IndexPatterns: []string{"test2"},
IndexPatterns: []string{testPolicyChannel},
Priority: 21,
},
},
},
},
},
)
},
},
{
Name: "Create with Alias",
Results: func(t *testing.T) (osismtest.Response, error) {
ostest.SkipIfBelowVersion(t, osClient, 2, 0, "policy with error notification channel")
return client.Policies.Put(
nil,
ism.PoliciesPutReq{
Policy: testPolicyAlias,
Body: ism.PoliciesPutBody{
Policy: ism.PolicyBody{
Description: "test",
DefaultState: "alias",
States: []ism.PolicyState{
ism.PolicyState{
Name: "alias",
Actions: []ism.PolicyStateAction{
ism.PolicyStateAction{
Alias: &ism.PolicyStateAlias{
Actions: []ism.PolicyStateAliasAction{
ism.PolicyStateAliasAction{
Add: &ism.PolicyStateAliasName{Aliases: []string{"alias-test"}},
},
ism.PolicyStateAliasAction{
Remove: &ism.PolicyStateAliasName{Aliases: []string{"alias-test"}},
},
},
},
},
},
},
},
Template: []ism.Template{
ism.Template{
IndexPatterns: []string{testPolicyAlias},
Priority: 21,
},
},
Expand All @@ -181,7 +228,7 @@ func TestPoliciesClient(t *testing.T) {
return client.Policies.Put(
nil,
ism.PoliciesPutReq{
Policy: testPolicy1,
Policy: testPolicy,
Params: ism.PoliciesPutParams{IfSeqNo: opensearch.ToPointer(putResp.SeqNo), IfPrimaryTerm: opensearch.ToPointer(putResp.PrimaryTerm)},
Body: ism.PoliciesPutBody{
Policy: putResp.Policy.Policy,
Expand Down Expand Up @@ -210,7 +257,7 @@ func TestPoliciesClient(t *testing.T) {
{
Name: "with request",
Results: func(t *testing.T) (osismtest.Response, error) {
return client.Policies.Get(nil, &ism.PoliciesGetReq{Policy: testPolicy1})
return client.Policies.Get(nil, &ism.PoliciesGetReq{Policy: testPolicy})
},
},
{
Expand All @@ -227,7 +274,7 @@ func TestPoliciesClient(t *testing.T) {
{
Name: "with request",
Results: func(t *testing.T) (osismtest.Response, error) {
return client.Policies.Delete(nil, ism.PoliciesDeleteReq{Policy: testPolicy1})
return client.Policies.Delete(nil, ism.PoliciesDeleteReq{Policy: testPolicy})
},
},
{
Expand Down
Loading