mapred 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 mapred command's usage text.
  19. ## @audience public
  20. ## @stability stable
  21. ## @replaceable no
  22. function hadoop_usage
  23. {
  24. hadoop_add_subcommand "classpath" client "prints the class path needed for running mapreduce subcommands"
  25. hadoop_add_subcommand "envvars" client "display computed Hadoop environment variables"
  26. hadoop_add_subcommand "historyserver" daemon "run job history servers as a standalone daemon"
  27. hadoop_add_subcommand "hsadmin" admin "job history server admin interface"
  28. hadoop_add_subcommand "job" client "manipulate MapReduce jobs"
  29. hadoop_add_subcommand "pipes" client "run a Pipes job"
  30. hadoop_add_subcommand "queue" client "get information regarding JobQueues"
  31. hadoop_add_subcommand "sampler" client "sampler"
  32. hadoop_add_subcommand "version" client "print the version"
  33. hadoop_generate_usage "${HADOOP_SHELL_EXECNAME}" true
  34. }
  35. ## @description Default command handler for hadoop command
  36. ## @audience public
  37. ## @stability stable
  38. ## @replaceable no
  39. ## @param CLI arguments
  40. function mapredcmd_case
  41. {
  42. subcmd=$1
  43. shift
  44. case ${subcmd} in
  45. mradmin|jobtracker|tasktracker|groups)
  46. hadoop_error "Sorry, the ${subcmd} command is no longer supported."
  47. hadoop_error "You may find similar functionality with the \"yarn\" shell command."
  48. hadoop_exit_with_usage 1
  49. ;;
  50. classpath)
  51. hadoop_do_classpath_subcommand HADOOP_CLASSNAME "$@"
  52. ;;
  53. envvars)
  54. echo "JAVA_HOME='${JAVA_HOME}'"
  55. echo "HADOOP_MAPRED_HOME='${HADOOP_MAPRED_HOME}'"
  56. echo "MAPRED_DIR='${MAPRED_DIR}'"
  57. echo "MAPRED_LIB_JARS_DIR='${MAPRED_LIB_JARS_DIR}'"
  58. echo "HADOOP_CONF_DIR='${HADOOP_CONF_DIR}'"
  59. echo "HADOOP_TOOLS_HOME='${HADOOP_TOOLS_HOME}'"
  60. echo "HADOOP_TOOLS_DIR='${HADOOP_TOOLS_DIR}'"
  61. echo "HADOOP_TOOLS_LIB_JARS_DIR='${HADOOP_TOOLS_LIB_JARS_DIR}'"
  62. exit 0
  63. ;;
  64. historyserver)
  65. HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true"
  66. HADOOP_CLASSNAME=org.apache.hadoop.mapreduce.v2.hs.JobHistoryServer
  67. if [[ -n "${HADOOP_JOB_HISTORYSERVER_HEAPSIZE}" ]]; then
  68. HADOOP_HEAPSIZE_MAX="${HADOOP_JOB_HISTORYSERVER_HEAPSIZE}"
  69. fi
  70. HADOOP_DAEMON_ROOT_LOGGER=${HADOOP_JHS_LOGGER:-$HADOOP_DAEMON_ROOT_LOGGER}
  71. if [[ "${HADOOP_DAEMON_MODE}" != "default" ]]; then
  72. hadoop_add_param HADOOP_OPTS mapred.jobsummary.logger "-Dmapred.jobsummary.logger=${HADOOP_DAEMON_ROOT_LOGGER}"
  73. fi
  74. ;;
  75. hsadmin)
  76. HADOOP_CLASSNAME=org.apache.hadoop.mapreduce.v2.hs.client.HSAdmin
  77. ;;
  78. job)
  79. HADOOP_CLASSNAME=org.apache.hadoop.mapred.JobClient
  80. ;;
  81. pipes)
  82. HADOOP_CLASSNAME=org.apache.hadoop.mapred.pipes.Submitter
  83. ;;
  84. queue)
  85. HADOOP_CLASSNAME=org.apache.hadoop.mapred.JobQueueClient
  86. ;;
  87. sampler)
  88. HADOOP_CLASSNAME=org.apache.hadoop.mapred.lib.InputSampler
  89. ;;
  90. version)
  91. HADOOP_CLASSNAME=org.apache.hadoop.util.VersionInfo
  92. ;;
  93. *)
  94. HADOOP_CLASSNAME="${subcmd}"
  95. if ! hadoop_validate_classname "${HADOOP_CLASSNAME}"; then
  96. hadoop_exit_with_usage 1
  97. fi
  98. ;;
  99. esac
  100. }
  101. bin=$(cd -P -- "$(dirname -- "${MYNAME}")" >/dev/null && pwd -P)
  102. # let's locate libexec...
  103. if [[ -n "${HADOOP_HOME}" ]]; then
  104. HADOOP_DEFAULT_LIBEXEC_DIR="${HADOOP_HOME}/libexec"
  105. else
  106. HADOOP_DEFAULT_LIBEXEC_DIR="${bin}/../libexec"
  107. fi
  108. HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$HADOOP_DEFAULT_LIBEXEC_DIR}"
  109. HADOOP_NEW_CONFIG=true
  110. if [[ -f "${HADOOP_LIBEXEC_DIR}/mapred-config.sh" ]]; then
  111. # shellcheck source=./hadoop-mapreduce-project/bin/mapred-config.sh
  112. . "${HADOOP_LIBEXEC_DIR}/mapred-config.sh"
  113. else
  114. echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/mapred-config.sh." 2>&1
  115. exit 1
  116. fi
  117. # now that we have support code, let's abs MYNAME so we can use it later
  118. MYNAME=$(hadoop_abs "${MYNAME}")
  119. if [ $# = 0 ]; then
  120. hadoop_exit_with_usage 1
  121. fi
  122. HADOOP_SUBCMD=$1
  123. shift
  124. if hadoop_need_reexec mapred "${HADOOP_SUBCMD}"; then
  125. hadoop_uservar_su mapred "${HADOOP_SUBCMD}" \
  126. "${MYNAME}" \
  127. "--reexec" \
  128. "${HADOOP_USER_PARAMS[@]}"
  129. exit $?
  130. fi
  131. hadoop_verify_user_perm "${HADOOP_SHELL_EXECNAME}" "${HADOOP_SUBCMD}"
  132. HADOOP_SUBCMD_ARGS=("$@")
  133. if declare -f mapred_subcommand_"${HADOOP_SUBCMD}" >/dev/null 2>&1; then
  134. hadoop_debug "Calling dynamically: mapred_subcommand_${HADOOP_SUBCMD} ${HADOOP_SUBCMD_ARGS[*]}"
  135. "mapred_subcommand_${HADOOP_SUBCMD}" "${HADOOP_SUBCMD_ARGS[@]}"
  136. else
  137. mapredcmd_case "${HADOOP_SUBCMD}" "${HADOOP_SUBCMD_ARGS[@]}"
  138. fi
  139. hadoop_add_client_opts
  140. if [[ ${HADOOP_WORKER_MODE} = true ]]; then
  141. hadoop_common_worker_mode_execute "${HADOOP_MAPRED_HOME}/bin/mapred" "${HADOOP_USER_PARAMS[@]}"
  142. exit $?
  143. fi
  144. hadoop_subcommand_opts "${HADOOP_SHELL_EXECNAME}" "${HADOOP_SUBCMD}"
  145. # everything is in globals at this point, so call the generic handler
  146. hadoop_generic_java_subcmd_handler