spec

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IgnoreCode              = "IgnoreCode"
	OK                      = "OK"
	ReturnOKDirectly        = "ReturnOKDirectly"
	InvalidTimestamp        = "InvalidTimestamp"
	Forbidden               = "Forbidden"
	HandlerNotFound         = "HandlerNotFound"
	TokenNotFound           = "TokenNotFound"
	DataNotFound            = "DataNotFound"
	GetProcessError         = "GetProcessError"
	ServerError             = "ServerError"
	HandlerClosed           = "HandlerClosed"
	Timeout                 = "Timeout"
	Uninitialized           = "Uninitialized"
	EncodeError             = "EncodeError"
	DecodeError             = "DecodeError"
	FileNotFound            = "FileNotFound"
	DownloadError           = "DownloadError"
	DeployError             = "DeployError"
	ServiceSwitchError      = "ServiceSwitchError"
	DiskNotFound            = "DiskNotFound"
	DatabaseError           = "DatabaseError"
	EnvironmentError        = "EnvironmentError"
	NoWritePermission       = "NoWritePermission"
	RemoveRecordError       = "RemoveRecordError"
	ParameterEmpty          = "ParameterEmpty"
	ParameterTypeError      = "ParameterTypeError"
	IllegalParameters       = "IllegalParameters"
	IllegalCommand          = "IllegalCommand"
	ExecCommandError        = "ExecCommandError"
	DuplicateError          = "DuplicateError"
	FaultInjectCmdError     = "FaultInjectCmdError"
	FaultInjectExecuteError = "FaultInjectExecuteError"
	FaultInjectNotSupport   = "FaultInjectNotSupport"
	JavaAgentCmdError       = "JavaAgentCmdError"
	K8sInvokeError          = "K8sInvokeError"
	DockerInvokeError       = "DockerInvokeError"
	DestroyNotSupported     = "DestroyNotSupported"
	PreHandleError          = "PreHandleError"
	SandboxInvokeError      = "SandboxInvokeError"
	CommandNotFound         = "CommandNotFound"
	StatusError             = "StatusError"
	UnexpectedCommandError  = "UnexpectedCommandError"
	CplusProxyCmdError      = "CplusProxyCmdError"
)
View Source
const (
	DestroyKey = "suid"
)
View Source
const UnknownUid = "unknown"

Variables

View Source
var Code = map[string]CodeType{
	IgnoreCode:              {100, "ignore code"},
	OK:                      {200, "success"},
	ReturnOKDirectly:        {201, "return ok directly"},
	InvalidTimestamp:        {401, "invalid timestamp"},
	Forbidden:               {403, "forbidden"},
	HandlerNotFound:         {404, "request handler not found"},
	TokenNotFound:           {405, "access token not found"},
	DataNotFound:            {406, "data not found"},
	DestroyNotSupported:     {407, "destroy not supported"},
	GetProcessError:         {408, "get process error"},
	ServerError:             {500, "server error"},
	HandlerClosed:           {501, "handler closed"},
	PreHandleError:          {502, "pre handle error"},
	CommandNotFound:         {503, "command not found"},
	StatusError:             {504, "status error"},
	Timeout:                 {510, "timeout"},
	Uninitialized:           {511, "uninitialized"},
	EncodeError:             {512, "encode error"},
	DecodeError:             {513, "decode error"},
	FileNotFound:            {514, "file not found"},
	DownloadError:           {515, "download file error"},
	DeployError:             {516, "deploy file error"},
	ServiceSwitchError:      {517, "service switch error"},
	DiskNotFound:            {518, "disk not found"},
	DatabaseError:           {520, "execute db error"},
	EnvironmentError:        {521, "environment error"},
	NoWritePermission:       {522, "no write permission"},
	RemoveRecordError:       {530, "remove record or resource err"},
	ParameterEmpty:          {600, "parameter is empty"},
	ParameterTypeError:      {601, "parameter type error"},
	IllegalParameters:       {602, "illegal parameters"},
	IllegalCommand:          {603, "illegal command"},
	ExecCommandError:        {604, "exec command error"},
	DuplicateError:          {605, "duplicate error"},
	FaultInjectCmdError:     {701, "cannot handle the faultInject cmd"},
	FaultInjectExecuteError: {702, "execute faultInject error"},
	FaultInjectNotSupport:   {703, "the inject type not support"},
	JavaAgentCmdError:       {704, "cannot handle the javaagent cmd"},
	K8sInvokeError:          {800, "invoke k8s server api error"},
	DockerInvokeError:       {801, "invoke docker command error"},
	SandboxInvokeError:      {802, "invoke sandbox error"},
	CplusProxyCmdError:      {803, "invoke cplus proxy error"},
	UnexpectedCommandError:  {901, "unexpected command error"},
}

