executor

package
v0.0.0-...-b44688a Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: Apache-2.0 Imports: 42 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRuntimeScheme

func NewRuntimeScheme() *runtime.Scheme

NewRuntimeScheme creates instance of runtime.Scheme and registers default conversions.

func StopAndEraseOutput

func StopAndEraseOutput(handle TaskHandle) (errorCollection errcollection.ErrorCollection)

StopAndEraseOutput run Stop and EraseOutput on TaskHandle and add errors to errorCollection

Types

type CPU

type CPU struct {
	Performance string
	Threads     string
}

CPU defines CPU data.

type ChainedTaskHandle

type ChainedTaskHandle struct {
	TaskHandle
	// contains filtered or unexported fields
}

ChainedTaskHandle is an links Launchers in a way that one will be launched after another.

func (*ChainedTaskHandle) Status

func (cth *ChainedTaskHandle) Status() TaskState

Status returns current TaskState.

func (*ChainedTaskHandle) Stop

func (cth *ChainedTaskHandle) Stop() error

Stop stops all execution of ChainedTaskHandle.

func (*ChainedTaskHandle) Wait

func (cth *ChainedTaskHandle) Wait(timeout time.Duration) (bool, error)

Wait waits for all tasks in ChainedTaskHandle to finish.

type ClusterTaskHandle

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

ClusterTaskHandle is a task handle for composition of master and multiple agents. - StdoutFile, StderrFile, ExitCode, Status, Address are taken from master task handle. - Clean, EraseOutput, Stop are done for master and all agents. - Wait waits for master task and when it's terminated it stops all agents. It implements TaskHandle interface.

func NewClusterTaskHandle

func NewClusterTaskHandle(master TaskHandle, agents []TaskHandle) *ClusterTaskHandle

NewClusterTaskHandle returns a ClusterTaskHandle instance.

func (*ClusterTaskHandle) AddAgent

func (m *ClusterTaskHandle) AddAgent(agent TaskHandle)

AddAgent dynamically adds agent to already handled agents.

func (*ClusterTaskHandle) Address

func (m *ClusterTaskHandle) Address() string

Address returns address of master task.

func (*ClusterTaskHandle) EraseOutput

func (m *ClusterTaskHandle) EraseOutput() (err error)

EraseOutput removes master's and agents' stdout & stderr files.

func (*ClusterTaskHandle) ExitCode

func (m *ClusterTaskHandle) ExitCode() (int, error)

ExitCode returns the master exitCode. If master is not terminated it returns error.

func (*ClusterTaskHandle) Status

func (m *ClusterTaskHandle) Status() TaskState

Status returns the state of the master.

func (*ClusterTaskHandle) StderrFile

func (m *ClusterTaskHandle) StderrFile() (*os.File, error)

StderrFile returns a file handle for the master's stderr file.

func (*ClusterTaskHandle) StdoutFile

func (m *ClusterTaskHandle) StdoutFile() (*os.File, error)

StdoutFile returns a file handle for the master's stdout file.

func (*ClusterTaskHandle) Stop

func (m *ClusterTaskHandle) Stop() (err error)

Stop terminates the master firstly and then all the agents.

func (*ClusterTaskHandle) String

func (m *ClusterTaskHandle) String() string

String returns name of underlying task.

func (*ClusterTaskHandle) Wait

func (m *ClusterTaskHandle) Wait(timeout time.Duration) (isMasterTerminated bool, err error)

Wait does the blocking wait for the master completion in case of 0 timeout time. Wait is a helper for waiting with a given timeout time. It returns true if all tasks are terminated.

type Disk

type Disk struct {
	Iops string
	Size string
}

Disk defines disk data.

type Executor

type Executor interface {
	fmt.Stringer
	// Execute executes command on underlying platform.
	// Invokes "bash -c <command>" and waits for short time to make sure that process has started.
	// Returns error if command exited immediately with non-zero exit status.
	Execute(command string) (TaskHandle, error)
}

