Skip to content

Commit

Permalink
Add -dry-run option to ApplyRoutingRules vtctl command
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Mason <[email protected]>
  • Loading branch information
ajm188 committed Jun 1, 2021
1 parent 3d2ac4a commit 88b1ad4
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions go/vt/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,7 @@ func commandApplyRoutingRules(ctx context.Context, wr *wrangler.Wrangler, subFla
routingRules := subFlags.String("rules", "", "Specify rules as a string")
routingRulesFile := subFlags.String("rules_file", "", "Specify rules in a file")
skipRebuild := subFlags.Bool("skip_rebuild", false, "If set, do no rebuild the SrvSchema objects.")
dryRun := subFlags.Bool("dry-run", false, "Do not upload the routing rules, but print what actions would be taken")
var cells flagutil.StringListValue
subFlags.Var(&cells, "cells", "If specified, limits the rebuild to the cells, after upload. Ignored if skipRebuild is set.")

Expand Down Expand Up @@ -3285,17 +3286,47 @@ func commandApplyRoutingRules(ctx context.Context, wr *wrangler.Wrangler, subFla

b, err := json2.MarshalIndentPB(rr, " ")
if err != nil {
wr.Logger().Errorf2(err, "Failed to marshal RoutingRules for display")
msg := &strings.Builder{}
if *dryRun {
msg.WriteString("DRY RUN: ")
}
msg.WriteString("Failed to marshal RoutingRules for display")

wr.Logger().Errorf2(err, msg.String())
} else {
wr.Logger().Printf("New RoutingRules object:\n%s\nIf this is not what you expected, check the input data (as JSON parsing will skip unexpected fields).\n", b)
msg := &strings.Builder{}
if *dryRun {
msg.WriteString("=== DRY RUN ===\n")
}
msg.WriteString(fmt.Sprintf("New RoutingRules object:\n%s\nIf this is not what you expected, check the input data (as JSON parsing will skip unexpected fields).\n", b))
if *dryRun {
msg.WriteString("=== (END) DRY RUN ===\n")
}

wr.Logger().Printf(msg.String())
}

_, err = wr.VtctldServer().ApplyRoutingRules(ctx, &vtctldatapb.ApplyRoutingRulesRequest{
RoutingRules: rr,
SkipRebuild: *skipRebuild,
RebuildCells: cells,
})
return err
if !*dryRun {
_, err = wr.VtctldServer().ApplyRoutingRules(ctx, &vtctldatapb.ApplyRoutingRulesRequest{
RoutingRules: rr,
SkipRebuild: *skipRebuild,
RebuildCells: cells,
})
if err != nil {
return err
}
}

if *skipRebuild {
msg := &strings.Builder{}
if *dryRun {
msg.WriteString("DRY RUN: ")
}
msg.WriteString("Skipping rebuild of SrvVSchema, will need to run RebuildVSchemaGraph for changes to take effect")
wr.Logger().Warningf(msg.String())
}

return nil
}

func commandGetSrvKeyspaceNames(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
Expand Down

0 comments on commit 88b1ad4

Please sign in to comment.