state

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2019 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NeedsUpgrade

func NeedsUpgrade(bdb *bolt.DB) (bool, error)

NeedsUpgrade returns true if the BoltDB needs upgrading or false if it is already up to date.

func UpgradeAllocs

func UpgradeAllocs(logger hclog.Logger, tx *boltdd.Tx) error

UpgradeSchema upgrades the boltdb schema. Example 0.8 schema:

  • allocations
  • 15d83e8a-74a2-b4da-3f17-ed5c12895ea8
  • echo
  • simple-all (342 bytes)
  • alloc (2827 bytes)
  • alloc-dir (166 bytes)
  • immutable (15 bytes)
  • mutable (1294 bytes)

Types

type BoltStateDB

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

BoltStateDB persists and restores Nomad client state in a boltdb. All methods are safe for concurrent access.

func (*BoltStateDB) Close

func (s *BoltStateDB) Close() error

Close releases all database resources and unlocks the database file on disk. All transactions must be closed before closing the database.

func (*BoltStateDB) DB

func (s *BoltStateDB) DB() *boltdd.DB

DB allows access to the underlying BoltDB for testing purposes.

func (*BoltStateDB) DeleteAllocationBucket

func (s *BoltStateDB) DeleteAllocationBucket(allocID string) error

DeleteAllocationBucket is used to delete an allocation bucket if it exists.

func (*BoltStateDB) DeleteTaskBucket

func (s *BoltStateDB) DeleteTaskBucket(allocID, taskName string) error

DeleteTaskBucket is used to delete a task bucket if it exists.

func (*BoltStateDB) GetAllAllocations

func (s *BoltStateDB) GetAllAllocations() ([]*structs.Allocation, map[string]error, error)

GetAllAllocations gets all allocations persisted by this client and returns a map of alloc ids to errors for any allocations that could not be restored.

If a fatal error was encountered it will be returned and the other two values will be nil.

func (*BoltStateDB) GetDeploymentStatus

func (s *BoltStateDB) GetDeploymentStatus(allocID string) (*structs.AllocDeploymentStatus, error)

GetDeploymentStatus retrieves an allocation's DeploymentStatus or returns an error.

func (*BoltStateDB) GetDevicePluginState

func (s *BoltStateDB) GetDevicePluginState() (*dmstate.PluginState, error)

GetDevicePluginState stores the device manager's plugin state or returns an error.

func (*BoltStateDB) GetDriverPluginState

func (s *BoltStateDB) GetDriverPluginState() (*driverstate.PluginState, error)

GetDriverPluginState stores the driver manager's plugin state or returns an error.

func (*BoltStateDB) GetTaskRunnerState

func (s *BoltStateDB) GetTaskRunnerState(allocID, taskName string) (*trstate.LocalState, *structs.TaskState, error)

GetTaskRunnerState returns the LocalState and TaskState for a TaskRunner. LocalState or TaskState will be nil if they do not exist.

If an error is encountered both LocalState and TaskState will be nil.

func (*BoltStateDB) Name

func (s *BoltStateDB) Name() string

func (*BoltStateDB) PutAllocation

func (s *BoltStateDB) PutAllocation(alloc *structs.Allocation) error

PutAllocation stores an allocation or returns an error.

func (*BoltStateDB) PutDeploymentStatus

func (s *BoltStateDB) PutDeploymentStatus(allocID string, ds *structs.AllocDeploymentStatus) error

PutDeploymentStatus stores an allocation's DeploymentStatus or returns an error.

func (*BoltStateDB) PutDevicePluginState

func (s *BoltStateDB) PutDevicePluginState(ps *dmstate.PluginState) error

PutDevicePluginState stores the device manager's plugin state or returns an error.

func (*BoltStateDB) PutDriverPluginState

func (s *BoltStateDB) PutDriverPluginState(ps *driverstate.PluginState) error