Functions

func AddExecutorToModelSpec

func AddExecutorToModelSpec(executor Executor, expSpecs ...ExpModelCommandSpec)

AddExecutorToModelSpec

func AddFlagsToModelSpec

func AddFlagsToModelSpec(flagsFunc func() []ExpFlagSpec, expSpecs ...ExpModelCommandSpec)

AddFlagsToModelSpec

func ConvertExpMatchersToString

func ConvertExpMatchersToString(expModel *ExpModel, createExcludeKeyFunc func() map[string]Empty) string

ConvertExpMatchersToString returns the flag arguments for cli

func IsDestroy

func IsDestroy(ctx context.Context) (string, bool)

IsDestroy command

func SetDestroyFlag

func SetDestroyFlag(ctx context.Context, suid string) context.Context

Types

type ActionModel

type ActionModel struct {
	ActionName      string    `yaml:"action"`
	ActionAliases   []string  `yaml:"aliases,flow,omitempty"`
	ActionShortDesc string    `yaml:"shortDesc"`
	ActionLongDesc  string    `yaml:"longDesc"`
	ActionMatchers  []ExpFlag `yaml:"matchers,omitempty"`
	ActionFlags     []ExpFlag `yaml:"flags,omitempty"`
	ActionExample   string    `yaml:"example"`

	ActionPrograms []string `yaml:"programs,omitempty"`
	// contains filtered or unexported fields
}

ActionModel for yaml file

func (*ActionModel) Aliases

func (am *ActionModel) Aliases() []string

func (*ActionModel) Example

func (am *ActionModel) Example() string

func (*ActionModel) Executor

func (am *ActionModel) Executor() Executor

func (*ActionModel) Flags

func (am *ActionModel) Flags() []ExpFlagSpec

func (*ActionModel) LongDesc

func (am *ActionModel) LongDesc() string

func (*ActionModel) Matchers

func (am *ActionModel) Matchers() []ExpFlagSpec

func (*ActionModel) Name

func (am *ActionModel) Name() string

func (*ActionModel) Programs

func (am *ActionModel) Programs() []string

func (*ActionModel) SetExample

func (am *ActionModel) SetExample(example string)

func (*ActionModel) SetExecutor

func (am *ActionModel) SetExecutor(executor Executor)

func (*ActionModel) SetLongDesc

func (am *ActionModel) SetLongDesc(longDesc string)

func (*ActionModel) ShortDesc

func (am *ActionModel) ShortDesc() string

type BaseExpActionCommandSpec

type BaseExpActionCommandSpec struct {
	ActionMatchers []ExpFlagSpec
	ActionFlags    []ExpFlagSpec
	ActionExecutor Executor
	ActionLongDesc string
	ActionExample  string
	ActionPrograms []string
}

BaseExpActionCommandSpec defines the common struct of the implementation of ExpActionCommandSpec

func (*BaseExpActionCommandSpec) Example

func (b *BaseExpActionCommandSpec) Example() string

func (*BaseExpActionCommandSpec) Executor

func (b *BaseExpActionCommandSpec) Executor() Executor

func (*BaseExpActionCommandSpec) Flags

func (*BaseExpActionCommandSpec) Matchers

func (b *BaseExpActionCommandSpec) Matchers() []ExpFlagSpec

func (*BaseExpActionCommandSpec) Programs

func (b *BaseExpActionCommandSpec) Programs() []string

func (*BaseExpActionCommandSpec) SetExample

func (b *BaseExpActionCommandSpec) SetExample(example string)

func (*BaseExpActionCommandSpec) SetExecutor