Executor is responsible for creating execution environment for given workload. It returns Task handle when workload started gracefully. Workload is executed asynchronously.

func NewKubernetes

func NewKubernetes(config KubernetesConfig) (Executor, error)

NewKubernetes returns an executor which lets the user run commands in pods in a kubernetes cluster.

func NewOpenstack

func NewOpenstack(config *OpenstackConfig) Executor

NewOpenstack creates OpenStack executor.

func NewRemote

func NewRemote(address string, config RemoteConfig) (Executor, error)

NewRemote returns a remote executor instance.

func NewRemoteFromIP

func NewRemoteFromIP(address string) (Executor, error)

NewRemoteFromIP returns a remote executo instance.

func NewRemoteIsolated

func NewRemoteIsolated(address string, config RemoteConfig, decorators isolation.Decorators) (Executor, error)

NewRemoteIsolated returns a remote executor instance.

func NewShell

func NewShell(ip string) (Executor, error)

NewShell is a wrapper constructor for NewLocal or NewRemote executor depending on ip provided.

type HostAggregate

type HostAggregate struct {
	Name             string
	ConfigurationID  string
	AvailabilityZone string
	Disk             Disk
	RAM              RAM
	CPU              CPU
}

HostAggregate defines OpenStack host aggregate data.

type Hypervisor

type Hypervisor struct {
	InstanceName string
	Address      string
}

Hypervisor defines OpenStack hypervisor data.

type KubernetesConfig

type KubernetesConfig struct {
	// PodName vs PodNamePrefix:
	// - PodName(deprecated; by default is empty string) - when this field is
	// configured, Kubernetes executor is using it as a Pod name. Kubernetes
	// doesn't support spawning pods with same name, so this field shouldn't
	// be in use.
	// - PodNamePrefix(by default is "swan") - If PodName field is not
	// configured, this field is used as a prefix for random generated Pod
	// name.
	PodName        string
	PodNamePrefix  string
	NodeName       string
	Address        string
	CPURequest     int64
	CPULimit       int64
	MemoryRequest  int64
	MemoryLimit    int64
	Decorators     isolation.Decorators
	ContainerName  string
	ContainerImage string
	Namespace      string
	Privileged     bool
	HostNetwork    bool
	LaunchTimeout  time.Duration
}

KubernetesConfig describes the necessary information to connect to a Kubernetes cluster.

func DefaultKubernetesConfig

func DefaultKubernetesConfig() KubernetesConfig

DefaultKubernetesConfig returns a KubernetesConfig object with safe defaults.

type LaunchTimedOutError

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

LaunchTimedOutError is the error type returned when launching new pods exceed the timeout value defined in kubernetes.Config.LaunchTimeout.

func (*LaunchTimedOutError) Error

func (err *LaunchTimedOutError) Error() string

Error is one method needed to implement the error interface. Here, we just return an the error message.

type Launcher

type Launcher interface {
	fmt.Stringer
	// Launch starts the workload (process or group of processes). It returns a workload
	// represented as a Task Handle instance.
	// Error is returned when Launcher is unable to start a job.
	Launch() (TaskHandle, error)
}

Launcher responsibility is to launch previously configured job.

type LoadGenerator

type LoadGenerator interface {
	// Populate inserts initial data.
	Populate() error

	// Tune does the tuning phase which is a process of searching for a targetQPS
	// for given SLO.
	Tune(slo int) (achievedLoad int, achievedSLI int, err error)

	// Load starts a load on the specific workload with the defined loadPoint (number of QPS).
	// The task will do the load for specified amount of time.
	// Note: Results from Load needs to be fetched out of band e.g using Snap.
	Load(load int, duration time.Duration) (task TaskHandle, err error)
}

LoadGenerator launches stresser which generates load on specified workload.

type Local

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

Local provisioning is responsible for providing the execution environment on local machine via exec.Command. It runs command as current user.

