~kos.tsakalozos/charms/trusty/hdp-storm/trunk

« back to all changes in this revision

Viewing changes to hooks/hdputils.py

  • Committer: amir sanjar
  • Date: 2014-09-19 03:22:08 UTC
  • Revision ID: amir.sanjar@canonical.com-20140919032208-5zlexs7imnadgpll
merged chuck's changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import subprocess
5
5
import tarfile
6
6
import shutil
7
 
from bdutils import wgetPkg, append_bashrc, fileSetKV, setHadoopEnvVarFromFile, setHadoopConfigXML
 
7
from bdutils import append_bashrc, fileSetKV, setHadoopEnvVarFromFile
8
8
from charmhelpers.core.host import service_start, service_stop
9
9
 
10
10
#sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
11
11
from charmhelpers.core.hookenv import log
 
12
from charmhelpers.fetch.archiveurl import ArchiveUrlFetchHandler
12
13
try:
13
14
    from charmhelpers.fetch import apt_install, apt_update,  apt_purge
14
15
except:
15
16
    pass
16
17
 
 
18
def createPropertyElement(name, value):
 
19
    import xml.etree.ElementTree as ET
 
20
    propertyE = ET.Element("property")
 
21
    eName = ET.Element("name")
 
22
    eName.text = name
 
23
    propertyE.append(eName)
 
24
    eValue = ET.Element("value")
 
25
    eValue.text = value
 
26
    propertyE.append(eValue)
 
27
    return propertyE
 
28
 
 
29
def setHadoopConfigXML (xmlfileName, name, value):
 
30
    import xml.dom.minidom as minidom
 
31
    print("==> setHadoopConfigXML ","INFO")
 
32
    import xml.etree.ElementTree as ET
 
33
    found = False
 
34
    hConf = os.environ["HADOOP_CONF_DIR"]
 
35
    if not hConf:
 
36
        print("==> HADOOP_CONF_DIR is not set","ERROR")
 
37
    xmlfileNamePath = os.path.join(os.path.sep, hConf, xmlfileName)
 
38
    with open(xmlfileNamePath,'rb+') as f:
 
39
        root = ET.parse(f).getroot()
 
40
        proList = root.findall("property")
 
41
        for p in proList:
 
42
            cList = p.getchildren()
 
43
            for c in cList:
 
44
                if c.text == name:
 
45
                    p.find("value").text = value
 
46
                    found = True
 
47
 
 
48
        if not found:
 
49
            root.append(createPropertyElement(name, value))
 
50
 
 
51
        f.seek(0)
 
52
        f.write((minidom.parseString(ET.tostring(root, encoding='UTF-8'))).toprettyxml(indent="\t"))
 
53
        f.truncate()
 
54
 
 
55
    return found
 
56
 
17
57
 
18
58
def install_base_pkg(packages):
19
59
    log ("==> install_base_pkg", "INFO")
20
 
    wgetPkg("http://public-repo-1.hortonworks.com/HDP/ubuntu12/2.1.3.0/hdp.list -O /etc/apt/sources.list.d/hdp.list","")
21
 
    cmd =gpg_script 
22
 
    subprocess.call(cmd)   
 
60
    listpath = os.path.join(os.path.sep, 'etc', 'apt', 'sources.list.d', 'hdp.list')
 
61
    au = ArchiveUrlFetchHandler()
 
62
    if not os.path.exists(listpath):
 
63
      listsum = '3e53ca19f2c4461a6f4246a049a73779c4e81bce'
 
64
      listurl = 'https://public-repo-1.hortonworks.com/HDP/ubuntu12/2.1.3.0/hdp.list'
 
65
 
 
66
      tmpfile = au.download_and_validate(listurl, listsum)
 
67
      shutil.move(tmpfile, listpath)
 
68
 
 
69
    cmd =gpg_script
 
70
    subprocess.call(cmd)
23
71
    apt_update()
24
72
    apt_install(packages)
25
73
    os.chdir(home);
26
 
    wgetPkg("http://public-repo-1.hortonworks.com/HDP/tools/2.1.2.1/hdp_manual_install_rpm_helper_files-2.1.2.471.tar.gz","")
 
74
 
 
75
    helperpath = os.path.join(home, tarfilename)
 
76
    if not os.path.exists(helperpath):
 
77
      helperurl = 'https://public-repo-1.hortonworks.com/HDP/tools/2.1.2.1/'+tarfilename
 
78
      helpersum = '0cb6501e22588b001286ad3b01c474e80b332bf0'
 
79
      tmpfile = au.download_and_validate(helperurl, helpersum)
 
80
      shutil.move(tmpfile, helperpath)
 
81
 
 
82
 
27
83
    if tarfile.is_tarfile(tarfilename):
28
84
        tball = tarfile.open(tarfilename)
29
85
        tball.extractall(home)
33
89
        shutil.rmtree(hdpScript)
34
90
    os.rename(tarfilenamePre, hdpScript)
35
91
    log("<== install_base_pkg", "INFO")
36
 
    
 
92
 
37
93
def uninstall_base_pkg(packages):
38
94
    log("==> uninstall_base_pkg" ,"INFO")
39
95
    apt_purge(packages)