build-functions 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/bin/bash
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. # Common functions for hudson build scripts
  18. if [ ! -e $HOME/.hue_cache ]; then
  19. mkdir -p $HOME/.hue_cache
  20. fi;
  21. check_mtime() {
  22. MTIME_FILE=${1}
  23. MTIME=$( curl -Is ${2} | awk 'BEGIN {FS=":"} { if ($1 == "Last-Modified") { print substr($2,2) } }' )
  24. if echo "${MTIME}" | diff ${MTIME_FILE} - > /dev/null; then
  25. return 0
  26. else
  27. echo ${MTIME} > ${MTIME_FILE}
  28. return 1
  29. fi;
  30. }
  31. ##########
  32. #
  33. # Use $CDH_URL to control where to download Hadoop.
  34. # If not specified, it uses the $CDH variable to select an archive location.
  35. #
  36. CDH_URL=${CDH_URL:-http://nightly.cloudera.com/cdh4/cdh/4/hadoop-2.0.0-cdh4.5.0-SNAPSHOT.tar.gz}
  37. CDH_TGZ=$(basename $CDH_URL)
  38. CDH_VERSION=${CDH_TGZ/.tar.gz/}
  39. CDH_CACHE="$HOME/.hue_cache/${CDH_TGZ}"
  40. CDH_MTIME_FILE="$HOME/.hue_cache/.cdh_mtime"
  41. build_hadoop() {
  42. if ! check_mtime ${CDH_MTIME_FILE} ${CDH_URL} || [ ! -f $CDH_CACHE ]; then
  43. echo "Downloading $CDH_URL..."
  44. wget $CDH_URL -O $CDH_CACHE
  45. fi
  46. HADOOP_DIR=$HUE_ROOT/ext/hadoop
  47. export YARN_HOME="$HADOOP_DIR/${CDH_VERSION}"
  48. export HADOOP_HDFS_HOME="$HADOOP_DIR/${CDH_VERSION}/share/hadoop/hdfs"
  49. export HADOOP_BIN="$HADOOP_DIR/${CDH_VERSION}/bin/hadoop"
  50. export HADOOP_MAPRED_HOME="$HADOOP_DIR/${CDH_VERSION}/share/hadoop/mapreduce2"
  51. export HADOOP_MAPRED_BIN="$HADOOP_DIR/${CDH_VERSION}/bin/mapred"
  52. mkdir -p $HADOOP_DIR
  53. rm -rf "$HADOOP_DIR/${CDH_VERSION}"
  54. echo "Unpacking $CDH_CACHE to $HADOOP_DIR"
  55. tar -C $HADOOP_DIR -xzf $CDH_CACHE
  56. # For Hive
  57. #ln -s "$HADOOP_DIR/${CDH_VERSION}/bin-mapreduce1" $HADOOP_MR1_HOME/bin
  58. # For MR2
  59. #rm -f "$HADOOP_DIR/${CDH_VERSION}/share/hadoop/mapreduce"
  60. ln -sf "$HADOOP_DIR/${CDH_VERSION}/share/hadoop/mapreduce2" "$HADOOP_DIR/${CDH_VERSION}/share/hadoop/mapreduce"
  61. #ln -sf "mapreduce" "$HADOOP_DIR/${CDH_VERSION}/share/hadoop/mapreduce"
  62. ln -s $HADOOP_DIR/${CDH_VERSION} $HADOOP_DIR/hadoop
  63. }
  64. ##########
  65. HIVE_URL=${HIVE_URL:-http://nightly.cloudera.com/cdh4/cdh/4/hive-0.10.0-cdh4.5.0-SNAPSHOT.tar.gz}
  66. HIVE_TGZ=$(basename $HIVE_URL)
  67. HIVE_VERSION=${HIVE_TGZ/.tar.gz/}
  68. HIVE_CACHE="$HOME/.hue_cache/${HIVE_TGZ}"
  69. HIVE_MTIME_FILE="$HOME/.hue_cache/.hive_mtime"
  70. build_hive() {
  71. if ! check_mtime ${HIVE_MTIME_FILE} ${HIVE_URL} || [ ! -f $HIVE_CACHE ]; then
  72. echo "Downloading $HIVE_URL..."
  73. wget $HIVE_URL -O $HIVE_CACHE
  74. fi
  75. HIVE_DIR=$HUE_ROOT/ext/hive
  76. export HIVE_HOME="$HIVE_DIR/${HIVE_VERSION}"
  77. mkdir -p $HIVE_DIR
  78. rm -rf $HIVE_HOME
  79. echo "Unpacking $HIVE_CACHE to $HIVE_DIR"
  80. tar -C $HIVE_DIR -xzf $HIVE_CACHE
  81. ln -s $HIVE_DIR/${HIVE_VERSION} $HIVE_DIR/hive
  82. export HIVE_CONF_DIR=$HIVE_HOME/conf
  83. }
  84. ##########
  85. OOZIE_URL=${OOZIE_URL:-http://nightly.cloudera.com/cdh4/cdh/4/oozie-3.3.2-cdh4.5.0-SNAPSHOT.tar.gz}
  86. OOZIE_TGZ=$(basename $OOZIE_URL)
  87. OOZIE_VERSION=${OOZIE_TGZ/.tar.gz/}
  88. OOZIE_CACHE="$HOME/.hue_cache/${OOZIE_TGZ}"
  89. OOZIE_MTIME_FILE="$HOME/.hue_cache/.oozie_mtime"
  90. build_oozie() {
  91. if ! check_mtime ${OOZIE_MTIME_FILE} ${OOZIE_URL} || [ ! -f $OOZIE_CACHE ]; then
  92. echo "Downloading $OOZIE_URL..."
  93. wget $OOZIE_URL -O $OOZIE_CACHE
  94. fi
  95. OOZIE_DIR=$HUE_ROOT/ext/oozie
  96. export OOZIE_HOME="$OOZIE_DIR/${OOZIE_VERSION}"
  97. mkdir -p $OOZIE_DIR
  98. rm -rf $OOZIE_HOME
  99. echo "Unpacking $OOZIE_CACHE to $OOZIE_DIR"
  100. tar -C $OOZIE_DIR -xzf $OOZIE_CACHE
  101. export OOZIE_CONF_DIR=$OOZIE_HOME/conf
  102. rm -rf $OOZIE_DIR/oozie
  103. ln -s $OOZIE_DIR/${OOZIE_VERSION} $OOZIE_DIR/oozie
  104. mkdir -p $OOZIE_HOME/libext
  105. tar -C $OOZIE_HOME/libext -zxvf $OOZIE_HOME/oozie-hadooplibs-*.tar.gz
  106. HADOOP_LIB=`echo "${CDH_VERSION}" | sed -r 's/hadoop/hadooplib/g'`
  107. cp $OOZIE_HOME/libext/oozie-*/hadooplibs/${HADOOP_LIB}*/*jar $OOZIE_HOME/libext/
  108. tar -C $OOZIE_HOME -zxvf $OOZIE_HOME/oozie-examples.tar.gz
  109. tar -C $OOZIE_HOME -zxvf $OOZIE_HOME/oozie-sharelib-*SNAPSHOT-yarn.tar.gz
  110. $OOZIE_HOME/bin/oozie-setup.sh prepare-war
  111. $OOZIE_HOME/bin/ooziedb.sh create -sqlfile oozie.sql -run
  112. }
  113. ##########
  114. SQOOP_URL=${SQOOP_URL:-http://nightly.cloudera.com/cdh4/cdh/4/sqoop2-1.99.2-cdh4.5.0-SNAPSHOT.tar.gz}
  115. SQOOP_TGZ=$(basename $SQOOP_URL)
  116. SQOOP_VERSION=${SQOOP_TGZ/.tar.gz/}
  117. SQOOP_CACHE="$HOME/.hue_cache/${SQOOP_TGZ}"
  118. SQOOP_MTIME_FILE="$HOME/.hue_cache/.sqoop_mtime"
  119. build_sqoop() {
  120. if ! check_mtime ${SQOOP_MTIME_FILE} ${SQOOP_URL} || [ ! -f $SQOOP_CACHE ]; then
  121. echo "Downloading $SQOOP_URL..."
  122. wget $SQOOP_URL -O $SQOOP_CACHE
  123. fi
  124. SQOOP_DIR=$HUE_ROOT/ext/sqoop
  125. export SQOOP_HOME="$SQOOP_DIR/${SQOOP_VERSION}"
  126. mkdir -p $SQOOP_DIR
  127. rm -rf $SQOOP_HOME
  128. echo "Unpacking $SQOOP_CACHE to $SQOOP_DIR"
  129. tar -C $SQOOP_DIR -xzf $SQOOP_CACHE
  130. export SQOOP_CONF_DIR=$SQOOP_HOME/server/conf
  131. rm -rf $SQOOP_DIR/sqoop
  132. ln -s $SQOOP_DIR/${SQOOP_VERSION} $SQOOP_DIR/sqoop
  133. # Change ports and hostnames to be configurable or replaceable
  134. sed -i'.bk' 's/12000/${test.port.http}/g' $SQOOP_CONF_DIR/server.xml
  135. sed -i'.bk' 's/12001/${test.port.shutdown}/g' $SQOOP_CONF_DIR/server.xml
  136. sed -i'.bk' 's/localhost/${test.host.local}/g' $SQOOP_CONF_DIR/server.xml
  137. sed -i'.bk' "s|\(common.loader.*$\)|\1,$HADOOP_DIR/hadoop/share/hadoop/common/lib/*.jar,$HADOOP_DIR/hadoop/share/hadoop/mapreduce1/*.jar,$HADOOP_DIR/hadoop/share/hadoop/mapreduce1/lib/*.jar|g" $SQOOP_CONF_DIR/catalina.properties
  138. sed -i'.bk' "s|\${catalina\.base}/logs|\${test.log.dir}|g" $SQOOP_CONF_DIR/logging.properties
  139. sed -i'.bk' "s|\@LOGDIR\@|\${test.log.dir}|g" $SQOOP_CONF_DIR/sqoop.properties
  140. sed -i'.bk' "s|\@BASEDIR\@|\${test.base.dir}|g" $SQOOP_CONF_DIR/sqoop.properties
  141. sed -i'.bk' "s|/etc/hadoop/conf|\${test.hadoop.conf.dir}|g" $SQOOP_CONF_DIR/sqoop.properties
  142. }