ctxt

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// CtxBaseTopo is key of store the base topology in context.Context
	CtxBaseTopo = contextKey("BASE_TOPO")
)

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, limit int, logger *logprinter.Logger) context.Context

New create a context instance.

Types

type Context

type Context struct {
	Ev EventBus

	// The private/public key is used to access remote server via the user `tidb`
	PrivateKeyPath string
	PublicKeyPath  string

	Concurrency int // max number of parallel tasks running at the same time
	// contains filtered or unexported fields
}

Context is used to share state while multiple tasks execution. We should use mutex to prevent concurrent R/W for some fields because of the same context can be shared in parallel tasks.

func GetInner

func GetInner(ctx context.Context) *Context

GetInner return *Context from context.Context's value

func (*Context) Get

func (ctx *Context) Get(host string) (e Executor)

Get implements the operation.ExecutorGetter interface.

func (*Context) GetCheckResults

func (ctx *Context) GetCheckResults(host string) (results []any, ok bool)

GetCheckResults get the the check result of a host (if has any)

func (*Context) GetExecutor

func (ctx *Context) GetExecutor(host string) (e Executor, ok bool)

GetExecutor get the executor.

func (*Context) GetOutputs

func (ctx *Context) GetOutputs(hostID string) ([]byte, []byte, bool)

GetOutputs get the outputs of a host (if has any)

func (*Context) GetSSHKeySet

func (ctx *Context) GetSSHKeySet() (privateKeyPath, publicKeyPath string)

GetSSHKeySet implements the operation.ExecutorGetter interface.

func (*Context) SetCheckResults

func (ctx *Context) SetCheckResults(host string, results []any)

SetCheckResults append the check result of a host to the list

func (*Context) SetExecutor

func (ctx *Context) SetExecutor(host string, e Executor)

SetExecutor set the executor.

func (*Context) SetOutputs

func (ctx *Context) SetOutputs(hostID string, stdout []byte, stderr []byte)

SetOutputs set the outputs of a host

type EventBus

type EventBus struct {
	// contains filtered or unexported fields
}

EventBus is an event bus for task events.

func NewEventBus

func NewEventBus() EventBus

NewEventBus creates a new EventBus.

func (*EventBus) PublishTaskBegin

func (ev *EventBus) PublishTaskBegin(task fmt.Stringer)

PublishTaskBegin publishes a TaskBegin event. This should be called only by Parallel or Serial.

func (*EventBus) PublishTaskFinish

func (ev *EventBus) PublishTaskFinish(task fmt.Stringer, err error)

PublishTaskFinish publishes a TaskFinish event. This should be called only by Parallel or Serial.

func (*EventBus) PublishTaskProgress

func (ev *EventBus) PublishTaskProgress(task fmt.Stringer, progress string)

PublishTaskProgress publishes a TaskProgress event.

func (*EventBus) Subscribe

func (ev *EventBus) Subscribe(eventName EventKind, handler any)

Subscribe subscribes events.

func (*EventBus) Unsubscribe

func (ev *EventBus) Unsubscribe(eventName EventKind, handler any)

Unsubscribe unsubscribes events.

type EventKind

type EventKind string

EventKind is the task event kind.

const (
	// EventTaskBegin is emitted when a task is going to be executed.
	EventTaskBegin EventKind = "task_begin"
	// EventTaskFinish is emitted when a task finishes executing.
	EventTaskFinish EventKind = "task_finish"
	// EventTaskProgress is emitted when a task has made some progress.
	EventTaskProgress EventKind = "task_progress"
)

type Executor

type Executor interface {
	// Execute run the command, then return its stdout and stderr
	// NOTE: stdin is not supported as it seems we don't need it (for now). If
	// at some point in the future we need to pass stdin to a command, we'll
	// need to refactor this function and its implementations.
	// If the cmd can't quit in timeout, it will return error, the default timeout is 60 seconds.
	Execute(ctx context.Context, cmd string, sudo bool, timeout ...time.Duration) (stdout []byte, stderr []byte, err error)

	// Transfer copies files from or to a target
	Transfer(ctx context.Context, src, dst string, download bool, limit int, compress bool) error
}

Executor is the executor interface for TiUP, all tasks will in the end be passed to an executor and then be actually performed.

type ExecutorGetter

type ExecutorGetter interface {
	Get(host string) (e Executor)
	// GetSSHKeySet gets the SSH private and public key path
	GetSSHKeySet() (privateKeyPath, publicKeyPath string)
}

ExecutorGetter get the executor by host.

Jump to

Keyboard shortcuts

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