forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_topology.go
77 lines (66 loc) · 1.52 KB
/
cluster_topology.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
package ravendb
// ClusterTopology is a part of ClusterTopologyResponse
type ClusterTopology struct {
TopologyID string `json:"TopologyId"`
AllNodes map[string]string `json:"AllNodes"`
// Those map name like A to server url like http://localhost:9999
Members map[string]string `json:"Members"`
Promotables map[string]string `json:"Promotables"`
Watchers map[string]string `json:"Watchers"`
LastNodeId string `json:"LastNodeId"`
Etag int `json:"Etag"`
}
// contains returns true if topology contains a given node
func (t *ClusterTopology) contains(node string) bool {
if t.Members != nil {
if _, ok := t.Members[node]; ok {
return true
}
}
if t.Promotables != nil {
if _, ok := t.Promotables[node]; ok {
return true
}
}
if t.Watchers != nil {
if _, ok := t.Watchers[node]; ok {
return true
}
}
return false
}
func (t *ClusterTopology) getUrlFromTag(tag string) string {
if tag == "" {
return ""
}
if t.Members != nil {
if v, ok := t.Members[tag]; ok {
return v
}
}
if t.Promotables != nil {
if v, ok := t.Promotables[tag]; ok {
return v
}
}
if t.Watchers != nil {
if v, ok := t.Watchers[tag]; ok {
return v
}
}
return ""
}
// getAllNodes returns all nodes
func (t *ClusterTopology) getAllNodes() map[string]string {
res := map[string]string{}
for name, uri := range t.Members {
res[name] = uri
}
for name, uri := range t.Promotables {
res[name] = uri
}
for name, uri := range t.Watchers {
res[name] = uri
}
return res
}