hadoop.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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. # SHELLDOC-IGNORE
  18. #
  19. # Override these to match Apache Hadoop's requirements
  20. personality_plugins "all,-ant,-gradle,-scalac,-scaladoc"
  21. ## @description Globals specific to this personality
  22. ## @audience private
  23. ## @stability evolving
  24. function personality_globals
  25. {
  26. # shellcheck disable=SC2034
  27. BUILDTOOL=maven
  28. #shellcheck disable=SC2034
  29. PATCH_BRANCH_DEFAULT=trunk
  30. #shellcheck disable=SC2034
  31. PATCH_NAMING_RULE="https://cwiki.apache.org/confluence/display/HADOOP/How+To+Contribute"
  32. #shellcheck disable=SC2034
  33. JIRA_ISSUE_RE='^(HADOOP|YARN|MAPREDUCE|HDFS)-[0-9]+$'
  34. #shellcheck disable=SC2034
  35. GITHUB_REPO_DEFAULT="apache/hadoop"
  36. HADOOP_HOMEBREW_DIR=${HADOOP_HOMEBREW_DIR:-$(brew --prefix 2>/dev/null)}
  37. if [[ -z "${HADOOP_HOMEBREW_DIR}" ]]; then
  38. HADOOP_HOMEBREW_DIR=/usr/local
  39. fi
  40. }
  41. function personality_parse_args
  42. {
  43. declare i
  44. for i in "$@"; do
  45. case ${i} in
  46. --hadoop-isal-prefix=*)
  47. delete_parameter "${i}"
  48. ISAL_HOME=${i#*=}
  49. ;;
  50. --hadoop-openssl-prefix=*)
  51. delete_parameter "${i}"
  52. OPENSSL_HOME=${i#*=}
  53. ;;
  54. --hadoop-snappy-prefix=*)
  55. delete_parameter "${i}"
  56. SNAPPY_HOME=${i#*=}
  57. ;;
  58. esac
  59. done
  60. }
  61. ## @description Calculate the actual module ordering
  62. ## @audience private
  63. ## @stability evolving
  64. ## @param ordering
  65. function hadoop_order
  66. {
  67. declare ordering=$1
  68. declare hadoopm
  69. if [[ ${ordering} = normal ]]; then
  70. hadoopm="${CHANGED_MODULES[*]}"
  71. elif [[ ${ordering} = union ]]; then
  72. hadoopm="${CHANGED_UNION_MODULES}"
  73. elif [[ ${ordering} = mvnsrc ]]; then
  74. hadoopm="${MAVEN_SRC_MODULES[*]}"
  75. elif [[ ${ordering} = mvnsrctest ]]; then
  76. hadoopm="${MAVEN_SRCTEST_MODULES[*]}"
  77. else
  78. hadoopm="${ordering}"
  79. fi
  80. echo "${hadoopm}"
  81. }
  82. ## @description Determine if it is safe to run parallel tests
  83. ## @audience private
  84. ## @stability evolving
  85. ## @param ordering
  86. function hadoop_test_parallel
  87. {
  88. if [[ -f "${BASEDIR}/pom.xml" ]]; then
  89. HADOOP_VERSION=$(grep '<version>' "${BASEDIR}/pom.xml" \
  90. | head -1 \
  91. | "${SED}" -e 's|^ *<version>||' -e 's|</version>.*$||' \
  92. | cut -f1 -d- )
  93. export HADOOP_VERSION
  94. else
  95. return 1
  96. fi
  97. hmajor=${HADOOP_VERSION%%\.*}
  98. hmajorminor=${HADOOP_VERSION%\.*}
  99. hminor=${hmajorminor##*\.}
  100. # ... and just for reference
  101. #hmicro=${HADOOP_VERSION##*\.}
  102. # Apache Hadoop v2.8.0 was the first one to really
  103. # get working parallel unit tests
  104. if [[ ${hmajor} -lt 3 && ${hminor} -lt 8 ]]; then
  105. return 1
  106. fi
  107. return 0
  108. }
  109. ## @description Install extra modules for unit tests
  110. ## @audience private
  111. ## @stability evolving
  112. ## @param ordering
  113. function hadoop_unittest_prereqs
  114. {
  115. declare input=$1
  116. declare mods
  117. declare need_common=0
  118. declare building_common=0
  119. declare module
  120. declare flags
  121. declare fn
  122. # prior to running unit tests, hdfs needs libhadoop.so built
  123. # if we're building root, then this extra work is moot
  124. #shellcheck disable=SC2086
  125. mods=$(hadoop_order ${input})
  126. for module in ${mods}; do
  127. if [[ ${module} = hadoop-hdfs-project* ]]; then
  128. need_common=1
  129. elif [[ ${module} = hadoop-common-project/hadoop-common
  130. || ${module} = hadoop-common-project ]]; then
  131. building_common=1
  132. elif [[ ${module} = . ]]; then
  133. return
  134. fi
  135. done
  136. # Windows builds *ALWAYS* need hadoop-common compiled
  137. case ${OSTYPE} in
  138. Windows_NT|CYGWIN*|MINGW*|MSYS*)
  139. need_common=1
  140. ;;
  141. esac
  142. if [[ ${need_common} -eq 1
  143. && ${building_common} -eq 0 ]]; then
  144. echo "unit test pre-reqs:"
  145. module="hadoop-common-project/hadoop-common"
  146. fn=$(module_file_fragment "${module}")
  147. flags="$(hadoop_native_flags) $(yarn_ui2_flag)"
  148. pushd "${BASEDIR}/${module}" >/dev/null || return 1
  149. # shellcheck disable=SC2086
  150. echo_and_redirect "${PATCH_DIR}/maven-unit-prereq-${fn}-install.txt" \
  151. "${MAVEN}" "${MAVEN_ARGS[@]}" install -DskipTests ${flags}
  152. popd >/dev/null || return 1
  153. fi
  154. }
  155. ## @description Calculate the flags/settings for yarn-ui v2 build
  156. ## @description based upon the OS
  157. ## @audience private
  158. ## @stability evolving
  159. function yarn_ui2_flag
  160. {
  161. if [[ ${BUILD_NATIVE} != true ]]; then
  162. return
  163. fi
  164. # Now it only tested on Linux/OSX, don't enable the profile on
  165. # windows until it get verified
  166. case ${OSTYPE} in
  167. Linux)
  168. # shellcheck disable=SC2086
  169. echo -Pyarn-ui
  170. ;;
  171. Darwin)
  172. echo -Pyarn-ui
  173. ;;
  174. *)
  175. # Do nothing
  176. ;;
  177. esac
  178. }
  179. ## @description Calculate the flags/settings for native code
  180. ## @description based upon the OS
  181. ## @audience private
  182. ## @stability evolving
  183. function hadoop_native_flags
  184. {
  185. if [[ ${BUILD_NATIVE} != true ]]; then
  186. return
  187. fi
  188. declare -a args
  189. # Based upon HADOOP-11937
  190. #
  191. # Some notes:
  192. #
  193. # - getting fuse to compile on anything but Linux
  194. # is always tricky.
  195. # - Darwin assumes homebrew is in use.
  196. # - HADOOP-12027 required for bzip2 on OS X.
  197. # - bzip2 is broken in lots of places
  198. # (the shared library is considered experimental)
  199. # e.g, HADOOP-12027 for OS X. so no -Drequire.bzip2
  200. #
  201. args=("-Drequire.test.libhadoop")
  202. if [[ -d "${ISAL_HOME}/include" ]]; then
  203. args=("${args[@]}" "-Disal.prefix=${ISAL_HOME}")
  204. fi
  205. if [[ -d "${OPENSSL_HOME}/include" ]]; then
  206. args=("${args[@]}" "-Dopenssl.prefix=${OPENSSL_HOME}")
  207. elif [[ -d "${HADOOP_HOMEBREW_DIR}/opt/openssl/" ]]; then
  208. args=("${args[@]}" "-Dopenssl.prefix=${HADOOP_HOMEBREW_DIR}/opt/openssl/")
  209. fi
  210. if [[ -d "${SNAPPY_HOME}/include" ]]; then
  211. args=("${args[@]}" "-Dsnappy.prefix=${SNAPPY_HOME}")
  212. elif [[ -d "${HADOOP_HOMEBREW_DIR}/include/snappy.h" ]]; then
  213. args=("${args[@]}" "-Dsnappy.prefix=${HADOOP_HOMEBREW_DIR}/opt/snappy")
  214. fi
  215. case ${OSTYPE} in
  216. Linux)
  217. # shellcheck disable=SC2086
  218. echo \
  219. -Pnative \
  220. -Drequire.fuse \
  221. -Drequire.openssl \
  222. -Drequire.snappy \
  223. -Drequire.valgrind \
  224. -Drequire.zstd \
  225. "${args[@]}"
  226. ;;
  227. Darwin)
  228. echo \
  229. "${args[@]}" \
  230. -Pnative \
  231. -Drequire.snappy \
  232. -Drequire.openssl
  233. ;;
  234. Windows_NT|CYGWIN*|MINGW*|MSYS*)
  235. echo \
  236. "${args[@]}" \
  237. -Drequire.snappy -Drequire.openssl -Pnative-win
  238. ;;
  239. *)
  240. echo \
  241. "${args[@]}"
  242. ;;
  243. esac
  244. }
  245. ## @description Queue up modules for this personality
  246. ## @audience private
  247. ## @stability evolving
  248. ## @param repostatus
  249. ## @param testtype
  250. function personality_modules
  251. {
  252. declare repostatus=$1
  253. declare testtype=$2
  254. declare extra=""
  255. declare ordering="normal"
  256. declare needflags=false
  257. declare foundbats=false
  258. declare flags
  259. declare fn
  260. declare i
  261. declare hadoopm
  262. yetus_debug "Personality: ${repostatus} ${testtype}"
  263. clear_personality_queue
  264. case ${testtype} in
  265. asflicense)
  266. # this is very fast and provides the full path if we do it from
  267. # the root of the source
  268. personality_enqueue_module .
  269. return
  270. ;;
  271. checkstyle)
  272. ordering="union"
  273. extra="-DskipTests"
  274. ;;
  275. compile)
  276. ordering="union"
  277. extra="-DskipTests"
  278. needflags=true
  279. # if something in common changed, we build the whole world
  280. if [[ "${CHANGED_MODULES[*]}" =~ hadoop-common ]]; then
  281. yetus_debug "hadoop personality: javac + hadoop-common = ordering set to . "
  282. ordering="."
  283. fi
  284. ;;
  285. distclean)
  286. ordering="."
  287. extra="-DskipTests"
  288. ;;
  289. javadoc)
  290. if [[ "${CHANGED_MODULES[*]}" =~ \. ]]; then
  291. ordering=.
  292. fi
  293. if [[ "${repostatus}" = patch && "${BUILDMODE}" = patch ]]; then
  294. echo "javadoc pre-reqs:"
  295. for i in hadoop-project \
  296. hadoop-common-project/hadoop-annotations; do
  297. fn=$(module_file_fragment "${i}")
  298. pushd "${BASEDIR}/${i}" >/dev/null || return 1
  299. echo "cd ${i}"
  300. echo_and_redirect "${PATCH_DIR}/maven-${fn}-install.txt" \
  301. "${MAVEN}" "${MAVEN_ARGS[@]}" install
  302. popd >/dev/null || return 1
  303. done
  304. fi
  305. extra="-Pdocs -DskipTests"
  306. ;;
  307. mvneclipse)
  308. if [[ "${CHANGED_MODULES[*]}" =~ \. ]]; then
  309. ordering=.
  310. fi
  311. ;;
  312. mvninstall)
  313. extra="-DskipTests"
  314. if [[ "${repostatus}" = branch || "${BUILDMODE}" = full ]]; then
  315. ordering=.
  316. fi
  317. ;;
  318. mvnsite)
  319. if [[ "${CHANGED_MODULES[*]}" =~ \. ]]; then
  320. ordering=.
  321. fi
  322. ;;
  323. unit)
  324. if [[ "${BUILDMODE}" = full ]]; then
  325. ordering=mvnsrc
  326. elif [[ "${CHANGED_MODULES[*]}" =~ \. ]]; then
  327. ordering=.
  328. fi
  329. if [[ ${TEST_PARALLEL} = "true" ]] ; then
  330. if hadoop_test_parallel; then
  331. extra="-Pparallel-tests"
  332. if [[ -n ${TEST_THREADS:-} ]]; then
  333. extra="${extra} -DtestsThreadCount=${TEST_THREADS}"
  334. fi
  335. fi
  336. fi
  337. needflags=true
  338. hadoop_unittest_prereqs "${ordering}"
  339. if ! verify_needed_test javac; then
  340. yetus_debug "hadoop: javac not requested"
  341. if ! verify_needed_test native; then
  342. yetus_debug "hadoop: native not requested"
  343. yetus_debug "hadoop: adding -DskipTests to unit test"
  344. extra="-DskipTests"
  345. fi
  346. fi
  347. for i in "${CHANGED_FILES[@]}"; do
  348. if [[ "${i}" =~ \.bats ]]; then
  349. foundbats=true
  350. fi
  351. done
  352. if ! verify_needed_test shellcheck && [[ ${foundbats} = false ]]; then
  353. yetus_debug "hadoop: NO shell code change detected; disabling shelltest profile"
  354. extra="${extra} -P!shelltest"
  355. else
  356. extra="${extra} -Pshelltest"
  357. fi
  358. ;;
  359. *)
  360. extra="-DskipTests"
  361. ;;
  362. esac
  363. if [[ ${needflags} = true ]]; then
  364. flags="$(hadoop_native_flags) $(yarn_ui2_flag)"
  365. extra="${extra} ${flags}"
  366. fi
  367. extra="-Ptest-patch ${extra}"
  368. for module in $(hadoop_order ${ordering}); do
  369. # shellcheck disable=SC2086
  370. personality_enqueue_module ${module} ${extra}
  371. done
  372. }
  373. ## @description Add tests based upon personality needs
  374. ## @audience private
  375. ## @stability evolving
  376. ## @param filename
  377. function personality_file_tests
  378. {
  379. declare filename=$1
  380. yetus_debug "Using Hadoop-specific personality_file_tests"
  381. if [[ ${filename} =~ src/main/webapp ]]; then
  382. yetus_debug "tests/webapp: ${filename}"
  383. add_test shadedclient
  384. elif [[ ${filename} =~ \.sh
  385. || ${filename} =~ \.cmd
  386. || ${filename} =~ src/scripts
  387. || ${filename} =~ src/test/scripts
  388. || ${filename} =~ src/main/bin
  389. || ${filename} =~ shellprofile\.d
  390. || ${filename} =~ src/main/conf
  391. ]]; then
  392. yetus_debug "tests/shell: ${filename}"
  393. add_test mvnsite
  394. add_test unit
  395. elif [[ ${filename} =~ \.md$
  396. || ${filename} =~ \.md\.vm$
  397. || ${filename} =~ src/site
  398. ]]; then
  399. yetus_debug "tests/site: ${filename}"
  400. add_test mvnsite
  401. elif [[ ${filename} =~ \.c$
  402. || ${filename} =~ \.cc$
  403. || ${filename} =~ \.h$
  404. || ${filename} =~ \.hh$
  405. || ${filename} =~ \.proto$
  406. || ${filename} =~ \.cmake$
  407. || ${filename} =~ CMakeLists.txt
  408. ]]; then
  409. yetus_debug "tests/units: ${filename}"
  410. add_test compile
  411. add_test cc
  412. add_test mvnsite
  413. add_test javac
  414. add_test unit
  415. elif [[ ${filename} =~ build.xml$
  416. || ${filename} =~ pom.xml$
  417. || ${filename} =~ \.java$
  418. || ${filename} =~ src/main
  419. ]]; then
  420. yetus_debug "tests/javadoc+units: ${filename}"
  421. add_test compile
  422. add_test javac
  423. add_test javadoc
  424. add_test mvninstall
  425. add_test mvnsite
  426. add_test unit
  427. add_test shadedclient
  428. fi
  429. # if we change anything in here, e.g. the test scripts
  430. # then run the client artifact tests
  431. if [[ ${filename} =~ hadoop-client-modules ]]; then
  432. add_test shadedclient
  433. fi
  434. if [[ ${filename} =~ src/test ]]; then
  435. yetus_debug "tests: src/test"
  436. add_test unit
  437. fi
  438. if [[ ${filename} =~ \.java$ ]]; then
  439. add_test spotbugs
  440. fi
  441. }
  442. ## @description Image to print on success
  443. ## @audience private
  444. ## @stability evolving
  445. function hadoop_console_success
  446. {
  447. printf "IF9fX19fX19fX18gCjwgU3VjY2VzcyEgPgogLS0tLS0tLS0tLSAKIFwgICAg";
  448. printf "IC9cICBfX18gIC9cCiAgXCAgIC8vIFwvICAgXC8gXFwKICAgICAoKCAgICBP";
  449. printf "IE8gICAgKSkKICAgICAgXFwgLyAgICAgXCAvLwogICAgICAgXC8gIHwgfCAg";
  450. printf "XC8gCiAgICAgICAgfCAgfCB8ICB8ICAKICAgICAgICB8ICB8IHwgIHwgIAog";
  451. printf "ICAgICAgIHwgICBvICAgfCAgCiAgICAgICAgfCB8ICAgfCB8ICAKICAgICAg";
  452. printf "ICB8bXwgICB8bXwgIAo"
  453. }
  454. ###################################################
  455. # Hadoop project specific check of IT for shaded artifacts
  456. add_test_type shadedclient
  457. ## @description check for test modules and add test/plugins as needed
  458. ## @audience private
  459. ## @stability evolving
  460. function shadedclient_initialize
  461. {
  462. maven_add_install shadedclient
  463. }
  464. ## @description build client facing shaded and non-shaded artifacts and test them
  465. ## @audience private
  466. ## @stability evolving
  467. ## @param repostatus
  468. function shadedclient_rebuild
  469. {
  470. declare repostatus=$1
  471. declare logfile="${PATCH_DIR}/${repostatus}-shadedclient.txt"
  472. declare module
  473. declare -a modules=()
  474. if [[ ${OSTYPE} = Windows_NT ||
  475. ${OSTYPE} =~ ^CYGWIN.* ||
  476. ${OSTYPE} =~ ^MINGW32.* ||
  477. ${OSTYPE} =~ ^MSYS.* ]]; then
  478. echo "hadoop personality: building on windows, skipping check of client artifacts."
  479. return 0
  480. fi
  481. yetus_debug "hadoop personality: seeing if we need the test of client artifacts."
  482. for module in hadoop-client-modules/hadoop-client-check-invariants \
  483. hadoop-client-modules/hadoop-client-check-test-invariants \
  484. hadoop-client-modules/hadoop-client-integration-tests; do
  485. if [ -d "${module}" ]; then
  486. yetus_debug "hadoop personality: test module '${module}' is present."
  487. modules+=(-pl "${module}")
  488. fi
  489. done
  490. if [ ${#modules[@]} -eq 0 ]; then
  491. echo "hadoop personality: no test modules present, skipping check of client artifacts."
  492. return 0
  493. fi
  494. big_console_header "Checking client artifacts on ${repostatus} with shaded clients"
  495. echo_and_redirect "${logfile}" \
  496. "${MAVEN}" "${MAVEN_ARGS[@]}" verify -fae --batch-mode -am \
  497. "${modules[@]}" \
  498. -Dtest=NoUnitTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotbugs.skip=true
  499. big_console_header "Checking client artifacts on ${repostatus} with non-shaded clients"
  500. echo_and_redirect "${logfile}" \
  501. "${MAVEN}" "${MAVEN_ARGS[@]}" verify -fae --batch-mode -am \
  502. "${modules[@]}" \
  503. -DskipShade -Dtest=NoUnitTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotbugs.skip=true
  504. count=$("${GREP}" -c '\[ERROR\]' "${logfile}")
  505. if [[ ${count} -gt 0 ]]; then
  506. add_vote_table -1 shadedclient "${repostatus} has errors when building and testing our client artifacts."
  507. return 1
  508. fi
  509. add_vote_table +1 shadedclient "${repostatus} has no errors when building and testing our client artifacts."
  510. return 0
  511. }