instance

package
v0.0.0-...-e053da5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MonitorStateStrings = map[MonitorState]string{
		MonitorStateBooted:            "booted",
		MonitorStateBootFailed:        "boot failed",
		MonitorStateBooting:           "booting",
		MonitorStateDeleted:           "deleted",
		MonitorStateDeleteFailed:      "delete failed",
		MonitorStateDeleting:          "deleting",
		MonitorStateFreezeFailed:      "freeze failed",
		MonitorStateFreezing:          "freezing",
		MonitorStateFrozen:            "frozen",
		MonitorStateIdle:              "idle",
		MonitorStateProvisioned:       "provisioned",
		MonitorStateProvisioning:      "provisioning",
		MonitorStateProvisionFailed:   "provision failed",
		MonitorStatePurgeFailed:       "purge failed",
		MonitorStateReady:             "ready",
		MonitorStateRestarted:         "restarted",
		MonitorStateRunning:           "running",
		MonitorStateShutdown:          "shutdown",
		MonitorStateShutdownFailed:    "shutdown failed",
		MonitorStateShutting:          "shutting",
		MonitorStateStarted:           "started",
		MonitorStateStartFailed:       "start failed",
		MonitorStateStarting:          "starting",
		MonitorStateStopFailed:        "stop failed",
		MonitorStateStopped:           "stopped",
		MonitorStateStopping:          "stopping",
		MonitorStateSyncing:           "syncing",
		MonitorStateThawed:            "thawed",
		MonitorStateThawedFailed:      "unfreeze failed",
		MonitorStateThawing:           "thawing",
		MonitorStateUnprovisioned:     "unprovisioned",
		MonitorStateUnprovisionFailed: "unprovision failed",
		MonitorStateUnprovisioning:    "unprovisioning",
		MonitorStateWaitChildren:      "wait children",
		MonitorStateWaitLeader:        "wait leader",
		MonitorStateWaitNonLeader:     "wait non-leader",
		MonitorStateWaitParents:       "wait parents",
		MonitorStateWaitPriors:        "wait priors",
		MonitorStateInit:              "init",
	}

	MonitorStateValues = map[string]MonitorState{
		"init":               MonitorStateInit,
		"booted":             MonitorStateBooted,
		"boot failed":        MonitorStateBootFailed,
		"booting":            MonitorStateBooting,
		"idle":               MonitorStateIdle,
		"deleted":            MonitorStateDeleted,
		"deleting":           MonitorStateDeleting,
		"freeze failed":      MonitorStateFreezeFailed,
		"freezing":           MonitorStateFreezing,
		"frozen":             MonitorStateFrozen,
		"provisioned":        MonitorStateProvisioned,
		"provisioning":       MonitorStateProvisioning,
		"provision failed":   MonitorStateProvisionFailed,
		"purge failed":       MonitorStatePurgeFailed,
		"ready":              MonitorStateReady,
		"restarted":          MonitorStateRestarted,
		"running":            MonitorStateRunning,
		"shutdown":           MonitorStateShutdown,
		"shutdown failed":    MonitorStateShutdownFailed,
		"shutting":           MonitorStateShutting,
		"started":            MonitorStateStarted,
		"start failed":       MonitorStateStartFailed,
		"starting":           MonitorStateStarting,
		"stop failed":        MonitorStateStopFailed,
		"stopped":            MonitorStateStopped,
		"stopping":           MonitorStateStopping,
		"syncing":            MonitorStateSyncing,
		"thawed":             MonitorStateThawed,
		"unfreeze failed":    MonitorStateThawedFailed,
		"thawing":            MonitorStateThawing,
		"unprovisioned":      MonitorStateUnprovisioned,
		"unprovision failed": MonitorStateUnprovisionFailed,
		"unprovisioning":     MonitorStateUnprovisioning,
		"wait children":      MonitorStateWaitChildren,
		"wait leader":        MonitorStateWaitLeader,
		"wait non-leader":    MonitorStateWaitNonLeader,
		"wait parents":       MonitorStateWaitParents,
		"wait priors":        MonitorStateWaitPriors,
	}

	MonitorLocalExpectStrings = map[MonitorLocalExpect]string{
		MonitorLocalExpectEvicted:  "evicted",
		MonitorLocalExpectStarted:  "started",
		MonitorLocalExpectShutdown: "shutdown",
		MonitorLocalExpectNone:     "none",
		MonitorLocalExpectInit:     "init",
	}

	MonitorLocalExpectValues = map[string]MonitorLocalExpect{
		"evicted":  MonitorLocalExpectEvicted,
		"shutdown": MonitorLocalExpectShutdown,
		"started":  MonitorLocalExpectStarted,
		"none":     MonitorLocalExpectNone,
		"init":     MonitorLocalExpectInit,
	}

	MonitorGlobalExpectStrings = map[MonitorGlobalExpect]string{
		MonitorGlobalExpectAborted:       "aborted",
		MonitorGlobalExpectDeleted:       "deleted",
		MonitorGlobalExpectInit:          "init",
		MonitorGlobalExpectFrozen:        "frozen",
		MonitorGlobalExpectNone:          "none",
		MonitorGlobalExpectPlaced:        "placed",
		MonitorGlobalExpectPlacedAt:      "placed@",
		MonitorGlobalExpectProvisioned:   "provisioned",
		MonitorGlobalExpectPurged:        "purged",
		MonitorGlobalExpectRestarted:     "restarted",
		MonitorGlobalExpectStarted:       "started",
		MonitorGlobalExpectStopped:       "stopped",
		MonitorGlobalExpectThawed:        "thawed",
		MonitorGlobalExpectUnprovisioned: "unprovisioned",
	}

	MonitorGlobalExpectValues = map[string]MonitorGlobalExpect{
		"aborted":       MonitorGlobalExpectAborted,
		"deleted":       MonitorGlobalExpectDeleted,
		"init":          MonitorGlobalExpectInit,
		"frozen":        MonitorGlobalExpectFrozen,
		"placed":        MonitorGlobalExpectPlaced,
		"placed@":       MonitorGlobalExpectPlacedAt,
		"provisioned":   MonitorGlobalExpectProvisioned,
		"purged":        MonitorGlobalExpectPurged,
		"restarted":     MonitorGlobalExpectRestarted,
		"started":       MonitorGlobalExpectStarted,
		"stopped":       MonitorGlobalExpectStopped,
		"thawed":        MonitorGlobalExpectThawed,
		"unprovisioned": MonitorGlobalExpectUnprovisioned,
		"none":          MonitorGlobalExpectNone,
	}

	ErrInvalidGlobalExpect = errors.New("invalid instance monitor global expect")
	ErrInvalidLocalExpect  = errors.New("invalid instance monitor local expect")
	ErrInvalidState        = errors.New("invalid instance monitor state")
	ErrSameGlobalExpect    = errors.New("instance monitor global expect is already set to the same value")
	ErrSameLocalExpect     = errors.New("instance monitor local expect is already set to the same value")
	ErrSameState           = errors.New("instance monitor state is already set to the same value")

	MonitorActionNone       MonitorAction = "none"
	MonitorActionCrash      MonitorAction = "crash"
	MonitorActionFreezeStop MonitorAction = "freezestop"
	MonitorActionReboot     MonitorAction = "reboot"
	MonitorActionSwitch     MonitorAction = "switch"
)

