Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
[vtctl] Replace legacy implementation with calls to new implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Mason <amason@slack-corp.com>
  • Loading branch information
ajm188 committed Jun 1, 2021
1 parent a491d28 commit a36e2ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
40 changes: 20 additions & 20 deletions go/vt/vtctl/cell_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (

"context"

"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/wrangler"

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

// This file contains the Cells command group for vtctl.
Expand Down Expand Up @@ -73,18 +73,19 @@ func commandAddCellInfo(ctx context.Context, wr *wrangler.Wrangler, subFlags *fl
if err := subFlags.Parse(args); err != nil {
return err
}
if *root == "" {
return fmt.Errorf("root must be non-empty")
}
if subFlags.NArg() != 1 {
return fmt.Errorf("the <cell> argument is required for the AddCellInfo command")
}
cell := subFlags.Arg(0)

return wr.TopoServer().CreateCellInfo(ctx, cell, &topodatapb.CellInfo{
ServerAddress: *serverAddress,
Root: *root,
_, err := wr.VtctldServer().AddCellInfo(ctx, &vtctldatapb.AddCellInfoRequest{
Name: cell,
CellInfo: &topodatapb.CellInfo{
ServerAddress: *serverAddress,
Root: *root,
},
})
return err
}

func commandUpdateCellInfo(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
Expand All @@ -98,19 +99,14 @@ func commandUpdateCellInfo(ctx context.Context, wr *wrangler.Wrangler, subFlags
}
cell := subFlags.Arg(0)

return wr.TopoServer().UpdateCellInfoFields(ctx, cell, func(ci *topodatapb.CellInfo) error {
if (*serverAddress == "" || ci.ServerAddress == *serverAddress) &&
(*root == "" || ci.Root == *root) {
return topo.NewError(topo.NoUpdateNeeded, cell)
}
if *serverAddress != "" {
ci.ServerAddress = *serverAddress
}
if *root != "" {
ci.Root = *root
}
return nil
_, err := wr.VtctldServer().UpdateCellInfo(ctx, &vtctldatapb.UpdateCellInfoRequest{
Name: cell,
CellInfo: &topodatapb.CellInfo{
ServerAddress: *serverAddress,
Root: *root,
},
})
return err
}

func commandDeleteCellInfo(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
Expand All @@ -123,7 +119,11 @@ func commandDeleteCellInfo(ctx context.Context, wr *wrangler.Wrangler, subFlags
}
cell := subFlags.Arg(0)

return wr.TopoServer().DeleteCellInfo(ctx, cell, *force)
_, err := wr.VtctldServer().DeleteCellInfo(ctx, &vtctldatapb.DeleteCellInfoRequest{
Name: cell,
Force: *force,
})
return err
}

func commandGetCellInfoNames(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
Expand Down
21 changes: 14 additions & 7 deletions go/vt/vtctl/cells_aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"vitess.io/vitess/go/vt/wrangler"

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

// This file contains the CellsAliases command group for vtctl.
Expand Down Expand Up @@ -75,10 +76,11 @@ func commandAddCellsAlias(ctx context.Context, wr *wrangler.Wrangler, subFlags *
}

alias := subFlags.Arg(0)

return wr.TopoServer().CreateCellsAlias(ctx, alias, &topodatapb.CellsAlias{
_, err := wr.VtctldServer().AddCellsAlias(ctx, &vtctldatapb.AddCellsAliasRequest{
Name: alias,
Cells: cells,
})
return err
}

func commandUpdateCellsAlias(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
Expand All @@ -96,11 +98,13 @@ func commandUpdateCellsAlias(ctx context.Context, wr *wrangler.Wrangler, subFlag
}

alias := subFlags.Arg(0)

return wr.TopoServer().UpdateCellsAlias(ctx, alias, func(ca *topodatapb.CellsAlias) error {
ca.Cells = cells
return nil
_, err := wr.VtctldServer().UpdateCellsAlias(ctx, &vtctldatapb.UpdateCellsAliasRequest{
Name: alias,
CellsAlias: &topodatapb.CellsAlias{
Cells: cells,
},
})
return err
}

func commandDeleteCellsAlias(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
Expand All @@ -112,7 +116,10 @@ func commandDeleteCellsAlias(ctx context.Context, wr *wrangler.Wrangler, subFlag
}
alias := subFlags.Arg(0)

return wr.TopoServer().DeleteCellsAlias(ctx, alias)
_, err := wr.VtctldServer().DeleteCellsAlias(ctx, &vtctldatapb.DeleteCellsAliasRequest{
Name: alias,
})
return err
}

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

0 comments on commit a36e2ce

Please sign in to comment.