PutDriverPluginState stores the driver manager's plugin state or returns an error.

func (*BoltStateDB) PutTaskRunnerLocalState

func (s *BoltStateDB) PutTaskRunnerLocalState(allocID, taskName string, val *trstate.LocalState) error

PutTaskRunnerLocalState stores TaskRunner's LocalState or returns an error.

func (*BoltStateDB) PutTaskState

func (s *BoltStateDB) PutTaskState(allocID, taskName string, state *structs.TaskState) error

PutTaskState stores a task's state or returns an error.

func (*BoltStateDB) Upgrade

func (s *BoltStateDB) Upgrade() error

Upgrade bolt state db from 0.8 schema to 0.9 schema. Noop if already using 0.9 schema. Creates a backup before upgrading.

type ErrDB

type ErrDB struct {
	// Allocs is a preset slice of allocations used in GetAllAllocations
	Allocs []*structs.Allocation
}

ErrDB implements a StateDB that returns errors on restore methods, used for testing

func (*ErrDB) Close

func (m *ErrDB) Close() error

func (*ErrDB) DeleteAllocationBucket

func (m *ErrDB) DeleteAllocationBucket(allocID string) error

func (*ErrDB) DeleteTaskBucket

func (m *ErrDB) DeleteTaskBucket(allocID, taskName string) error

func (*ErrDB) GetAllAllocations

func (m *ErrDB) GetAllAllocations() ([]*structs.Allocation, map[string]error, error)

func (*ErrDB) GetDeploymentStatus

func (m *ErrDB) GetDeploymentStatus(allocID string) (*structs.AllocDeploymentStatus, error)

func (*ErrDB) GetDevicePluginState

func (m *ErrDB) GetDevicePluginState() (*dmstate.PluginState, error)

GetDevicePluginState stores the device manager's plugin state or returns an error.

func (*ErrDB) GetDriverPluginState

func (m *ErrDB) GetDriverPluginState() (*driverstate.PluginState, error)

func (*ErrDB) GetTaskRunnerState

func (m *ErrDB) GetTaskRunnerState(allocID string, taskName string) (*state.LocalState, *structs.TaskState, error)

func (*ErrDB) Name

func (m *ErrDB) Name() string

func (*ErrDB) PutAllocation

func (m *ErrDB) PutAllocation(alloc *structs.Allocation) error

func (*ErrDB) PutDeploymentStatus

func (m *ErrDB) PutDeploymentStatus(allocID string, ds *structs.AllocDeploymentStatus) error

func (*ErrDB) PutDevicePluginState

func (m *ErrDB) PutDevicePluginState(ps *dmstate.PluginState) error

func (*ErrDB) PutDriverPluginState

func (m *ErrDB) PutDriverPluginState(ps *driverstate.PluginState) error

func (*ErrDB) PutTaskRunnerLocalState

func (m *ErrDB) PutTaskRunnerLocalState(allocID string, taskName string, val *state.LocalState) error

func (*ErrDB) PutTaskState

func (m *ErrDB) PutTaskState(allocID string, taskName string, state *structs.TaskState) error

func (*ErrDB) Upgrade

func (m *ErrDB) Upgrade() error

type MemDB

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

MemDB implements a StateDB that stores data in memory and should only be used for testing. All methods are safe for concurrent use.

func NewMemDB

func NewMemDB(logger hclog.Logger) *MemDB

func (*MemDB) Close

func (m *MemDB) Close() error

func (*MemDB) DeleteAllocationBucket

func (m *MemDB) DeleteAllocationBucket(allocID string) error

func (*MemDB) DeleteTaskBucket

func (m *MemDB) DeleteTaskBucket(allocID, taskName string) error

func (*MemDB) GetAllAllocations

func (m *MemDB) GetAllAllocations() ([]*structs.Allocation, map[string]error, error)

func (*MemDB) GetDeploymentStatus

