-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathmetrika.go
111 lines (105 loc) · 2.85 KB
/
metrika.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package ckconfig
import (
"github.com/housepower/ckman/common"
"github.com/housepower/ckman/model"
"github.com/housepower/ckman/service/zookeeper"
)
func GenerateMetrikaXML(filename string, conf *model.CKManClickHouseConfig) (string, error) {
xml := common.NewXmlFile(filename)
xml.Begin("yandex")
xml.Append(GenZookeeperMetrika(xml.GetIndent(), conf))
xml.Begin("remote_servers")
xml.Append(GenLocalMetrika(xml.GetIndent(), conf))
xml.End("remote_servers")
xml.End("yandex")
err := xml.Dump()
if err != nil {
return "", err
}
return filename, nil
}
func GenerateMetrikaXMLwithLogic(filename string, conf *model.CKManClickHouseConfig, logicMrtrika string) (string, error) {
xml := common.NewXmlFile(filename)
xml.Begin("yandex")
xml.Append(GenZookeeperMetrika(xml.GetIndent(), conf))
xml.Begin("remote_servers")
xml.Append(GenLocalMetrika(xml.GetIndent(), conf))
xml.Append(logicMrtrika)
xml.End("remote_servers")
xml.End("yandex")
err := xml.Dump()
if err != nil {
return "", err
}
return filename, nil
}
func GenZookeeperMetrika(indent int, conf *model.CKManClickHouseConfig) string {
xml := common.NewXmlFile("")
xml.SetIndent(indent)
xml.Begin("zookeeper")
nodes, port := zookeeper.GetZkInfo(conf)
for index, zk := range nodes {
xml.BeginwithAttr("node", []common.XMLAttr{{Key: "index", Value: index + 1}})
xml.Write("host", zk)
xml.Write("port", port)
xml.End("node")
}
xml.End("zookeeper")
return xml.GetContext()
}
func GenLocalMetrika(indent int, conf *model.CKManClickHouseConfig) string {
xml := common.NewXmlFile("")
xml.SetIndent(indent)
xml.Begin(conf.Cluster)
secret := true
if common.CompareClickHouseVersion(conf.Version, "20.10.3.30") < 0 {
secret = false
}
if secret {
xml.Write("secret", "foo")
}
for _, shard := range conf.Shards {
xml.Begin("shard")
xml.Write("internal_replication", conf.IsReplica)
for _, replica := range shard.Replicas {
xml.Begin("replica")
xml.Write("host", replica.Ip)
xml.Write("port", conf.Port)
if !secret {
xml.Write("user", conf.User)
xml.Write("password", conf.Password)
}
xml.End("replica")
}
xml.End("shard")
}
xml.End(conf.Cluster)
return xml.GetContext()
}
func GenLogicMetrika(logicName string, clusters []model.CKManClickHouseConfig, secret bool) string {
xml := common.NewXmlFile("")
xml.SetIndent(2)
xml.Begin(logicName)
if secret {
xml.Write("secret", "foo")
}
for _, conf := range clusters {
for _, shard := range conf.Shards {
xml.Begin("shard")
xml.Write("internal_replication", conf.IsReplica)
for _, replica := range shard.Replicas {
xml.Begin("replica")
xml.Write("host", replica.Ip)
xml.Write("port", conf.Port)
if !secret {
xml.Write("user", conf.User)
xml.Write("password", conf.Password)
}
xml.End("replica")
}
xml.End("shard")
}
}
xml.End(logicName)
return xml.GetContext()
}