mapred 5.2 KB

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