yarn 12 KB

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