Functions

func ConfigEqual

func ConfigEqual(a, b *Config) bool

ConfigEqual returns a boolean reporting whether a == b

Nodename and Path are not compared

func DropNode

func DropNode(nodename string)

func InitData

func InitData()

InitData reset package instances data, it can be used for tests.

func InstanceString

func InstanceString(p naming.Path, nodename string) string

Types

type Config

type Config struct {
	App              string           `json:"app,omitempty"`
	Checksum         string           `json:"csum"`
	Children         naming.Relations `json:"children,omitempty"`
	DRP              bool             `json:"drp,omitempty"`
	Env              string           `json:"env,omitempty"`
	FlexMax          int              `json:"flex_max,omitempty"`
	FlexMin          int              `json:"flex_min,omitempty"`
	FlexTarget       int              `json:"flex_target,omitempty"`
	MonitorAction    []MonitorAction  `json:"monitor_action,omitempty"`
	PreMonitorAction string           `json:"pre_monitor_action,omitempty"`
	Orchestrate      string           `json:"orchestrate"`
	Path             naming.Path      `json:"-"`
	Parents          naming.Relations `json:"parents,omitempty"`
	PlacementPolicy  placement.Policy `json:"placement_policy"`
	Priority         priority.T       `json:"priority,omitempty"`
	Resources        ResourceConfigs  `json:"resources"`
	Scope            []string         `json:"scope"`
	Subsets          SubsetConfigs    `json:"subsets"`
	Topology         topology.T       `json:"topology"`
	UpdatedAt        time.Time        `json:"updated_at"`

	// Volume specific
	Pool *string `json:"pool,omitempty"`
	Size *int64  `json:"size,omitempty"`
}

