yarn 10 KB

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