model

package
v0.0.0-...-2cf5803 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InstanceStatusUP Ready to receive traffic
	InstanceStatusUP = uint32(1)
	// InstancestatusWating Intentionally shutdown for traffic
	InstancestatusWating = uint32(1) << 1
)
View Source
const (
	// AppID is discvoery id
	AppID = "infra.discovery"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int

Action Replicate type of node

const (
	// Register Replicate the add action to all nodes
	Register Action = iota
	// Renew Replicate the heartbeat action to all nodes
	Renew
	// Cancel Replicate the cancel action to all nodes
	Cancel
	// Weight Replicate the Weight action to all nodes
	Weight
	// Delete Replicate the Delete action to all nodes
	Delete
	// Status Replicate the Status action to all nodes
	Status
)

type App

type App struct {
	AppID string
	Zone  string
	// contains filtered or unexported fields
}

App Instances distinguished by hostname

func NewApp

func NewApp(zone, appid string) (a *App)

NewApp new App.

func (*App) Cancel

func (a *App) Cancel(hostname string, latestTime int64) (i *Instance, l int, ok bool)

Cancel cancel a instance.

func (*App) Instances

func (a *App) Instances() (is []*Instance)

Instances return slice of instances.

func (*App) Len

func (a *App) Len() (l int)

Len returns the length of instances.

func (*App) NewInstance

func (a *App) NewInstance(ni *Instance, latestTime int64) (i *Instance, ok bool)

NewInstance new a instance.

func (*App) Renew

func (a *App) Renew(hostname string) (i *Instance, ok bool)

Renew new a instance.

func (*App) Set

func (a *App) Set(changes *ArgSet) (ok bool)

Set set new status,metadata,color of instance .

type Apps

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

Apps app distinguished by zone

func NewApps

func NewApps() *Apps

NewApps return new Apps.

func (*Apps) App

func (p *Apps) App(zone string) (as []*App)

App get app by zone.

func (*Apps) Del

func (p *Apps) Del(zone string)

Del del app by zone.

func (*Apps) InstanceInfo

func (p *Apps) InstanceInfo(zone string, latestTime int64, status uint32) (ci *InstanceInfo, err error)

InstanceInfo return slice of instances.if up is true,return all status instance else return up status instance

func (*Apps) NewApp

func (p *Apps) NewApp(zone, appid string, lts int64) (a *App, new bool)

NewApp news a app by appid. If ok=false, returns the app of already exist.

func (*Apps) UpdateLatest

func (p *Apps) UpdateLatest(latestTime int64)

UpdateLatest update LatestTimestamp.

type ArgCancel

type ArgCancel struct {
	Zone            string `form:"zone" validate:"required"`
	Env             string `form:"env" validate:"required"`
	AppID           string `form:"appid" validate:"required"`
	Hostname        string `form:"hostname" validate:"required"`
	Replication     bool   `form:"replication"`
	LatestTimestamp int64  `form:"latest_timestamp"`
}

ArgCancel define cancel params.

type ArgFetch

type ArgFetch struct {
	Zone   string `form:"zone"`
	Env    string `form:"env" validate:"required"`
	AppID  string `form:"appid" validate:"required"`
	Status uint32 `form:"status" validate:"required"`
}

ArgFetch define fetch param.

type ArgFetchs

type ArgFetchs struct {
	Zone   string   `form:"zone"`
	Env    string   `form:"env" validate:"required"`
	AppID  []string `form:"appid" validate:"gt=0"`
	Status uint32   `form:"status" validate:"required"`
}

ArgFetchs define fetchs arg.

type ArgPoll

type ArgPoll struct {
	Zone            string `form:"zone"`
	Env             string `form:"env" validate:"required"`
	AppID           string `form:"appid" validate:"required"`
	Hostname        string `form:"hostname" validate:"required"`
	LatestTimestamp int64  `form:"latest_timestamp"`
}

ArgPoll define poll param.

type ArgPolls

type ArgPolls struct {
	Zone            string   `form:"zone"`
	Env             string   `form:"env" validate:"required"`
	AppID           []string `form:"appid" validate:"gt=0"`
	Hostname        string   `form:"hostname" validate:"required"`
	LatestTimestamp []int64  `form:"latest_timestamp"`
}

ArgPolls define poll param.

type ArgRegister

type ArgRegister struct {
	Region          string   `form:"region"`
	Zone            string   `form:"zone" validate:"required"`
	Env             string   `form:"env" validate:"required"`
	AppID           string   `form:"appid" validate:"required"`
	Hostname        string   `form:"hostname" validate:"required"`
	Status          uint32   `form:"status" validate:"required"`
	Addrs           []string `form:"addrs" validate:"gt=0"`
	Version         string   `form:"version"`
	Metadata        string   `form:"metadata"`
	Replication     bool     `form:"replication"`
	LatestTimestamp int64    `form:"latest_timestamp"`
	DirtyTimestamp  int64    `form:"dirty_timestamp"`
}

ArgRegister define register param.

type ArgRenew

type ArgRenew struct {
	Zone           string `form:"zone" validate:"required"`
	Env            string `form:"env" validate:"required"`
	AppID          string `form:"appid" validate:"required"`
	Hostname       string `form:"hostname" validate:"required"`
	Replication    bool   `form:"replication"`
	DirtyTimestamp int64  `form:"dirty_timestamp"`
}

ArgRenew define renew params.

type ArgSet

type ArgSet struct {
	Zone         string   `form:"zone" validate:"required"`
	Env          string   `form:"env" validate:"required"`
	AppID        string   `form:"appid" validate:"required"`
	Hostname     []string `form:"hostname" validate:"gte=0"`
	Status       []uint32 `form:"status" validate:"gte=0"`
	Metadata     []string `form:"metadata" validate:"gte=0"`
	Replication  bool     `form:"replication"`
	SetTimestamp int64    `form:"set_timestamp"`
}

ArgSet define set param.

type Instance

type Instance struct {
	Region   string            `json:"region"`
	Zone     string            `json:"zone"`
	Env      string            `json:"env"`
	AppID    string            `json:"appid"`
	Hostname string            `json:"hostname"`
	Addrs    []string          `json:"addrs"`
	Version  string            `json:"version"`
	Metadata map[string]string `json:"metadata"`

	// Status enum instance status
	Status uint32 `json:"status"`

	// timestamp
	RegTimestamp   int64 `json:"reg_timestamp"`
	UpTimestamp    int64 `json:"up_timestamp"` // NOTE: It is latest timestamp that status becomes UP.
	RenewTimestamp int64 `json:"renew_timestamp"`
	DirtyTimestamp int64 `json:"dirty_timestamp"`

	LatestTimestamp int64 `json:"latest_timestamp"`
}

Instance holds information required for registration with <Discovery Server> and to be discovered by other components.

func NewInstance

func NewInstance(arg *ArgRegister) (i *Instance)

NewInstance new a instance.

type InstanceInfo

type InstanceInfo struct {
	Instances       map[string][]*Instance `json:"instances"`
	Scheduler       []Zone                 `json:"scheduler,omitempty"`
	LatestTimestamp int64                  `json:"latest_timestamp"`
}

InstanceInfo the info get by consumer.

type Node

type Node struct {
	Addr   string     `json:"addr"`
	Status NodeStatus `json:"status"`
	Zone   string     `json:"zone"`
}

Node node

type NodeStatus

type NodeStatus int

NodeStatus Status of instance

const (
	// NodeStatusUP Ready to receive register
	NodeStatusUP NodeStatus = iota
	// NodeStatusLost lost with each other
	NodeStatusLost
)

type Scheduler

type Scheduler struct {
	AppID  string `json:"app_id,omitempty"`
	Env    string `json:"env"`
	Zones  []Zone `json:"zones"` // zone-ratio
	Remark string `json:"remark"`
}

Scheduler info.

type Zone

type Zone struct {
	Src string         `json:"src"`
	Dst map[string]int `json:"dst"`
}

Zone info.

Jump to

Keyboard shortcuts

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