Config describes a configuration file content checksum, timestamp of last change and the nodes it should be installed on.

func (Config) DeepCopy

func (cfg Config) DeepCopy() *Config

func (Config) Unstructured

func (t Config) Unstructured() map[string]any

type Data

type Data[T Dataer] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Data defines a shared holder for all instances Dataer

var (
	// StatusData is the package data holder for all instances statuses
	StatusData *Data[Status]

	// MonitorData is the package data holder for all instances monitors
	MonitorData *Data[Monitor]

	// ConfigData is the package data holder for all instances configs
	ConfigData *Data[Config]
)

func NewData

func NewData[T Dataer]() *Data[T]

func (*Data[T]) DropNode

func (c *Data[T]) DropNode(nodename string)

DropNode removes node instances

func (*Data[T]) Get

func (c *Data[T]) Get(p naming.Path, nodename string) *T

Get returns an instance data or nil if data is not found

func (*Data[T]) GetAll

func (c *Data[T]) GetAll() []DataElement[T]

GetAll returns all instance data as a list of DataElements

func (*Data[T]) GetByNode

func (c *Data[T]) GetByNode(nodename string) map[naming.Path]*T

GetByNode returns a map (indexed by path) of instance data for nodename

func (*Data[T]) GetByPath

func (c *Data[T]) GetByPath(p naming.Path) map[string]*T

GetByPath returns a map (indexed by nodename) of instance data for path p

func (*Data[T]) Set

func (c *Data[T]) Set(p naming.Path, nodename string, v *T)

Set will add or update instance data

func (*Data[T]) Unset

func (c *Data[T]) Unset(p naming.Path, nodename string)

Unset removes an instance data

type DataElement

type DataElement[T Dataer] struct {
	Path  naming.Path
	Node  string
	Value *T
}

type Dataer

type Dataer interface {
	Status | Monitor | Config
}

type Instance

type Instance struct {
	Config  *Config  `json:"config"`
	Monitor *Monitor `json:"monitor"`
	Status  *Status  `json:"status"`
}

type Monitor

type Monitor struct {
	GlobalExpect          MonitorGlobalExpect `json:"global_expect"`
	GlobalExpectUpdatedAt time.Time           `json:"global_expect_updated_at"`
	GlobalExpectOptions   any                 `json:"global_expect_options"`

	// IsLeader flags the instance as the one where to provision as leader.
	// The provisioning leader is responsible for preparing the shared resources.
	// There can be only one leader, whatever the topology.
	IsLeader bool `json:"is_leader"`

	// IsHALeader flags the instances to start automatically if orchestrate=ha
	// or when the admin posted a start orchestration.
	// There can be one leader on a failover object, or many leaders with a flex topology.
	IsHALeader bool `json:"is_ha_leader"`

	LocalExpect          MonitorLocalExpect `json:"local_expect"`
	LocalExpectUpdatedAt time.Time          `json:"local_expect_updated_at"`

	// OrchestrationID is the accepted orchestration id that will be unset
	// when orchestration is reached on local node
	OrchestrationID uuid.UUID `json:"orchestration_id"`

	// OrchestrationIsDone is set by the orchestration when it decides the instance state has reached its target.
	// A orchestration is cleaned up when all instance monitors have OrchestrationIsDone set.
	OrchestrationIsDone bool `json:"orchestration_is_done"`

	SessionID               uuid.UUID        `json:"session_id"`
	State                   MonitorState     `json:"state"`
	StateUpdatedAt          time.Time        `json:"state_updated_at"`
	MonitorActionExecutedAt time.Time        `json:"monitor_action_executed_at"`
	IsPreserved             bool             `json:"preserved"`
	Resources               ResourceMonitors `json:"resources,omitempty"`
	UpdatedAt               time.Time        `json:"updated_at"`

	Parents  map[string]status.T `json:"parents,omitempty"`
	Children map[string]status.T `json:"children,omitempty"`
}

