Documentation ¶
Index ¶
- Constants
- Variables
- func AddExecutorToModelSpec(executor Executor, expSpecs ...ExpModelCommandSpec)
- func AddFlagsToModelSpec(flagsFunc func() []ExpFlagSpec, expSpecs ...ExpModelCommandSpec)
- func ConvertExpMatchersToString(expModel *ExpModel, createExcludeKeyFunc func() map[string]Empty) string
- func IsDestroy(ctx context.Context) (string, bool)
- func SetDestroyFlag(ctx context.Context, suid string) context.Context
- type ActionModel
- func (am *ActionModel) Aliases() []string
- func (am *ActionModel) Example() string
- func (am *ActionModel) Executor() Executor
- func (am *ActionModel) Flags() []ExpFlagSpec
- func (am *ActionModel) LongDesc() string
- func (am *ActionModel) Matchers() []ExpFlagSpec
- func (am *ActionModel) Name() string
- func (am *ActionModel) Programs() []string
- func (am *ActionModel) SetExample(example string)
- func (am *ActionModel) SetExecutor(executor Executor)
- func (am *ActionModel) SetLongDesc(longDesc string)
- func (am *ActionModel) ShortDesc() string
- type BaseExpActionCommandSpec
- func (b *BaseExpActionCommandSpec) Example() string
- func (b *BaseExpActionCommandSpec) Executor() Executor
- func (b *BaseExpActionCommandSpec) Flags() []ExpFlagSpec
- func (b *BaseExpActionCommandSpec) Matchers() []ExpFlagSpec
- func (b *BaseExpActionCommandSpec) Programs() []string
- func (b *BaseExpActionCommandSpec) SetExample(example string)
- func (b *BaseExpActionCommandSpec) SetExecutor(executor Executor)
- func (b *BaseExpActionCommandSpec) SetLongDesc(longDesc string)
- type BaseExpModelCommandSpec
- type Channel
- type CodeType
- type Empty
- type Executor
- type ExpActionCommandSpec
- type ExpCommandModel
- func (ecm *ExpCommandModel) Actions() []ExpActionCommandSpec
- func (ecm *ExpCommandModel) Flags() []ExpFlagSpec
- func (ecm *ExpCommandModel) LongDesc() string
- func (ecm *ExpCommandModel) Name() string
- func (ecm *ExpCommandModel) Scope() string
- func (ecm *ExpCommandModel) SetFlags(flags []ExpFlagSpec)
- func (ecm *ExpCommandModel) ShortDesc() string
- type ExpFlag
- type ExpFlagSpec
- type ExpModel
- type ExpModelCommandSpec
- type ExpPrepareModel
- type Models
- type Response
- func Decode(content string, defaultValue *Response) *Response
- func Return(codeType CodeType, success bool) *Response
- func ReturnFail(codeType CodeType, err string) *Response
- func ReturnFailWitResult(codeType CodeType, err string, result interface{}) *Response
- func ReturnResultIgnoreCode(result interface{}) *Response
- func ReturnSuccess(result interface{}) *Response
Constants ¶
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" )
const (
DestroyKey = "suid"
)
const UnknownUid = "unknown"
Variables ¶
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
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 (b *BaseExpActionCommandSpec) Flags() []ExpFlagSpec
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 (b *BaseExpModelCommandSpec) Actions() []ExpActionCommandSpec
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 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) FlagNoArgs ¶
func (*ExpFlag) FlagRequired ¶
func (*ExpFlag) FlagRequiredWhenDestroyed ¶
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 ¶
ConvertCommandsToExpModel returns the ExpModel by action, target and flags
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 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 ReturnFail ¶
func ReturnFailWitResult ¶
func ReturnResultIgnoreCode ¶
func ReturnResultIgnoreCode(result interface{}) *Response
func ReturnSuccess ¶
func ReturnSuccess(result interface{}) *Response