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

SyncIQ policy modify support #36

Merged
merged 1 commit into from
Jan 5, 2023
Merged
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
5 changes: 3 additions & 2 deletions api/v11/api_v11_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ package v11
import (
"context"
"fmt"
"github.com/dell/goisilon/api"
"strconv"

"github.com/dell/goisilon/api"
)

const (
Expand Down Expand Up @@ -86,7 +87,7 @@ type Policy struct {
TargetHost string `json:"target_host,omitempty"`
TargetCert string `json:"target_certificate_id,omitempty"`
JobDelay int `json:"job_delay,omitempty"`
Schedule string `json:"schedule,omitempty"`
Schedule string `json:"schedule"`
LastJobState JOB_STATE `json:"last_job_state,omitempty"`
}

Expand Down
47 changes: 30 additions & 17 deletions replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ limitations under the License.

import (
"context"
"time"

log "github.com/akutz/gournal"
"github.com/dell/goisilon/api/common/utils"
apiv11 "github.com/dell/goisilon/api/v11"
"time"
)

const defaultPoll = 5 * time.Second
Expand Down Expand Up @@ -110,9 +111,34 @@ func (c *Client) SetPolicyEnabledField(ctx context.Context, name string, value b
return nil
}

p := &apiv11.Policy{
Id: pp.Id,
Enabled: value,
Schedule: pp.Schedule, // keep existing schedule, otherwise it will be cleared
}

return apiv11.UpdatePolicy(ctx, c.API, p)
}

// Modifies the policy schedule and job delay.
// scdeule - can be either empty string (manual) or when-source-modified
// rpo - can be 0 (manual) or in seconds (when-source-modified)
func (c *Client) ModifyPolicy(ctx context.Context, name string, schedule string, rpo int) error {
pp, err := c.GetPolicyByName(ctx, name)
if err != nil {
return err
}

p := &apiv11.Policy{
Id: pp.Id,
Enabled: value,
Enabled: pp.Enabled, // keep existing enabled state, otherwise it will be cleared
}

if schedule == "" { // manual
p.Schedule = schedule
} else if schedule == "when-source-modified" {
p.Schedule = schedule
p.JobDelay = rpo
}

return apiv11.UpdatePolicy(ctx, c.API, p)
Expand Down Expand Up @@ -163,20 +189,7 @@ func (c *Client) DisallowWrites(ctx context.Context, policyName string) error {
}

func (c *Client) ResyncPrep(ctx context.Context, policyName string) error {
targetPolicy, err := c.GetTargetPolicyByName(ctx, policyName)
if err != nil {
return err
}
if targetPolicy.FailoverFailbackState == RESYNC_POLICY_CREATED {
return nil
}

_, err = c.RunActionForPolicy(ctx, policyName, apiv11.RESYNC_PREP)
if err != nil {
return err
}

err = c.WaitForTargetPolicyCondition(ctx, policyName, RESYNC_POLICY_CREATED)
_, err := c.RunActionForPolicy(ctx, policyName, apiv11.RESYNC_PREP)
if err != nil {
return err
}
Expand Down Expand Up @@ -305,7 +318,7 @@ func (c *Client) SyncPolicy(ctx context.Context, policyName string) error {
if err != nil {
return err
}
if policy.Enabled != true {
if !policy.Enabled {
return nil
}

Expand Down