func NewLocal

func NewLocal() Local

NewLocal returns instance of local executors without any isolators.

func NewLocalIsolated

func NewLocalIsolated(deco ...isolation.Decorator) Local

NewLocalIsolated returns a Local instance with some isolators set.

func (Local) Execute

func (l Local) Execute(command string) (TaskHandle, error)

Execute runs the command given as input. Returned Task is able to stop & monitor the provisioned process.

func (Local) String

func (l Local) String() string

String returns user-friendly name of executor.

type MockExecutor

type MockExecutor struct {
	mock.Mock
}

MockExecutor is an autogenerated mock type for the Executor type

func (*MockExecutor) Execute

func (_m *MockExecutor) Execute(command string) (TaskHandle, error)

Execute provides a mock function with given fields: command

func (*MockExecutor) String

func (_m *MockExecutor) String() string

String provides a mock function with given fields:

type MockLauncher

type MockLauncher struct {
	mock.Mock
}

MockLauncher is an autogenerated mock type for the Launcher type

func (*MockLauncher) Launch

func (_m *MockLauncher) Launch() (TaskHandle, error)

Launch provides a mock function with given fields:

func (*MockLauncher) String

func (_m *MockLauncher) String() string

String provides a mock function with given fields:

type MockLoadGenerator

type MockLoadGenerator struct {
	mock.Mock
}

MockLoadGenerator is an autogenerated mock type for the LoadGenerator type

func (*MockLoadGenerator) Load

func (_m *MockLoadGenerator) Load(load int, duration time.Duration) (TaskHandle, error)

Load provides a mock function with given fields: load, duration

func (*MockLoadGenerator) Populate

func (_m *MockLoadGenerator) Populate() error

Populate provides a mock function with given fields:

func (*MockLoadGenerator) Tune

func (_m *MockLoadGenerator) Tune(slo int) (int, int, error)

Tune provides a mock function with given fields: slo

type MockTaskControl

type MockTaskControl struct {
	mock.Mock
}

MockTaskControl is an autogenerated mock type for the TaskControl type

func (*MockTaskControl) EraseOutput

func (_m *MockTaskControl) EraseOutput() error

EraseOutput provides a mock function with given fields:

func (*MockTaskControl) Stop

func (_m *MockTaskControl) Stop() error

Stop provides a mock function with given fields:

func (*MockTaskControl) Wait

func (_m *MockTaskControl) Wait(timeout time.Duration) (bool, error)

Wait provides a mock function with given fields: timeout

type MockTaskHandle

type MockTaskHandle struct {
	mock.Mock
}

MockTaskHandle is an autogenerated mock type for the TaskHandle type

func (*MockTaskHandle) Address

func (_m *MockTaskHandle) Address() string

Address provides a mock function with given fields:

func (*MockTaskHandle) EraseOutput

func (_m *MockTaskHandle) EraseOutput() error

EraseOutput provides a mock function with given fields:

func (*MockTaskHandle) ExitCode

func (_m *MockTaskHandle) ExitCode() (int, error)

ExitCode provides a mock function with given fields:

func (*MockTaskHandle) Status

func (_m *MockTaskHandle) Status() TaskState

Status provides a mock function with given fields:

func (*MockTaskHandle) StderrFile

func (_m *MockTaskHandle) StderrFile() (*os.File, error)

StderrFile provides a mock function with given fields:

func (*MockTaskHandle) StdoutFile

func (_m *MockTaskHandle) StdoutFile() (*os.File, error)

StdoutFile provides a mock function with given fields:

func (*MockTaskHandle) Stop

func (_m *MockTaskHandle) Stop() error

Stop provides a mock function with given fields:

func (*MockTaskHandle) String

func (_m *MockTaskHandle) String() string

String provides a mock function with given fields:

func (*MockTaskHandle) Wait

func (_m *MockTaskHandle) Wait(timeout time.Duration) (bool, error)

