mapred 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. bin=`which $0`
  17. bin=`dirname ${bin}`
  18. bin=`cd "$bin"; pwd`
  19. DEFAULT_LIBEXEC_DIR="$bin"/../libexec
  20. HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
  21. if [ -e ${HADOOP_LIBEXEC_DIR}/mapred-config.sh ]; then
  22. . ${HADOOP_LIBEXEC_DIR}/mapred-config.sh
  23. else
  24. . "$bin/mapred-config.sh"
  25. fi
  26. function print_usage(){
  27. echo "Usage: mapred [--config confdir] [--loglevel loglevel] COMMAND"
  28. echo " where COMMAND is one of:"
  29. echo " pipes run a Pipes job"
  30. echo " job manipulate MapReduce jobs"
  31. echo " queue get information regarding JobQueues"
  32. echo " classpath prints the class path needed for running"
  33. echo " mapreduce subcommands"
  34. echo " historyserver run job history servers as a standalone daemon"
  35. echo " distcp <srcurl> <desturl> copy file or directories recursively"
  36. echo " archive -archiveName NAME -p <parent path> <src>* <dest> create a hadoop archive"
  37. echo " archive-logs combine aggregated logs into hadoop archives"
  38. echo " hsadmin job history server admin interface"
  39. echo ""
  40. echo "Most commands print help when invoked w/o parameters."
  41. }
  42. if [ $# = 0 ]; then
  43. print_usage
  44. exit
  45. fi
  46. COMMAND=$1
  47. shift
  48. case $COMMAND in
  49. # usage flags
  50. --help|-help|-h)
  51. print_usage
  52. exit
  53. ;;
  54. esac
  55. if [ "$COMMAND" = "job" ] ; then
  56. CLASS=org.apache.hadoop.mapred.JobClient
  57. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  58. elif [ "$COMMAND" = "queue" ] ; then
  59. CLASS=org.apache.hadoop.mapred.JobQueueClient
  60. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  61. elif [ "$COMMAND" = "pipes" ] ; then
  62. CLASS=org.apache.hadoop.mapred.pipes.Submitter
  63. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  64. elif [ "$COMMAND" = "sampler" ] ; then
  65. CLASS=org.apache.hadoop.mapred.lib.InputSampler
  66. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  67. elif [ "$COMMAND" = "classpath" ] ; then
  68. echo -n
  69. elif [ "$COMMAND" = "historyserver" ] ; then
  70. CLASS=org.apache.hadoop.mapreduce.v2.hs.JobHistoryServer
  71. HADOOP_OPTS="$HADOOP_OPTS -Dmapred.jobsummary.logger=${HADOOP_JHS_LOGGER:-INFO,console} $HADOOP_JOB_HISTORYSERVER_OPTS"
  72. if [ "$HADOOP_JOB_HISTORYSERVER_HEAPSIZE" != "" ]; then
  73. JAVA_HEAP_MAX="-Xmx""$HADOOP_JOB_HISTORYSERVER_HEAPSIZE""m"
  74. fi
  75. elif [ "$COMMAND" = "mradmin" ] \
  76. || [ "$COMMAND" = "jobtracker" ] \
  77. || [ "$COMMAND" = "tasktracker" ] \
  78. || [ "$COMMAND" = "groups" ] ; then
  79. echo "Sorry, the $COMMAND command is no longer supported."
  80. echo "You may find similar functionality with the \"yarn\" shell command."
  81. print_usage
  82. exit 1
  83. elif [ "$COMMAND" = "distcp" ] ; then
  84. CLASS=org.apache.hadoop.tools.DistCp
  85. CLASSPATH=${CLASSPATH}:${TOOL_PATH}
  86. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  87. elif [ "$COMMAND" = "archive" ] ; then
  88. CLASS=org.apache.hadoop.tools.HadoopArchives
  89. CLASSPATH=${CLASSPATH}:${TOOL_PATH}
  90. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  91. elif [ "$COMMAND" = "archive-logs" ] ; then
  92. CLASS=org.apache.hadoop.tools.HadoopArchiveLogs
  93. CLASSPATH=${CLASSPATH}:${TOOL_PATH}
  94. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  95. elif [ "$COMMAND" = "hsadmin" ] ; then
  96. CLASS=org.apache.hadoop.mapreduce.v2.hs.client.HSAdmin
  97. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  98. else
  99. echo $COMMAND - invalid command
  100. print_usage
  101. exit 1
  102. fi
  103. # for developers, add mapred classes to CLASSPATH
  104. if [ -d "$HADOOP_MAPRED_HOME/build/classes" ]; then
  105. CLASSPATH=${CLASSPATH}:$HADOOP_MAPRED_HOME/build/classes
  106. fi
  107. if [ -d "$HADOOP_MAPRED_HOME/build/webapps" ]; then
  108. CLASSPATH=${CLASSPATH}:$HADOOP_MAPRED_HOME/build
  109. fi
  110. if [ -d "$HADOOP_MAPRED_HOME/build/test/classes" ]; then
  111. CLASSPATH=${CLASSPATH}:$HADOOP_MAPRED_HOME/build/test/classes
  112. fi
  113. if [ -d "$HADOOP_MAPRED_HOME/build/tools" ]; then
  114. CLASSPATH=${CLASSPATH}:$HADOOP_MAPRED_HOME/build/tools
  115. fi
  116. # for releases, add core mapred jar & webapps to CLASSPATH
  117. if [ -d "$HADOOP_PREFIX/${MAPRED_DIR}/webapps" ]; then
  118. CLASSPATH=${CLASSPATH}:$HADOOP_PREFIX/${MAPRED_DIR}
  119. fi
  120. for f in $HADOOP_MAPRED_HOME/${MAPRED_DIR}/*.jar; do
  121. CLASSPATH=${CLASSPATH}:$f;
  122. done
  123. # Need YARN jars also
  124. for f in $HADOOP_YARN_HOME/${YARN_DIR}/*.jar; do
  125. CLASSPATH=${CLASSPATH}:$f;
  126. done
  127. # add libs to CLASSPATH
  128. for f in $HADOOP_MAPRED_HOME/${MAPRED_LIB_JARS_DIR}/*.jar; do
  129. CLASSPATH=${CLASSPATH}:$f;
  130. done
  131. # add modules to CLASSPATH
  132. for f in $HADOOP_MAPRED_HOME/modules/*.jar; do
  133. CLASSPATH=${CLASSPATH}:$f;
  134. done
  135. if [ "$COMMAND" = "classpath" ] ; then
  136. if [ "$#" -gt 0 ]; then
  137. CLASS=org.apache.hadoop.util.Classpath
  138. else
  139. if [ "$cygwin" = true ]; then
  140. CLASSPATH=$(cygpath -p -w "$CLASSPATH" 2>/dev/null)
  141. fi
  142. echo $CLASSPATH
  143. exit 0
  144. fi
  145. fi
  146. # cygwin path translation
  147. if [ "$cygwin" = true ]; then
  148. CLASSPATH=$(cygpath -p -w "$CLASSPATH" 2>/dev/null)
  149. HADOOP_LOG_DIR=$(cygpath -w "$HADOOP_LOG_DIR" 2>/dev/null)
  150. HADOOP_PREFIX=$(cygpath -w "$HADOOP_PREFIX" 2>/dev/null)
  151. HADOOP_CONF_DIR=$(cygpath -w "$HADOOP_CONF_DIR" 2>/dev/null)
  152. HADOOP_COMMON_HOME=$(cygpath -w "$HADOOP_COMMON_HOME" 2>/dev/null)
  153. HADOOP_HDFS_HOME=$(cygpath -w "$HADOOP_HDFS_HOME" 2>/dev/null)
  154. HADOOP_YARN_HOME=$(cygpath -w "$HADOOP_YARN_HOME" 2>/dev/null)
  155. HADOOP_MAPRED_HOME=$(cygpath -w "$HADOOP_MAPRED_HOME" 2>/dev/null)
  156. fi
  157. HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,NullAppender}"
  158. export CLASSPATH
  159. exec "$JAVA" -Dproc_$COMMAND $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"