2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2018-06-22 00:35:07 +00:00
|
|
|
package interfaces
|
|
|
|
|
2018-07-18 20:45:55 +00:00
|
|
|
import (
|
2023-05-12 17:29:44 +00:00
|
|
|
"github.com/hashicorp/nomad/client/allocdir"
|
2018-10-04 23:22:01 +00:00
|
|
|
"github.com/hashicorp/nomad/client/allocrunner/state"
|
2023-04-03 15:03:36 +00:00
|
|
|
"github.com/hashicorp/nomad/client/pluginmanager/csimanager"
|
2023-05-12 17:29:44 +00:00
|
|
|
"github.com/hashicorp/nomad/client/pluginmanager/drivermanager"
|
2018-10-04 22:45:46 +00:00
|
|
|
cstructs "github.com/hashicorp/nomad/client/structs"
|
2023-05-12 17:29:44 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
"github.com/hashicorp/nomad/plugins/drivers"
|
2018-07-18 20:45:55 +00:00
|
|
|
)
|
2018-06-22 00:35:07 +00:00
|
|
|
|
2023-05-12 17:29:44 +00:00
|
|
|
// AllocRunner is the interface to the allocRunner struct used by client.Client
|
2018-06-22 00:35:07 +00:00
|
|
|
type AllocRunner interface {
|
2023-05-12 17:29:44 +00:00
|
|
|
Alloc() *structs.Allocation
|
2018-06-22 00:35:07 +00:00
|
|
|
|
|
|
|
Run()
|
2023-05-12 17:29:44 +00:00
|
|
|
Restore() error
|
|
|
|
Update(*structs.Allocation)
|
|
|
|
Reconnect(update *structs.Allocation) error
|
|
|
|
Shutdown()
|
|
|
|
Destroy()
|
2018-06-22 00:35:07 +00:00
|
|
|
|
2023-05-12 17:29:44 +00:00
|
|
|
IsDestroyed() bool
|
|
|
|
IsMigrating() bool
|
|
|
|
IsWaiting() bool
|
2018-07-18 20:45:55 +00:00
|
|
|
|
2023-05-12 17:29:44 +00:00
|
|
|
WaitCh() <-chan struct{}
|
|
|
|
DestroyCh() <-chan struct{}
|
|
|
|
ShutdownCh() <-chan struct{}
|
|
|
|
|
|
|
|
AllocState() *state.State
|
|
|
|
PersistState() error
|
|
|
|
AcknowledgeState(*state.State)
|
2023-05-31 19:34:16 +00:00
|
|
|
GetUpdatePriority(*structs.Allocation) cstructs.AllocUpdatePriority
|
2023-05-12 17:29:44 +00:00
|
|
|
SetClientStatus(string)
|
|
|
|
|
|
|
|
Signal(taskName, signal string) error
|
|
|
|
RestartTask(taskName string, taskEvent *structs.TaskEvent) error
|
|
|
|
RestartRunning(taskEvent *structs.TaskEvent) error
|
|
|
|
RestartAll(taskEvent *structs.TaskEvent) error
|
|
|
|
|
|
|
|
GetTaskEventHandler(taskName string) drivermanager.EventHandler
|
|
|
|
GetTaskExecHandler(taskName string) drivermanager.TaskExecHandler
|
|
|
|
GetTaskDriverCapabilities(taskName string) (*drivers.Capabilities, error)
|
|
|
|
StatsReporter() AllocStatsReporter
|
|
|
|
Listener() *cstructs.AllocListener
|
|
|
|
GetAllocDir() *allocdir.AllocDir
|
2018-06-22 00:35:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 20:45:55 +00:00
|
|
|
// TaskStateHandler exposes a handler to be called when a task's state changes
|
|
|
|
type TaskStateHandler interface {
|
2018-10-16 03:38:12 +00:00
|
|
|
// TaskStateUpdated is used to notify the alloc runner about task state
|
|
|
|
// changes.
|
|
|
|
TaskStateUpdated()
|
2018-06-22 00:35:07 +00:00
|
|
|
}
|
2018-10-04 22:45:46 +00:00
|
|
|
|
2020-10-12 17:43:04 +00:00
|
|
|
// AllocStatsReporter gives access to the latest resource usage from the
|
2018-10-04 22:45:46 +00:00
|
|
|
// allocation
|
|
|
|
type AllocStatsReporter interface {
|
|
|
|
LatestAllocStats(taskFilter string) (*cstructs.AllocResourceUsage, error)
|
|
|
|
}
|
2023-04-03 15:03:36 +00:00
|
|
|
|
|
|
|
// HookResourceSetter is used to communicate between alloc hooks and task hooks
|
|
|
|
type HookResourceSetter interface {
|
|
|
|
SetCSIMounts(map[string]*csimanager.MountInfo)
|
|
|
|
GetCSIMounts(map[string]*csimanager.MountInfo)
|
|
|
|
}
|