Skip to content

Commit 7517b4f

Browse files
committed
add missing files (got from percona/percona-orchestrator:3.2.6-13)
1 parent 3a4d367 commit 7517b4f

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

conf/orc-topology.cnf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[client]
2+
user=orchestrator
3+
password=

docker/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ COPY --from=build /etc/orchestrator.conf.json /etc/orchestrator.conf.json
4040

4141
WORKDIR /usr/local/orchestrator
4242
ADD docker/entrypoint.sh /entrypoint.sh
43+
RUN mkdir -p /etc/orchestrator/
44+
ADD conf/orc-topology.cnf /etc/orchestrator/orc-topology.cnf
45+
ADD docker/add_mysql_nodes.sh /usr/bin/add_mysql_nodes.sh
4346
CMD /entrypoint.sh

docker/add_mysql_nodes.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
ORC_HOST=127.0.0.1:3000
6+
7+
log() {
8+
local level=$1
9+
local message=$2
10+
local now=$(date +%Y-%m-%dT%H:%M:%S%z)
11+
12+
echo "${now} [${level}] ${message}"
13+
}
14+
15+
wait_for_leader() {
16+
local retry=0
17+
local leader=""
18+
19+
log WARNING "Waiting for leader. Will fail after 60 attempts"
20+
21+
until [[ ${leader} != "" ]]; do
22+
if [ ${retry} -gt 60 ]; then
23+
exit 1
24+
fi
25+
26+
local leader=$(curl "${ORC_HOST}/api/raft-leader" 2>/dev/null)
27+
28+
retry=$((retry + 1))
29+
sleep 1
30+
done
31+
}
32+
33+
am_i_leader() {
34+
local http_code=$(curl -w httpcode=%{http_code} "${ORC_HOST}/api/leader-check" 2>/dev/null | sed -e 's/.*\httpcode=//')
35+
36+
if [ ${http_code} -ne 200 ]; then
37+
return 1
38+
fi
39+
40+
log INFO "I am the leader"
41+
return 0
42+
}
43+
44+
discover() {
45+
local host=$1
46+
local port=$2
47+
48+
HOSTNAME=$(curl -s "${ORC_HOST}/api/instance/${host}/${port}" | jq '.InstanceAlias' | tr -d 'null')
49+
if [ -n "$HOSTNAME" ]; then
50+
log INFO "The MySQL node ${host} is already discovered by orchestrator. Skipping..."
51+
return 0
52+
fi
53+
54+
for i in {1..5}; do
55+
R_CODE=$(curl -s "${ORC_HOST}/api/discover/${host}/${port}" | jq '.Code' | tr -d '"')
56+
if [ "$R_CODE" == 'ERROR' ]; then
57+
log ERROR "MySQL node ${host} can't be discovered"
58+
sleep 1
59+
continue
60+
else
61+
log INFO "MySQL node ${host} is discovered"
62+
break
63+
fi
64+
done
65+
}
66+
67+
main() {
68+
log INFO "Starting to discover MySQL nodes."
69+
70+
# Wait for the leader election
71+
wait_for_leader
72+
73+
log INFO "Orchestrator cluster selected a leader."
74+
75+
local retry=0
76+
# Exit if not leader
77+
while ! am_i_leader; do
78+
if [ ${retry} -gt 30 ]; then
79+
log INFO "I am not the leader. Exiting..."
80+
exit 0
81+
fi
82+
83+
retry=$((retry + 1))
84+
sleep 1
85+
done
86+
87+
# Discover
88+
while read mysql_host; do
89+
if [ -z "$mysql_host" ]; then
90+
log INFO "Could not find PEERS..."
91+
exit 0
92+
fi
93+
94+
discover "${mysql_host}" 3306
95+
done
96+
}
97+
98+
main

0 commit comments

Comments
 (0)