func (b *BaseExpActionCommandSpec) SetExecutor(executor Executor)

func (*BaseExpActionCommandSpec) SetLongDesc

func (b *BaseExpActionCommandSpec) SetLongDesc(longDesc string)

type BaseExpModelCommandSpec

type BaseExpModelCommandSpec struct {
	ExpScope   string
	ExpActions []ExpActionCommandSpec
	ExpFlags   []ExpFlagSpec
}

BaseExpModelCommandSpec defines the common struct of the implementation of ExpModelCommandSpec

func (*BaseExpModelCommandSpec) Actions

func (*BaseExpModelCommandSpec) Flags

func (b *BaseExpModelCommandSpec) Flags() []ExpFlagSpec

func (*BaseExpModelCommandSpec) Scope

func (b *BaseExpModelCommandSpec) Scope() string

Scope default value is "" means localhost

func (*BaseExpModelCommandSpec) SetFlags

func (b *BaseExpModelCommandSpec) SetFlags(flags []ExpFlagSpec)

type Channel

type Channel interface {
	// Run script with args and returns response that wraps the result
	Run(ctx context.Context, script, args string) *Response

	// GetScriptPath return the script path
	GetScriptPath() string
}

Channel is an interface for command invocation

type CodeType

type CodeType struct {
	Code int32
	Msg  string
}

type Empty

type Empty struct{}

type Executor

type Executor interface {
	// Name is used to identify the ExpExecutor
	Name() string

	// Exec is used to execute the experiment
	Exec(uid string, ctx context.Context, model *ExpModel) *Response

	// SetChannel
	SetChannel(channel Channel)
}

ExpExecutor defines the ExpExecutor interface

type ExpActionCommandSpec

type ExpActionCommandSpec interface {
	// Name returns the action name
	Name() string

	// Aliases returns command alias names
	Aliases() []string

	// ShortDesc returns short description for the action
	ShortDesc() string

	// LongDesc returns full description for the action
	LongDesc() string

	// SetLongDesc
	SetLongDesc(longDesc string)

	// Matchers returns the list of matchers supported by the action
	Matchers() []ExpFlagSpec

	// Flags returns the list of flags supported by the action
	Flags() []ExpFlagSpec

	//Example returns command example
	Example() string

	//Example returns command example
	SetExample(example string)

	// ExpExecutor returns the action command ExpExecutor
	Executor() Executor

	// SetExecutor
	SetExecutor(executor Executor)

	// Programs executed
	Programs() []string
}

ExpActionCommandSpec defines the action command interface for the experimental plugin

type ExpCommandModel

type ExpCommandModel struct {
	ExpName         string          `yaml:"target"`
	ExpShortDesc    string          `yaml:"shortDesc"`
	ExpLongDesc     string          `yaml:"longDesc"`
	ExpActions      []ActionModel   `yaml:"actions"`
	ExpExecutor     Executor        `yaml:"-"`
	ExpFlags        []ExpFlag       `yaml:"flags,omitempty"`
	ExpScope        string          `yaml:"scope"`
	ExpPrepareModel ExpPrepareModel `yaml:"prepare,omitempty"`
	ExpSubTargets   []string        `yaml:"subTargets,flow,omitempty"`
}

func (*ExpCommandModel) Actions

func (ecm *ExpCommandModel) Actions() []ExpActionCommandSpec

func (*ExpCommandModel) Flags

func (ecm *ExpCommandModel) Flags() []ExpFlagSpec

func (*ExpCommandModel) LongDesc

func (ecm *ExpCommandModel) LongDesc() string

func (*ExpCommandModel) Name

func (ecm *ExpCommandModel) Name() string

func (*ExpCommandModel) Scope

func (ecm *ExpCommandModel) Scope() string

func (*ExpCommandModel) SetFlags

func (ecm *ExpCommandModel) SetFlags(flags []ExpFlagSpec)

func (*ExpCommandModel) ShortDesc

func (ecm *ExpCommandModel) ShortDesc() string

type ExpFlag