func (m *MemDB) GetDeploymentStatus(allocID string) (*structs.AllocDeploymentStatus, error)

func (*MemDB) GetDevicePluginState

func (m *MemDB) GetDevicePluginState() (*dmstate.PluginState, error)

GetDevicePluginState stores the device manager's plugin state or returns an error.

func (*MemDB) GetDriverPluginState

func (m *MemDB) GetDriverPluginState() (*driverstate.PluginState, error)

func (*MemDB) GetTaskRunnerState

func (m *MemDB) GetTaskRunnerState(allocID string, taskName string) (*state.LocalState, *structs.TaskState, error)

func (*MemDB) Name

func (m *MemDB) Name() string

func (*MemDB) PutAllocation

func (m *MemDB) PutAllocation(alloc *structs.Allocation) error

func (*MemDB) PutDeploymentStatus

func (m *MemDB) PutDeploymentStatus(allocID string, ds *structs.AllocDeploymentStatus) error

func (*MemDB) PutDevicePluginState

func (m *MemDB) PutDevicePluginState(ps *dmstate.PluginState) error

func (*MemDB) PutDriverPluginState

func (m *MemDB) PutDriverPluginState(ps *driverstate.PluginState) error

func (*MemDB) PutTaskRunnerLocalState

func (m *MemDB) PutTaskRunnerLocalState(allocID string, taskName string, val *state.LocalState) error

func (*MemDB) PutTaskState

func (m *MemDB) PutTaskState(allocID string, taskName string, state *structs.TaskState) error

func (*MemDB) Upgrade

func (m *MemDB) Upgrade() error

type NewStateDBFunc

type NewStateDBFunc func(logger hclog.Logger, stateDir string) (StateDB, error)

NewStateDBFunc creates a StateDB given a state directory.

func GetStateDBFactory

func GetStateDBFactory(devMode bool) NewStateDBFunc

GetStateDBFactory returns a func for creating a StateDB

type NoopDB

type NoopDB struct{}

NoopDB implements a StateDB that does not persist any data.

func (NoopDB) Close

func (n NoopDB) Close() error

func (NoopDB) DeleteAllocationBucket

func (n NoopDB) DeleteAllocationBucket(allocID string) error

func (NoopDB) DeleteTaskBucket

func (n NoopDB) DeleteTaskBucket(allocID, taskName string) error

func (NoopDB) GetAllAllocations

func (n NoopDB) GetAllAllocations() ([]*structs.Allocation, map[string]error, error)

func (NoopDB) GetDeploymentStatus

func (n NoopDB) GetDeploymentStatus(allocID string) (*structs.AllocDeploymentStatus, error)

func (NoopDB) GetDevicePluginState

func (n NoopDB) GetDevicePluginState() (*dmstate.PluginState, error)

func (NoopDB) GetDriverPluginState

func (n NoopDB) GetDriverPluginState() (*driverstate.PluginState, error)

func (NoopDB) GetTaskRunnerState

func (n NoopDB) GetTaskRunnerState(allocID string, taskName string) (*state.LocalState, *structs.TaskState, error)

func (NoopDB) Name

func (n NoopDB) Name() string

func (NoopDB) PutAllocation

func (n NoopDB) PutAllocation(*structs.Allocation) error

func (NoopDB) PutDeploymentStatus

func (n NoopDB) PutDeploymentStatus(allocID string, ds *structs.AllocDeploymentStatus) error

func (NoopDB) PutDevicePluginState

func (n NoopDB) PutDevicePluginState(ps *dmstate.PluginState) error

func (NoopDB) PutDriverPluginState

func (n NoopDB) PutDriverPluginState(ps *driverstate.PluginState) error

func (NoopDB) PutTaskRunnerLocalState

func (n NoopDB) PutTaskRunnerLocalState(allocID string, taskName string, val *state.LocalState) error

func (NoopDB) PutTaskState

