forked from pinterest/mysql_utils
-
Notifications
You must be signed in to change notification settings - Fork 2
/
other_slave_running_etl.py
executable file
·66 lines (49 loc) · 1.89 KB
/
other_slave_running_etl.py
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
#!/usr/bin/python
import argparse
import sys
import mysql_backup_status
from lib import host_utils
OTHER_SLAVE_RUNNING_ETL = 0
OTHER_SLAVE_NOT_RUNNING_ETL = 1
ERROR = 3
def main():
parser = argparse.ArgumentParser(description="Is ETL running on a "
"different instance?")
parser.add_argument('instance',
nargs='?',
help="Instance to inspect, default is localhost:3306",
default=''.join((host_utils.HOSTNAME, ':3306')))
args = parser.parse_args()
instance = host_utils.HostAddr(args.instance)
zk = host_utils.MysqlZookeeper()
(replica_set, replica_type) = zk.get_replica_set_from_instance(instance)
if replica_type == host_utils.REPLICA_ROLE_DR_SLAVE:
inst = zk.get_mysql_instance_from_replica_set(replica_set,
host_utils.REPLICA_ROLE_SLAVE)
elif replica_type == host_utils.REPLICA_ROLE_SLAVE:
inst = zk.get_mysql_instance_from_replica_set(replica_set,
host_utils.REPLICA_ROLE_DR_SLAVE)
else:
exit_unknown_error()
if not inst:
# if there is not another slave in zk, there is not possibility
# it is ok
exit_other_slave_not_running_etl()
try:
running = mysql_backup_status.csv_backups_running(instance)
except:
exit_other_slave_not_running_etl()
if not running:
exit_other_slave_not_running_etl()
exit_other_slave_running_etl()
def exit_other_slave_not_running_etl():
print "OTHER_SLAVE_NOT_RUNNING_ETL"
sys.exit(OTHER_SLAVE_NOT_RUNNING_ETL)
def exit_other_slave_running_etl():
print "OTHER_SLAVE_RUNNING_ETL"
sys.exit(OTHER_SLAVE_RUNNING_ETL)
def exit_unknown_error():
print "UNKNOWN"
sys.exit(ERROR)
if __name__ == '__main__':
main()