oozieSmoke2.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env bash
  2. #
  3. #
  4. # Licensed to the Apache Software Foundation (ASF) under one
  5. # or more contributor license agreements. See the NOTICE file
  6. # distributed with this work for additional information
  7. # regarding copyright ownership. The ASF licenses this file
  8. # to you under the Apache License, Version 2.0 (the
  9. # "License"); you may not use this file except in compliance
  10. # with the License. You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing,
  15. # software distributed under the License is distributed on an
  16. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. # KIND, either express or implied. See the License for the
  18. # specific language governing permissions and limitations
  19. # under the License.
  20. #
  21. #
  22. export os_family=$1
  23. export oozie_lib_dir=$2
  24. export oozie_conf_dir=$3
  25. export oozie_bin_dir=$4
  26. export oozie_server_url=$5
  27. export oozie_examples_dir=$6
  28. export hadoop_conf_dir=$7
  29. export hadoop_bin_dir=$8
  30. export smoke_test_user=$9
  31. export security_enabled=${10}
  32. export smoke_user_keytab=${11}
  33. export kinit_path_local=${12}
  34. export smokeuser_principal=${13}
  35. function checkOozieJobStatus {
  36. local job_id=$1
  37. local num_of_tries=$2
  38. #default num_of_tries to 10 if not present
  39. num_of_tries=${num_of_tries:-10}
  40. local i=0
  41. local rc=1
  42. local cmd="source ${oozie_conf_dir}/oozie-env.sh ; ${oozie_bin_dir}/oozie job -oozie ${OOZIE_SERVER} -info $job_id"
  43. /var/lib/ambari-agent/ambari-sudo.sh su ${smoke_test_user} -s /bin/bash - -c "$cmd"
  44. while [ $i -lt $num_of_tries ] ; do
  45. cmd_output=`/var/lib/ambari-agent/ambari-sudo.sh su ${smoke_test_user} -s /bin/bash - -c "$cmd"`
  46. (IFS='';echo $cmd_output)
  47. act_status=$(IFS='';echo $cmd_output | grep ^Status | cut -d':' -f2 | sed 's| ||g')
  48. echo "workflow_status=$act_status"
  49. if [ "RUNNING" == "$act_status" ]; then
  50. #increment the counter and get the status again after waiting for 15 secs
  51. sleep 15
  52. (( i++ ))
  53. elif [ "SUCCEEDED" == "$act_status" ]; then
  54. rc=0;
  55. break;
  56. else
  57. rc=1
  58. break;
  59. fi
  60. done
  61. return $rc
  62. }
  63. export OOZIE_EXIT_CODE=0
  64. export OOZIE_SERVER=$oozie_server_url
  65. cd $oozie_examples_dir
  66. if [[ $security_enabled == "True" ]]; then
  67. kinitcmd="${kinit_path_local} -kt ${smoke_user_keytab} ${smokeuser_principal}; "
  68. else
  69. kinitcmd=""
  70. fi
  71. cmd="${kinitcmd}source ${oozie_conf_dir}/oozie-env.sh ; ${oozie_bin_dir}/oozie -Doozie.auth.token.cache=false job -oozie $OOZIE_SERVER -config $oozie_examples_dir/examples/apps/map-reduce/job.properties -run"
  72. echo $cmd
  73. job_info=`/var/lib/ambari-agent/ambari-sudo.sh su ${smoke_test_user} -s /bin/bash - -c "$cmd" | grep "job:"`
  74. job_id="`echo $job_info | cut -d':' -f2`"
  75. checkOozieJobStatus "$job_id" 15
  76. OOZIE_EXIT_CODE="$?"
  77. exit $OOZIE_EXIT_CODE