open-nomad/client/allocrunnerv2/interfaces/task_lifecycle.go

113 lines
2.6 KiB
Go
Raw Normal View History

2018-06-22 00:35:07 +00:00
package interfaces
import (
2018-07-11 22:42:35 +00:00
"context"
2018-06-27 23:57:31 +00:00
"github.com/hashicorp/nomad/client/driver/env"
2018-06-22 00:35:07 +00:00
"github.com/hashicorp/nomad/nomad/structs"
)
/*
2018-07-17 00:19:56 +00:00
prestart poststart exited stop
2018-06-22 00:35:07 +00:00
| | | |
| | | |
--------> run ------> exited ----------> not restart ---------> garbage collect
2018-07-17 00:19:56 +00:00
|
|
kill -> exited -> stop
2018-06-22 00:35:07 +00:00
*/
// TaskHook is a lifecycle hook into the life cycle of a task runner.
type TaskHook interface {
Name() string
}
2018-07-17 00:19:56 +00:00
type TaskPrestartRequest struct {
2018-06-22 00:35:07 +00:00
// HookData is previously set data by the hook
HookData map[string]string
// Task is the task to run
Task *structs.Task
// Vault token may optionally be set if a Vault token is available
VaultToken string
// TaskDir is the task's directory on the host
TaskDir string
2018-06-27 23:57:31 +00:00
// TaskEnv is the task's environment
TaskEnv *env.TaskEnv
2018-06-22 00:35:07 +00:00
}
2018-07-17 00:19:56 +00:00
type TaskPrestartResponse struct {
2018-06-22 00:35:07 +00:00
// Env is the environment variables to set for the task
Env map[string]string
// HookData allows the hook to emit data to be passed in the next time it is
// run
HookData map[string]string
// Done lets the hook indicate that it should only be run once
Done bool
2018-06-22 00:35:07 +00:00
}
2018-07-17 00:19:56 +00:00
type TaskPrestartHook interface {
2018-06-27 23:57:31 +00:00
TaskHook
2018-07-17 00:40:04 +00:00
// Prestart is called before the task is started.
2018-07-17 00:19:56 +00:00
Prestart(context.Context, *TaskPrestartRequest, *TaskPrestartResponse) error
2018-06-22 00:35:07 +00:00
}
2018-07-17 00:19:56 +00:00
type TaskPoststartRequest struct {
2018-06-22 00:35:07 +00:00
// Network info
}
2018-07-17 00:19:56 +00:00
type TaskPoststartResponse struct{}
2018-06-22 00:35:07 +00:00
2018-07-17 00:19:56 +00:00
type TaskPoststartHook interface {
2018-06-27 23:57:31 +00:00
TaskHook
2018-07-17 00:40:04 +00:00
// Poststart is called after the task has started.
2018-07-17 00:19:56 +00:00
Poststart(context.Context, *TaskPoststartRequest, *TaskPoststartResponse) error
2018-06-22 00:35:07 +00:00
}
2018-07-17 00:19:56 +00:00
type TaskKillRequest struct{}
type TaskKillResponse struct{}
2018-06-22 00:35:07 +00:00
2018-07-17 00:19:56 +00:00
type TaskKillHook interface {
2018-06-27 23:57:31 +00:00
TaskHook
2018-07-17 00:40:04 +00:00
// Kill is called when a task is going to be killed.
2018-07-17 00:19:56 +00:00
Kill(context.Context, *TaskKillRequest, *TaskKillResponse) error
2018-06-22 00:35:07 +00:00
}
2018-07-17 00:19:56 +00:00
type TaskExitedRequest struct{}
type TaskExitedResponse struct{}
2018-06-22 00:35:07 +00:00
2018-07-17 00:19:56 +00:00
type TaskExitedHook interface {
2018-06-27 23:57:31 +00:00
TaskHook
2018-07-17 00:40:04 +00:00
// Exited is called when a task exits and may or may not be restarted.
2018-07-17 00:19:56 +00:00
Exited(context.Context, *TaskExitedRequest, *TaskExitedResponse) error
2018-06-22 00:35:07 +00:00
}
type TaskUpdateRequest struct {
2018-07-12 23:15:33 +00:00
VaultToken string
2018-06-22 00:35:07 +00:00
}
type TaskUpdateResponse struct{}
type TaskUpdateHook interface {
2018-06-27 23:57:31 +00:00
TaskHook
2018-07-12 23:15:33 +00:00
Update(context.Context, *TaskUpdateRequest, *TaskUpdateResponse) error
2018-06-22 00:35:07 +00:00
}
2018-07-17 00:19:56 +00:00
type TaskStopRequest struct{}
type TaskStopResponse struct{}
type TaskStopHook interface {
TaskHook
2018-07-17 00:40:04 +00:00
// Stop is called after the task has exited and will not be started again.
2018-07-17 00:19:56 +00:00
Stop(context.Context, *TaskStopRequest, *TaskStopResponse) error
}