func (n NoopDB) PutTaskState(allocID string, taskName string, state *structs.TaskState) error

func (NoopDB) Upgrade

func (n NoopDB) Upgrade() error

type StateDB

type StateDB interface {
	// Name of implementation.
	Name() string

	// Upgrade ensures the layout of the database is at the latest version
	// or returns an error. Corrupt data will be dropped when possible.
	// Errors should be considered critical and unrecoverable.
	Upgrade() error

	// GetAllAllocations returns all valid allocations and a map of
	// allocation IDs to retrieval errors.
	//
	// If a single error is returned then both allocations and the map will be nil.
	GetAllAllocations() ([]*structs.Allocation, map[string]error, error)

	// PulAllocation stores an allocation or returns an error if it could
	// not be stored.
	PutAllocation(*structs.Allocation) error

	// Get/Put DeploymentStatus get and put the allocation's deployment
	// status. It may be nil.
	GetDeploymentStatus(allocID string) (*structs.AllocDeploymentStatus, error)
	PutDeploymentStatus(allocID string, ds *structs.AllocDeploymentStatus) error

	// GetTaskRunnerState returns the LocalState and TaskState for a
	// TaskRunner. Either state may be nil if it is not found, but if an
	// error is encountered only the error will be non-nil.
	GetTaskRunnerState(allocID, taskName string) (*state.LocalState, *structs.TaskState, error)

	// PutTaskRunnerLocalTask stores the LocalState for a TaskRunner or
	// returns an error.
	PutTaskRunnerLocalState(allocID, taskName string, val *state.LocalState) error

	// PutTaskState stores the TaskState for a TaskRunner or returns an
	// error.
	PutTaskState(allocID, taskName string, state *structs.TaskState) error

	// DeleteTaskBucket deletes a task's state bucket if it exists. No
	// error is returned if it does not exist.
	DeleteTaskBucket(allocID, taskName string) error

	// DeleteAllocationBucket deletes an allocation's state bucket if it
	// exists. No error is returned if it does not exist.
	DeleteAllocationBucket(allocID string) error

	// GetDevicePluginState is used to retrieve the device manager's plugin
	// state.
	GetDevicePluginState() (*dmstate.PluginState, error)

	// PutDevicePluginState is used to store the device manager's plugin
	// state.
	PutDevicePluginState(state *dmstate.PluginState) error

	// GetDriverPluginState is used to retrieve the driver manager's plugin
	// state.
	GetDriverPluginState() (*driverstate.PluginState, error)

	// PutDriverPluginState is used to store the driver manager's plugin
	// state.
	PutDriverPluginState(state *driverstate.PluginState) error

	// Close the database. Unsafe for further use after calling regardless
	// of return value.
	Close() error
}

StateDB implementations store and load Nomad client state.

func NewBoltStateDB

func NewBoltStateDB(logger hclog.Logger, stateDir string) (StateDB, error)

NewBoltStateDB creates or opens an existing boltdb state file or returns an error.

type TaskRunnerHandle08

type TaskRunnerHandle08 struct {
	// Docker specific handle info
	ContainerID string `json:"ContainerID"`
	Image       string `json:"Image"`

	// LXC specific handle info
	ContainerName string `json:"ContainerName"`
	LxcPath       string `json:"LxcPath"`

	// Executor reattach config
	PluginConfig struct {
		Pid      int    `json:"Pid"`
		AddrNet  string `json:"AddrNet"`
		AddrName string `json:"AddrName"`
	} `json:"PluginConfig"`
}

func UnmarshalPre09HandleID

func UnmarshalPre09HandleID(raw []byte) (*TaskRunnerHandle08, error)

UnmarshalPre09HandleID decodes the pre09 json encoded handle ID

func (*TaskRunnerHandle08) ReattachConfig

func (t *TaskRunnerHandle08) ReattachConfig() *pstructs.ReattachConfig

Jump to

Keyboard shortcuts

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