-
Notifications
You must be signed in to change notification settings - Fork 110
/
test_cluster.sh
executable file
·281 lines (229 loc) · 7.52 KB
/
test_cluster.sh
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/sh
set -o errexit
action=$1
usage() {
echo "cmd args unvalid"
echo "usage: $0 start | start_debug | restart | restart_debug | kill | clean | test_naming"
exit 2
}
app_name='rnacos'
test_dir='cluster_example'
#defuat path
app_path="./target/release/$app_name"
kill() {
echo "Killing all running ${app_name}"
if [ "$(uname)" = "Darwin" ]; then
if pgrep -xq -- "${app_name}"; then
pkill -f "${app_name}"
fi
else
set +e # killall will error if finds no process to kill
killall ${app_name}
set -e
fi
}
#kill
#sleep 1
clean_cluster_dir() {
echo "init cluster dir: $test_dir"
rm -rf $test_dir
mkdir -p $test_dir
}
start_cluster() {
echo "start node:1"
local env_file="$test_dir/env_01"
cat >$env_file <<EOF
#file:env01
#RUST_LOG=debug|info|warn|error, default is info
RNACOS_HTTP_PORT=8848
RNACOS_RAFT_NODE_ADDR=127.0.0.1:9848
RNACOS_CONFIG_DB_DIR=cluster_example/db_01
RNACOS_RAFT_NODE_ID=1
RNACOS_RAFT_AUTO_INIT=true
RNACOS_ENABLE_NO_AUTH_CONSOLE=true
EOF
nohup ${app_path} -e $env_file >"$test_dir/node_01.log" &
sleep 1
echo "start node:2"
local env_file="$test_dir/env_02"
cat >$env_file <<EOF
#file:env02
#RUST_LOG=debug|info|warn|error, default is info
RNACOS_HTTP_PORT=8849
RNACOS_RAFT_NODE_ADDR=127.0.0.1:9849
RNACOS_CONFIG_DB_DIR=cluster_example/db_02
RNACOS_RAFT_NODE_ID=2
RNACOS_RAFT_JOIN_ADDR=127.0.0.1:9848
RNACOS_ENABLE_NO_AUTH_CONSOLE=true
EOF
nohup ${app_path} -e $env_file >"$test_dir/node_02.log" &
sleep 1
echo "start node:3"
local env_file="$test_dir/env_03"
cat >$env_file <<EOF
#file:env03
#RUST_LOG=debug|info|warn|error, default is info
#RUST_LOG=warn
RNACOS_HTTP_PORT=8850
RNACOS_RAFT_NODE_ADDR=127.0.0.1:9850
RNACOS_CONFIG_DB_DIR=cluster_example/db_03
RNACOS_RAFT_NODE_ID=3
RNACOS_RAFT_JOIN_ADDR=127.0.0.1:9848
RNACOS_ENABLE_NO_AUTH_CONSOLE=true
EOF
nohup ${app_path} -e $env_file >"$test_dir/node_03.log" &
sleep 1
}
query_node_metrics() {
echo "\n the node1 raft metrics"
curl "http://127.0.0.1:8848/nacos/v1/raft/metrics"
echo "\n the node2 raft metrics"
curl "http://127.0.0.1:8849/nacos/v1/raft/metrics"
echo "\n the node3 raft metrics"
curl "http://127.0.0.1:8850/nacos/v1/raft/metrics"
}
#start_cluster
#query_node_metrics
test_config_cluster() {
echo "\npublish config t001:contentTest to node 1"
curl -X POST 'http://127.0.0.1:8848/nacos/v1/cs/configs' -d 'dataId=t001&group=foo&content=contentTest'
sleep 1
echo "\nget config info t001 from node 1, value:"
curl 'http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=t001&group=foo'
echo "\nget config info t001 from node 2, value:"
curl 'http://127.0.0.1:8849/nacos/v1/cs/configs?dataId=t001&group=foo'
echo "\nget config info t001 from node 3, value:"
curl 'http://127.0.0.1:8850/nacos/v1/cs/configs?dataId=t001&group=foo'
sleep 1
echo "\npublish config t002:contentTest02 to node 2"
curl -X POST 'http://127.0.0.1:8849/nacos/v1/cs/configs' -d 'dataId=t002&group=foo&content=contentTest02'
sleep 1
echo "\nget config info t002 from node 1, value:"
curl 'http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=t002&group=foo'
echo "\nget config info t002 from node 2, value:"
curl 'http://127.0.0.1:8849/nacos/v1/cs/configs?dataId=t002&group=foo'
echo "\nget config info t002 from node 3, value:"
curl 'http://127.0.0.1:8850/nacos/v1/cs/configs?dataId=t002&group=foo'
}
test_restart_config_cluster() {
echo "\n\nquery the contents before restart"
echo "\nget config info t002 from node 1, value:"
curl 'http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=t002&group=foo'
echo "\nget config info t002 from node 2, value:"
curl 'http://127.0.0.1:8849/nacos/v1/cs/configs?dataId=t002&group=foo'
echo "\nget config info t002 from node 3, value:"
curl 'http://127.0.0.1:8850/nacos/v1/cs/configs?dataId=t002&group=foo'
echo "\n\npublish config t003:contentTest03 to node 3"
curl -X POST 'http://127.0.0.1:8850/nacos/v1/cs/configs' -d 'dataId=t003&group=foo&content=contentTest03'
sleep 1
echo "\nget config info t003 from node 1, value:"
curl 'http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=t003&group=foo'
echo "\nget config info t003 from node 2, value:"
curl 'http://127.0.0.1:8849/nacos/v1/cs/configs?dataId=t003&group=foo'
echo "\nget config info t002 from node 3, value:"
curl 'http://127.0.0.1:8850/nacos/v1/cs/configs?dataId=t003&group=foo'
}
test_naming_cluster() {
echo "\nregister instance nacos.test.001 to node 1"
curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance' -d 'port=8000&healthy=true&ip=192.168.1.11&weight=1.0&serviceName=nacos.test.001&groupName=foo&metadata={"app":"foo","id":"001"}'
echo "\nregister instance nacos.test.001 to node 2"
curl -X POST 'http://127.0.0.1:8849/nacos/v1/ns/instance' -d 'port=8000&healthy=true&ip=192.168.1.12&weight=1.0&serviceName=nacos.test.001&groupName=foo&metadata={"app":"foo","id":"002"}'
echo "\nregister instance nacos.test.001 to node 3"
curl -X POST 'http://127.0.0.1:8850/nacos/v1/ns/instance' -d 'port=8000&healthy=true&ip=192.168.1.13&weight=1.0&serviceName=nacos.test.001&groupName=foo&metadata={"app":"foo","id":"003"}'
sleep 1
echo "\n\nquery service instance nacos.test.001 from node 1, value:"
curl "http://127.0.0.1:8848/nacos/v1/ns/instance/list?&namespaceId=public&serviceName=foo%40%40nacos.test.001&groupName=foo&clusters=&healthyOnly=true"
echo "\n\nquery service instance nacos.test.001 from node 2, value:"
curl "http://127.0.0.1:8849/nacos/v1/ns/instance/list?&namespaceId=public&serviceName=foo%40%40nacos.test.001&groupName=foo&clusters=&healthyOnly=true"
echo "\n\nquery service instance nacos.test.001 from node 3, value:"
curl "http://127.0.0.1:8850/nacos/v1/ns/instance/list?&namespaceId=public&serviceName=foo%40%40nacos.test.001&groupName=foo&clusters=&healthyOnly=true"
echo "\n"
}
#query_node_metrics
restart_cluster() {
kill
echo "\nrestart cluster"
sleep 1
start_cluster
sleep 1
echo "\ncluster restart metrics:"
query_node_metrics
echo "\n\nwait until the clusters restart (need 5 seconds)"
# the async-raft-ext all clusters restart need 5 seconds
sleep 6
query_node_metrics
}
#restart_cluster
#kill
start() {
kill
sleep 1
cargo build --release
app_path="./target/release/$app_name"
clean_cluster_dir
start_cluster
query_node_metrics
test_config_cluster
test_naming_cluster
query_node_metrics
}
start_debug() {
kill
sleep 1
cargo build
app_path="./target/debug/$app_name"
clean_cluster_dir
start_cluster
query_node_metrics
test_config_cluster
test_naming_cluster
query_node_metrics
}
restart() {
cargo build --release
app_path="./target/release/$app_name"
restart_cluster
test_restart_config_cluster
test_naming_cluster
query_node_metrics
}
restart_debug() {
cargo build
app_path="./target/debug/$app_name"
restart_cluster
test_restart_config_cluster
test_naming_cluster
query_node_metrics
}
main() {
case $action in
start)
start
;;
start_debug)
start_debug
;;
restart)
restart
;;
restart_debug)
restart_debug
;;
clean)
kill
sleep 1
clean_cluster_dir
;;
test_naming)
test_naming_cluster
;;
kill)
kill
;;
*)
usage
;;
esac
}
main
echo "\n==== end ===="