| | |
| | | "context" |
| | | "encoding/json" |
| | | "fmt" |
| | | "github.com/mitchellh/mapstructure" |
| | | "os" |
| | | "os/signal" |
| | | "regexp" |
| | |
| | | } |
| | | |
| | | // 查询集群状态, 返回 master, slave, leave |
| | | func (ss *SyncServer) QueryClusterStat() string { |
| | | func (ss *SyncServer) QueryClusterStat() *bhomeclient.Reply { |
| | | clusterStatTopic := "/data/api-v/cluster/status" |
| | | req := bhomeclient.Request{ |
| | | Path: clusterStatTopic, |
| | |
| | | if err != nil { |
| | | fmt.Println("RequestTopic error", err.Error()) |
| | | |
| | | return "" |
| | | return reply |
| | | } |
| | | |
| | | ss.ClusterStatus = reply.Msg |
| | | |
| | | logx.Debugf("当前集群状态: %s", ss.ClusterStatus) |
| | | |
| | | return reply.Msg |
| | | return reply |
| | | } |
| | | |
| | | func (ss *SyncServer) handleDbLoggerPrint() { |
| | |
| | | |
| | | return "" |
| | | } |
| | | |
| | | type NodeInfo struct { |
| | | NodeID string `json:"node_id,omitempty"` |
| | | NodeIp string `json:"node_ip,omitempty"` |
| | | NodeName string `json:"node_name,omitempty"` |
| | | ClusterID string `json:"cluster_id"` |
| | | CreateTime string `json:"create_time"` |
| | | DeviceType string `json:"device_type"` |
| | | DriftState string `json:"drift_state"` |
| | | Online string `json:"online"` |
| | | } |
| | | |
| | | func QueryClusterStatusAndNodeQuantity() (string, int) { |
| | | reply := agent.QueryClusterStat() |
| | | if reply == nil { |
| | | return "", 0 |
| | | } |
| | | var nodes []NodeInfo |
| | | err := mapstructure.Decode(reply.Data, &nodes) |
| | | if err != nil { |
| | | logx.Errorf("mapstructure.Decode QueryClusterStat data err:%v", err) |
| | | return reply.Msg, 0 |
| | | } |
| | | return reply.Msg, len(nodes) |
| | | } |