Add flag to admin replicate update to toggle synchronous replication (#4514)

This commit is contained in:
Poorna
2023-04-08 08:54:39 -07:00
committed by GitHub
parent a9fb9426f1
commit 2c3f0e8ccf
3 changed files with 38 additions and 12 deletions
+10 -5
View File
@@ -70,16 +70,21 @@ func (i srInfo) String() string {
Field{"Deployment ID", 36},
Field{"Name", 15},
Field{"Endpoint", 50},
).buildRow("Deployment ID", "Site Name", "Endpoint"))
Field{"Endpoint", 46},
Field{"Sync", 4},
).buildRow("Deployment ID", "Site Name", "Endpoint", "Sync"))
messages = append(messages, r)
for _, peer := range info.Sites {
var chk string
if peer.SyncState == madmin.SyncEnabled {
chk = check
}
r := console.Colorize("TDetail", newPrettyTable(" | ",
Field{"Deployment ID", 36},
Field{"Name", 15},
Field{"Endpoint", 50},
).buildRow(peer.DeploymentID, peer.Name, peer.Endpoint))
Field{"Endpoint", 46},
Field{"Sync", 4},
).buildRow(peer.DeploymentID, peer.Name, peer.Endpoint, chk))
messages = append(messages, r)
}
} else {
+26 -7
View File
@@ -38,6 +38,11 @@ var adminReplicateUpdateFlags = []cli.Flag{
Name: "endpoint",
Usage: "endpoint for the site",
},
cli.StringFlag{
Name: "sync",
Usage: "enable synchronous replication for this target, valid values are ['enable', 'disable'].",
Value: "disable",
},
}
var adminReplicateUpdateCmd = cli.Command{
@@ -110,17 +115,31 @@ func mainAdminReplicateUpdate(ctx *cli.Context) error {
if !ctx.IsSet("deployment-id") {
fatalIf(errInvalidArgument(), "--deployment-id is a required flag")
}
if !ctx.IsSet("endpoint") {
fatalIf(errInvalidArgument(), "--endpoint is a required flag")
if !ctx.IsSet("endpoint") && !ctx.IsSet("sync") {
fatalIf(errInvalidArgument(), "--endpoint or --sync is a required flag")
}
parsedURL := ctx.String("endpoint")
u, e := url.Parse(parsedURL)
if e != nil {
fatalIf(errInvalidArgument().Trace(parsedURL), "Unsupported URL format %v", e)
var syncState string
if ctx.IsSet("sync") {
syncState = strings.ToLower(ctx.String("sync"))
switch syncState {
case "enable", "disable":
default:
fatalIf(errInvalidArgument().Trace(args...), "--sync can be either [enable|disable]")
}
}
var ep string
if ctx.IsSet("endpoint") {
parsedURL := ctx.String("endpoint")
u, e := url.Parse(parsedURL)
if e != nil {
fatalIf(errInvalidArgument().Trace(parsedURL), "Unsupported URL format %v", e)
}
ep = u.String()
}
res, e := client.SiteReplicationEdit(globalContext, madmin.PeerInfo{
DeploymentID: ctx.String("deployment-id"),
Endpoint: u.String(),
Endpoint: ep,
SyncState: madmin.SyncStatus(syncState),
})
fatalIf(probe.NewError(e).Trace(args...), "Unable to edit cluster replication site endpoint")
+2
View File
@@ -588,6 +588,8 @@ github.com/pkg/xattr v0.4.9/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6kt
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/poornas/madmin-go/v2 v2.0.0-20230322192724-66f8756c816f h1:l0vXMhCfsn8kXtI0GbbUO5Aahg1tVVRaJk3n8OOA5SA=
github.com/poornas/madmin-go/v2 v2.0.0-20230322192724-66f8756c816f/go.mod h1:8bL1RMNkblIENFSgGYjeHrzUx9PxROb7OqfNuMU9ivE=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo=
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=