models

package
v0.0.0-...-110c355 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionNothing   = ""
	ActionPending   = "pending"
	ActionPreparing = "preparing"
	ActionPrepared  = "prepared"
	ActionMigrating = "migrating"
	ActionFinished  = "finished"
	ActionSyncing   = "syncing"
)
View Source
const (
	ServerMasterSlaveNode = "master_slave_node"
	ServerOberserNode     = "observer_node"
	ServerWitnessNode     = "witness_node"
	ServerDeRaftNode      = "deraft_single_node"
)
View Source
const (
	MigratePrepred int = 0
	MigrateRunning int = 1
	MigrateFinshed int = 2
)
View Source
const (
	Local_Cache_Prefix = "Local_Cache_Prefix_PC-"
	Black_Keys         = "Black_Keys"
)
View Source
const MaxGroupId = 9999
View Source
const MaxSlotNum = 1024
View Source
const StoredDir = "/stored"

Variables

View Source
var DefaultPconfigKeyList = map[string]*Pconfig{
	Local_Cache_Prefix: {
		Name:   Local_Cache_Prefix,
		Remark: "Black and white list configuration: Proxy local cache",
		Content: &WhiteAndBlackList{
			White:         []string{},
			Black:         []string{},
			WhitePrefixes: []string{},
			BlackPrefixes: []string{},
			WhiteTrie:     trie.NewCharTrie([]string{}),
			BlackTrie:     trie.NewCharTrie([]string{}),
		},
		OutOfSync: true,
	},
	Black_Keys: {
		Name:   Black_Keys,
		Remark: "Black and white list configuration: Block key",
		Content: &WhiteAndBlackList{
			White:         []string{},
			Black:         []string{},
			WhitePrefixes: []string{},
			BlackPrefixes: []string{},
			WhiteTrie:     trie.NewCharTrie([]string{}),
			BlackTrie:     trie.NewCharTrie([]string{}),
		},
		OutOfSync: true,
	},
}

Functions

func AdminDir

func AdminDir() string

func AdminPath

func AdminPath(name string) string

func CheckInServerRole

func CheckInServerRole(role string) bool

func CloudPath

func CloudPath(product string) string

func DashCoreBackupPath

func DashCoreBackupPath(product string) string

func DepartmentPath

func DepartmentPath(product string) string

func GroupDir

func GroupDir(product string) string

func GroupPath

func GroupPath(product string, gid int) string

func JsonDecode

func JsonDecode(v interface{}, b []byte) error

func LockPath

func LockPath(product string) string

func MigrateDir

func MigrateDir(product string) string

func MigratePath

func MigratePath(product string, sid int) string

func PconfigDir

func PconfigDir(product string) string

func PconfigPath

func PconfigPath(product string, name string) string

func ProductDir

func ProductDir(product string) string

func ProxyDir

func ProxyDir(product string) string

func ProxyPath

func ProxyPath(product string, token string) string

func SlotPath

func SlotPath(product string, sid int) string

func SqliteInit

func SqliteInit(db *gorm.DB)

func ValidateProduct

func ValidateProduct(name string) error

Types

type Admin

type Admin struct {
	Username string    `form:"username" binding:"required" json:"username"`
	Password string    `form:"password" binding:"required" json:"password"`
	Role     AdminRole `form:"role" json:"role"`
}

func (*Admin) CheckAddRolePower

func (a *Admin) CheckAddRolePower() bool

func (*Admin) CheckOPRolePower

func (a *Admin) CheckOPRolePower() bool

func (*Admin) CheckReadRolePower

func (a *Admin) CheckReadRolePower() bool

func (*Admin) Encode

func (a *Admin) Encode() []byte

func (*Admin) Snapshot

func (a *Admin) Snapshot() *Admin

type AdminRole

type AdminRole int
const (
	SUPERADMIN AdminRole = 1
	OPADMIN    AdminRole = 2
	READADMIN  AdminRole = 3
)

type Client

type Client interface {
	Create(path string, data []byte) error
	Update(path string, data []byte) error
	Delete(path string) error

	Read(path string) ([]byte, error)
	List(path string) ([]string, error)
	Details(path string) ([]string, error)
	SubList(subPath string) (interface{}, error)

	Close() error
}