Wait provides a mock function with given fields: timeout

type MockTaskInfo

type MockTaskInfo struct {
	mock.Mock
}

MockTaskInfo is an autogenerated mock type for the TaskInfo type

func (*MockTaskInfo) Address

func (_m *MockTaskInfo) Address() string

Address provides a mock function with given fields:

func (*MockTaskInfo) ExitCode

func (_m *MockTaskInfo) ExitCode() (int, error)

ExitCode provides a mock function with given fields:

func (*MockTaskInfo) Status

func (_m *MockTaskInfo) Status() TaskState

Status provides a mock function with given fields:

func (*MockTaskInfo) StderrFile

func (_m *MockTaskInfo) StderrFile() (*os.File, error)

StderrFile provides a mock function with given fields:

func (*MockTaskInfo) StdoutFile

func (_m *MockTaskInfo) StdoutFile() (*os.File, error)

StdoutFile provides a mock function with given fields:

func (*MockTaskInfo) String

func (_m *MockTaskInfo) String() string

String provides a mock function with given fields:

type Openstack

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

Openstack defines OpenStack server configuration and client.

func (Openstack) Execute

func (stack Openstack) Execute(command string) (TaskHandle, error)

Execute runs provided command on OpenStack cluster.

func (Openstack) String

func (stack Openstack) String() string

String returns user-friendly name of executor.

type OpenstackAuthConfig

type OpenstackAuthConfig struct {
	Username   string
	Password   string
	TenantID   string
	DomainName string
	Endpoint   string
}

OpenstackAuthConfig defines OpenStack authentication configuration data.

type OpenstackConfig

type OpenstackConfig struct {
	Auth          gophercloud.AuthOptions
	Flavor        OpenstackFlavor
	Image         string
	User          string
	SSHKeyPath    string
	Name          string
	ID            string
	Hypervisor    Hypervisor
	HostAggregate HostAggregate
}

OpenstackConfig defines OpenStack instance configuration data.

func DefaultOpenstackConfig

func DefaultOpenstackConfig(auth gophercloud.AuthOptions) OpenstackConfig

DefaultOpenstackConfig creates default OpenStack config.

type OpenstackFlavor

type OpenstackFlavor struct {
	Name  string
	Disk  int
	RAM   int
	VCPUs int
}

OpenstackFlavor defines OpenStack flavor data.

type OpenstackTaskHandle

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

OpenstackTaskHandle represents an abstraction to control task lifecycle and status.

func (*OpenstackTaskHandle) Address

func (th *OpenstackTaskHandle) Address() string

Address returns ip address of host where task is located.

func (*OpenstackTaskHandle) EraseOutput

func (th *OpenstackTaskHandle) EraseOutput() error

EraseOutput removes directory where output files resides.

func (*OpenstackTaskHandle) ExitCode

func (th *OpenstackTaskHandle) ExitCode() (int, error)

ExitCode returns exit code of finished task. If task is still running, return error.

func (*OpenstackTaskHandle) Instance

func (th *OpenstackTaskHandle) Instance() string

Instance returns OpenStack instance name.

func (*OpenstackTaskHandle) Status

func (th *OpenstackTaskHandle) Status() TaskState

Status returns task status.

func (*OpenstackTaskHandle) StderrFile

func (th *OpenstackTaskHandle) StderrFile() (*os.File, error)

StderrFile returns file handle for file to the task's stderr file.

func (*OpenstackTaskHandle) StdoutFile

func (th *OpenstackTaskHandle) StdoutFile() (*os.File, error)

StdoutFile returns file handle for file to the task's stdout file.

func (*OpenstackTaskHandle) Stop

func (th *OpenstackTaskHandle) Stop() error

Stop stops task.

func (*OpenstackTaskHandle) String

func (th *OpenstackTaskHandle) String() string

String returns user-friendly name of task handle.

func (*OpenstackTaskHandle) Wait

