in bigtop-packages/src/charm/hbase/layer-hbase/reactive/hbase.py [0:0]
def handle_peers():
'''
We use HBase peers to keep track of the RegionServer IP addresses in a
cluster. Use get_nodes() from the appropriate peer relation to retrieve
a list of peer tuples, e.g.:
[('hbase/0', '172.31.5.161'), ('hbase/2', '172.31.5.11')]
Depending on the state, this handler will add or remove peer IP addresses
from the regionservers config file.
'''
if is_state('hbpeer.departed'):
hbpeer = RelationBase.from_state('hbpeer.departed')
is_departing = True
message = 'removing hbase peer(s)'
else:
hbpeer = RelationBase.from_state('hbpeer.joined')
is_departing = False
message = 'adding hbase peer(s)'
# Make sure we have a valid relation object
if hbpeer:
nodes = hbpeer.get_nodes()
else:
hookenv.log('Ignoring unknown HBase peer state')
return
hookenv.status_set('maintenance', message)
hbase = HBase()
ip_addrs = [node[1] for node in nodes]
hookenv.log('{}: {}'.format(message, ip_addrs))
hbase.update_regionservers(ip_addrs, remove=is_departing)
# NB: the rs conf file will always change when handling peer updates, but
# we still include this condition to keep the files_changed kv current.
if any_file_changed(['/etc/hbase/conf/regionservers']):
hbase.restart()
# Dismiss appropriate state now that we've handled the peer
if is_departing:
hbpeer.dismiss_departed()
else:
hbpeer.dismiss_joined()
report_status()