type ExpFlag struct {
	// Name returns the flag FlagName
	Name string `yaml:"name"`

	// Desc returns the flag description
	Desc string `yaml:"desc"`

	// NoArgs means no arguments
	NoArgs bool `yaml:"noArgs"`

	// Required means necessary or not
	Required bool `yaml:"required"`
	// RequiredWhenDestroyed is true if the flag is necessary when destroying experiment
	RequiredWhenDestroyed bool `yaml:"requiredWhenDestroyed"`
}

ExpFlag defines the action flag

func (*ExpFlag) FlagDesc

func (f *ExpFlag) FlagDesc() string

func (*ExpFlag) FlagName

func (f *ExpFlag) FlagName() string

func (*ExpFlag) FlagNoArgs

func (f *ExpFlag) FlagNoArgs() bool

func (*ExpFlag) FlagRequired

func (f *ExpFlag) FlagRequired() bool

func (*ExpFlag) FlagRequiredWhenDestroyed

func (f *ExpFlag) FlagRequiredWhenDestroyed() bool

type ExpFlagSpec

type ExpFlagSpec interface {
	// FlagName returns the flag FlagName
	FlagName() string
	// FlagDesc returns the flag description
	FlagDesc() string
	// FlagNoArgs returns true if the flag is bool type
	FlagNoArgs() bool
	// FlagRequired returns true if the flag is necessary when creating experiment
	FlagRequired() bool
	// FlagRequiredWhenDestroyed returns true if the flag is necessary when destroying experiment
	FlagRequiredWhenDestroyed() bool
}

type ExpModel

type ExpModel struct {
	// Target is experiment target
	Target string `json:"target,omitempty"`

	// Scope is the experiment scope
	Scope string `json:"scope,omitempty"`

	// ActionName is the experiment action FlagName, for example delay
	ActionName string `json:"action,omitempty"`

	// ActionFlags is the experiment action flags, for example time and offset
	ActionFlags map[string]string `json:"flags,omitempty"`

	// Programs
	ActionPrograms []string `json:"programs,omitempty"`
}

ExpModel is the experiment data object

func ConvertCommandsToExpModel

func ConvertCommandsToExpModel(action, target, rules string) *ExpModel

ConvertCommandsToExpModel returns the ExpModel by action, target and flags

func (*ExpModel) GetFlags

func (exp *ExpModel) GetFlags() string

type ExpModelCommandSpec

type ExpModelCommandSpec interface {
	// Name returns the target name
	Name() string

	// Scope returns the experiment scope
	Scope() string

	// ShortDesc returns short description for the command
	ShortDesc() string

	// LongDesc returns full description for the command
	LongDesc() string

	// Actions returns the list of actions supported by the command
	Actions() []ExpActionCommandSpec

	// Flags returns the command flags
	Flags() []ExpFlagSpec

	// SetFlags
	SetFlags(flags []ExpFlagSpec)
}

ExpModelCommandSpec defines the command interface for the experimental plugin

type ExpPrepareModel

type ExpPrepareModel struct {
	PrepareType     string    `yaml:"type"`
	PrepareFlags    []ExpFlag `yaml:"flags"`
	PrepareRequired bool      `yaml:"required"`
}

type Models

type Models struct {
	Version string            `yaml:"version"`
	Kind    string            `yaml:"kind"`
	Models  []ExpCommandModel `yaml:"items"`
}

type Response

type Response struct {
	Code    int32       `json:"code"`
	Success bool        `json:"success"`
	Err     string      `json:"error,omitempty"`
	Result  interface{} `json:"result,omitempty"`
}

func Decode

func Decode(content string, defaultValue *Response) *Response

Decode return the response that wraps the content

func Return

func Return(codeType CodeType, success bool) *Response

func ReturnFail

func ReturnFail(codeType CodeType, err string) *Response

func ReturnFailWitResult

func ReturnFailWitResult(codeType CodeType, err string, result interface{}) *Response

func ReturnResultIgnoreCode

func ReturnResultIgnoreCode(result interface{}) *Response

func ReturnSuccess

func ReturnSuccess(result interface{}) *Response

func (*Response) Error

func (response *Response) Error() string

func (*Response) Print

func (response *Response) Print() string

func (*Response) ToString

func (response *Response) ToString() string

ToString

Jump to

Keyboard shortcuts

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