~arosales/charms/trusty/datameer/trunk

« back to all changes in this revision

Viewing changes to hooks/namenode-relation-changed

  • Committer: Antonio Rosales
  • Date: 2015-02-24 17:36:21 UTC
  • Revision ID: antonio.rosales@canonical.com-20150224173621-axjdwc682g82rdom
Create stub relations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
import os
 
3
import sys
 
4
import subprocess
 
5
from charmhelpers.core.hookenv import relation_get
 
6
from bdutils import fileLineSearchReplace, fconfigured
 
7
from common import hue_ini, restart_hue
 
8
 
 
9
sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
 
10
from charmhelpers.core import (
 
11
    hookenv,
 
12
    host,
 
13
)
 
14
 
 
15
hooks = hookenv.Hooks()
 
16
log = hookenv.log
 
17
 
 
18
SERVICE = 'apache-hue'
 
19
@hooks.hook('namenode-relation-changed')
 
20
def namenode_relation_changed():
 
21
    import time
 
22
    ready  = relation_get("ready")
 
23
    if ready != "true":
 
24
        log ("Hue  ==> namenide not ready","INFO")
 
25
        sys.exit(0)
 
26
    # do nothing if namenode connection is configured 
 
27
    if fconfigured("hadoop_nn"):
 
28
        return    
 
29
    log('hue ==> namenode-relation-changed')
 
30
    namenodeIP = relation_get('private-address')
 
31
    log("hue ==> namenode_IP={}".format(namenodeIP),"INFO")
 
32
    
 
33
    namenode = namenodeIP+":8020"
 
34
    fileLineSearchReplace(hue_ini, "fs_defaultfs=hdfs://localhost:8020", \
 
35
                          "fs_defaultfs=hdfs://"+namenode)
 
36
    fileLineSearchReplace(hue_ini, "## webhdfs_url=http://localhost:50070/webhdfs/v1",\
 
37
                          "webhdfs_url=http://"+namenodeIP+":50070/webhdfs/v1")
 
38
    restart_hue()
 
39
    
 
40
 
 
41
 
 
42
if __name__ == "__main__":
 
43
    # execute a hook based on the name the program is called by
 
44
    hooks.execute(sys.argv)