Add basic status checks

This commit is contained in:
James Page 2015-10-07 12:29:00 -07:00
parent a9817008ce
commit c9591e2262
3 changed files with 29 additions and 0 deletions

View File

@ -24,6 +24,7 @@ from charmhelpers.core.hookenv import (
INFO,
WARNING,
is_leader,
status_set,
)
from charmhelpers.core.host import (
service,
@ -61,6 +62,7 @@ from percona_utils import (
notify_bootstrapped,
is_bootstrapped,
get_wsrep_value,
cluster_in_sync,
)
from charmhelpers.contrib.database.mysql import (
PerconaClusterHelper,
@ -620,11 +622,27 @@ def update_nrpe_config():
nrpe_setup.write()
def assess_status():
'''Assess the status of the current unit'''
# Ensure that number of peers > cluster size configuration
if not is_bootstrapped():
status_set('blocked', 'Insufficient peers to bootstrap cluster')
return
# Once running, ensure that cluster is in sync and has the required peers
# will need to access mysql to determine status.
# Also check to see if hacluster has presented 'clustered' back yet
if is_bootstrapped() and cluster_in_sync():
status_set('active', 'Unit is ready and in sync')
else:
status_set('blocked', 'Unit is not in sync')
def main():
try:
hooks.execute(sys.argv)
except UnregisteredHookError as e:
log('Unknown hook {} - skipping.'.format(e))
assess_status()
if __name__ == '__main__':

View File

@ -360,3 +360,13 @@ def notify_bootstrapped(cluster_rid=None, cluster_uuid=None):
(cluster_uuid), DEBUG)
for rid in rids:
relation_set(relation_id=rid, **{'bootstrap-uuid': cluster_uuid})
def cluster_in_sync():
'''Determines whether the current unit is in sync with the rest of the cluster'''
ready = get_wsrep_value('wsrep_ready') or False
sync_status = get_wsrep_value('wsrep_local_state') or 0
if ready and int(sync_status) == 4:
return True
return False

1
hooks/update-status Symbolic link
View File

@ -0,0 +1 @@
percona_hooks.py