ha

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentState

AgentState is the interface that abstract manipulation of agent internal state

type AgentStateSnapshot

type AgentStateSnapshot struct {
	MeasIdx      int64                             `json:"meas_idx"`
	HbIdx        int64                             `json:"hb_idx"`
	Schedulers   map[string]SchedulerStateSnapshot `json:"schedulers"`
	FaultIdx     int32                             `json:"fault_idx"`
	AlertInfos   map[int32]AlertInfosStateSnapShot `json:"alertInfos"`
	StorageFault map[string]int32                  `json:"storageFault"`
}

AgentStateSnapshot holds a serializable copy of agent state

func (*AgentStateSnapshot) Persist

func (snap *AgentStateSnapshot) Persist(sink raft.SnapshotSink) error

Persist serialize the snapshot to the given output sink

func (*AgentStateSnapshot) Release

func (snap *AgentStateSnapshot) Release()

Release realeases resources used by snapshot. Currently does nothing for AgentStateSnapshot

type AlertInfosStateSnapShot

type AlertInfosStateSnapShot struct {
	Sn    int64 `json:"sn"`
	Epoch int64 `json:"epoch"`
}

AlertInfosStateSnapShot is a snapshot of an alert info

type Cluster

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

Cluster is a replicated AgentState in a raft cluster. It provides consistent write operations across the cluster, and those write operations are permitted only on the leader node.

func NewCluster

func NewCluster(datadir string, cfg *config.ClusterConfiguration, state SnapshotableAgentState) (*Cluster, error)

NewCluster creates and start a new cluster around `state`. Cluster topology is included in `cfg`, but if `cfg` is null, the cluster will fallsback into single-node mode. On first creation, the cluster is boostrapped

func (*Cluster) DeleteFaultInStorage

func (cluster *Cluster) DeleteFaultInStorage(faultName string) error

DeleteFaultInStorage delete Fault in storage

func (*Cluster) GetFaultInStorage

func (cluster *Cluster) GetFaultInStorage(faultName string) int32

GetFaultInStorage checks if faultName already associated to an index

func (*Cluster) GetFaultSn

func (cluster *Cluster) GetFaultSn(faultID int32) int64

GetFaultSn return the fault sequence number

func (*Cluster) GetFaultStartEpoch

func (cluster *Cluster) GetFaultStartEpoch(faultID int32) int64

GetFaultStartEpoch return the startEpoch

func (*Cluster) IncrementFaultSn

func (cluster *Cluster) IncrementFaultSn(faultID int32) error

IncrementFaultSn increments the fault sequence number

func (*Cluster) InitAlertInfos

func (cluster *Cluster) InitAlertInfos(faultID int32) error

InitAlertInfos update the alertInfos map

func (*Cluster) Interval

func (cluster *Cluster) Interval(sched string) time.Duration

Interval returns the scheduler exceution interval

func (*Cluster) LeaderCh

func (cluster *Cluster) LeaderCh() <-chan bool

LeaderCh returns a buffered channel which receive cluster leadership changes for the current node. It MUST be consummed

func (*Cluster) NextFaultIndex

func (cluster *Cluster) NextFaultIndex() (int32, error)

NextFaultIndex return the Fault Index and increments it

func (*Cluster) NextHeartbeatIndex

func (cluster *Cluster) NextHeartbeatIndex() (int64, error)

NextHeartbeatIndex return the next event index and increments it

func (*Cluster) NextMeasurementIndex

func (cluster *Cluster) NextMeasurementIndex() (int64, error)

NextMeasurementIndex return the next event index and increments it

func (*Cluster) NextRun

func (cluster *Cluster) NextRun(sched string) time.Time

NextRun returns the time at which next execution should occure

func (*Cluster) SetFaultStartEpoch

func (cluster *Cluster) SetFaultStartEpoch(faultID int32, epoch int64) error

SetFaultStartEpoch set the startEpoch

func (*Cluster) Shutdown

func (cluster *Cluster) Shutdown() error

Shutdown stops the current raft node, and all associated goroutines

func (*Cluster) Stats

func (cluster *Cluster) Stats() map[string]string

Stats return a map with stats about the Raft cluster. This should be used only for debugging purpose. Do net expect this interface to remain stable over time

func (*Cluster) StoreFaultInStorage

func (cluster *Cluster) StoreFaultInStorage(faultName string, faultID int32) error

StoreFaultInStorage stores the index associated to the faultName

func (*Cluster) UpdateInterval

func (cluster *Cluster) UpdateInterval(sched string, interval time.Duration) error

UpdateInterval set a new execution interval for the scheduler

func (*Cluster) UpdateNextRun

func (cluster *Cluster) UpdateNextRun(sched string, next time.Time) error

UpdateNextRun set the time of the next execution

func (*Cluster) UpdateScheduler

func (cluster *Cluster) UpdateScheduler(sched string, interval time.Duration, next time.Time) error

