KYLIN-2526 improve find-hive-dependency.sh
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/146c52d6 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/146c52d6 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/146c52d6 Branch: refs/heads/2.0.x Commit: 146c52d6ed5b6067ec31f01bb854470e1918cb9b Parents: da90122 Author: Cheng Wang <cheng.w...@kyligence.io> Authored: Wed May 10 18:30:02 2017 +0800 Committer: Roger Shi <rogershijich...@hotmail.com> Committed: Wed May 10 18:56:10 2017 +0800 ---------------------------------------------------------------------- build/bin/find-hive-dependency.sh | 58 +++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/146c52d6/build/bin/find-hive-dependency.sh ---------------------------------------------------------------------- diff --git a/build/bin/find-hive-dependency.sh b/build/bin/find-hive-dependency.sh index 25e26d2..72cb958 100644 --- a/build/bin/find-hive-dependency.sh +++ b/build/bin/find-hive-dependency.sh @@ -71,8 +71,8 @@ fi if [ -z "$HCAT_HOME" ] then verbose "HCAT_HOME not found, try to find hcatalog path from hadoop home" - hadoop_home=`echo $hive_exec_path | awk -F '/hive.*/lib/hive-exec[a-z0-9A-Z.-]*.jar' '{print $1}'` - hive_home=`echo $hive_exec_path | awk -F '/lib/hive-exec[a-z0-9A-Z.-]*.jar' '{print $1}'` + hadoop_home=`echo $hive_exec_path | awk -F '/hive.*/lib/' '{print $1}'` + hive_home=`echo $hive_exec_path | awk -F '/lib/' '{print $1}'` is_aws=`uname -r | grep amzn` if [ -d "${hadoop_home}/hive-hcatalog" ]; then hcatalog_home=${hadoop_home}/hive-hcatalog @@ -83,7 +83,7 @@ then elif [ -n is_aws ] && [ -d "/usr/lib/hive-hcatalog" ]; then # special handling for Amazon EMR hcatalog_home=/usr/lib/hive-hcatalog - else + else quit "Couldn't locate hcatalog installation, please make sure it is installed and set HCAT_HOME to the path." fi else @@ -98,8 +98,56 @@ then quit "hcatalog lib not found" fi +function checkFileExist() +{ + files=$1 + misFiles=0 + outputMissFiles= + for file in ${files//:/ } + do + let allFiles++ + if [ ! -f "${file}" ]; then + outputMissFiles=${outputMissFiles}${file}", " + let misFiles++ + fi + done + ratio=`echo "scale=3; ${misFiles}/${allFiles}" | bc` + [[ `echo "$ratio < 0.01" | bc ` -eq 1 ]] || quit "A couple of hive jars can't be found: ${outputMisFiles}!" +} + +function validateDirectory() +{ + conf_path=$1 + [[ -d "${conf_path}" ]] || quit "${conf_path} doesn't exist!" + unit=${conf_path: -1} + [[ "${unit}" == "/" ]] || conf_path=${conf_path}"/" + + find="false" + filelist=`ls ${conf_path}` + for file in $filelist + do + if [ "${file}" == "hive-site.xml" ] + then + find="true" + break + fi + done + [[ "${find}" == "true" ]] || quit "ERROR, no hive-site.xml found under dir: ${conf_path}!" +} + +if [ -z "$HIVE_LIB" ] +then + verbose "HIVE_LIB is not set, try to retrieve hive lib from hive_exec_path" + hive_lib_dir="$(dirname $hive_exec_path)" +else + hive_lib_dir="$HIVE_LIB" +fi +hive_lib=`find -L ${hive_lib_dir} -name '*.jar' ! -name '*calcite*' -printf '%p:' | sed 's/:$//'` + +validateDirectory ${hive_conf_path} +checkFileExist ${hive_lib} +checkFileExist ${hcatalog} -hive_lib=`find -L "$(dirname $hive_exec_path)" -name '*.jar' ! -name '*calcite*' -printf '%p:' | sed 's/:$//'` hive_dependency=${hive_conf_path}:${hive_lib}:${hcatalog} verbose "hive dependency: $hive_dependency" -export hive_dependency +export hive_dependency \ No newline at end of file