Skip to content

Commit

Permalink
Add cli entrypoints
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 Sep 16, 2021
1 parent 1f27702 commit e53673c
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions go/cmd/vtctldclient/internal/command/tablets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/spf13/cobra"

"vitess.io/vitess/go/cmd/vtctldclient/cli"
"vitess.io/vitess/go/protoutil"
"vitess.io/vitess/go/vt/topo/topoproto"

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
Expand Down Expand Up @@ -81,6 +83,14 @@ Valid output formats are "awk" and "json".`,
Args: cobra.NoArgs,
RunE: commandGetTablets,
}
// PingTablet makes a PingTablet gRPC call to a vtctld.
PingTablet = &cobra.Command{
Use: "PingTablet <alias>",
Short: "Checks that the specified tablet is awake and responding to RPCs. This command can be blocked by other in-flight operations.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandPingTablet,
}
// RefreshState makes a RefreshState gRPC call to a vtctld.
RefreshState = &cobra.Command{
Use: "RefreshState <alias>",
Expand All @@ -105,6 +115,14 @@ Valid output formats are "awk" and "json".`,
Args: cobra.ExactArgs(2),
RunE: commandSetWritable,
}
// SleepTablet makes a SleepTablet gRPC call to a vtctld.
SleepTablet = &cobra.Command{
Use: "SleepTablet <alias> <duration>",
Short: "Blocks the action queue on the specified tablet for the specified amount of time. This is typically used for testing.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
RunE: commandSleepTablet,
}
// StartReplication makes a StartReplication gRPC call to a vtctld.
StartReplication = &cobra.Command{
Use: "StartReplication <alias>",
Expand Down Expand Up @@ -285,6 +303,20 @@ func commandGetTablets(cmd *cobra.Command, args []string) error {
return nil
}

func commandPingTablet(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
return err
}

cli.FinishedParsing(cmd)

_, err = client.PingTablet(commandCtx, &vtctldatapb.PingTabletRequest{
TabletAlias: alias,
})
return err
}

func commandRefreshState(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
Expand Down Expand Up @@ -359,6 +391,26 @@ func commandSetWritable(cmd *cobra.Command, args []string) error {
return err
}

func commandSleepTablet(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
return err
}

duration, err := time.ParseDuration(cmd.Flags().Arg(1))
if err != nil {
return err
}

cli.FinishedParsing(cmd)

_, err = client.SleepTablet(commandCtx, &vtctldatapb.SleepTabletRequest{
TabletAlias: alias,
Duration: protoutil.DurationToProto(duration),
})
return err
}

func commandStartReplication(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
Expand Down Expand Up @@ -404,12 +456,14 @@ func init() {
GetTablets.Flags().BoolVar(&getTabletsOptions.Strict, "strict", false, "Require all cells to return successful tablet data. Without --strict, tablet listings may be partial.")
Root.AddCommand(GetTablets)

Root.AddCommand(PingTablet)
Root.AddCommand(RefreshState)

RefreshStateByShard.Flags().StringSliceVarP(&refreshStateByShardOptions.Cells, "cells", "c", nil, "If specified, only call RefreshState on tablets in the specified cells. If empty, all cells are considered.")
Root.AddCommand(RefreshStateByShard)

Root.AddCommand(SetWritable)
Root.AddCommand(SleepTablet)
Root.AddCommand(StartReplication)
Root.AddCommand(StopReplication)
}

0 comments on commit e53673c

Please sign in to comment.