func NewClient

func NewClient(coordinator string, db *gorm.DB) (Client, error)

type DashCore

type DashCore struct {
	Token     string `json:"token"`
	StartTime string `json:"start_time"`
	AdminAddr string `json:"admin_addr"`
	HostPort  string `json:"hostport"`

	BackupAddr     string `json:"backup_addr"`
	BackupHostPort string `json:"backup_hostport"`

	ProductName string `json:"product_name"`

	ReadCrossCloud bool `json:"read_cross_cloud"`

	Pid int    `json:"pid"`
	Pwd string `json:"pwd"`
	Sys string `json:"sys"`
}

func LoadBackUpDashCore

func LoadBackUpDashCore(client Client, product string) (*DashCore, error)

func LoadDashCore

func LoadDashCore(client Client, product string) (*DashCore, error)

func (*DashCore) Encode

func (t *DashCore) Encode() []byte

type Department

type Department struct {
	Name string `json:"name"`
}

func LoadDepartment

func LoadDepartment(client Client, product string) (*Department, error)

type Group

type Group struct {
	Id          int            `json:"id"`
	Servers     []*GroupServer `json:"servers"`
	MasterAddr  string         `json:"master_addr,omitempty"`
	OutOfSync   bool           `json:"out_of_sync,omitempty"`
	IsExpanding bool           `json:"is_expanding"`

	Promoting struct {
		Index int    `json:"index,omitempty"`
		State string `json:"state,omitempty"`
	} `json:"promoting"`
}

func SortGroup

func SortGroup(group map[int]*Group) []*Group

func (*Group) Encode

func (g *Group) Encode() []byte

type GroupServer

type GroupServer struct {
	Addr         string `json:"server"`
	DataCenter   string `json:"datacenter"`
	CloudType    string `json:"cloudtype"`
	ServerRole   string `json:"server_role"`
	ReplicaGroup bool   `json:"replica_group"`

	Action struct {
		Index int    `json:"index,omitempty"`
		State string `json:"state,omitempty"`
	} `json:"action"`
}

type GroupSlice

type GroupSlice []*Group

func (GroupSlice) Len

func (s GroupSlice) Len() int

func (GroupSlice) Less

func (s GroupSlice) Less(i, j int) bool

func (GroupSlice) Swap

func (s GroupSlice) Swap(i, j int)

type Migrate

type Migrate struct {
	SID           int            `json:"sid"`
	SourceGroupID int            `json:"source_group_id"`
	TargetGroupID int            `json:"target_group_id"`
	Status        *MigrateStatus `json:"status"`
	CreateTime    string         `json:"create_time"`
	UpdateTime    string         `json:"update_time"`
}

func SortMigrate

func SortMigrate(group map[int]*Migrate) []*Migrate

func (*Migrate) Encode

func (g *Migrate) Encode() []byte

type MigrateSlice

type MigrateSlice []*Migrate

func (MigrateSlice) Len

func (s MigrateSlice) Len() int

func (MigrateSlice) Less

func (s MigrateSlice) Less(i, j int) bool

func (MigrateSlice) Swap

func (s MigrateSlice) Swap(i, j int)

type MigrateStatus

type MigrateStatus struct {
	Unixtime    int64  `json:"unixtime"`
	Costs       int64  `json:"costs"`
	From        string `json:"from"`
	To          string `json:"to"`
	SlotId      int64  `json:"slot_id"`
	Total       int64  `json:"total"`
	Fails       int64  `json:"fails"`
	SuccPercent string `json:"succ_percent"`
	Status      int    `json:"status"`
}

func (*MigrateStatus) Encode

func (ms *MigrateStatus) Encode() []byte

type Pconfig

type Pconfig struct {
	Name      string             `json:"name"`
	Remark    string             `json:"remark"`
	Content   *WhiteAndBlackList `json:"content"`
	OutOfSync bool               `json:"out_of_sync,omitempty"`
}

func (*Pconfig) BuildTrie

func (pc *Pconfig) BuildTrie()

func (*Pconfig) Encode

func (p *Pconfig) Encode() []byte

type Proxy

