hadoop-validate-setup.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. ###############################################################################
  17. # Run the following jobs to validate a hadoop cluster
  18. ## teragen
  19. ## terasort
  20. ## teravalidate
  21. # If they all pass 0 will be returned and 1 otherwise
  22. # The test will work for both secure and unsecure deploys. If the kerberos-realm
  23. # is passed we will assume that the deploy is secure and proceed with a kinit before
  24. # running the validation jobs.
  25. ################################################################################
  26. bin=`dirname "$0"`
  27. bin=`cd "$bin"; pwd`
  28. . "$bin"/../libexec/hadoop-config.sh
  29. usage() {
  30. echo "
  31. usage: $0 <parameters>
  32. Optional parameters:
  33. -h Display this message
  34. --user=hdfs
  35. --user_keytab=/home/hdfs/hdfs.keytab
  36. --kerberos-realm=KERBEROS.EXAMPLE.COM Set Kerberos realm
  37. "
  38. exit 1
  39. }
  40. OPTS=$(getopt \
  41. -n $0 \
  42. -o '' \
  43. -l 'user:' \
  44. -l 'user-keytab:' \
  45. -l 'kerberos-realm:' \
  46. -o 'h' \
  47. -- "$@")
  48. if [ $? != 0 ] ; then
  49. usage
  50. fi
  51. eval set -- "${OPTS}"
  52. while true ; do
  53. case "$1" in
  54. --user)
  55. TEST_USER=$2; shift 2
  56. AUTOMATED=1
  57. ;;
  58. --user-keytab)
  59. USER_KEYTAB_FILE=$2; shift 2
  60. AUTOMATED=1
  61. ;;
  62. --kerberos-realm)
  63. KERBEROS_REALM=$2; shift 2
  64. AUTOMATED=1
  65. ;;
  66. --)
  67. shift ; break
  68. ;;
  69. *)
  70. echo "Unknown option: $1"
  71. usage
  72. exit 1
  73. ;;
  74. esac
  75. done
  76. #set the hadoop command and the path to the hadoop examples jar
  77. HADOOP_CMD="${HADOOP_PREFIX}/bin/hadoop --config $HADOOP_CONF_DIR"
  78. #find the hadoop examples jar
  79. HADOOP_EXAMPLES_JAR=''
  80. #find under HADOOP_PREFIX (tar ball install)
  81. HADOOP_EXAMPLES_JAR=`find ${HADOOP_PREFIX} -name 'hadoop-examples-*.jar' | head -n1`
  82. #if its not found look under /usr/share/hadoop (rpm/deb installs)
  83. if [ "$HADOOP_EXAMPLES_JAR" == '' ]
  84. then
  85. HADOOP_EXAMPLES_JAR=`find /usr/share/hadoop -name 'hadoop-examples-*.jar' | head -n1`
  86. fi
  87. #if it is still empty then dont run the tests
  88. if [ "$HADOOP_EXAMPLES_JAR" == '' ]
  89. then
  90. echo "Did not find hadoop-examples-*.jar under '${HADOOP_PREFIX} or '/usr/share/hadoop'"
  91. exit 1
  92. fi
  93. # do a kinit if secure
  94. if [ "${KERBEROS_REALM}" != "" ]; then
  95. # Determine kerberos location base on Linux distro.
  96. if [ -e /etc/lsb-release ]; then
  97. KERBEROS_BIN=/usr/bin
  98. else
  99. KERBEROS_BIN=/usr/kerberos/bin
  100. fi
  101. kinit_cmd="su -c '${KERBEROS_BIN}/kinit -kt ${USER_KEYTAB_FILE} ${TEST_USER}' ${TEST_USER}"
  102. echo $kinit_cmd
  103. eval $kinit_cmd
  104. if [ $? -ne 0 ]
  105. then
  106. echo "kinit command did not run successfully."
  107. exit 1
  108. fi
  109. fi
  110. #dir where to store the data on hdfs. The data is relative of the users home dir on hdfs.
  111. PARENT_DIR="validate_deploy_`date +%s`"
  112. TERA_GEN_OUTPUT_DIR="${PARENT_DIR}/tera_gen_data"
  113. TERA_SORT_OUTPUT_DIR="${PARENT_DIR}/tera_sort_data"
  114. TERA_VALIDATE_OUTPUT_DIR="${PARENT_DIR}/tera_validate_data"
  115. #tera gen cmd
  116. TERA_GEN_CMD="su -c '$HADOOP_CMD jar $HADOOP_EXAMPLES_JAR teragen 10000 $TERA_GEN_OUTPUT_DIR' $TEST_USER"
  117. #tera sort cmd
  118. TERA_SORT_CMD="su -c '$HADOOP_CMD jar $HADOOP_EXAMPLES_JAR terasort $TERA_GEN_OUTPUT_DIR $TERA_SORT_OUTPUT_DIR' $TEST_USER"
  119. #tera validate cmd
  120. TERA_VALIDATE_CMD="su -c '$HADOOP_CMD jar $HADOOP_EXAMPLES_JAR teravalidate $TERA_SORT_OUTPUT_DIR $TERA_VALIDATE_OUTPUT_DIR' $TEST_USER"
  121. echo "Starting teragen...."
  122. #run tera gen
  123. echo $TERA_GEN_CMD
  124. eval $TERA_GEN_CMD
  125. if [ $? -ne 0 ]; then
  126. echo "tera gen failed."
  127. exit 1
  128. fi
  129. echo "Teragen passed starting terasort...."
  130. #run tera sort
  131. echo $TERA_SORT_CMD
  132. eval $TERA_SORT_CMD
  133. if [ $? -ne 0 ]; then
  134. echo "tera sort failed."
  135. exit 1
  136. fi
  137. echo "Terasort passed starting teravalidate...."
  138. #run tera validate
  139. echo $TERA_VALIDATE_CMD
  140. eval $TERA_VALIDATE_CMD
  141. if [ $? -ne 0 ]; then
  142. echo "tera validate failed."
  143. exit 1
  144. fi
  145. echo "teragen, terasort, teravalidate passed."
  146. echo "Cleaning the data created by tests: $PARENT_DIR"
  147. CLEANUP_CMD="su -c '$HADOOP_CMD dfs -rmr -skipTrash $PARENT_DIR' $TEST_USER"
  148. echo $CLEANUP_CMD
  149. eval $CLEANUP_CMD
  150. exit 0