executor

package
v0.0.0-...-a197711 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() []string

Available returns all Worker's Name

func RegisterWorker

func RegisterWorker(constructor WorkerConstructor)

RegisterWorker used for plugins to register new Worker

Types

type Executor

type Executor struct {
	Parameter *Parameter
	// contains filtered or unexported fields
}

Executor is a singleton class. Holds meta info for worker.

func NewExecutor

func NewExecutor(p Parameter) (exec *Executor, err error)

NewExecutor returns an empty Executor

func (*Executor) AddFormatter

func (exec *Executor) AddFormatter(category string, fmt formatter.Formatter) *Executor

AddFormatter adds formatter into a hash. Formatters are devided into categories, and each category can hold only one Formatter. Obviously, the key for hash is `category`.

func (*Executor) HostCount

func (exec *Executor) HostCount() int

HostCount returns length of HostInfoList

func (*Executor) Run

func (exec *Executor) Run() (failed int, err error)

Run will initialize and drive worker and send output to Formatter(s)

func (*Executor) SetHostInfoList

func (exec *Executor) SetHostInfoList(list hostlist.HostInfoList) *Executor

SetHostInfoList is extended version of SetHostlist. Executor will adjust it at the beginning of Run, which would set correct User & Cmd.

func (*Executor) SetHostlist

func (exec *Executor) SetHostlist(list []string) *Executor

SetHostlist sets hostlist for execution, without check or modification. DEPRECATED

func (*Executor) SetTransfer

func (exec *Executor) SetTransfer(src, dst string) *Executor

SetTransfer sets source(local) and destination(remote) for file copy.

func (*Executor) SetTransferHook

func (exec *Executor) SetTransferHook(before, after string) *Executor

SetTransferHook sets a hook, which would be executed before and after, for the file copying.

type Parameter

type Parameter struct {
	Cmd          string
	User         string
	Passwd       string
	Script       string
	Account      string
	Method       string
	Retry        int
	Concurrency  int64
	Hostlist     []string
	HostInfoList hostlist.HostInfoList
	Timeout      int64
	Transfer     *TransferFile
}

Parameter holds data for worker

func (*Parameter) NeedTransferFile

func (data *Parameter) NeedTransferFile() bool

NeedTransferFile returns whether Worker should handle file copying.

func (*Parameter) WrapCmdWithHook

func (data *Parameter) WrapCmdWithHook(cmd string) string

WrapCmdWithHook returns wrapped cmd, e.g. add `-a` and `-b` args

type TransferFile

type TransferFile struct {
	Data        []byte
	Perm        string
	Basename    string
	Destination string // Destination DIRECTORY
	Src         string // Final Destination, Destination/Basename
	Dst         string
	// contains filtered or unexported fields
}

TransferFile describes file information that should be transferred.

type Worker

type Worker interface {
	Init(*Parameter) error
	Name() string
	Execute(done <-chan struct{}) (<-chan *formatter.Output, <-chan error)
}

Worker should able to 1. execute cmd string 2. copy file (from *Executor.transferFile)

type WorkerConstructor

type WorkerConstructor func() Worker

WorkerConstructor is function that receives no parameter and returns Worker

type WorkerWithRecommendedConcurrency

type WorkerWithRecommendedConcurrency interface {
	// @Return
	//   == 0: Recommended Concurrency
	//   < 0: Hostlist Length
	RecommendedConcurrency() int64
	Worker
}

WorkerWithRecommendedConcurrency could give its recommended concurrency

Jump to

Keyboard shortcuts

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