tasks

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDiffID = cerr.FromErr(errors.New("different IsID"))
View Source
var ErrNotFoundID = cerr.NotFound("ID")
View Source
var ErrNotFoundSysID = cerr.NotFoundType[SysPID]()
View Source
var ErrNotFoundTaskID = cerr.NotFound("TaskID")
View Source
var ErrNotFoundTypeTaskConfig = cerr.NotFoundType[TaskConfig]()
View Source
var ErrNotPodContainerName = cerr.NotType[PodContainerName]()
View Source
var ErrNotTypeSysID = cerr.NotType[SysPID]()
View Source
var ErrPodProcessMapNotInit = cerr.NotInit[map[PodContainerName]SysPID]().WrapName("PodContainerNameProcessMap").Err()
View Source
var ErrTaskConfigMapNotInit = cerr.NotInit[map[TaskID]TaskConfig]().WrapName("TaskConfigMap").Err()

Functions

This section is empty.

Types

type Assign

type Assign interface {
	Assign(Injectable) error
}

Assign change some of an Injectable task with its own values. We use it in a case that we use TaskConfig.Data to update an Injectable task.

type ChaosOnPOD

type ChaosOnPOD interface {
	Injectable
	Recoverable
}

ChaosOnPOD stand for the inner process injector for container.

type ChaosOnProcessGroup

type ChaosOnProcessGroup interface {
	Fork() (ChaosOnProcessGroup, error)
	Assign

	Injectable
	Recoverable
}

ChaosOnProcessGroup is used for inject a chaos on a linux process group. Fork is used for create a new chaos on child process. Assign is used for update a chaos on child process.

type Creator

type Creator interface {
	New(values interface{}) (Injectable, error)
}

Creator init an Injectable with values. We use it in a case that TaskConfig.Data init an Injectable task here.

type Injectable

type Injectable interface {
	Inject(pid IsID) error
}

Injectable stand for the base behavior of task : inject a process with IsID.

type IsID

type IsID interface {
	ToID() string
}

type LockMap

type LockMap[K comparable] struct {
	sync.Map
}

func NewLockMap

func NewLockMap[K comparable]() LockMap[K]

func (*LockMap[K]) Del

func (l *LockMap[K]) Del(key K)

Del :TODO: Fix bug on deleting a using value

func (*LockMap[K]) Lock

func (l *LockMap[K]) Lock(key K) func()

type Mergeable

type Mergeable interface {
	Merge(a Mergeable) error
}

Mergeable introduces the data gathering ability.

type Object

type Object interface {
	DeepCopy() Object
}

Object ensure the outer config change will not change the data inside the TaskManager.

type PodContainerName

type PodContainerName string

func (PodContainerName) ToID

func (p PodContainerName) ToID() string

type PodContainerNameProcessMap

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

func NewPodProcessMap

func NewPodProcessMap() PodContainerNameProcessMap

func (*PodContainerNameProcessMap) Delete

func (p *PodContainerNameProcessMap) Delete(podPID PodContainerName)

func (*PodContainerNameProcessMap) Read

func (p *PodContainerNameProcessMap) Read(PodContainerName PodContainerName) (SysPID, error)

func (*PodContainerNameProcessMap) Write

func (p *PodContainerNameProcessMap) Write(PodContainerName PodContainerName, sysPID SysPID)

type PodHandler

type PodHandler struct {
	PodProcessMap *PodContainerNameProcessMap
	SubProcess    ChaosOnPOD
	Logger        logr.Logger
}

PodHandler implements injecting & recovering on a kubernetes POD.

func NewPodHandler

func NewPodHandler(podProcessMap *PodContainerNameProcessMap, sub ChaosOnPOD, logger logr.Logger) PodHandler

func (*PodHandler) Inject

func (p *PodHandler) Inject(id IsID) error

Inject get the container process IsID and Inject it with major injector. Be careful about the error handling here.

func (*PodHandler) Recover

func (p *PodHandler) Recover(id IsID) error

Recover get the container process IsID and Recover it with major injector. Be careful about the error handling here.

type ProcessGroupHandler

type ProcessGroupHandler struct {
	LeaderProcess ChaosOnProcessGroup

	Logger logr.Logger
	// contains filtered or unexported fields
}

ProcessGroupHandler implements injecting & recovering on a linux process group.

func NewProcessGroupHandler

func NewProcessGroupHandler(logger logr.Logger, leader ChaosOnProcessGroup) ProcessGroupHandler

func (*ProcessGroupHandler) Inject

func (gp *ProcessGroupHandler) Inject(pid IsID) error

Inject try to inject the leader process and then try to inject child process. If something wrong in injecting a child process, Inject will just log error & continue.

func (*ProcessGroupHandler) Recover

func (gp *ProcessGroupHandler) Recover(pid IsID) error

Recover try to recover the leader process and then try to recover child process.

type Recoverable

type Recoverable interface {
	Recover(pid IsID) error
}

Recoverable introduce the task recovering ability. Used in Recover.

type SysPID

type SysPID uint32

func (SysPID) ToID

func (s SysPID) ToID() string

type TaskConfig

type TaskConfig struct {
	Id   IsID
	Data Object
}

TaskConfig defines a composite of flexible config with an immutable target. TaskConfig.Id is the ID of task. TaskConfig.Data is the config provided by developer.

func NewTaskConfig

func NewTaskConfig(id IsID, data Object) TaskConfig

type TaskConfigManager

type TaskConfigManager struct {
	TaskConfigMap map[TaskID]TaskConfig
}

