hadoop 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. MYNAME="${BASH_SOURCE-$0}"
  17. HADOOP_SHELL_EXECNAME="${MYNAME##*/}"
  18. ## @description build up the hadoop command's usage text.
  19. ## @audience public
  20. ## @stability stable
  21. ## @replaceable no
  22. function hadoop_usage
  23. {
  24. hadoop_add_option "buildpaths" "attempt to add class files from build tree"
  25. hadoop_add_option "hostnames list[,of,host,names]" "hosts to use in slave mode"
  26. hadoop_add_option "loglevel level" "set the log4j level for this command"
  27. hadoop_add_option "hosts filename" "list of hosts to use in slave mode"
  28. hadoop_add_option "workers" "turn on worker mode"
  29. hadoop_add_subcommand "checknative" client "check native Hadoop and compression libraries availability"
  30. hadoop_add_subcommand "classpath" client "prints the class path needed to get the Hadoop jar and the required libraries"
  31. hadoop_add_subcommand "conftest" client "validate configuration XML files"
  32. hadoop_add_subcommand "credential" client "interact with credential providers"
  33. hadoop_add_subcommand "daemonlog" admin "get/set the log level for each daemon"
  34. hadoop_add_subcommand "dtutil" client "operations related to delegation tokens"
  35. hadoop_add_subcommand "envvars" client "display computed Hadoop environment variables"
  36. hadoop_add_subcommand "fs" client "run a generic filesystem user client"
  37. hadoop_add_subcommand "jar <jar>" client "run a jar file. NOTE: please use \"yarn jar\" to launch YARN applications, not this command."
  38. hadoop_add_subcommand "jnipath" client "prints the java.library.path"
  39. hadoop_add_subcommand "kerbname" client "show auth_to_local principal conversion"
  40. hadoop_add_subcommand "key" client "manage keys via the KeyProvider"
  41. hadoop_add_subcommand "trace" client "view and modify Hadoop tracing settings"
  42. hadoop_add_subcommand "version" client "print the version"
  43. hadoop_generate_usage "${HADOOP_SHELL_EXECNAME}" true
  44. }
  45. ## @description Default command handler for hadoop command
  46. ## @audience public
  47. ## @stability stable
  48. ## @replaceable no
  49. ## @param CLI arguments
  50. function hadoopcmd_case
  51. {
  52. subcmd=$1
  53. shift
  54. case ${subcmd} in
  55. balancer|datanode|dfs|dfsadmin|dfsgroups| \
  56. namenode|secondarynamenode|fsck|fetchdt|oiv| \
  57. portmap|nfs3)
  58. hadoop_error "WARNING: Use of this script to execute ${subcmd} is deprecated."
  59. subcmd=${subcmd/dfsgroups/groups}
  60. hadoop_error "WARNING: Attempting to execute replacement \"hdfs ${subcmd}\" instead."
  61. hadoop_error ""
  62. #try to locate hdfs and if present, delegate to it.
  63. if [[ -f "${HADOOP_HDFS_HOME}/bin/hdfs" ]]; then
  64. exec "${HADOOP_HDFS_HOME}/bin/hdfs" \
  65. --config "${HADOOP_CONF_DIR}" "${subcmd}" "$@"
  66. elif [[ -f "${HADOOP_HOME}/bin/hdfs" ]]; then
  67. exec "${HADOOP_HOME}/bin/hdfs" \
  68. --config "${HADOOP_CONF_DIR}" "${subcmd}" "$@"
  69. else
  70. hadoop_error "HADOOP_HDFS_HOME not found!"
  71. exit 1
  72. fi
  73. ;;
  74. #mapred commands for backwards compatibility
  75. pipes|job|queue|mrgroups|mradmin|jobtracker|tasktracker)
  76. hadoop_error "WARNING: Use of this script to execute ${subcmd} is deprecated."
  77. subcmd=${subcmd/mrgroups/groups}
  78. hadoop_error "WARNING: Attempting to execute replacement \"mapred ${subcmd}\" instead."
  79. hadoop_error ""
  80. #try to locate mapred and if present, delegate to it.
  81. if [[ -f "${HADOOP_MAPRED_HOME}/bin/mapred" ]]; then
  82. exec "${HADOOP_MAPRED_HOME}/bin/mapred" \
  83. --config "${HADOOP_CONF_DIR}" "${subcmd}" "$@"
  84. elif [[ -f "${HADOOP_HOME}/bin/mapred" ]]; then
  85. exec "${HADOOP_HOME}/bin/mapred" \
  86. --config "${HADOOP_CONF_DIR}" "${subcmd}" "$@"
  87. else
  88. hadoop_error "HADOOP_MAPRED_HOME not found!"
  89. exit 1
  90. fi
  91. ;;
  92. checknative)
  93. HADOOP_CLASSNAME=org.apache.hadoop.util.NativeLibraryChecker
  94. ;;
  95. classpath)
  96. hadoop_do_classpath_subcommand HADOOP_CLASSNAME "$@"
  97. ;;
  98. conftest)
  99. HADOOP_CLASSNAME=org.apache.hadoop.util.ConfTest
  100. ;;
  101. credential)
  102. HADOOP_CLASSNAME=org.apache.hadoop.security.alias.CredentialShell
  103. ;;
  104. daemonlog)
  105. HADOOP_CLASSNAME=org.apache.hadoop.log.LogLevel
  106. ;;
  107. dtutil)
  108. HADOOP_CLASSNAME=org.apache.hadoop.security.token.DtUtilShell
  109. ;;
  110. envvars)
  111. echo "JAVA_HOME='${JAVA_HOME}'"
  112. echo "HADOOP_COMMON_HOME='${HADOOP_COMMON_HOME}'"
  113. echo "HADOOP_COMMON_DIR='${HADOOP_COMMON_DIR}'"
  114. echo "HADOOP_COMMON_LIB_JARS_DIR='${HADOOP_COMMON_LIB_JARS_DIR}'"
  115. echo "HADOOP_COMMON_LIB_NATIVE_DIR='${HADOOP_COMMON_LIB_NATIVE_DIR}'"
  116. echo "HADOOP_CONF_DIR='${HADOOP_CONF_DIR}'"
  117. echo "HADOOP_TOOLS_HOME='${HADOOP_TOOLS_HOME}'"
  118. echo "HADOOP_TOOLS_DIR='${HADOOP_TOOLS_DIR}'"
  119. echo "HADOOP_TOOLS_LIB_JARS_DIR='${HADOOP_TOOLS_LIB_JARS_DIR}'"
  120. exit 0
  121. ;;
  122. fs)
  123. HADOOP_CLASSNAME=org.apache.hadoop.fs.FsShell
  124. ;;
  125. jar)
  126. if [[ -n "${YARN_OPTS}" ]] || [[ -n "${YARN_CLIENT_OPTS}" ]]; then
  127. hadoop_error "WARNING: Use \"yarn jar\" to launch YARN applications."
  128. fi
  129. HADOOP_CLASSNAME=org.apache.hadoop.util.RunJar
  130. ;;
  131. jnipath)
  132. hadoop_finalize
  133. echo "${JAVA_LIBRARY_PATH}"
  134. exit 0
  135. ;;
  136. kerbname)
  137. HADOOP_CLASSNAME=org.apache.hadoop.security.HadoopKerberosName
  138. ;;
  139. key)
  140. HADOOP_CLASSNAME=org.apache.hadoop.crypto.key.KeyShell
  141. ;;
  142. trace)
  143. HADOOP_CLASSNAME=org.apache.hadoop.tracing.TraceAdmin
  144. ;;
  145. version)
  146. HADOOP_CLASSNAME=org.apache.hadoop.util.VersionInfo
  147. ;;
  148. *)
  149. HADOOP_CLASSNAME="${subcmd}"
  150. if ! hadoop_validate_classname "${HADOOP_CLASSNAME}"; then
  151. hadoop_exit_with_usage 1
  152. fi
  153. ;;
  154. esac
  155. }
  156. # This script runs the hadoop core commands.
  157. # let's locate libexec...
  158. if [[ -n "${HADOOP_HOME}" ]]; then
  159. HADOOP_DEFAULT_LIBEXEC_DIR="${HADOOP_HOME}/libexec"
  160. else
  161. bin=$(cd -P -- "$(dirname -- "${MYNAME}")" >/dev/null && pwd -P)
  162. HADOOP_DEFAULT_LIBEXEC_DIR="${bin}/../libexec"
  163. fi
  164. HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$HADOOP_DEFAULT_LIBEXEC_DIR}"
  165. HADOOP_NEW_CONFIG=true
  166. if [[ -f "${HADOOP_LIBEXEC_DIR}/hadoop-config.sh" ]]; then
  167. # shellcheck source=./hadoop-common-project/hadoop-common/src/main/bin/hadoop-config.sh
  168. . "${HADOOP_LIBEXEC_DIR}/hadoop-config.sh"
  169. else
  170. echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/hadoop-config.sh." 2>&1
  171. exit 1
  172. fi
  173. # now that we have support code, let's abs MYNAME so we can use it later
  174. MYNAME=$(hadoop_abs "${MYNAME}")
  175. if [[ $# = 0 ]]; then
  176. hadoop_exit_with_usage 1
  177. fi
  178. HADOOP_SUBCMD=$1
  179. shift
  180. if hadoop_need_reexec hadoop "${HADOOP_SUBCMD}"; then
  181. hadoop_uservar_su hadoop "${HADOOP_SUBCMD}" \
  182. "${MYNAME}" \
  183. "--reexec" \
  184. "${HADOOP_USER_PARAMS[@]}"
  185. exit $?
  186. fi
  187. hadoop_verify_user_perm "${HADOOP_SHELL_EXECNAME}" "${HADOOP_SUBCMD}"
  188. HADOOP_SUBCMD_ARGS=("$@")
  189. if declare -f hadoop_subcommand_"${HADOOP_SUBCMD}" >/dev/null 2>&1; then
  190. hadoop_debug "Calling dynamically: hadoop_subcommand_${HADOOP_SUBCMD} ${HADOOP_SUBCMD_ARGS[*]}"
  191. "hadoop_subcommand_${HADOOP_SUBCMD}" "${HADOOP_SUBCMD_ARGS[@]}"
  192. else
  193. hadoopcmd_case "${HADOOP_SUBCMD}" "${HADOOP_SUBCMD_ARGS[@]}"
  194. fi
  195. hadoop_add_client_opts
  196. if [[ ${HADOOP_WORKER_MODE} = true ]]; then
  197. hadoop_common_worker_mode_execute "${HADOOP_COMMON_HOME}/bin/hadoop" "${HADOOP_USER_PARAMS[@]}"
  198. exit $?
  199. fi
  200. hadoop_subcommand_opts "${HADOOP_SHELL_EXECNAME}" "${HADOOP_SUBCMD}"
  201. # everything is in globals at this point, so call the generic handler
  202. hadoop_generic_java_subcmd_handler