Commit 0eef7ca9 authored by luxq's avatar luxq

update worker info

parent 19330834
......@@ -32,6 +32,11 @@ func (g baseService) List() ([]string, error) {
return res, nil
}
func (g baseService) Count() int {
count, _ := getCount(g.rdb, g.service)
return count
}
func (g baseService) ListByPage(pageSize int, pageNum int) ([]string, int, error) {
all, err := getAll(g.rdb, g.service)
if err != nil {
......@@ -73,6 +78,14 @@ func parseInfo(stype common.ServiceType, res *redis.MapStringStringCmd) ServiceI
return regInfo
}
func getCount(rdb *redis.Client, serviceType common.ServiceType) (int, error) {
keys, err := rdb.Keys(context.Background(), common.GetServiceKeyPrefix(serviceType)+"*").Result()
if err != nil {
return 0, err
}
return len(keys), nil
}
func getAll(rdb *redis.Client, serviceType common.ServiceType) (ServiceInfoList, error) {
keys, err := rdb.Keys(context.Background(), common.GetServiceKeyPrefix(serviceType)+"*").Result()
if err != nil {
......
......@@ -7,6 +7,7 @@ type ServiceQuery interface {
List() ([]string, error)
ListByPage(pageSize int, pageNum int) ([]string, int, error)
ServiceInfo(instance string) (string, error)
Count() int
}
type ServiceInfo interface {
......
......@@ -9,13 +9,26 @@ import (
func TestQuery(t *testing.T) {
q := NewQuery(registry.RedisConnParam{
Addr: "localhost:6379",
Password: "",
Addr: "43.198.252.255:6379",
Password: "iH0g2CqzjI6SfercGwsT",
DbIndex: 0,
})
workerPage, _, err := q.Select(common.SERVICE_WORKER).ListByPage(1, 2)
_ = workerPage
nmlistInfo, err := q.Select(common.SERVICE_NODE_MANAGER).List()
_ = nmlistInfo
assert.Equal(t, err, nil)
gatewayInfo, err := q.Select(common.SERVICE_API_GATEWAY).ServiceInfo("gateway1")
gatewayListInfo, err := q.Select(common.SERVICE_API_GATEWAY).List()
_ = gatewayListInfo
assert.Equal(t, err, nil)
t.Logf("nmlistInfo: %v, gatewayInfo: %v", nmlistInfo, gatewayInfo)
sclistInfo, err := q.Select(common.SERVICE_SCHEDULER).List()
_ = sclistInfo
assert.Equal(t, err, nil)
workerListInfo, err := q.Select(common.SERVICE_WORKER).List()
_ = workerListInfo
assert.Equal(t, err, nil)
backendInfo, err := q.Select(common.SERVICE_BACKEND).List()
_ = backendInfo
assert.Equal(t, err, nil)
//t.Logf("nmlistInfo: %v, gatewayInfo: %v, sclistInfo: %v, workerListInfo: %v, backendInfo: %v", nmlistInfo, gatewayInfo, sclistInfo, workerListInfo, backendInfo)
}
......@@ -15,6 +15,16 @@ type WorkerInfo struct {
IP string `redis:"ip" json:"ip"`
Nonce int64 `redis:"nonce" json:"nonce"`
TaskList []string `redis:"task_list" json:"task_list"`
CpuModel string `redis:"cpu_model" json:"cpu_model"`
CpuCore int `redis:"cpu_core" json:"cpu_core"`
GPUModel string `redis:"gpu_model" json:"gpu_model" json:"gpu_model"`
GPURam int `redis:"gpu_ram" json:"gpu_ram"`
RamTotal int64 `redis:"ram_total" json:"ram_total"`
RamUsed int64 `redis:"ram_used" json:"ram_used"`
CreateTime int64 `redis:"create_time" json:"create_time"`
BootupTime int64 `redis:"bootup_time" json:"bootup_time"`
Workload int `redis:"workload" json:"workload"`
MacAddress string `redis:"mac_address" json:"mac_address"`
}
type workerQuery struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment