common

package
v0.0.0-...-be15534 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Master specifies member master type.
	Master = "master"
	// Worker specifies member worker type.
	Worker = "worker"

	// DefaultErrorCnt represents default count of errors to display for check-task.
	DefaultErrorCnt = 10
	// DefaultWarnCnt represents count of warns to display for check-task.
	DefaultWarnCnt = 10
)

Variables

View Source
var (

	// GlobalCtlClient is the globally used CtlClient in this package. Exposed to be used in test.
	GlobalCtlClient = &CtlClient{}
)

Functions

func AdjustArgumentsForPflags

func AdjustArgumentsForPflags(args []string) []string

AdjustArgumentsForPflags adjust flag format args to pflags format.

func DefineConfigFlagSet

func DefineConfigFlagSet(fs *pflag.FlagSet)

DefineConfigFlagSet defines flag definitions for configs.

func ExtractSQLsFromArgs

func ExtractSQLsFromArgs(args []string) ([]string, error)

ExtractSQLsFromArgs extract multiple sql from args.

func GetFileContent

func GetFileContent(fpath string) ([]byte, error)

GetFileContent reads and returns file's content.

func GetSourceArgs

func GetSourceArgs(cmd *cobra.Command) ([]string, error)

GetSourceArgs extracts sources from cmd.

func GetTaskNameFromArgOrFile

func GetTaskNameFromArgOrFile(arg string) string

GetTaskNameFromArgOrFile tries to retrieve name from the file if arg is yaml-filename-like, otherwise returns arg directly.

func InitClient

func InitClient(addr string, securityCfg security.Security) error

InitClient initializes dm-master client.

func InitUtils

func InitUtils(cfg *Config) error

InitUtils inits necessary dmctl utils.

func OperateRelay

func OperateRelay(op pb.RelayOp, workers []string) (*pb.OperateWorkerRelayResponse, error)

OperateRelay does operation on relay unit.

func OperateTask

func OperateTask(op pb.TaskOp, name string, sources []string) (*pb.OperateTaskResponse, error)

OperateTask does operation on task.

func PrettyPrintInterface

func PrettyPrintInterface(resp interface{})

PrettyPrintInterface prints an interface through encoding/json prettily.

func PrettyPrintResponse

func PrettyPrintResponse(resp proto.Message)

PrettyPrintResponse prints a PRC response prettily.

func PrettyPrintResponseWithCheckTask

func PrettyPrintResponseWithCheckTask(resp proto.Message, subStr string) bool

PrettyPrintResponseWithCheckTask prints a RPC response may contain response Msg with check-task's response prettily. check-task's response may contain json-string when checking fail in `detail` field. ugly code, but it is a little hard to refine this because needing to convert type.

func PrintCmdUsage

func PrintCmdUsage(cmd *cobra.Command)

PrintCmdUsage prints the usage of the command.

func PrintLinesf

func PrintLinesf(format string, a ...interface{})

PrintLinesf adds a wrap to support `\n` within `chzyer/readline`.

func SendRequest

func SendRequest(ctx context.Context, reqName string, req interface{}, respPointer interface{}) error

SendRequest send request to master.

func SplitArgsRespectQuote

func SplitArgsRespectQuote(line string) []string

SplitArgsRespectQuote splits args by space, but won't split space inside single or double quotes.

Types

type Config

type Config struct {
	*pflag.FlagSet `json:"-"`

	MasterAddr string `toml:"master-addr" json:"master-addr"`

	RPCTimeoutStr string        `toml:"rpc-timeout" json:"rpc-timeout"`
	RPCTimeout    time.Duration `json:"-"`

	ConfigFile string `json:"config-file"`

	security.Security
}

Config is the configuration.

func GlobalConfig

func GlobalConfig() *Config

GlobalConfig returns global dmctl config.

func NewConfig

func NewConfig(fs *pflag.FlagSet) *Config

NewConfig creates a new base config for dmctl.

func (*Config) Adjust

func (c *Config) Adjust() error

Adjust parses flag definitions from the argument list.

func (*Config) String

func (c *Config) String() string

func (*Config) Validate

func (c *Config) Validate() error

Validate check config is ready to execute command.

type CtlClient

type CtlClient struct {
	MasterClient pb.MasterClient  // exposed to be used in test
	EtcdClient   *clientv3.Client // exposed to be used in export config
	// contains filtered or unexported fields
}

CtlClient used to get master client for dmctl.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL