Documentation
¶
Index ¶
- type ListDistributedTasksResponse
- type Manager
- func (m *Manager) AddTask(c *api.ApplyRequest, seqNum uint64) error
- func (m *Manager) CancelTask(a *api.ApplyRequest) error
- func (m *Manager) CleanUpTask(a *api.ApplyRequest) error
- func (m *Manager) ListDistributedTasks(_ context.Context) (map[string][]*Task, error)
- func (m *Manager) ListDistributedTasksPayload(ctx context.Context) ([]byte, error)
- func (m *Manager) RecordNodeCompletion(c *api.ApplyRequest, numberOfNodesInTheCluster int) error
- func (m *Manager) Restore(bytes []byte) error
- func (m *Manager) Snapshot() ([]byte, error)
- type ManagerParameters
- type MockTaskCleaner
- type MockTaskCleaner_CleanUpDistributedTask_Call
- func (_c *MockTaskCleaner_CleanUpDistributedTask_Call) Return(_a0 error) *MockTaskCleaner_CleanUpDistributedTask_Call
- func (_c *MockTaskCleaner_CleanUpDistributedTask_Call) Run(...) *MockTaskCleaner_CleanUpDistributedTask_Call
- func (_c *MockTaskCleaner_CleanUpDistributedTask_Call) RunAndReturn(run func(context.Context, string, string, uint64) error) *MockTaskCleaner_CleanUpDistributedTask_Call
- type MockTaskCleaner_Expecter
- type MockTaskCompletionRecorder
- func (_m *MockTaskCompletionRecorder) EXPECT() *MockTaskCompletionRecorder_Expecter
- func (_m *MockTaskCompletionRecorder) RecordDistributedTaskNodeCompletion(ctx context.Context, namespace string, taskID string, version uint64) error
- func (_m *MockTaskCompletionRecorder) RecordDistributedTaskNodeFailure(ctx context.Context, namespace string, taskID string, version uint64, ...) error
- type MockTaskCompletionRecorder_Expecter
- func (_e *MockTaskCompletionRecorder_Expecter) RecordDistributedTaskNodeCompletion(ctx interface{}, namespace interface{}, taskID interface{}, ...) *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call
- func (_e *MockTaskCompletionRecorder_Expecter) RecordDistributedTaskNodeFailure(ctx interface{}, namespace interface{}, taskID interface{}, ...) *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call
- type MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call
- func (_c *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call) Return(_a0 error) *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call
- func (_c *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call) Run(run func(ctx context.Context, namespace string, taskID string, version uint64)) *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call
- func (_c *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call) RunAndReturn(run func(context.Context, string, string, uint64) error) *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call
- type MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call
- func (_c *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call) Return(_a0 error) *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call
- func (_c *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call) Run(...) *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call
- func (_c *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call) RunAndReturn(run func(context.Context, string, string, uint64, string) error) *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call
- type Provider
- type Scheduler
- type SchedulerParams
- type Task
- type TaskCleaner
- type TaskCompletionRecorder
- type TaskDescriptor
- type TaskHandle
- type TaskStatus
- type TasksLister
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is responsible for managing distributed tasks across the cluster.
func NewManager ¶
func NewManager(params ManagerParameters) *Manager
func (*Manager) CancelTask ¶
func (m *Manager) CancelTask(a *api.ApplyRequest) error
func (*Manager) CleanUpTask ¶
func (m *Manager) CleanUpTask(a *api.ApplyRequest) error
func (*Manager) ListDistributedTasks ¶
func (*Manager) ListDistributedTasksPayload ¶
func (*Manager) RecordNodeCompletion ¶
func (m *Manager) RecordNodeCompletion(c *api.ApplyRequest, numberOfNodesInTheCluster int) error
type ManagerParameters ¶
type MockTaskCleaner ¶
MockTaskCleaner is an autogenerated mock type for the TaskCleaner type
func NewMockTaskCleaner ¶
func NewMockTaskCleaner(t interface {
mock.TestingT
Cleanup(func())
}) *MockTaskCleaner
NewMockTaskCleaner creates a new instance of MockTaskCleaner. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockTaskCleaner) CleanUpDistributedTask ¶
func (_m *MockTaskCleaner) CleanUpDistributedTask(ctx context.Context, namespace string, taskID string, taskVersion uint64) error
CleanUpDistributedTask provides a mock function with given fields: ctx, namespace, taskID, taskVersion
func (*MockTaskCleaner) EXPECT ¶
func (_m *MockTaskCleaner) EXPECT() *MockTaskCleaner_Expecter
type MockTaskCleaner_CleanUpDistributedTask_Call ¶
MockTaskCleaner_CleanUpDistributedTask_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CleanUpDistributedTask'
func (*MockTaskCleaner_CleanUpDistributedTask_Call) Return ¶
func (_c *MockTaskCleaner_CleanUpDistributedTask_Call) Return(_a0 error) *MockTaskCleaner_CleanUpDistributedTask_Call
func (*MockTaskCleaner_CleanUpDistributedTask_Call) Run ¶
func (_c *MockTaskCleaner_CleanUpDistributedTask_Call) Run(run func(ctx context.Context, namespace string, taskID string, taskVersion uint64)) *MockTaskCleaner_CleanUpDistributedTask_Call
func (*MockTaskCleaner_CleanUpDistributedTask_Call) RunAndReturn ¶
func (_c *MockTaskCleaner_CleanUpDistributedTask_Call) RunAndReturn(run func(context.Context, string, string, uint64) error) *MockTaskCleaner_CleanUpDistributedTask_Call
type MockTaskCleaner_Expecter ¶
type MockTaskCleaner_Expecter struct {
// contains filtered or unexported fields
}
func (*MockTaskCleaner_Expecter) CleanUpDistributedTask ¶
func (_e *MockTaskCleaner_Expecter) CleanUpDistributedTask(ctx interface{}, namespace interface{}, taskID interface{}, taskVersion interface{}) *MockTaskCleaner_CleanUpDistributedTask_Call
CleanUpDistributedTask is a helper method to define mock.On call
- ctx context.Context
- namespace string
- taskID string
- taskVersion uint64
type MockTaskCompletionRecorder ¶
MockTaskCompletionRecorder is an autogenerated mock type for the TaskCompletionRecorder type
func NewMockTaskCompletionRecorder ¶
func NewMockTaskCompletionRecorder(t interface {
mock.TestingT
Cleanup(func())
}) *MockTaskCompletionRecorder
NewMockTaskCompletionRecorder creates a new instance of MockTaskCompletionRecorder. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockTaskCompletionRecorder) EXPECT ¶
func (_m *MockTaskCompletionRecorder) EXPECT() *MockTaskCompletionRecorder_Expecter
func (*MockTaskCompletionRecorder) RecordDistributedTaskNodeCompletion ¶
func (_m *MockTaskCompletionRecorder) RecordDistributedTaskNodeCompletion(ctx context.Context, namespace string, taskID string, version uint64) error
RecordDistributedTaskNodeCompletion provides a mock function with given fields: ctx, namespace, taskID, version
func (*MockTaskCompletionRecorder) RecordDistributedTaskNodeFailure ¶
func (_m *MockTaskCompletionRecorder) RecordDistributedTaskNodeFailure(ctx context.Context, namespace string, taskID string, version uint64, errMsg string) error
RecordDistributedTaskNodeFailure provides a mock function with given fields: ctx, namespace, taskID, version, errMsg
type MockTaskCompletionRecorder_Expecter ¶
type MockTaskCompletionRecorder_Expecter struct {
// contains filtered or unexported fields
}
func (*MockTaskCompletionRecorder_Expecter) RecordDistributedTaskNodeCompletion ¶
func (_e *MockTaskCompletionRecorder_Expecter) RecordDistributedTaskNodeCompletion(ctx interface{}, namespace interface{}, taskID interface{}, version interface{}) *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call
RecordDistributedTaskNodeCompletion is a helper method to define mock.On call
- ctx context.Context
- namespace string
- taskID string
- version uint64
func (*MockTaskCompletionRecorder_Expecter) RecordDistributedTaskNodeFailure ¶
func (_e *MockTaskCompletionRecorder_Expecter) RecordDistributedTaskNodeFailure(ctx interface{}, namespace interface{}, taskID interface{}, version interface{}, errMsg interface{}) *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call
RecordDistributedTaskNodeFailure is a helper method to define mock.On call
- ctx context.Context
- namespace string
- taskID string
- version uint64
- errMsg string
type MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call ¶
MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RecordDistributedTaskNodeCompletion'
func (*MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call) Run ¶
func (_c *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call) Run(run func(ctx context.Context, namespace string, taskID string, version uint64)) *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call
func (*MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call) RunAndReturn ¶
func (_c *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call) RunAndReturn(run func(context.Context, string, string, uint64) error) *MockTaskCompletionRecorder_RecordDistributedTaskNodeCompletion_Call
type MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call ¶
MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RecordDistributedTaskNodeFailure'
func (*MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call) Run ¶
func (_c *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call) Run(run func(ctx context.Context, namespace string, taskID string, version uint64, errMsg string)) *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call
func (*MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call) RunAndReturn ¶
func (_c *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call) RunAndReturn(run func(context.Context, string, string, uint64, string) error) *MockTaskCompletionRecorder_RecordDistributedTaskNodeFailure_Call
type Provider ¶
type Provider interface {
// SetCompletionRecorder is invoked on node startup to register TaskCompletionRecorder which
// should be passed to all launch tasks so they could mark their completion.
SetCompletionRecorder(recorder TaskCompletionRecorder)
// GetLocalTasks returns a list of tasks that provider is aware of from the local node state.
GetLocalTasks() []TaskDescriptor
// CleanupTask is a signal to clean up the task local state.
CleanupTask(desc TaskDescriptor) error
// StartTask is a signal to start executing the task in the background.
StartTask(task *Task) (TaskHandle, error)
}
Provider is an interface for the management and execution of a group of tasks denoted by a namespace.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler is the component which is responsible for polling the active tasks in the cluster (via the Manager) and making sure that the tasks are running on the local node.
The general flow of a distributed task is as follows: 1. A Provider is registered with the Scheduler at startup to handle all tasks under a specific namespace. 2. A task is created and added to the cluster via the Manager.AddTask. 3. Scheduler regularly scans all available tasks in the cluster, picks up new ones and instructs the Provider to execute them locally. 4. A task is responsible for updating its status in the cluster via TaskCompletionRecorder. 6. Scheduler polls the cluster for the task status and checks if it is still running. It cancels the local task if it is not marked as STARTED anymore. 7. After completed task TTL has passed, the Scheduler issues the Manager.CleanUpDistributedTask request to remove the task from the cluster list. 8. After a task is removed from the cluster list, the Scheduler instructs the Provider to clean up the local task state.
func NewScheduler ¶
func NewScheduler(params SchedulerParams) *Scheduler
type SchedulerParams ¶
type SchedulerParams struct {
CompletionRecorder TaskCompletionRecorder
TasksLister TasksLister
TaskCleaner TaskCleaner
Providers map[string]Provider
Clock clockwork.Clock
Logger logrus.FieldLogger
MetricsRegisterer prometheus.Registerer
LocalNode string
CompletedTaskTTL time.Duration
TickInterval time.Duration
}
type Task ¶
type Task struct {
// Namespace is the namespace of distributed tasks which are managed by different Provider implementations
Namespace string `json:"namespace"`
TaskDescriptor `json:",inline"`
// Payload is arbitrary data that is needed to execute a task of Namespace.
Payload []byte `json:"payload"`
// Status is the current status of the task.
Status TaskStatus `json:"status"`
// StartedAt is the time that a task was submitted to the cluster.
StartedAt time.Time `json:"startedAt"`
// FinishedAt is the time that task reached a terminal status.
// Additionally, it is used to schedule task clean up.
FinishedAt time.Time `json:"finishedAt"`
// Error is an optional field to store the error which moved the task to FAILED status.
Error string `json:"error,omitempty"`
// FinishedNodes is a map of nodeIDs that successfully finished the task.
FinishedNodes map[string]bool `json:"finishedNodes"`
}
type TaskCleaner ¶
type TaskCleaner interface {
CleanUpDistributedTask(ctx context.Context, namespace, taskID string, taskVersion uint64) error
}
TaskCleaner is an interface for issuing a request to clean up a distributed task.
type TaskCompletionRecorder ¶
type TaskCompletionRecorder interface {
RecordDistributedTaskNodeCompletion(ctx context.Context, namespace, taskID string, version uint64) error
RecordDistributedTaskNodeFailure(ctx context.Context, namespace, taskID string, version uint64, errMsg string) error
}
TaskCompletionRecorder is an interface for recording the completion of a distributed task.
type TaskDescriptor ¶
type TaskDescriptor struct {
// ID is the identifier of the task in the namespace.
ID string `json:"ID"`
// Version is the version of the task with task ID.
// It is used to differentiate between multiple runs of the same task.
Version uint64 `json:"version"`
}
TaskDescriptor is a struct identifying a task execution under a certain task namespace.
type TaskHandle ¶
type TaskHandle interface {
// Terminate is a signal to stop executing the task. If the task is no longer running because it already finished,
// the method call should be a no-op.
//
// Terminated task can be started later again, therefore, no local state can be removed.
Terminate()
}
TaskHandle is an interface to control a locally running task.
type TaskStatus ¶
type TaskStatus string
const ( // TaskStatusStarted means that the task is still running on some of the nodes. TaskStatusStarted TaskStatus = "STARTED" // TaskStatusFinished means that the task was successfully executed by all nodes. TaskStatusFinished TaskStatus = "FINISHED" // TaskStatusCancelled means that the task was cancelled by user. TaskStatusCancelled TaskStatus = "CANCELLED" // TaskStatusFailed means that one of the nodes got a non-retryable error and all other nodes // terminated the execution. TaskStatusFailed TaskStatus = "FAILED" )
func (TaskStatus) String ¶
func (t TaskStatus) String() string