type Proxy struct {
	Id         int    `json:"id,omitempty"`
	Token      string `json:"token"`
	VersionTag string `json:"version_tag"`
	StartTime  string `json:"start_time"`
	AdminAddr  string `json:"admin_addr"`

	ProtoType string `json:"proto_type"`
	ProxyAddr string `json:"proxy_addr"`

	ProductName string `json:"product_name"`
	CloudType   string `json:"cloudtype"`

	Pid int    `json:"pid"`
	Pwd string `json:"pwd"`
	Sys string `json:"sys"`

	Hostname  string         `json:"hostname"`
	HostPort  string         `json:"hostport"`
	RedisConf *RedisConnConf `json:"redis_conf"`
}

func SortProxy

func SortProxy(proxy map[string]*Proxy) []*Proxy

func (*Proxy) Encode

func (p *Proxy) Encode() []byte

type ProxySlice

type ProxySlice []*Proxy

func (ProxySlice) Len

func (s ProxySlice) Len() int

func (ProxySlice) Less

func (s ProxySlice) Less(i, j int) bool

func (ProxySlice) Swap

func (s ProxySlice) Swap(i, j int)

type RedisConnConf

type RedisConnConf struct {
	HostPort     string            `toml:"host_port" json:"host_port,omitempty"`
	MaxIdle      int               `toml:"max_idle" json:"max_idle"`
	MaxActive    int               `toml:"max_active" json:"max_active"`
	IdleTimeout  timesize.Duration `toml:"idle_timeout" json:"idle_timeout"`
	ConnLifeTime timesize.Duration `toml:"conn_lifetime" json:"conn_lifetime"`
	Password     string            `toml:"password" json:"password"`
	DataBase     int               `toml:"database" json:"database"`
	ConnTimeout  timesize.Duration `toml:"conn_timeout" json:"conn_timeout"`
	ReadTimeout  timesize.Duration `toml:"read_timeout" json:"read_timeout"`
	WriteTimeout timesize.Duration `toml:"write_timeout" json:"write_timeout"`
}

type Slot

type Slot struct {
	Id                   int               `json:"id"`
	Locked               bool              `json:"locked"`
	Switched             bool              `json:"switched"`
	MasterAddr           string            `json:"master_addr"`
	MasterAddrGroupId    int               `json:"master_addr_group_id"`
	RoundRobinNum        uint64            `json:"round_robin_num"`
	LocalCloudServers    []string          `json:"local_servers"`
	BackupCloudServers   []string          `json:"backup_servers"`
	WitnessServers       []string          `json:"witness_servers"`
	GroupServersCloudMap map[string]string `json:"group_servers_cloudmap"`
	GroupServersStats    map[string]bool   `json:"group_servers_stats"`
}

func (*Slot) Encode

func (s *Slot) Encode() []byte

type SlotMapping

type SlotMapping struct {
	Id      int `json:"id"`
	GroupId int `json:"group_id"`

	Action struct {
		NotMigrateData bool   `json:"not_migrate_data,omitempty"`
		Index          int    `json:"index,omitempty"`
		State          string `json:"state,omitempty"`
		TargetId       int    `json:"target_id,omitempty"`
	} `json:"action"`
}

func (*SlotMapping) Encode

func (m *SlotMapping) Encode() []byte

type Store

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

func NewStore

func NewStore(client Client, product string) *Store

func (*Store) Acquire

func (s *Store) Acquire(dashCore *DashCore) error

func (*Store) AdminDir

func (s *Store) AdminDir() string

func (*Store) AdminPath

func (s *Store) AdminPath(username string) string

func (*Store) BackUp

func (s *Store) BackUp(dashCore *DashCore) error

func (*Store) BackUpPath

func (s *Store) BackUpPath() string

func (*Store) Client

func (s *Store) Client() Client

func (*Store) Close

func (s *Store) Close() error

func (*Store) DeRaftGroup

func (s *Store) DeRaftGroup(gid int, addr, token string) error

func (*Store) DeleteAdmin

func (s *Store) DeleteAdmin(username string) error

func (*Store) DeleteGroup

func (s *Store) DeleteGroup(gid int) error