Monitor describes the in-daemon states of an instance

func (Monitor) DeepCopy

func (mon Monitor) DeepCopy() *Monitor

func (Monitor) ResourceFlagRestartString

func (mon Monitor) ResourceFlagRestartString(rid resourceid.T, r resource.Status) string

func (*Monitor) UnmarshalJSON

func (t *Monitor) UnmarshalJSON(b []byte) error

func (Monitor) Unstructured

func (t Monitor) Unstructured() map[string]any

type MonitorAction

type MonitorAction string

type MonitorGlobalExpect

type MonitorGlobalExpect int
const (
	MonitorGlobalExpectInit MonitorGlobalExpect = iota
	MonitorGlobalExpectAborted
	MonitorGlobalExpectDeleted
	MonitorGlobalExpectFrozen
	MonitorGlobalExpectNone
	MonitorGlobalExpectPlaced
	MonitorGlobalExpectPlacedAt
	MonitorGlobalExpectProvisioned
	MonitorGlobalExpectPurged
	MonitorGlobalExpectRestarted
	MonitorGlobalExpectStarted
	MonitorGlobalExpectStopped
	MonitorGlobalExpectThawed
	MonitorGlobalExpectUnprovisioned
)

func (MonitorGlobalExpect) MarshalText

func (t MonitorGlobalExpect) MarshalText() ([]byte, error)

func (MonitorGlobalExpect) String

func (t MonitorGlobalExpect) String() string

func (*MonitorGlobalExpect) UnmarshalText

func (t *MonitorGlobalExpect) UnmarshalText(b []byte) error

type MonitorGlobalExpectOptionsPlacedAt

type MonitorGlobalExpectOptionsPlacedAt struct {
	Destination []string `json:"destination"`
}

type MonitorGlobalExpectOptionsRestarted

type MonitorGlobalExpectOptionsRestarted struct {
	Force bool `json:"force"`
}

type MonitorLocalExpect

type MonitorLocalExpect int
const (
	MonitorLocalExpectInit MonitorLocalExpect = iota
	MonitorLocalExpectNone
	MonitorLocalExpectStarted
	MonitorLocalExpectShutdown
	MonitorLocalExpectEvicted
)

func (MonitorLocalExpect) MarshalText

func (t MonitorLocalExpect) MarshalText() ([]byte, error)

func (MonitorLocalExpect) String

func (t MonitorLocalExpect) String() string

func (*MonitorLocalExpect) UnmarshalText

func (t *MonitorLocalExpect) UnmarshalText(b []byte) error

type MonitorState

type MonitorState int
const (
	MonitorStateInit MonitorState = iota
	MonitorStateBooted
	MonitorStateBootFailed
	MonitorStateBooting
	MonitorStateIdle
	MonitorStateDeleted
	MonitorStateDeleteFailed
	MonitorStateDeleting
	MonitorStateFreezeFailed
	MonitorStateFreezing
	MonitorStateFrozen
	MonitorStateProvisioned
	MonitorStateProvisioning
	MonitorStateProvisionFailed
	MonitorStatePurgeFailed
	MonitorStateReady
	MonitorStateRestarted
	MonitorStateRunning
	MonitorStateShutdownFailed
	MonitorStateShutdown
	MonitorStateShutting
	MonitorStateStarted
	MonitorStateStartFailed
	MonitorStateStarting
	MonitorStateStopFailed
	MonitorStateStopped
	MonitorStateStopping
	MonitorStateSyncing
	MonitorStateThawed
	MonitorStateThawedFailed
	MonitorStateThawing
	MonitorStateUnprovisioned
	MonitorStateUnprovisionFailed
	MonitorStateUnprovisioning
	MonitorStateWaitChildren
	MonitorStateWaitLeader
	MonitorStateWaitNonLeader
	MonitorStateWaitParents
	MonitorStateWaitPriors
)