func (th *OpenstackTaskHandle) Wait(timeout time.Duration) (bool, error)

Wait blocks and waits for task to terminate. For '0' it'll wait until task termination.

type Parallel

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

Parallel allows to run same command using same executor multiple times. Using Parallel decorator will mix output from all the commands executed. Parallel is run in new PID namespace (using isolation.Namespace) as children might not be killed correctly otherwise.

func NewParallel

func NewParallel(numberOfClones int) Parallel

NewParallel prepares instance of Decorator that allows to ran tasks in parallel.

func (Parallel) Decorate

func (p Parallel) Decorate(command string) string

Decorate implements isolation.Decorator interface by adding invocation of parallel to a command.

type RAM

type RAM struct {
	Bandwidth string
	Size      string
}

RAM defines RAM data.

type Remote

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

Remote provisioning is responsible for providing the execution environment on remote machine via ssh.

func (Remote) Execute

func (remote Remote) Execute(command string) (TaskHandle, error)

Execute runs the command given as input. Returned Task Handle is able to stop & monitor the provisioned process.

func (Remote) String

func (remote Remote) String() string

String returns User-friendly name of executor.

type RemoteConfig

type RemoteConfig struct {
	User    string
	KeyPath string

	Port int
}

RemoteConfig is configuration for Remote Executor.

func DefaultRemoteConfig

func DefaultRemoteConfig() RemoteConfig

DefaultRemoteConfig returns default Remote Executor configuration from flags.

type ServiceLauncher

type ServiceLauncher struct {
	Launcher
}

ServiceLauncher is a decorator and Launcher implementation that should be used for tasks that do not stop on their own.

func NewServiceLauncher

func NewServiceLauncher(launcher Launcher) ServiceLauncher

NewServiceLauncher is constructor for ServiceLauncher.

func (ServiceLauncher) Launch

func (sl ServiceLauncher) Launch() (TaskHandle, error)

Launch implements Launcher interface.

type TaskControl

type TaskControl interface {
	// Stops a task.
	// Returns error if something wrong has happen during task execution.
	Stop() error
	// Wait blocks and waits for task to terminate.
	// Parameter `timeout` is waiting timeout. For `0` it wil wait until task termination.
	// Returns `terminated` true when task terminates.
	// Returns error if something wrong has happen during task execution.
	Wait(timeout time.Duration) (terminated bool, err error)
	// EraseOutput deletes the directory where output files resides.
	EraseOutput() error
}

TaskControl controls task's lifecycle and garbage collection.

type TaskHandle

type TaskHandle interface {
	TaskInfo
	TaskControl
}

TaskHandle represents an abstraction to control task lifecycle and status.

func NewChainedTaskHandle

func NewChainedTaskHandle(handle TaskHandle, launchers ...Launcher) TaskHandle

NewChainedTaskHandle returns TaskHandle that executes current handle, and will launch Launcher when handle will finish it's execution.

func NewServiceHandle

func NewServiceHandle(handle TaskHandle) TaskHandle

NewServiceHandle wraps TaskHandle with serviceHandle.

type TaskInfo

type TaskInfo interface {
	fmt.Stringer
	// Location returns address where task was located.
	Address() string
	// ExitCode returns an exit code of finished task.
	// Returns error if If task is not terminated.
	ExitCode() (int, error)
	// Status returns a state of the task.
	Status() TaskState
	// StdoutFile returns a file handle for file to the task's stdout file.
	StdoutFile() (*os.File, error)
	// StderrFile returns a file handle for file to the task's stderr file.
	StderrFile() (*os.File, error)
}

TaskInfo represents task's address, status and output information.

type TaskState

type TaskState int

TaskState is an enum presenting current task state.

const (
	// RUNNING task state means that task is still running.
	RUNNING TaskState = iota
	// TERMINATED task state means that task completed or stopped.
	TERMINATED
)

Jump to

Keyboard shortcuts

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