Documentation
¶
Overview ¶
Package spawn used as a HTTP REST sync service, that makes clustering mode simpler and easier for most of applications.
What's the idea? There are several applications, which are developed to provide their service through HTTP Rest API. But you have no idea how to provide failover processing and clustering mode for these applications, because they are not compatible with, etc. And here we go. The Spawn service will make this job instead of the whole bunch of services that must be configured and communicating each other.
Spawn Sync Service
Index ¶
- Constants
- type HealthCheck
- type Metrics
- type MetricsBandle
- type Node
- type NodeBundle
- func (bundle *NodeBundle) CurrentFromRing() (Node, bool)
- func (bundle *NodeBundle) Delete(host string, port uint64) bool
- func (bundle *NodeBundle) DeleteAll()
- func (bundle *NodeBundle) DeleteAllByHost(host string) bool
- func (bundle *NodeBundle) Get(host string, port uint64) (node Node, ok bool)
- func (bundle *NodeBundle) GetAll() (nodes []Node, total int)
- func (bundle *NodeBundle) GetAllByHost(host string) (nodes []Node, total int)
- func (bundle *NodeBundle) InitRing()
- func (bundle *NodeBundle) Set(node *Node) bool
- func (bundle *NodeBundle) SetAll(nodes []Node) bool
- func (bundle *NodeBundle) TwistRing()
- type Server
Constants ¶
const ( // VERSION - current version of the service VERSION = "0.3.5" // DATE - revision date of the service DATE = "2016-04-24T01:27:17Z" // MaxSignals - maximum count of update signals MaxSignals = 1000 // MaxJobs - maximum count of update jobs for every bundle MaxJobs = 100000 // DefaultTimeout is a timeout for the worker's response DefaultTimeout time.Duration = 10 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HealthCheck ¶
type HealthCheck struct { // health check time of the node in seconds Seconds time.Duration `json:"seconds"` // url which will be checked URL string `json:"url"` // regexp pattern for extended check analyze Pattern string `json:"regexp"` }
HealthCheck contains parameters which used for checking node
type Metrics ¶
type Metrics struct { Success struct { Get uint64 `json:"get"` Set uint64 `json:"set"` Delete uint64 `json:"delete"` } `json:"success"` Failure struct { Get uint64 `json:"get"` Set uint64 `json:"set"` Delete uint64 `json:"delete"` } `json:"failure"` Queued struct { Get uint64 `json:"get"` Set uint64 `json:"set"` Delete uint64 `json:"delete"` } `json:"queued"` }
type MetricsBandle ¶
type MetricsBandle struct { *Server // contains filtered or unexported fields }
MetricsBandle contains an embedded server link and Node records
func (*MetricsBandle) SetMetrics ¶
func (bundle *MetricsBandle) SetMetrics(id, metricType, method string)
type Node ¶
type Node struct { Host string `json:"host"` Port uint64 `json:"port"` Priority int `json:"priority"` Active bool `json:"active"` Maintenance bool `json:"maintenance"` }
Node contains the node parameters:
- Host is the host name or IP,
- Port is the port number,
- Priority defines a sequence, which will be operating according to attribute of the priority. A example of sorted values by priority - from highest to lowest (1,2,3,0,0,0,-1,-2,-3) the priority '0' has neutral priority value between high and low,
- Active defines status of the node. If it will be set to false, the queue which related with the node will be deleted or it will be created otherwise
- Maintenance mode is using to stop the worker and accumulate updates in the queue. If maintenance mode set to false all updates will posted in the node.
type NodeBundle ¶
type NodeBundle struct { *Server // contains filtered or unexported fields }
NodeBundle contains an embedded server link and Node records
func (*NodeBundle) CurrentFromRing ¶
func (bundle *NodeBundle) CurrentFromRing() (Node, bool)
CurrentFromRing gets a current Node from the the ring ('round-robin')
func (*NodeBundle) Delete ¶
func (bundle *NodeBundle) Delete(host string, port uint64) bool
Delete one of the node record specified by host and port
func (*NodeBundle) DeleteAll ¶
func (bundle *NodeBundle) DeleteAll()
DeleteAll - deletes all the nodes records
func (*NodeBundle) DeleteAllByHost ¶
func (bundle *NodeBundle) DeleteAllByHost(host string) bool
DeleteAllByHost - deletes all the nodes records specified by host
func (*NodeBundle) Get ¶
func (bundle *NodeBundle) Get(host string, port uint64) (node Node, ok bool)
Get - gets one of the node record specified by host and port
func (*NodeBundle) GetAll ¶
func (bundle *NodeBundle) GetAll() (nodes []Node, total int)
GetAll - gets all the nodes records sorted according to priority
func (*NodeBundle) GetAllByHost ¶
func (bundle *NodeBundle) GetAllByHost(host string) (nodes []Node, total int)
GetAllByHost - gets all the nodes records specified by host and sorted according to priority
func (*NodeBundle) InitRing ¶
func (bundle *NodeBundle) InitRing()
InitRing - inits the nodes in the ring ('round-robin') and resets a pointer to the node
func (*NodeBundle) Set ¶
func (bundle *NodeBundle) Set(node *Node) bool
Set - updates the node record or create one if it does not exist
func (*NodeBundle) SetAll ¶
func (bundle *NodeBundle) SetAll(nodes []Node) bool
SetAll - updates all the nodes records or create them if records do not exist
func (*NodeBundle) TwistRing ¶
func (bundle *NodeBundle) TwistRing()
TwistRing - sets a pointer to the next node from the ring
type Server ¶
type Server struct { // Server name/description Name string // Embeded router *router.Router // Node Bundle contains the Node records Nodes *NodeBundle // Metrics Bundle contains the Metrics records Metrics *MetricsBandle // contains filtered or unexported fields }
Server Record
func (*Server) Run ¶
func (server *Server) Run( hostPort, apiHostPort string, transport http.RoundTripper, nodes []Node, roundRobin, byPriority bool, check HealthCheck, authService auth.Auth, ) (status string, err error)
Run the server, init the handlers, init the specified modes. If transport http.RoundTripper is not defined will be used default transport. http.RoundTripper contains callback function which handle all incoming requests and get responses/errors