~bigdata-dev/charms/trusty/apache-hadoop-yarn-master/unstable

« back to all changes in this revision

Viewing changes to hooks/resourcemanager-relation-changed

  • Committer: Kevin W. Monroe
  • Date: 2015-05-08 06:00:46 UTC
  • Revision ID: kevin.monroe@canonical.com-20150508060046-qhm2my11j0u1o5ut
update to CH r438: initialize and set etc_hosts as required key on master relations

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from charmhelpers.core import hookenv
16
16
from charmhelpers.contrib.bigdata import utils
17
17
 
18
 
# get the hostname attrs from our local unit and update the kv store. do this
19
 
# every time this hook fires in case our ip/name changed (maybe overkill)
20
 
local_ip = hookenv.unit_private_ip()
21
 
local_host = hookenv.local_unit().replace('/', '-')
22
 
utils.update_kv_host(local_ip, local_host)
23
 
 
24
18
# unlike the nodemanager relation, the other side of the resourcemanager
25
19
# relation only needs our ip/host in its /etc/hosts. that side doesn't grab
26
20
# data from the kv store (because it doesn't need all those hosts), so send it
27
21
# on the relation now.
 
22
local_host = hookenv.local_unit().replace('/', '-')
28
23
hookenv.relation_set(hostname=local_host)
29
24
 
30
25
# even though the other side of this relation doesn't need it, we still want
34
29
remote_ip = hookenv.relation_get('private-address')
35
30
remote_host = hookenv.relation_get('hostname') or ""
36
31
 
37
 
# update if we have a valid hostname
 
32
# update if we have a valid remote hostname
38
33
if remote_host:
39
34
    utils.update_kv_host(remote_ip, remote_host)
 
35
 
 
36
    # get all the hosts we know about from the kv (which includes the one we
 
37
    # just set) and set them on the relation
 
38
    kv_hosts = utils.get_kv_hosts()
 
39
    if kv_hosts:
 
40
        hookenv.relation_set(etc_hosts=kv_hosts)
 
41
 
 
42
        # update /etc/hosts on the local unit.
 
43
        hookenv.log('Updating yarn-master /etc/hosts with %s %s' %
 
44
                    (remote_ip, remote_host), hookenv.INFO)
 
45
        utils.update_etc_hosts(kv_hosts)
 
46
    else:
 
47
        hookenv.log('No hosts found in the yarn-master key-value store', hookenv.WARNING)
40
48
else:
41
 
    hookenv.log('Incomplete hostname data; not updating key-value store',
 
49
    hookenv.log('Incomplete hostname data; not updating the yarn-master key-value store',
42
50
                hookenv.INFO)
43
51
 
44
 
# get all the hosts we know about from the kv (which includes the one we
45
 
# may have just set) and set them on the relation
46
 
kv_hosts = utils.get_kv_hosts()
47
 
if kv_hosts:
48
 
    hookenv.relation_set(etc_hosts=kv_hosts)
49
 
 
50
 
    # update /etc/hosts on the local unit.
51
 
    hookenv.log('Updating yarn-master /etc/hosts with %s %s' %
52
 
                (remote_ip, remote_host), hookenv.INFO)
53
 
    utils.update_etc_hosts(kv_hosts)
54
 
else:
55
 
    hookenv.log('No hosts found in the key-value store', hookenv.WARNING)
56
 
 
57
52
common.manage()