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

Commit

Permalink
Add CLI entrypoints for CellInfo/CellsAlias rw commands
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 c5e8e0c commit a491d28
Showing 1 changed file with 201 additions and 0 deletions.
201 changes: 201 additions & 0 deletions go/cmd/vtctldclient/internal/command/cells.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,55 @@ import (

"vitess.io/vitess/go/cmd/vtctldclient/cli"

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

var (
// AddCellInfo makes an AddCellInfo gRPC call to a vtctld.
AddCellInfo = &cobra.Command{
Use: "AddCellInfo --root <root> [--server-address <addr>] <cell>",
Short: "Registers a local topology service in a new cell by creating the CellInfo.",
Long: `Registers a local topology service in a new cell by creating the CellInfo
with the provided parameters.
The address will be used to connect to the topology service, and Vitess data will
be stored starting at the provided root.`,
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandAddCellInfo,
}
// AddCellsAlias makes an AddCellsAlias gRPC call to a vtctld.
AddCellsAlias = &cobra.Command{
Use: "AddCellsAlias --cells <cell1,cell2,...> [--cells <cell3> ...] <alias>",
Short: "Defines a group of cells that can be referenced by a single name (the alias).",
Long: `Defines a group of cells that can be referenced by a single name (the alias).
When routing query traffic, replica/rdonly traffic can be routed across cells
within the group (alias). Only primary traffic can be routed across cells not in
the same group (alias).`,
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandAddCellsAlias,
}
// DeleteCellInfo makes a DeleteCellInfo gRPC call to a vtctld.
DeleteCellInfo = &cobra.Command{
Use: "DeleteCellInfo [--force] <cell>",
Short: "Deletes the CellInfo for the provided cell.",
Long: "Deletes the CellInfo for the provided cell. The cell cannot be referenced by any Shard record.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandDeleteCellInfo,
}
// DeleteCellsAlias makes a DeleteCellsAlias gRPC call to a vtctld.
DeleteCellsAlias = &cobra.Command{
Use: "DeleteCellsAlias <alias>",
Short: "Deletes the CellsAlias for the provided alias.",
Long: "Deletes the CellsAlias for the provided alias.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandDeleteCellsAlias,
}
// GetCellInfoNames makes a GetCellInfoNames gRPC call to a vtctld.
GetCellInfoNames = &cobra.Command{
Use: "GetCellInfoNames",
Expand All @@ -46,8 +91,99 @@ var (
Args: cobra.NoArgs,
RunE: commandGetCellsAliases,
}
// UpdateCellInfo makes an UpdateCellInfo gRPC call to a vtctld.
UpdateCellInfo = &cobra.Command{
Use: "UpdateCellInfo [--root <root>] [--server-address <addr>] <cell>",
Short: "Updates the content of a CellInfo with the provided parameters, creating the CellInfo if it does not exist.",
Long: `Updates the content of a CellInfo with the provided parameters, creating the CellInfo if it does not exist.
If a value is empty, it is ignored.`,
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandUpdateCellInfo,
}
// UpdateCellsAlias makes an UpdateCellsAlias gRPC call to a vtctld.
UpdateCellsAlias = &cobra.Command{
Use: "UpdateCellsAlias [--cells <cell1,cell2,...> [--cells <cell4> ...]] <alias>",
Short: "Updates the content of a CellsAlias with the provided parameters, creating the CellsAlias if it does not exist.",
Long: "Updates the content of a CellsAlias with the provided parameters, creating the CellsAlias if it does not exist.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandUpdateCellsAlias,
}
)

var addCellInfoOptions topodatapb.CellInfo

func commandAddCellInfo(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

cell := cmd.Flags().Arg(0)
_, err := client.AddCellInfo(commandCtx, &vtctldatapb.AddCellInfoRequest{
Name: cell,
CellInfo: &addCellInfoOptions,
})
if err != nil {
return err
}

fmt.Printf("Created cell: %s\n", cell)
return nil
}

var addCellsAliasOptions topodatapb.CellsAlias

func commandAddCellsAlias(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

alias := cmd.Flags().Arg(0)
_, err := client.AddCellsAlias(commandCtx, &vtctldatapb.AddCellsAliasRequest{
Name: alias,
Cells: addCellsAliasOptions.Cells,
})
if err != nil {
return err
}

fmt.Printf("Created cells alias: %s (cells = %v)\n", alias, addCellsAliasOptions.Cells)
return nil
}

var deleteCellInfoOptions = struct {
Force bool
}{}

func commandDeleteCellInfo(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

cell := cmd.Flags().Arg(0)
_, err := client.DeleteCellInfo(commandCtx, &vtctldatapb.DeleteCellInfoRequest{
Name: cell,
Force: deleteCellInfoOptions.Force,
})
if err != nil {
return err
}

fmt.Printf("Deleted cell %s\n", cell)
return nil
}

func commandDeleteCellsAlias(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

alias := cmd.Flags().Arg(0)
_, err := client.DeleteCellsAlias(commandCtx, &vtctldatapb.DeleteCellsAliasRequest{
Name: alias,
})
if err != nil {
return err
}

fmt.Printf("Delete cells alias %s\n", alias)
return nil
}

func commandGetCellInfoNames(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

Expand Down Expand Up @@ -99,8 +235,73 @@ func commandGetCellsAliases(cmd *cobra.Command, args []string) error {
return nil
}

var updateCellInfoOptions topodatapb.CellInfo

func commandUpdateCellInfo(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

cell := cmd.Flags().Arg(0)
resp, err := client.UpdateCellInfo(commandCtx, &vtctldatapb.UpdateCellInfoRequest{
Name: cell,
CellInfo: &updateCellInfoOptions,
})
if err != nil {
return err
}

data, err := cli.MarshalJSON(resp.CellInfo)
if err != nil {
return err
}

fmt.Printf("Updated cell %s. New CellInfo:\n%s\n", resp.Name, data)
return nil
}

var updateCellsAliasOptions topodatapb.CellsAlias

func commandUpdateCellsAlias(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

alias := cmd.Flags().Arg(0)
resp, err := client.UpdateCellsAlias(commandCtx, &vtctldatapb.UpdateCellsAliasRequest{
Name: alias,
CellsAlias: &updateCellsAliasOptions,
})
if err != nil {
return err
}

data, err := cli.MarshalJSON(resp.CellsAlias)
if err != nil {
return err
}

fmt.Printf("Updated cells alias %s. New CellsAlias:\n%s\n", resp.Name, data)
return nil
}

func init() {
AddCellInfo.Flags().StringVarP(&addCellInfoOptions.ServerAddress, "server-address", "a", "", "The address the topology server will connect to for this cell.")
AddCellInfo.Flags().StringVarP(&addCellInfoOptions.Root, "root", "r", "", "The root path the topology server will use for this cell")
AddCellInfo.MarkFlagRequired("root")
Root.AddCommand(AddCellInfo)

AddCellsAlias.Flags().StringSliceVarP(&addCellsAliasOptions.Cells, "cells", "c", nil, "The list of cell names that are members of this alias.")
Root.AddCommand(AddCellsAlias)

DeleteCellInfo.Flags().BoolVarP(&deleteCellInfoOptions.Force, "force", "f", false, "Proceeds even if the cell's topology server cannot be reached. The assumption is that you shut down the entire cell, and just need to update the global topo data.")
Root.AddCommand(DeleteCellInfo)
Root.AddCommand(DeleteCellsAlias)

Root.AddCommand(GetCellInfoNames)
Root.AddCommand(GetCellInfo)
Root.AddCommand(GetCellsAliases)

UpdateCellInfo.Flags().StringVarP(&updateCellInfoOptions.ServerAddress, "server-address", "a", "", "The address the topology server will connect to for this cell.")
UpdateCellInfo.Flags().StringVarP(&updateCellInfoOptions.Root, "root", "r", "", "The root path the topology server will use for this cell")
Root.AddCommand(UpdateCellInfo)

UpdateCellsAlias.Flags().StringSliceVarP(&updateCellsAliasOptions.Cells, "cells", "c", nil, "The list of cell names that are members of this alias.")
Root.AddCommand(UpdateCellsAlias)
}

0 comments on commit a491d28

Please sign in to comment.