func (MonitorState) Is

func (t MonitorState) Is(states ...MonitorState) bool

func (MonitorState) IsDoing

func (t MonitorState) IsDoing() bool

func (MonitorState) MarshalText

func (t MonitorState) MarshalText() ([]byte, error)

func (MonitorState) String

func (t MonitorState) String() string

func (*MonitorState) UnmarshalText

func (t *MonitorState) UnmarshalText(b []byte) error

type MonitorUpdate

type MonitorUpdate struct {
	GlobalExpect        *MonitorGlobalExpect `json:"global_expect"`
	GlobalExpectOptions any                  `json:"global_expect_options"`
	LocalExpect         *MonitorLocalExpect  `json:"local_expect"`
	State               *MonitorState        `json:"state"`

	// CandidateOrchestrationID is a candidate orchestration id for a new imon orchestration.
	CandidateOrchestrationID uuid.UUID `json:"orchestration_id"`
}

MonitorUpdate is embedded in the SetInstanceMonitor message to change some Monitor values. A nil value does not change the current value.

func (MonitorUpdate) String

func (t MonitorUpdate) String() string

type Node

type Node struct {
	Name     string    `json:"name"`
	FrozenAt time.Time `json:"frozen_at,omitempty"`
}

Node contains the node information displayed in print status.

type ResourceConfig

type ResourceConfig struct {
	IsDisabled   bool           `json:"is_disabled"`
	IsMonitored  bool           `json:"is_monitored"`
	IsStandby    bool           `json:"is_standby"`
	Restart      int            `json:"restart"`
	RestartDelay *time.Duration `json:"restart_delay"`
}

func (ResourceConfig) Unstructured

func (t ResourceConfig) Unstructured() map[string]any

type ResourceConfigs

type ResourceConfigs map[string]ResourceConfig

func (ResourceConfigs) DeepCopy

func (m ResourceConfigs) DeepCopy() ResourceConfigs

func (ResourceConfigs) Get

func (rcfgs ResourceConfigs) Get(rid string) *ResourceConfig

func (ResourceConfigs) Unstructured

func (t ResourceConfigs) Unstructured() map[string]map[string]any

type ResourceMonitor

type ResourceMonitor struct {
	Restart ResourceMonitorRestart `json:"restart"`
}

ResourceMonitor describes the restart states maintained by the daemon for an object instance.

func (*ResourceMonitor) DecRestartRemaining

func (rmon *ResourceMonitor) DecRestartRemaining()

func (*ResourceMonitor) StopRestartTimer

func (rmon *ResourceMonitor) StopRestartTimer() bool

func (ResourceMonitor) Unstructured

func (t ResourceMonitor) Unstructured() map[string]any

type ResourceMonitorRestart

type ResourceMonitorRestart struct {
	Remaining int         `json:"remaining"`
	LastAt    time.Time   `json:"last_at"`
	Timer     *time.Timer `json:"-"`
}

func (ResourceMonitorRestart) Unstructured

func (t ResourceMonitorRestart) Unstructured() map[string]any

type ResourceMonitors

type ResourceMonitors map[string]ResourceMonitor

func (ResourceMonitors) DeepCopy

func (m ResourceMonitors) DeepCopy() ResourceMonitors

func (ResourceMonitors) Get

func (ResourceMonitors) Set

func (m ResourceMonitors) Set(rid string, rmon ResourceMonitor)

func (ResourceMonitors) Unstructured

