Permalink
Browse files

Improve status message by updating every minute

  • Loading branch information...
1 parent 29e1231 commit e6ad8fd44f119fdc411c6104498276aa4d2ac1a8 @johnsca johnsca committed Apr 26, 2016
Showing with 29 additions and 2 deletions.
  1. +18 −0 reactive/namenode_ha_cluster.py
  2. +11 −2 reactive/namenode_status.py
@@ -1,3 +1,4 @@
+from subprocess import check_output, CalledProcessError
from charms.reactive import when
from charms.reactive import when_not
from charms.reactive import is_state
@@ -152,6 +153,23 @@ def init_ha_standby(datanode, cluster):
set_state('namenode.started')
+@when('leadership.set.ha-initialized')
+@when_not('namenode.crontab')
+def register_crontab():
+ local_unit = hookenv.local_unit()
+ try:
+ crontab = check_output(['crontab', '-lu', 'hdfs'],
+ universal_newlines=True)
+ except CalledProcessError:
+ crontab = ''
+ crontab += '*/1 * * * * ' \
+ 'juju-run %s "PYTHONPATH=lib reactive/namenode_status.py"\n' % (
+ local_unit)
+ check_output(['crontab', '-', '-u', 'hdfs'],
+ input=crontab, universal_newlines=True)
+ set_state('namenode.crontab')
+
+
# FIXME: The transition to active fails; uncertain if it would fail if done
# manually by the admin as well, or if it's just a timing issue; needs
# more testing. It would be nice, though, if the transition to HA would
View
13 reactive/namenode_status.py 100644 → 100755
@@ -1,7 +1,9 @@
+#!/usr/bin/env python3
from charms.reactive import when
from charms.reactive import when_not
from charms.reactive import when_any
from charms.reactive import is_state
+from charms.reactive import RelationBase
from charmhelpers.core import hookenv
from jujubigdata import utils
from charms.layer.apache_hadoop_namenode import get_cluster_nodes
@@ -48,18 +50,25 @@ def report_status(datanode):
else:
role = 'extra'
if not degraded:
- extra = '{}, with {} fail-over'.format(role, failover)
+ extra = 'HA {}, with {} fail-over'.format(role, failover)
else:
missing = ' and '.join(filter(None, [
'NameNode' if not clustered else None,
'JournalNodes' if not quorum else None,
'active' if not active else None,
'standby' if not standby else None,
]))
- extra = 'degraded {} (missing: {}), with {} fail-over'.format(
+ extra = 'HA degraded {} (missing: {}), with {} fail-over'.format(
role, missing, failover)
hookenv.status_set('active', 'Ready ({count} DataNode{s}, {extra})'.format(
count=num_slaves,
s='s' if num_slaves > 1 else '',
extra=extra,
))
+
+
+if __name__ == '__main__':
+ if is_state('datanode.joined'):
+ report_status(RelationBase.from_state('datanode.joined'))
+ else:
+ report_blocked()

2 comments on commit e6ad8fd

Member

ktsakalozos replied Apr 26, 2016

LGTM (not tested)

Member

kwmonroe replied Apr 26, 2016

I'm with the Jackal. +1 assuming it works ;)

Please sign in to comment.