yarn 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 yarn 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 "--daemon (start|status|stop)" "operate on a daemon"
  26. hadoop_add_option "--hostnames list[,of,host,names]" "hosts to use in worker mode"
  27. hadoop_add_option "--loglevel level" "set the log4j level for this command"
  28. hadoop_add_option "--hosts filename" "list of hosts to use in worker mode"
  29. hadoop_add_option "--workers" "turn on worker mode"
  30. hadoop_add_subcommand "application" "prints application(s) report/kill application"
  31. hadoop_add_subcommand "applicationattempt" "prints applicationattempt(s) report"
  32. hadoop_add_subcommand "classpath" "prints the class path needed to get the hadoop jar and the required libraries"
  33. hadoop_add_subcommand "cluster" "prints cluster information"
  34. hadoop_add_subcommand "container" "prints container(s) report"
  35. hadoop_add_subcommand "daemonlog" "get/set the log level for each daemon"
  36. hadoop_add_subcommand "envvars" "display computed Hadoop environment variables"
  37. hadoop_add_subcommand "jar <jar>" "run a jar file"
  38. hadoop_add_subcommand "logs" "dump container logs"
  39. hadoop_add_subcommand "node" "prints node report(s)"
  40. hadoop_add_subcommand "nodemanager" "run a nodemanager on each worker"
  41. hadoop_add_subcommand "proxyserver" "run the web app proxy server"
  42. hadoop_add_subcommand "queue" "prints queue information"
  43. hadoop_add_subcommand "resourcemanager" "run the ResourceManager"
  44. hadoop_add_subcommand "rmadmin" "admin tools"
  45. hadoop_add_subcommand "scmadmin" "SharedCacheManager admin tools"
  46. hadoop_add_subcommand "sharedcachemanager" "run the SharedCacheManager daemon"
  47. hadoop_add_subcommand "timelinereader" "run the timeline reader server"
  48. hadoop_add_subcommand "timelineserver" "run the timeline server"
  49. hadoop_add_subcommand "top" "view cluster information"
  50. hadoop_add_subcommand "version" "print the version"
  51. hadoop_generate_usage "${HADOOP_SHELL_EXECNAME}" true
  52. }
  53. ## @description Default command handler for yarn command
  54. ## @audience public
  55. ## @stability stable
  56. ## @replaceable no
  57. ## @param CLI arguments
  58. function yarncmd_case
  59. {
  60. subcmd=$1
  61. shift
  62. case ${subcmd} in
  63. application|applicationattempt|container)
  64. HADOOP_CLASSNAME=org.apache.hadoop.yarn.client.cli.ApplicationCLI
  65. set -- "${subcmd}" "$@"
  66. HADOOP_SUBCMD_ARGS=("$@")
  67. ;;
  68. classpath)
  69. hadoop_do_classpath_subcommand HADOOP_CLASSNAME "$@"
  70. ;;
  71. cluster)
  72. HADOOP_CLASSNAME=org.apache.hadoop.yarn.client.cli.ClusterCLI
  73. ;;
  74. daemonlog)
  75. HADOOP_CLASSNAME=org.apache.hadoop.log.LogLevel
  76. ;;
  77. envvars)
  78. echo "JAVA_HOME='${JAVA_HOME}'"
  79. echo "HADOOP_YARN_HOME='${HADOOP_YARN_HOME}'"
  80. echo "YARN_DIR='${YARN_DIR}'"
  81. echo "YARN_LIB_JARS_DIR='${YARN_LIB_JARS_DIR}'"
  82. echo "HADOOP_CONF_DIR='${HADOOP_CONF_DIR}'"
  83. echo "HADOOP_TOOLS_HOME='${HADOOP_TOOLS_HOME}'"
  84. echo "HADOOP_TOOLS_DIR='${HADOOP_TOOLS_DIR}'"
  85. echo "HADOOP_TOOLS_LIB_JARS_DIR='${HADOOP_TOOLS_LIB_JARS_DIR}'"
  86. exit 0
  87. ;;
  88. jar)
  89. HADOOP_CLASSNAME=org.apache.hadoop.util.RunJar
  90. ;;
  91. historyserver)
  92. HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true"
  93. echo "DEPRECATED: Use of this command to start the timeline server is deprecated." 1>&2
  94. echo "Instead use the timelineserver command for it." 1>&2
  95. echo "Starting the History Server anyway..." 1>&2
  96. HADOOP_CLASSNAME='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
  97. ;;
  98. logs)
  99. HADOOP_CLASSNAME=org.apache.hadoop.yarn.client.cli.LogsCLI
  100. ;;
  101. node)
  102. HADOOP_CLASSNAME=org.apache.hadoop.yarn.client.cli.NodeCLI
  103. ;;
  104. nodemanager)
  105. HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true"
  106. HADOOP_CLASSNAME='org.apache.hadoop.yarn.server.nodemanager.NodeManager'
  107. # Backwards compatibility
  108. if [[ -n "${YARN_NODEMANAGER_HEAPSIZE}" ]]; then
  109. HADOOP_HEAPSIZE_MAX="${YARN_NODEMANAGER_HEAPSIZE}"
  110. fi
  111. ;;
  112. proxyserver)
  113. HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true"
  114. HADOOP_CLASSNAME='org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer'
  115. # Backwards compatibility
  116. if [[ -n "${YARN_PROXYSERVER_HEAPSIZE}" ]]; then
  117. # shellcheck disable=SC2034
  118. HADOOP_HEAPSIZE_MAX="${YARN_PROXYSERVER_HEAPSIZE}"
  119. fi
  120. ;;
  121. queue)
  122. HADOOP_CLASSNAME=org.apache.hadoop.yarn.client.cli.QueueCLI
  123. ;;
  124. resourcemanager)
  125. HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true"
  126. HADOOP_CLASSNAME='org.apache.hadoop.yarn.server.resourcemanager.ResourceManager'
  127. # Backwards compatibility
  128. if [[ -n "${YARN_RESOURCEMANAGER_HEAPSIZE}" ]]; then
  129. # shellcheck disable=SC2034
  130. HADOOP_HEAPSIZE_MAX="${YARN_RESOURCEMANAGER_HEAPSIZE}"
  131. fi
  132. ;;
  133. rmadmin)
  134. HADOOP_CLASSNAME='org.apache.hadoop.yarn.client.cli.RMAdminCLI'
  135. ;;
  136. scmadmin)
  137. HADOOP_CLASSNAME='org.apache.hadoop.yarn.client.SCMAdmin'
  138. ;;
  139. sharedcachemanager)
  140. HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true"
  141. HADOOP_CLASSNAME='org.apache.hadoop.yarn.server.sharedcachemanager.SharedCacheManager'
  142. ;;
  143. timelinereader)
  144. HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true"
  145. HADOOP_CLASSNAME='org.apache.hadoop.yarn.server.timelineservice.reader.TimelineReaderServer'
  146. ;;
  147. timelineserver)
  148. HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true"
  149. HADOOP_CLASSNAME='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
  150. # Backwards compatibility
  151. if [[ -n "${YARN_TIMELINESERVER_HEAPSIZE}" ]]; then
  152. # shellcheck disable=SC2034
  153. HADOOP_HEAPSIZE_MAX="${YARN_TIMELINESERVER_HEAPSIZE}"
  154. fi
  155. ;;
  156. version)
  157. HADOOP_CLASSNAME=org.apache.hadoop.util.VersionInfo
  158. ;;
  159. top)
  160. doNotSetCols=0
  161. doNotSetRows=0
  162. for i in "$@"; do
  163. if [[ $i == "-cols" ]]; then
  164. doNotSetCols=1
  165. fi
  166. if [[ $i == "-rows" ]]; then
  167. doNotSetRows=1
  168. fi
  169. done
  170. if [ $doNotSetCols == 0 ] && [ -n "${TERM}" ]; then
  171. cols=$(tput cols)
  172. if [ -n "$cols" ]; then
  173. args=( $@ )
  174. args=("${args[@]}" "-cols" "$cols")
  175. set -- "${args[@]}"
  176. fi
  177. fi
  178. if [ $doNotSetRows == 0 ] && [ -n "${TERM}" ]; then
  179. rows=$(tput lines)
  180. if [ -n "$rows" ]; then
  181. args=( $@ )
  182. args=("${args[@]}" "-rows" "$rows")
  183. set -- "${args[@]}"
  184. fi
  185. fi
  186. HADOOP_CLASSNAME=org.apache.hadoop.yarn.client.cli.TopCLI
  187. HADOOP_SUBCMD_ARGS=("$@")
  188. ;;
  189. *)
  190. HADOOP_CLASSNAME="${subcmd}"
  191. if ! hadoop_validate_classname "${HADOOP_CLASSNAME}"; then
  192. hadoop_exit_with_usage 1
  193. fi
  194. ;;
  195. esac
  196. }
  197. # let's locate libexec...
  198. if [[ -n "${HADOOP_HOME}" ]]; then
  199. HADOOP_DEFAULT_LIBEXEC_DIR="${HADOOP_HOME}/libexec"
  200. else
  201. bin=$(cd -P -- "$(dirname -- "${MYNAME}")" >/dev/null && pwd -P)
  202. HADOOP_DEFAULT_LIBEXEC_DIR="${bin}/../libexec"
  203. fi
  204. HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$HADOOP_DEFAULT_LIBEXEC_DIR}"
  205. # shellcheck disable=SC2034
  206. HADOOP_NEW_CONFIG=true
  207. if [[ -f "${HADOOP_LIBEXEC_DIR}/yarn-config.sh" ]]; then
  208. . "${HADOOP_LIBEXEC_DIR}/yarn-config.sh"
  209. else
  210. echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/yarn-config.sh." 2>&1
  211. exit 1
  212. fi
  213. # now that we have support code, let's abs MYNAME so we can use it later
  214. MYNAME=$(hadoop_abs "${MYNAME}")
  215. # if no args specified, show usage
  216. if [[ $# = 0 ]]; then
  217. hadoop_exit_with_usage 1
  218. fi
  219. # get arguments
  220. HADOOP_SUBCMD=$1
  221. shift
  222. if hadoop_need_reexec yarn "${HADOOP_SUBCMD}"; then
  223. hadoop_uservar_su yarn "${HADOOP_SUBCMD}" \
  224. "${MYNAME}" \
  225. "--reexec" \
  226. "${HADOOP_USER_PARAMS[@]}"
  227. exit $?
  228. fi
  229. hadoop_verify_user "${HADOOP_SHELL_EXECNAME}" "${HADOOP_SUBCMD}"
  230. HADOOP_SUBCMD_ARGS=("$@")
  231. if declare -f yarn_subcommand_"${HADOOP_SUBCMD}" >/dev/null 2>&1; then
  232. hadoop_debug "Calling dynamically: yarn_subcommand_${HADOOP_SUBCMD} ${HADOOP_SUBCMD_ARGS[*]}"
  233. "yarn_subcommand_${HADOOP_SUBCMD}" "${HADOOP_SUBCMD_ARGS[@]}"
  234. else
  235. yarncmd_case "${HADOOP_SUBCMD}" "${HADOOP_SUBCMD_ARGS[@]}"
  236. fi
  237. # It's unclear if YARN_CLIENT_OPTS is actually a useful
  238. # thing to have separate from HADOOP_CLIENT_OPTS. Someone
  239. # might use it, so let's not deprecate it and just override
  240. # HADOOP_CLIENT_OPTS instead before we (potentially) add it
  241. # to the command line
  242. if [[ -n "${YARN_CLIENT_OPTS}" ]]; then
  243. # shellcheck disable=SC2034
  244. HADOOP_CLIENT_OPTS=${YARN_CLIENT_OPTS}
  245. fi
  246. hadoop_add_client_opts
  247. if [[ ${HADOOP_WORKER_MODE} = true ]]; then
  248. hadoop_common_worker_mode_execute "${HADOOP_YARN_HOME}/bin/yarn" "${HADOOP_USER_PARAMS[@]}"
  249. exit $?
  250. fi
  251. hadoop_subcommand_opts "${HADOOP_SHELL_EXECNAME}" "${HADOOP_SUBCMD}"
  252. if [[ "${HADOOP_SUBCMD_SECURESERVICE}" = true ]]; then
  253. HADOOP_SECURE_USER="${HADOOP_SUBCMD_SECUREUSER}"
  254. hadoop_subcommand_secure_opts "${HADOOP_SHELL_EXECNAME}" "${HADOOP_SUBCMD}"
  255. hadoop_verify_secure_prereq
  256. hadoop_setup_secure_service
  257. priv_outfile="${HADOOP_LOG_DIR}/privileged-${HADOOP_IDENT_STRING}-${HADOOP_SUBCMD}-${HOSTNAME}.out"
  258. priv_errfile="${HADOOP_LOG_DIR}/privileged-${HADOOP_IDENT_STRING}-${HADOOP_SUBCMD}-${HOSTNAME}.err"
  259. priv_pidfile="${HADOOP_PID_DIR}/privileged-${HADOOP_IDENT_STRING}-${HADOOP_SUBCMD}.pid"
  260. daemon_outfile="${HADOOP_LOG_DIR}/hadoop-${HADOOP_SECURE_USER}-${HADOOP_IDENT_STRING}-${HADOOP_SUBCMD}-${HOSTNAME}.out"
  261. daemon_pidfile="${HADOOP_PID_DIR}/hadoop-${HADOOP_SECURE_USER}-${HADOOP_IDENT_STRING}-${HADOOP_SUBCMD}.pid"
  262. else
  263. daemon_outfile="${HADOOP_LOG_DIR}/hadoop-${HADOOP_IDENT_STRING}-${HADOOP_SUBCMD}-${HOSTNAME}.out"
  264. daemon_pidfile="${HADOOP_PID_DIR}/hadoop-${HADOOP_IDENT_STRING}-${HADOOP_SUBCMD}.pid"
  265. fi
  266. if [[ "${HADOOP_DAEMON_MODE}" != "default" ]]; then
  267. # shellcheck disable=SC2034
  268. HADOOP_ROOT_LOGGER="${HADOOP_DAEMON_ROOT_LOGGER}"
  269. # shellcheck disable=SC2034
  270. HADOOP_LOGFILE="hadoop-${HADOOP_IDENT_STRING}-${HADOOP_SUBCMD}-${HOSTNAME}.log"
  271. fi
  272. hadoop_finalize
  273. if [[ "${HADOOP_SUBCMD_SUPPORTDAEMONIZATION}" = true ]]; then
  274. if [[ "${HADOOP_SUBCMD_SECURESERVICE}" = true ]]; then
  275. hadoop_secure_daemon_handler \
  276. "${HADOOP_DAEMON_MODE}" \
  277. "${HADOOP_SUBCMD}" \
  278. "${HADOOP_CLASSNAME}" \
  279. "${daemon_pidfile}" \
  280. "${daemon_outfile}" \
  281. "${priv_pidfile}" \
  282. "${priv_outfile}" \
  283. "${priv_errfile}" \
  284. "${HADOOP_SUBCMD_ARGS[@]}"
  285. else
  286. hadoop_daemon_handler \
  287. "${HADOOP_DAEMON_MODE}" \
  288. "${HADOOP_SUBCMD}" \
  289. "${HADOOP_CLASSNAME}" \
  290. "${daemon_pidfile}" \
  291. "${daemon_outfile}" \
  292. "${HADOOP_SUBCMD_ARGS[@]}"
  293. fi
  294. exit $?
  295. else
  296. # shellcheck disable=SC2086
  297. hadoop_java_exec "${HADOOP_SUBCMD}" "${HADOOP_CLASSNAME}" "${HADOOP_SUBCMD_ARGS[@]}"
  298. fi