TaskConfigManager provides some basic methods on TaskConfig. If developers wants to use MergeTaskConfig, they must implement Mergeable for the TaskConfig.

func NewTaskConfigManager

func NewTaskConfigManager() TaskConfigManager

func (TaskConfigManager) AddTaskConfig

func (m TaskConfigManager) AddTaskConfig(id TaskID, task TaskConfig) error

func (TaskConfigManager) CheckTask

func (m TaskConfigManager) CheckTask(uid TaskID, pid IsID) error

func (TaskConfigManager) DeleteTaskConfig

func (m TaskConfigManager) DeleteTaskConfig(id TaskID) error

DeleteTaskConfig Delete task inside the TaskConfigManager

func (TaskConfigManager) GetConfigWithUID

func (m TaskConfigManager) GetConfigWithUID(id TaskID) (TaskConfig, error)

func (TaskConfigManager) GetUIDsWithPID

func (m TaskConfigManager) GetUIDsWithPID(id IsID) []TaskID

func (TaskConfigManager) MergeTaskConfig

func (m TaskConfigManager) MergeTaskConfig(uid TaskID) (TaskConfig, error)

MergeTaskConfig will sum the TaskConfig with a same TaskConfig.Id. If developers want to use it with type T, they must implement Mergeable for *T. IMPORTANT: Just here , we do not assume A.Merge(B) == B.Merge(A). What MergeTaskConfig do : A := new(TaskConfig), A.Merge(B).Merge(C).Merge(D)... , A marked as uid.

func (TaskConfigManager) UpdateTaskConfig

func (m TaskConfigManager) UpdateTaskConfig(id TaskID, task TaskConfig) (TaskConfig, error)

type TaskExecutor

type TaskExecutor interface {
	Object
	Mergeable
	Creator
	Assign
}

TaskExecutor indicate that the type can be used for execute task here as a task config. Mergeable means we can sum many task config in to one for apply. Creator means we can use the task config to create a running task which can Inject on IsID. Assign means we can use the task config to update an existing running task.

type TaskID

type TaskID = string

type TaskManager

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

TaskManager is a Manager for chaos tasks. A task base on a target marked with its IsID. We assume task should implement Injectable. We use TaskConfig.Data which implement TaskExecutor to:

Sum task configs on same IsID into one.
Create task.
Assign or update task.

SO if developers wants to use functions in TaskManager , their imported TaskConfig need to implement interface TaskExecutor. If developers wants to recover task successfully, the task must implement Recoverable. If not implement , the Recover function will return a ErrNotImplement("Recoverable") error. IMPORTANT: We assume task config obey that TaskConfig.Data A,B. A.Merge(B) is approximately equal to B.Merge(A)

func NewTaskManager

func NewTaskManager(logger logr.Logger) TaskManager

func (TaskManager) Apply

func (cm TaskManager) Apply(uid TaskID, pid IsID, config TaskExecutor) error

Apply the task when the target pid of task is already be Created. If it comes a TaskID injected , Apply will return ChaosErr.ErrDuplicateEntity. If the Process has not been Created , Apply will return ChaosErr.NotFound("IsID").

func (TaskManager) CheckTasks

func (cm TaskManager) CheckTasks(uid TaskID, pid IsID) error

func (TaskManager) ClearTask

func (cm TaskManager) ClearTask(pid IsID, ignoreRecoverErr bool) error

ClearTask clear the task totally. IMPORTANT: Developer should only use this function when want to force clear task with ignoreRecoverErr==true.

func (TaskManager) CopyTaskConfigManager

func (cm TaskManager) CopyTaskConfigManager() TaskConfigManager

func (TaskManager) CopyTaskMap

func (cm TaskManager) CopyTaskMap() map[IsID]Injectable

func (TaskManager) Create

func (cm TaskManager) Create(uid TaskID, pid IsID, config TaskExecutor, values interface{}) error

Create the first task, the New function of TaskExecutor:Creator will only be used here. values is only the import parameter of New function in TaskExecutor:Creator. If it comes a task are already be injected on the IsID, Create will return ChaosErr.ErrDuplicateEntity.

func (TaskManager) GetConfigWithUID

func (cm TaskManager) GetConfigWithUID(id TaskID) (TaskConfig, error)

func (TaskManager) GetTaskWithPID

func (cm TaskManager) GetTaskWithPID(pid IsID) (Injectable, error)

func (TaskManager) GetUIDsWithPID

func (cm TaskManager) GetUIDsWithPID(pid IsID) []TaskID

func (TaskManager) Recover

func (cm TaskManager) Recover(uid TaskID, pid IsID) error

Recover the task when there is no task config on IsID or recovering the task with last task config on IsID. Recover in Recoverable will be used here, if it runs failed it will just return the error. If Recover is failed but developer wants to clear it, just run : TaskManager.ClearTask(pid, true). If IsID is already recovered successfully, Recover will return ChaosErr.NotFound("IsID"). If TaskID is not Applied or Created or the target IsID of TaskID is not the import pid, Recover will return ChaosErr.NotFound("TaskID").

func (TaskManager) Update

func (cm TaskManager) Update(uid TaskID, pid IsID, config TaskExecutor) error

Update the task with a same TaskID, IsID and new task config. If it comes a TaskID not injected , Update will return ChaosErr.NotFound("TaskID"). If it comes the import IsID of task do not equal to the last one, Update will return ErrDiffID.

Jump to

Keyboard shortcuts

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