From 8c3e888dcd791cfc6b83d9bc74e3010570a02fe3 Mon Sep 17 00:00:00 2001 From: cnauroth Date: Fri, 9 Jan 2015 15:00:57 -0800 Subject: [PATCH] HADOOP-11464. Reinstate support for launching Hadoop processes on Windows using Cygwin. Contributed by Chris Nauroth. --- .../hadoop-common/CHANGES.txt | 3 ++ .../src/main/bin/hadoop-functions.sh | 41 +++++++++++++++++-- hadoop-yarn-project/hadoop-yarn/bin/yarn | 8 +++- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c73be9dbfc4..37a451eb129 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -466,6 +466,9 @@ Release 2.7.0 - UNRELEASED HADOOP-11032. Replace use of Guava's Stopwatch with Hadoop's StopWatch (ozawa) + HADOOP-11464. Reinstate support for launching Hadoop processes on Windows + using Cygwin. (cnauroth) + OPTIMIZATIONS HADOOP-11323. WritableComparator#compare keeps reference to byte array. diff --git a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh index 2d8e90ecd56..75d24998a63 100644 --- a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh +++ b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh @@ -562,8 +562,10 @@ function hadoop_os_tricks { local bindv6only - # some OSes have special needs. here's some out of the box - # examples for OS X and Linux. Vendors, replace this with your special sauce. + # Some OSes have special needs. Here's some out of the box examples for OS X, + # Linux and Windows on Cygwin. + # Vendors, replace this with your special sauce. + HADOOP_IS_CYGWIN=false case ${HADOOP_OS_TYPE} in Darwin) if [[ -z "${JAVA_HOME}" ]]; then @@ -594,6 +596,10 @@ function hadoop_os_tricks # down to prevent vmem explosion. export MALLOC_ARENA_MAX=${MALLOC_ARENA_MAX:-4} ;; + CYGWIN*) + # Flag that we're running on Cygwin to trigger path translation later. + HADOOP_IS_CYGWIN=true + ;; esac } @@ -621,6 +627,7 @@ function hadoop_java_setup function hadoop_finalize_libpaths { if [[ -n "${JAVA_LIBRARY_PATH}" ]]; then + hadoop_translate_cygwin_path JAVA_LIBRARY_PATH hadoop_add_param HADOOP_OPTS java.library.path \ "-Djava.library.path=${JAVA_LIBRARY_PATH}" export LD_LIBRARY_PATH @@ -652,14 +659,34 @@ function hadoop_finalize_hadoop_heap fi } +# Accepts a variable name. If running on Cygwin, sets the variable value to the +# equivalent translated Windows path by running the cygpath utility. If the +# second argument is true, then the variable is treated as a path list. +function hadoop_translate_cygwin_path +{ + if [[ "${HADOOP_IS_CYGWIN}" = "true" ]]; then + if [[ "$2" = "true" ]]; then + #shellcheck disable=SC2016 + eval "$1"='$(cygpath -p -w "${!1}" 2>/dev/null)' + else + #shellcheck disable=SC2016 + eval "$1"='$(cygpath -w "${!1}" 2>/dev/null)' + fi + fi +} + # # fill in any last minute options that might not have been defined yet # function hadoop_finalize_hadoop_opts { + hadoop_translate_cygwin_path HADOOP_LOG_DIR hadoop_add_param HADOOP_OPTS hadoop.log.dir "-Dhadoop.log.dir=${HADOOP_LOG_DIR}" hadoop_add_param HADOOP_OPTS hadoop.log.file "-Dhadoop.log.file=${HADOOP_LOGFILE}" - hadoop_add_param HADOOP_OPTS hadoop.home.dir "-Dhadoop.home.dir=${HADOOP_PREFIX}" + HADOOP_HOME=${HADOOP_PREFIX} + hadoop_translate_cygwin_path HADOOP_HOME + export HADOOP_HOME + hadoop_add_param HADOOP_OPTS hadoop.home.dir "-Dhadoop.home.dir=${HADOOP_HOME}" hadoop_add_param HADOOP_OPTS hadoop.id.str "-Dhadoop.id.str=${HADOOP_IDENT_STRING}" hadoop_add_param HADOOP_OPTS hadoop.root.logger "-Dhadoop.root.logger=${HADOOP_ROOT_LOGGER}" hadoop_add_param HADOOP_OPTS hadoop.policy.file "-Dhadoop.policy.file=${HADOOP_POLICYFILE}" @@ -673,6 +700,7 @@ function hadoop_finalize_classpath # user classpath gets added at the last minute. this allows # override of CONF dirs and more hadoop_add_to_classpath_userpath + hadoop_translate_cygwin_path CLASSPATH true } function hadoop_finalize_catalina_opts @@ -702,6 +730,13 @@ function hadoop_finalize hadoop_finalize_libpaths hadoop_finalize_hadoop_heap hadoop_finalize_hadoop_opts + + hadoop_translate_cygwin_path HADOOP_PREFIX + hadoop_translate_cygwin_path HADOOP_CONF_DIR + hadoop_translate_cygwin_path HADOOP_COMMON_HOME + hadoop_translate_cygwin_path HADOOP_HDFS_HOME + hadoop_translate_cygwin_path HADOOP_YARN_HOME + hadoop_translate_cygwin_path HADOOP_MAPRED_HOME } function hadoop_exit_with_usage diff --git a/hadoop-yarn-project/hadoop-yarn/bin/yarn b/hadoop-yarn-project/hadoop-yarn/bin/yarn index 6f5fd59322a..255082fa13b 100644 --- a/hadoop-yarn-project/hadoop-yarn/bin/yarn +++ b/hadoop-yarn-project/hadoop-yarn/bin/yarn @@ -210,9 +210,13 @@ fi # Note that we are replacing ' ' with '\ ' so that when we exec # stuff it works # -hadoop_add_param HADOOP_OPTS yarn.log.dir "-Dyarn.log.dir=${HADOOP_LOG_DIR/ /\ }" +YARN_LOG_DIR=$HADOOP_LOG_DIR +hadoop_translate_cygwin_path YARN_LOG_DIR +hadoop_add_param HADOOP_OPTS yarn.log.dir "-Dyarn.log.dir=${YARN_LOG_DIR/ /\ }" hadoop_add_param HADOOP_OPTS yarn.log.file "-Dyarn.log.file=${HADOOP_LOGFILE/ /\ }" -hadoop_add_param HADOOP_OPTS yarn.home.dir "-Dyarn.home.dir=${HADOOP_YARN_HOME/ /\ }" +YARN_HOME_DIR=$HADOOP_YARN_HOME +hadoop_translate_cygwin_path YARN_HOME_DIR +hadoop_add_param HADOOP_OPTS yarn.home.dir "-Dyarn.home.dir=${YARN_HOME_DIR/ /\ }" hadoop_add_param HADOOP_OPTS yarn.root.logger "-Dyarn.root.logger=${YARN_ROOT_LOGGER:-INFO,console}" hadoop_finalize