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

Support replication of site replication state changes #247

Merged
merged 2 commits into from
Nov 21, 2023
Merged
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
57 changes: 51 additions & 6 deletions cluster-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ type SiteReplicationInfo struct {
Name string `json:"name,omitempty"`
Sites []PeerInfo `json:"sites,omitempty"`
ServiceAccountAccessKey string `json:"serviceAccountAccessKey,omitempty"`
ReplicateILMExpiry bool `json:"replicate-ilm-expiry"`
}

// SiteReplicationInfo - returns cluster replication information.
Expand Down Expand Up @@ -151,11 +150,11 @@ func (adm *AdminClient) SiteReplicationInfo(ctx context.Context) (info SiteRepli

// SRPeerJoinReq - arg body for SRPeerJoin
type SRPeerJoinReq struct {
SvcAcctAccessKey string `json:"svcAcctAccessKey"`
SvcAcctSecretKey string `json:"svcAcctSecretKey"`
SvcAcctParent string `json:"svcAcctParent"`
Peers map[string]PeerInfo `json:"peers"`
ReplicateILMExpiry bool `json:"replicate-ilm-expiry"`
SvcAcctAccessKey string `json:"svcAcctAccessKey"`
SvcAcctSecretKey string `json:"svcAcctSecretKey"`
SvcAcctParent string `json:"svcAcctParent"`
Peers map[string]PeerInfo `json:"peers"`
UpdatedAt time.Time `json:"updatedAt"`
}

// PeerInfo - contains some properties of a cluster peer.
Expand Down Expand Up @@ -644,6 +643,7 @@ type SRInfo struct {
GroupPolicies map[string]SRPolicyMapping // map of groupname -> group policy mapping
ReplicationCfg map[string]replication.Config // map of bucket -> replication config
ILMExpiryRules map[string]ILMExpiryRule // map of ILM Expiry rule to content
State SRStateInfo // peer state
}

// SRMetaInfo - returns replication metadata info for a site.
Expand Down Expand Up @@ -813,6 +813,7 @@ type SRStatusOptions struct {
Groups bool
Metrics bool
ILMExpiryRules bool
PeerState bool
Entity SREntityType
EntityValue string
ShowDeleted bool
Expand Down Expand Up @@ -855,6 +856,7 @@ func (o *SRStatusOptions) getURLValues() url.Values {
urlValues.Set("showDeleted", strconv.FormatBool(o.ShowDeleted))
urlValues.Set("metrics", strconv.FormatBool(o.Metrics))
urlValues.Set("ilm-expiry-rules", strconv.FormatBool(o.ILMExpiryRules))
urlValues.Set("peer-state", strconv.FormatBool(o.PeerState))

if o.IsEntitySet() {
urlValues.Set("entityvalue", o.EntityValue)
Expand Down Expand Up @@ -983,6 +985,36 @@ func (adm *AdminClient) SRPeerEdit(ctx context.Context, pi PeerInfo) error {
return nil
}

// SRStateEdit - used only by minio server to update peer state
// for a server already in the site replication setup
func (adm *AdminClient) SRStateEdit(ctx context.Context, state SRStateEditReq) error {
b, err := json.Marshal(state)
if err != nil {
return err
}

q := make(url.Values)
q.Set("api-version", SiteReplAPIVersion)

reqData := requestData{
relPath: adminAPIPrefix + "/site-replication/state/edit",
content: b,
queryValues: q,
}

resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
defer closeResponse(resp)
if err != nil {
return err
}

if resp.StatusCode != http.StatusOK {
return httpRespToErrorResponse(resp)
}

return nil
}

// SiteReplicationRemove - unlinks a site from site replication
func (adm *AdminClient) SiteReplicationRemove(ctx context.Context, removeReq SRRemoveReq) (st ReplicateRemoveStatus, err error) {
rmvBytes, err := json.Marshal(removeReq)
Expand Down Expand Up @@ -1053,6 +1085,19 @@ type SRRemoveReq struct {
RemoveAll bool `json:"all"` // true if all sites are to be removed.
}

// SRStateEditReq - arg body for SRStateEditReq
type SRStateEditReq struct {
Peers map[string]PeerInfo `json:"peers"`
UpdatedAt time.Time `json:"updatedAt"`
}

// SRStateInfo - site replication state information
type SRStateInfo struct {
Name string `json:"name"`
Peers map[string]PeerInfo `json:"peers"`
UpdatedAt time.Time `json:"updatedAt"`
}

const (
ReplicateRemoveStatusSuccess = "Requested site(s) were removed from cluster replication successfully."
ReplicateRemoveStatusPartial = "Some site(s) could not be removed from cluster replication configuration."
Expand Down
Loading