SLIDER-734 Add install sub-command for hbase client
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/3337b31d Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/3337b31d Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/3337b31d Branch: refs/heads/feature/SLIDER-779_Move_to_Groovy_2.4.0 Commit: 3337b31d466d41d8b34df28e7b7713c4eb166eac Parents: c4a21ad Author: tedyu <[email protected]> Authored: Tue Feb 10 10:16:14 2015 -0800 Committer: tedyu <[email protected]> Committed: Tue Feb 10 10:16:14 2015 -0800 ---------------------------------------------------------------------- app-packages/hbase/hbase-slider.py | 60 ++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3337b31d/app-packages/hbase/hbase-slider.py ---------------------------------------------------------------------- diff --git a/app-packages/hbase/hbase-slider.py b/app-packages/hbase/hbase-slider.py index 38cea31..83b9658 100644 --- a/app-packages/hbase/hbase-slider.py +++ b/app-packages/hbase/hbase-slider.py @@ -54,6 +54,8 @@ if SLIDER_DIR == None or (not os.path.exists(SLIDER_DIR)): else: SLIDER_CMD = os.path.join(SLIDER_DIR, 'bin', 'slider.py') +HBASE_TMP_DIR=os.path.join(tempfile.gettempdir(), "hbase-temp") + # find path to given command def which(program): def is_exe(fpath): @@ -136,6 +138,58 @@ def writePropertiesToConfigXMLFile(infile, outfile, propertyMap): cfgnode.appendChild(pn) writeToFile(xmldoc.toxml(), outfile) +def install(cluster_instance, dir): + """Syntax: [hbase-slider cluster_instance install dir] + Installs a fully configured hbase client in the specified dir + The resulting client may be used on its own without hbase-slider + """ + if os.path.exists(dir): + raise Exception("Install dir must not exist: " + dir) + + workdir = os.path.join(tempfile.gettempdir(), 'install-work-dir') + + statusfile = os.path.join(workdir, 'status.json') + cmd = [SLIDER_CMD, "status", cluster_instance, "--out", statusfile] + call(cmd) + + infile = open(statusfile) + try: + content = json.load(infile) + finally: + infile.close() + + appdef = content['options']['application.def'] + appdeffile = appdef[appdef.rfind('/')+1:] + cmd = ["hadoop", "fs", "-copyToLocal", appdef, workdir] + call(cmd) + + cmd = ["unzip", os.path.join(workdir, appdeffile), "-d", workdir] + call(cmd) + + gzfile = glob.glob(os.path.join(workdir, 'package', 'files', 'hbase*gz')) + if len(gzfile) != 1: + raise Exception("got " + gzfile + " from glob") + cmd = ["tar", "xvzf", gzfile[0], '-C', workdir] + call(cmd) + + tmp_hbase = glob.glob(os.path.join(workdir, 'hbase-[.0-9]*')) + if len(tmp_hbase) != 1: + raise Exception("got " + tmp_hbase + " from glob") + tmp_hbase = tmp_hbase[0] + + confdir = os.path.join(tmp_hbase, 'conf') + tmpHBaseConfFile=os.path.join(tempfile.gettempdir(), "hbase-site.xml") + + call([SLIDER_CMD, "registry", "--getconf", "hbase-site", "--user", "hbase", "--format", "xml", "--dest", tmpHBaseConfFile, "--name", cluster_instance]) + global HBASE_TMP_DIR + propertyMap = {'hbase.tmp.dir' : HBASE_TMP_DIR, "instance" : cluster_instance} + writePropertiesToConfigXMLFile(tmpHBaseConfFile, os.path.join(confdir, "hbase-site.xml"), propertyMap) + + libdir = os.path.join(tmp_hbase, 'lib') + for jar in glob.glob(os.path.join(workdir, 'package', 'files', '*jar')): + shutil.move(jar, libdir) + shutil.move(tmp_hbase, dir) + def quicklinks(app_name): """Syntax: [hbase-slider appname quicklinks] Prints the quicklinks information of hbase-slider registry @@ -157,6 +211,7 @@ if len(sys.argv) < 2: print "the second parameter can be:" print " shell (default) - activates hbase shell based on retrieved hbase-site.xml" print " quicklinks - prints quicklinks from registry" + print " install <dir> - installs hbase client into <dir>" sys.exit(1) try: @@ -182,6 +237,9 @@ if len(args) > 1: if args[1] == 'quicklinks': quicklinks(cluster_instance) sys.exit(0) + elif args[1] == 'install': + install(cluster_instance, args[2]) + sys.exit(0) needToRetrieve=True HBaseConfFile=os.path.join(local_conf_dir, "hbase-site.xml") @@ -199,7 +257,7 @@ if needToRetrieve: tmpHBaseConfFile=os.path.join(tempfile.gettempdir(), "hbase-site.xml") call([SLIDER_CMD, "registry", "--getconf", "hbase-site", "--user", "hbase", "--format", "xml", "--dest", tmpHBaseConfFile, "--name", cluster_instance]) - propertyMap = {'hbase.tmp.dir' : '/tmp/hbase-tmp', "instance" : cluster_instance} + propertyMap = {'hbase.tmp.dir' : HBASE_TMP_DIR, "instance" : cluster_instance} writePropertiesToConfigXMLFile(tmpHBaseConfFile, HBaseConfFile, propertyMap) print "hbase configuration is saved in " + HBaseConfFile