func (t ResourceMonitors) Unstructured() map[string]map[string]any

type ResourceOrder

type ResourceOrder []resource.Status

ResourceOrder is a sortable list representation of the instance status resources map.

func (ResourceOrder) Len

func (a ResourceOrder) Len() int

func (ResourceOrder) Less

func (a ResourceOrder) Less(i, j int) bool

func (ResourceOrder) Swap

func (a ResourceOrder) Swap(i, j int)

type ResourceRunningSet

type ResourceRunningSet []string

ResourceRunningSet is the list of resource currently running (sync and task).

func (ResourceRunningSet) Has

func (t ResourceRunningSet) Has(rid string) bool

Has is true if the rid is found running in the Instance Monitor data sent by the daemon.

type ResourceStatuses

type ResourceStatuses map[string]resource.Status

func (ResourceStatuses) DeepCopy

func (m ResourceStatuses) DeepCopy() ResourceStatuses

func (ResourceStatuses) Unstructured

func (t ResourceStatuses) Unstructured() map[string]map[string]any

type States

type States struct {
	Path    naming.Path `json:"path"`
	Node    Node        `json:"node,omitempty"`
	Config  Config      `json:"config,omitempty"`
	Status  Status      `json:"status,omitempty"`
	Monitor Monitor     `json:"monitor,omitempty"`
}

States groups config and status of the object instance as seen by the daemon.

func (States) LoadTreeNode

func (t States) LoadTreeNode(head *tree.Node)

LoadTreeNode add the tree nodes representing the type instance into another tree, at the specified node.

func (States) LoadTreeNodeFolded

func (t States) LoadTreeNodeFolded(head *tree.Node)

LoadTreeNodeFolded add the tree nodes representing the type instance into another tree, at the specified node. TODO: probable bug, LoadTreeNodeFolded duplicate code of LoadTreeNode

func (States) Render

func (t States) Render() string

Render returns a human friendly string representation of the type instance.

func (States) Tree

func (t States) Tree() *tree.Tree

Tree returns a tree loaded with the type instance.

type StatesList

type StatesList []States

func (StatesList) ByNode

func (t StatesList) ByNode() map[string]States

type Status

type Status struct {
	Avail         status.T           `json:"avail"`
	FrozenAt      time.Time          `json:"frozen_at,omitempty"`
	LastStartedAt time.Time          `json:"last_started_at"`
	Optional      status.T           `json:"optional,omitempty"`
	Overall       status.T           `json:"overall"`
	Provisioned   provisioned.T      `json:"provisioned"`
	Resources     ResourceStatuses   `json:"resources,omitempty"`
	Running       ResourceRunningSet `json:"running,omitempty"`
	UpdatedAt     time.Time          `json:"updated_at"`
}

Status describes the instance status.

func (Status) DeepCopy

func (t Status) DeepCopy() *Status

func (Status) IsFrozen

func (t Status) IsFrozen() bool

func (Status) IsThawed

func (t Status) IsThawed() bool

func (Status) ResourceFlagsString

func (t Status) ResourceFlagsString(rid resourceid.T, r resource.Status) string

ResourceFlagsString formats resource flags as a vector of characters.

R  Running
M  Monitored
D  Disabled
O  Optional
E  Encap
P  Provisioned
S  Standby

func (*Status) SortedResources

func (t *Status) SortedResources() []resource.Status

SortedResources returns a list of resource identifiers sorted by: 1/ driver group 2/ subset 3/ resource name

func (Status) Unstructured

func (t Status) Unstructured() map[string]any

type SubsetConfig

type SubsetConfig struct {
	Parallel bool `json:"parallel,omitempty"`
}

func (SubsetConfig) Unstructured

func (t SubsetConfig) Unstructured() map[string]any

type SubsetConfigs

type SubsetConfigs map[string]SubsetConfig

func (SubsetConfigs) DeepCopy

func (m SubsetConfigs) DeepCopy() SubsetConfigs

func (SubsetConfigs) Unstructured

func (t SubsetConfigs) Unstructured() map[string]map[string]any

Jump to

Keyboard shortcuts

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