Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"arg.go",
"group.go",
"store.go",
"volume.go",
],
importpath = "go-common/app/admin/main/bfs/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,55 @@
package model
// ArgCluster .
type ArgCluster struct {
Cluster string `form:"cluster" validate:"required"`
}
// ArgAddVolume add volume
type ArgAddVolume struct {
Group string `form:"group" validate:"required"`
Num int64 `form:"num" validate:"required"`
}
// ArgAddFreeVolume add free volume
type ArgAddFreeVolume struct {
Group string `form:"group" validate:"required"`
Dir string `form:"dir" validate:"required"`
Num int64 `form:"num" validate:"required"`
}
// ArgCompact group compact
type ArgCompact struct {
Group string `form:"group" validate:"required"`
Vid int64 `form:"vid"`
}
// ArgGroupStatus group status
type ArgGroupStatus struct {
Group string `form:"group" validate:"required"`
Status string `form:"status" validate:"required"`
}
// RespRack .
type RespRack struct {
Racks map[string]*Rack `json:"racks"`
}
// RespGroup .
type RespGroup struct {
Groups map[string]*Group `json:"groups"`
}
// RespVolume .
type RespVolume struct {
Volumes map[string]*VolumeState `json:"volumes"`
}
// RespTotal .
type RespTotal struct {
Space int64 `json:"space"`
FreeSpace int64 `json:"free_space"`
Groups int64 `json:"groups"`
Stores int64 `json:"stores"`
Volumes int64 `json:"volumes"`
}

View File

@@ -0,0 +1,12 @@
package model
// Group .
type Group struct {
Stores []string `json:"stores"`
StoreDatas map[string]*Store `json:"store_datas"`
Total struct {
Space int64 `json:"space"`
FreeSpace int64 `json:"free_space"`
Volumes int64 `json:"volumes"`
} `json:"total"`
}

View File

@@ -0,0 +1,64 @@
package model
// zookeeper save the store meta data.
//
// /rack -- rack root path
// |
// /rack-a -------- --------- /rack-b -- rack node path
// |
// /store-a -------- /store-b -- store node path (data: {"stat":"localhost:6061","admin":"localhost:6063","api":"localhost:6062","status":0})
// | |
// /volume-1 - - /volume-4 volume node path (data: /tmp/block_1,/tmp/block_1.idx,1)
// /volume-2 - - /volume-5
// /volume-3 - - /volume-6
// Store status const.
const (
// bit
StoreStatusEnableBit = 31
StoreStatusReadBit = 0
StoreStatusWriteBit = 1
StoreStatusSyncBit = 2
// status
StoreStatusInit = 0 // 0
StoreStatusEnable = (1 << StoreStatusEnableBit) // 2147483648
StoreStatusRead = StoreStatusEnable | (1 << StoreStatusReadBit) // 2147483649
StoreStatusWrite = StoreStatusEnable | (1 << StoreStatusWriteBit) // 2147483650
StoreStatusHealth = StoreStatusRead | StoreStatusWrite // 2147483651
StoreStatusSync = StoreStatusEnable | (1 << StoreStatusSyncBit) // 2147483652
StoreStatusFail = StoreStatusEnable // 2147483648
)
// Rack get all store and volume.
type Rack struct {
Stores map[string]*Store `json:"stores"`
}
// Store meta data.
type Store struct {
Stat string `json:"stat"`
Admin string `json:"admin"`
API string `json:"api"`
ID string `json:"id"`
Rack string `json:"rack"`
Status int `json:"status"`
States struct {
Init bool `json:"init"`
Enable bool `json:"enable"`
Read bool `json:"read"`
Write bool `json:"write"`
Sync bool `json:"sync"`
Fail bool `json:"fail"`
} `json:"states"`
Volumes []string `json:"volumes"`
}
// ParseStates parse states.
func (s *Store) ParseStates() {
s.States.Init = s.Status == StoreStatusInit
s.States.Enable = s.Status&StoreStatusEnable == StoreStatusEnable
s.States.Read = s.Status&StoreStatusRead == StoreStatusRead
s.States.Write = s.Status&StoreStatusWrite == StoreStatusWrite
s.States.Sync = s.Status&StoreStatusSync == StoreStatusSync
s.States.Fail = s.Status == StoreStatusFail
}

View File

@@ -0,0 +1,21 @@
package model
// type Volumes struct {
// Vol map[string]*VolumeState
// }
// VolumeState for zk /volume stat
type VolumeState struct {
TotalWriteProcessed uint64 `json:"total_write_processed"`
TotalWriteDelay uint64 `json:"total_write_delay"`
FreeSpace uint32 `json:"free_space"`
Dir string `json:"dir"`
}
// func (v *Volumes) GetVolumeState(id string) *VolumeState {
// vs, ok := v.Vol[id]
// if !ok {
// return nil
// }
// return vs
// }