15
15
from charmhelpers.core import hookenv
16
16
from charmhelpers.contrib.bigdata import utils
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)
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)
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 ""
37
# update if we have a valid hostname
32
# update if we have a valid remote hostname
39
34
utils.update_kv_host(remote_ip, remote_host)
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()
40
hookenv.relation_set(etc_hosts=kv_hosts)
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)
47
hookenv.log('No hosts found in the yarn-master key-value store', hookenv.WARNING)
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',
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()
48
hookenv.relation_set(etc_hosts=kv_hosts)
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)
55
hookenv.log('No hosts found in the key-value store', hookenv.WARNING)