UpdateScheduler set both interval and next execution time for the scheduler

type CmdType

type CmdType int

CmdType is the kind of command sent into commit logs

const (
	IncrementAlarmIdx CmdType = iota
	IncrementMeasIdx
	IncrementHeartbeatIdx
	UpdateScheduler
	IncrementFaultIdx
	UpdateFault
	DeleteFault
)

CmdType values

type DeleteFaultFields

type DeleteFaultFields struct {
	// FaultName of the fault to create
	FaultName string `json:"faultName"`
}

DeleteFaultFields holds the fields for command of kind DeleteFault

func (*DeleteFaultFields) String

func (fields *DeleteFaultFields) String() string

type FSM

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

FSM is the internal Finite State Machine handling internal state changes across raft cluster

func NewFSM

func NewFSM(state SnapshotableAgentState, debug bool) *FSM

NewFSM creates a new finite state machine wrapping a snapshotable state, and handling state changes across the raft cluster If `debug` is true, Commit logs are displayed in log output

func (*FSM) Apply

func (fsm *FSM) Apply(logEntry *raft.Log) interface{}

Apply applies a Raft log to this FSM

func (*FSM) DeleteFaultInStorage

func (fsm *FSM) DeleteFaultInStorage(faultName string) error

DeleteFaultInStorage delete Fault in storage

func (*FSM) GetFaultInStorage

func (fsm *FSM) GetFaultInStorage(faultName string) int32

GetFaultInStorage checks if faultName already associated to an index

func (*FSM) GetFaultSn

func (fsm *FSM) GetFaultSn(fault int32) int64

GetFaultSn return the fault sequence number

func (*FSM) GetFaultStartEpoch

func (fsm *FSM) GetFaultStartEpoch(fault int32) int64

GetFaultStartEpoch return the startEpoch

func (*FSM) InitAlertInfos

func (fsm *FSM) InitAlertInfos(fault int32) error

InitAlertInfos update the alertInfos map

func (*FSM) Interval

func (fsm *FSM) Interval(sched string) time.Duration

Interval returns the scheduler exceution interval

func (*FSM) NextRun

func (fsm *FSM) NextRun(sched string) time.Time

NextRun returns the time at which next execution should occure

func (*FSM) Restore

func (fsm *FSM) Restore(input io.ReadCloser) error

Restore deserialize and applies a snapshot to this FSM, discarding previous state

func (*FSM) Snapshot

func (fsm *FSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot creates and return a new snapshot of the surrent state

type SchedulerStateSnapshot

type SchedulerStateSnapshot struct {
	Interval time.Duration `json:"interval"`
	Next     time.Time     `json:"time"`
}

SchedulerStateSnapshot is a snapshiot of a scheduler's state

type SnapshotableAgentState

type SnapshotableAgentState interface {
	AgentState
	// Snapshot creates a new state snapshot
	Snapshot() *AgentStateSnapshot
	// Restore state from the provided snapshot
	Restore(*AgentStateSnapshot)
}

SnapshotableAgentState represent an agent state that supports snapshots and restore from a snapshot

func NewInMemState

func NewInMemState() SnapshotableAgentState

NewInMemState creates a new snapshotable state stored in memory

type StateCmd

type StateCmd struct {
	// Kind of command
	Type CmdType `json:"ty"`
	// Fields for command of kind UpdateScheduler
	UpdateScheduler *UpdateSchedulerFields `json:"sched,omitempty"`
	// Fields for command of kind UpdateFault
	UpdateFault *UpdateFaultFields `json:"updatefault,omitempty"`
	// Fields for command of kind DeleteFault
	DeleteFault *DeleteFaultFields `json:"deletefault,omitempty"`
}

StateCmd is a state change command sent through commit logs

func (*StateCmd) String

func (cmd *StateCmd) String() string

type UpdateFaultFields

type UpdateFaultFields struct {
	// FaultID of the fault to update
	FaultID *int32 `json:"faultId"`
	// FaultName of the fault to create
	FaultName string `json:"faultName,omitempty"`
	// New value of sequenceNumber
	SequenceNumber *int64 `json:"sn,omitempty"`
	// New value of startEpoch
	StartEpoch *int64 `json:"epoch,omitempty"`
}

UpdateFaultFields holds the fields for command of kind UpdateFault

func (*UpdateFaultFields) String

func (fields *UpdateFaultFields) String() string

type UpdateSchedulerFields

type UpdateSchedulerFields struct {
	// Name of scheduler to update
	Name string `json:"name"`
	// New value of interval, if updated, or nil
	Interval *time.Duration `json:"intv,omitempty"`
	// New value of next run epoch time (in seconds), if updated, or nil
	Next *int64 `json:"nxt,omitempty"`
}

UpdateSchedulerFields holds the fields for command of kind UpdateScheduler

func (*UpdateSchedulerFields) String

func (fields *UpdateSchedulerFields) String() string

Jump to

Keyboard shortcuts

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