pool

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: MIT Imports: 8 Imported by: 36

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Cache - caches nodes by session ID. !!! no thread safe

func NewCache

func NewCache(expirationTime time.Duration) *Cache

NewCache - constructor of Cache.

func (*Cache) CleanUp

func (c *Cache) CleanUp()

CleanUp - removes an expired cache.

func (*Cache) Get

func (c *Cache) Get(key string) (node *Node, ok bool)

Get - returns node from cache.

func (*Cache) Set

func (c *Cache) Set(key string, node *Node)

Set - caches a node.

type Node

type Node struct {
	// A unique key, by which we understand how to find this object in the outer world + for not adding the second time the same thing.
	// The value may depend on the strategy:
	// - for constant nodes ip: port
	// - for temporary pod.name
	Key              string                      `json:"key"`
	Type             NodeType                    `json:"type"`
	Address          string                      `json:"address"`
	Status           NodeStatus                  `json:"status"`
	SessionID        string                      `json:"session_id"`
	Updated          int64                       `json:"updated"`
	Registered       int64                       `json:"registered"`
	CapabilitiesList []capabilities.Capabilities `json:"capabilities_list"`
}

func NewNode

func NewNode(
	key string,
	t NodeType,
	address string,
	status NodeStatus,
	sessionID string,
	updated int64,
	registered int64,
	capabilitiesList []capabilities.Capabilities,
) *Node

func (*Node) String

func (n *Node) String() string

type NodeStatus

type NodeStatus string
const (
	NodeStatusAvailable NodeStatus = "available"
	NodeStatusReserved  NodeStatus = "reserved"
	NodeStatusBusy      NodeStatus = "busy"
)

type NodeType

type NodeType string
const (
	NodeTypePersistent NodeType = "persistent"
	NodeTypeKubernetes NodeType = "kubernetes"
)

type Pool

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

func NewPool

func NewPool(storage StorageInterface, strategyList StrategyListInterface) *Pool

func (*Pool) Add

func (p *Pool) Add(key string, t NodeType, address string, capabilitiesList []capabilities.Capabilities) error

func (*Pool) CleanUpNode

func (p *Pool) CleanUpNode(node *Node) error

func (*Pool) CountNodes

func (p *Pool) CountNodes(status *NodeStatus) (int, error)

func (*Pool) FixNodeStatuses

func (p *Pool) FixNodeStatuses()

func (*Pool) GetAll

func (p *Pool) GetAll() ([]Node, error)

func (*Pool) GetNodeByAddress

func (p *Pool) GetNodeByAddress(address string) (*Node, error)

func (*Pool) GetNodeBySessionID

func (p *Pool) GetNodeBySessionID(sessionID string) (*Node, error)

func (*Pool) RegisterSession

func (p *Pool) RegisterSession(node *Node, sessionID string) error

func (*Pool) Remove

func (p *Pool) Remove(node *Node) error

удаляет ноду из пула

func (*Pool) ReserveAvailableNode

func (p *Pool) ReserveAvailableNode(caps capabilities.Capabilities) (*Node, error)

TODO: research close transaction and defer close mysql result body.

func (*Pool) SetBusyNodeDuration

func (p *Pool) SetBusyNodeDuration(duration time.Duration)

func (*Pool) SetReservedNodeDuration

func (p *Pool) SetReservedNodeDuration(duration time.Duration)

type StorageInterface

type StorageInterface interface {
	Add(node Node, limit int) error
	ReserveAvailable([]Node) (Node, error)
	SetBusy(Node, string) error
	SetAvailable(Node) error
	GetCountWithStatus(*NodeStatus) (int, error)
	GetBySession(string) (Node, error)
	GetByAddress(string) (Node, error)
	GetAll() ([]Node, error)
	Remove(Node) error
	UpdateAddress(node Node, newAddress string) error
}

type StorageMock

type StorageMock struct {
	mock.Mock
}

func (*StorageMock) Add

func (s *StorageMock) Add(node Node, limit int) error

func (*StorageMock) GetAll

func (s *StorageMock) GetAll() ([]Node, error)

func (*StorageMock) GetByAddress

func (s *StorageMock) GetByAddress(address string) (Node, error)

func (*StorageMock) GetBySession

func (s *StorageMock) GetBySession(sessionID string) (Node, error)

func (*StorageMock) GetCountWithStatus

func (s *StorageMock) GetCountWithStatus(nodeStatus *NodeStatus) (int, error)

func (*StorageMock) Remove

func (s *StorageMock) Remove(node Node) error

func (*StorageMock) ReserveAvailable

func (s *StorageMock) ReserveAvailable(nodeList []Node) (Node, error)

func (*StorageMock) SetAvailable

func (s *StorageMock) SetAvailable(node Node) error

func (*StorageMock) SetBusy

func (s *StorageMock) SetBusy(node Node, sessionID string) error

func (*StorageMock) UpdateAddress added in v0.4.0

func (s *StorageMock) UpdateAddress(node Node, newAddress string) error

type StrategyInterface

type StrategyInterface interface {
	Reserve(capabilities.Capabilities) (Node, error)
	CleanUp(Node) error
	FixNodeStatus(Node) error
}

type StrategyList

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

func NewStrategyList

func NewStrategyList(list []StrategyInterface) *StrategyList

func (*StrategyList) CleanUp

func (s *StrategyList) CleanUp(node Node) error

func (*StrategyList) FixNodeStatus

func (s *StrategyList) FixNodeStatus(node Node) error

func (*StrategyList) Reserve

func (s *StrategyList) Reserve(caps capabilities.Capabilities) (node Node, err error)

type StrategyListInterface

type StrategyListInterface interface {
	Reserve(caps capabilities.Capabilities) (node Node, err error)
	CleanUp(node Node) error
	FixNodeStatus(node Node) error
}

type StrategyListMock

type StrategyListMock struct {
	mock.Mock
}

func (*StrategyListMock) CleanUp

func (s *StrategyListMock) CleanUp(node Node) error

func (*StrategyListMock) FixNodeStatus

func (s *StrategyListMock) FixNodeStatus(node Node) error

func (*StrategyListMock) Reserve

func (s *StrategyListMock) Reserve(caps capabilities.Capabilities) (Node, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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