cluster

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFeatureNotExist = errors.New("No nodes in nodepool match the feature specificed")
	ErrIlegalPath      = errors.New("path out of boundary of setting temp folder")
	ErrMasterNotFound  = serializer.NewError(serializer.CodeMasterNotFound, "未知的主机节点", nil)
)

Functions

func Init

func Init()

Init 初始化从机节点池

func InitController

func InitController()

func RemoteCallback

func RemoteCallback(url string, body serializer.UploadCallback) error

RemoteCallback 发送远程存储策略上传回调请求

Types

type Controller

type Controller interface {
	// Handle heartbeat sent from master
	HandleHeartBeat(*serializer.NodePingReq) (serializer.NodePingResp, error)

	// Get Aria2 Instance by master node ID
	GetAria2Instance(string) (common.Aria2, error)

	// Send event change message to master node
	SendNotification(string, string, mq.Message) error

	// Submit async task into task pool
	SubmitTask(string, interface{}, string, func(interface{})) error

	// Get master node info
	GetMasterInfo(string) (*MasterInfo, error)

	// Get master OneDrive policy credential
	GetOneDriveToken(string, uint) (string, error)
}

Controller controls communications between master and slave

var DefaultController Controller

type MasterInfo

type MasterInfo struct {
	ID  string
	TTL int
	URL *url.URL
	// used to invoke aria2 rpc calls
	Instance Node
	Client   request.Client
	// contains filtered or unexported fields
}

info of master node

type MasterNode

type MasterNode struct {
	Model *model.Node
	// contains filtered or unexported fields
}

func (*MasterNode) DBModel

func (node *MasterNode) DBModel() *model.Node

func (*MasterNode) GetAria2Instance

func (node *MasterNode) GetAria2Instance() common.Aria2

GetAria2Instance 获取主机Aria2实例

func (*MasterNode) ID

func (node *MasterNode) ID() uint

func (*MasterNode) Init

func (node *MasterNode) Init(nodeModel *model.Node)

Init 初始化节点

func (*MasterNode) IsActive

func (node *MasterNode) IsActive() bool

IsActive 返回节点是否在线

func (*MasterNode) IsFeatureEnabled

func (node *MasterNode) IsFeatureEnabled(feature string) bool

IsFeatureEnabled 查询节点的某项功能是否启用

func (*MasterNode) IsMater

func (node *MasterNode) IsMater() bool

func (*MasterNode) Kill

func (node *MasterNode) Kill()

Kill 结束aria2请求

func (*MasterNode) MasterAuthInstance

func (node *MasterNode) MasterAuthInstance() auth.Auth

func (*MasterNode) Ping

func (*MasterNode) SlaveAuthInstance

func (node *MasterNode) SlaveAuthInstance() auth.Auth

func (*MasterNode) SubscribeStatusChange

func (node *MasterNode) SubscribeStatusChange(callback func(isActive bool, id uint))

SubscribeStatusChange 订阅节点状态更改

type Node

type Node interface {
	// Init a node from database model
	Init(node *model.Node)

	// Check if given feature is enabled
	IsFeatureEnabled(feature string) bool

	// Subscribe node status change to a callback function
	SubscribeStatusChange(callback func(isActive bool, id uint))

	// Ping the node
	Ping(req *serializer.NodePingReq) (*serializer.NodePingResp, error)

	// Returns if the node is active
	IsActive() bool

	// Get instances for aria2 calls
	GetAria2Instance() common.Aria2

	// Returns unique id of this node
	ID() uint

	// Kill node and recycle resources
	Kill()

	// Returns if current node is master node
	IsMater() bool

	// Get auth instance used to check RPC call from slave to master
	MasterAuthInstance() auth.Auth

	// Get auth instance used to check RPC call from master to slave
	SlaveAuthInstance() auth.Auth

	// Get node DB model
	DBModel() *model.Node
}

func NewNodeFromDBModel

func NewNodeFromDBModel(node *model.Node) Node

Create new node from DB model

type NodePool

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

NodePool 通用节点池

var Default *NodePool

func (*NodePool) Add

func (pool *NodePool) Add(node *model.Node)

func (*NodePool) BalanceNodeByFeature

func (pool *NodePool) BalanceNodeByFeature(feature string, lb balancer.Balancer) (error, Node)

BalanceNodeByFeature 根据 feature 和 LoadBalancer 取出节点

func (*NodePool) Delete

func (pool *NodePool) Delete(id uint)

func (*NodePool) GetNodeByID

func (pool *NodePool) GetNodeByID(id uint) Node

func (*NodePool) Init

func (pool *NodePool) Init()

type Pool

type Pool interface {
	// Returns active node selected by given feature and load balancer
	BalanceNodeByFeature(feature string, lb balancer.Balancer) (error, Node)

	// Returns node by ID
	GetNodeByID(id uint) Node

	// Add given node into pool. If node existed, refresh node.
	Add(node *model.Node)

	// Delete and kill node from pool by given node id
	Delete(id uint)
}

Pool 节点池

type SlaveNode

type SlaveNode struct {
	Model  *model.Node
	Active bool
	// contains filtered or unexported fields
}

func (*SlaveNode) DBModel

func (node *SlaveNode) DBModel() *model.Node

func (*SlaveNode) GetAria2Instance

func (node *SlaveNode) GetAria2Instance() common.Aria2

GetAria2Instance 获取从机Aria2实例

func (*SlaveNode) ID

func (node *SlaveNode) ID() uint

func (*SlaveNode) Init

func (node *SlaveNode) Init(nodeModel *model.Node)

Init 初始化节点

func (*SlaveNode) IsActive

func (node *SlaveNode) IsActive() bool

IsActive 返回节点是否在线

func (*SlaveNode) IsFeatureEnabled

func (node *SlaveNode) IsFeatureEnabled(feature string) bool

IsFeatureEnabled 查询节点的某项功能是否启用

func (*SlaveNode) IsMater

func (node *SlaveNode) IsMater() bool

func (*SlaveNode) Kill

func (node *SlaveNode) Kill()

Kill 结束节点内相关循环

func (*SlaveNode) MasterAuthInstance

func (node *SlaveNode) MasterAuthInstance() auth.Auth

func (*SlaveNode) Ping

Ping 从机节点,返回从机负载

func (*SlaveNode) SlaveAuthInstance

func (node *SlaveNode) SlaveAuthInstance() auth.Auth

func (*SlaveNode) StartPingLoop

func (node *SlaveNode) StartPingLoop()

func (*SlaveNode) SubscribeStatusChange

func (node *SlaveNode) SubscribeStatusChange(callback func(bool, uint))

SubscribeStatusChange 订阅节点状态更改

Jump to

Keyboard shortcuts

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