Skip to content

Commit 2742c91

Browse files
committed
added find_active_hbase_thrift.py
1 parent 742e6f8 commit 2742c91

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

find_active_hbase_thrift.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python
2+
# vim:ts=4:sts=4:sw=4:et
3+
#
4+
# Author: Hari Sekhon
5+
# Date: Wed Sep 13 13:58:21 CEST 2017
6+
#
7+
# https://github.com/harisekhon/pytools
8+
#
9+
# License: see accompanying Hari Sekhon LICENSE file
10+
#
11+
# If you're using my code you're welcome to connect with me on LinkedIn
12+
# and optionally send me feedback to help steer this or other code I publish
13+
#
14+
# https://www.linkedin.com/in/harisekhon
15+
#
16+
17+
"""
18+
19+
Tool to return an active HBase Thrift server from an argument list of hosts
20+
21+
Can mix and match between a comma separated list of hosts (--host server1,server2 or contents of the $HOST
22+
environment variable if not specified) and general free-form space separated arguments, which is useful if piping
23+
a host list through xargs.
24+
25+
Multi-threaded for speed and exits upon first available host response to minimize delay to ~ 1 second or less.
26+
27+
Useful for simplying scripting or generically extending tools that don't support HBase High Availability directly
28+
29+
By default checks the same --port on all servers. Hosts may have optional :<port> suffixes added to individually
30+
override each one.
31+
32+
Exits with return code 1 and NO_AVAILABLE_SERVER if none of the namenodes are active, --quiet mode will not print
33+
NO_AVAILABLE_SERVER.
34+
35+
Tested on Apache HBase 0.96, 0.98, 1.0, 1.1, 1.2, 1.3
36+
37+
"""
38+
39+
from __future__ import absolute_import
40+
from __future__ import division
41+
from __future__ import print_function
42+
#from __future__ import unicode_literals
43+
44+
import os
45+
import sys
46+
import traceback
47+
#from random import shuffle
48+
srcdir = os.path.abspath(os.path.dirname(__file__))
49+
libdir = os.path.join(srcdir, 'pylib')
50+
sys.path.append(libdir)
51+
try:
52+
# pylint: disable=wrong-import-position
53+
from find_active_server import FindActiveServer
54+
except ImportError as _:
55+
print(traceback.format_exc(), end='')
56+
sys.exit(4)
57+
58+
__author__ = 'Hari Sekhon'
59+
__version__ = '0.7.1'
60+
61+
62+
class FindActiveHBaseThrift(FindActiveServer):
63+
64+
def __init__(self):
65+
# Python 2.x
66+
super(FindActiveHBaseThrift, self).__init__()
67+
# Python 3.x
68+
# super().__init__()
69+
self.default_port = 9095
70+
self.protocol = 'http'
71+
self.url_path = '/thrift.jsp'
72+
self.regex = r'HBase.+Thrift'
73+
self.default_num_threads = 5
74+
75+
def add_options(self):
76+
self.add_hostoption(name='HBase Thrift', default_port=self.default_port)
77+
self.add_ssl_opt()
78+
self.add_common_opts()
79+
80+
def process_options(self):
81+
self.validate_common_opts()
82+
83+
84+
if __name__ == '__main__':
85+
FindActiveHBaseThrift().main()

0 commit comments

Comments
 (0)