func (*Store) DeleteMigrate

func (s *Store) DeleteMigrate(sid int) error

func (*Store) DeletePconfig

func (s *Store) DeletePconfig(name string) error

func (*Store) DeleteProxy

func (s *Store) DeleteProxy(token string) error

func (*Store) DepartmentPath

func (s *Store) DepartmentPath() string

func (*Store) GroupDir

func (s *Store) GroupDir() string

func (*Store) GroupPath

func (s *Store) GroupPath(gid int) string

func (*Store) ListAdmin

func (s *Store) ListAdmin() (map[string]*Admin, error)

func (*Store) ListGroup

func (s *Store) ListGroup() (map[int]*Group, error)

func (*Store) ListMigrate

func (s *Store) ListMigrate() (map[int]*Migrate, error)

func (*Store) ListPconfig

func (s *Store) ListPconfig() (map[string]*Pconfig, error)

func (*Store) ListProxy

func (s *Store) ListProxy() (map[string]*Proxy, error)

func (*Store) ListStored

func (s *Store) ListStored() ([]string, error)

func (*Store) LoadAdmin

func (s *Store) LoadAdmin(name string) (*Admin, error)

func (*Store) LoadBackUpDashCore

func (s *Store) LoadBackUpDashCore() (*DashCore, error)

func (*Store) LoadDashCore

func (s *Store) LoadDashCore() (*DashCore, error)

func (*Store) LoadDepartment

func (s *Store) LoadDepartment() (*Department, error)

func (*Store) LoadGroup

func (s *Store) LoadGroup(gid int) (*Group, error)

func (*Store) LoadMigrate

func (s *Store) LoadMigrate(sid int) (*Migrate, error)

func (*Store) LoadPconfig

func (s *Store) LoadPconfig(name string) (*Pconfig, error)

func (*Store) LoadProxy

func (s *Store) LoadProxy(token string) (*Proxy, error)

func (*Store) LoadSlotMapping

func (s *Store) LoadSlotMapping(sid int) (*SlotMapping, error)

func (*Store) LockPath

func (s *Store) LockPath() string

func (*Store) MigrateDir

func (s *Store) MigrateDir() string

func (*Store) MigratePath

func (s *Store) MigratePath(sid int) string

func (*Store) PconfigDir

func (s *Store) PconfigDir() string

func (*Store) PconfigPath

func (s *Store) PconfigPath(name string) string

func (*Store) ProxyDir

func (s *Store) ProxyDir() string

func (*Store) ProxyPath

func (s *Store) ProxyPath(token string) string

func (*Store) Release

func (s *Store) Release() error

func (*Store) ReleaseBackUp

func (s *Store) ReleaseBackUp() error

func (*Store) SlotMappings

func (s *Store) SlotMappings() ([]*SlotMapping, error)

func (*Store) SlotPath

func (s *Store) SlotPath(sid int) string

func (*Store) UpdateAdmin

func (s *Store) UpdateAdmin(a *Admin) error

func (*Store) UpdateDashCore

func (s *Store) UpdateDashCore(t *DashCore) error

func (*Store) UpdateDepartment

func (s *Store) UpdateDepartment(departmentName, productName string) error

func (*Store) UpdateGroup

func (s *Store) UpdateGroup(g *Group) error

func (*Store) UpdateMigrate

func (s *Store) UpdateMigrate(g *Migrate) error

func (*Store) UpdatePconfig

func (s *Store) UpdatePconfig(p *Pconfig) error

func (*Store) UpdateProxy

func (s *Store) UpdateProxy(p *Proxy) error

func (*Store) UpdateSlotMapping

func (s *Store) UpdateSlotMapping(m *SlotMapping) error

type WhiteAndBlackList

type WhiteAndBlackList struct {
	White    []string        `json:"whitelist"`
	Black    []string        `json:"blacklist"`
	BlackMap map[string]bool `json:"-"`
	WhiteMap map[string]bool `json:"-"`

	WhitePrefixes []string  `json:"white_prefixes"`
	BlackPrefixes []string  `json:"black_prefixes"`
	WhiteTrie     trie.Trie `json:"-"`
	BlackTrie     trie.Trie `json:"-"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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