-
Notifications
You must be signed in to change notification settings - Fork 7
/
opcluster.go
84 lines (79 loc) · 2.33 KB
/
opcluster.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package mysql
import "github.com/iguidao/redis-manager/src/middleware/logger"
// get all cluster
func (m *MySQL) GetAllCluster() []ClusterInfo {
var clusters []ClusterInfo
m.Find(&clusters)
return clusters
}
func (m *MySQL) GetClusterNumber() int64 {
var clusters []ClusterInfo
var count int64
m.Model(clusters).Find(&clusters).Count(&count)
return count
}
func (m *MySQL) GetClusterAddress(id string) (string, string) {
var clusterinfo *ClusterInfo
m.Where("id = ?", id).First(&clusterinfo)
return clusterinfo.Nodes, clusterinfo.Password
}
func (m *MySQL) GetClusterPassword(id string) string {
var clusterinfo *ClusterInfo
m.Where("id = ?", id).First(&clusterinfo)
return clusterinfo.Password
}
// add cluster
func (m *MySQL) AddCluster(name, nodes, password string) (int, bool) {
addcluster := &ClusterInfo{
Name: name,
Nodes: nodes,
Password: password,
}
result := m.Create(&addcluster)
if result.Error != nil {
logger.Error("Mysql add cluster error:", result.Error)
return 0, false
}
return addcluster.ID, true
// return gdarticle.ID.String(), true
}
func (m *MySQL) GetClusterNode(cluster string) []ClusterNode {
var nodes []ClusterNode
m.Model(nodes).Where("cluser_id = ?", cluster).Find(&nodes)
return nodes
}
func (m *MySQL) GetClusterNodeMaster(cluster string) []ClusterNode {
var nodes []ClusterNode
m.Model(nodes).Where("cluser_id = ? AND flags = ?", cluster, "master").Find(&nodes)
return nodes
}
func (m *MySQL) GetClusterNodeMasterAddress(nodeid string) string {
var nodes *ClusterNode
m.Where("node_id = ?", nodeid).First(&nodes)
return nodes.Ip + ":" + nodes.Port
}
func (m *MySQL) GetClusterNodeSlaverAddress(nodeid string) string {
var nodes *ClusterNode
m.Where("master_id = ?", nodeid).First(&nodes)
return nodes.Ip + ":" + nodes.Port
}
func (m *MySQL) AddClusterNode(nodeid, ip, port, flags, masterid, linkstate, slotrange string, clusterid, slotnumber int) (int, bool) {
addnode := &ClusterNode{
CluserId: clusterid,
NodeId: nodeid,
Ip: ip,
Port: port,
Flags: flags,
MasterId: masterid,
LinkState: linkstate,
SlotRange: slotrange,
SlotNumber: slotnumber,
}
result := m.Create(&addnode)
if result.Error != nil {
logger.Error("Mysql add cluster node error:", result.Error)
return 0, false
}
return addnode.ID, true
// return gdarticle.ID.String(), true
}