Skip to content

Commit

Permalink
Merge pull request #36 from dell/modify-policy
Browse files Browse the repository at this point in the history
SyncIQ policy modify support
  • Loading branch information
shefali-malhotra authored Jan 5, 2023
2 parents 4e82af9 + c2262eb commit 7aec9b1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
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

0 comments on commit 7aec9b1

Please sign in to comment.