forked from sanilcg/dr-elephant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.sh
executable file
·112 lines (87 loc) · 2.65 KB
/
compile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
#
# Copyright 2016 LinkedIn Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
function print_usage(){
echo "usage: ./compile.sh PATH_TO_CONFIG_FILE(optional)"
}
function play_command() {
if type activator 2>/dev/null; then
activator "$@"
else
play "$@"
fi
}
# Default configurations
HADOOP_VERSION="2.3.0"
SPARK_VERSION="1.4.0"
# User should pass an optional argument which is a path to config file
if [ -z "$1" ];
then
echo "Using the default configuration"
else
CONF_FILE_PATH=$1
echo "Using config file: "$CONF_FILE_PATH
# User must give a valid file as argument
if [ -f $CONF_FILE_PATH ];
then
echo "Reading from config file..."
else
echo "error: Couldn't find a valid config file at: " $CONF_FILE_PATH
print_usage
exit 1
fi
source $CONF_FILE_PATH
# Fetch the Hadoop version
if [ -n "${hadoop_version}" ]; then
HADOOP_VERSION=${hadoop_version}
fi
# Fetch the Spark version
if [ -n "${spark_version}" ]; then
SPARK_VERSION=${spark_version}
fi
# Fetch other play opts
if [ -n "${play_opts}" ]; then
PLAY_OPTS=${play_opts}
fi
fi
echo "Hadoop Version : $HADOOP_VERSION"
echo "Spark Version : $SPARK_VERSION"
echo "Other opts set : $PLAY_OPTS"
OPTS+=" -Dhadoopversion=$HADOOP_VERSION"
OPTS+=" -Dsparkversion=$SPARK_VERSION"
OPTS+=" $PLAY_OPTS"
set -x
trap "exit" SIGINT SIGTERM
project_root=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd ${project_root}
start_script=${project_root}/scripts/start.sh
stop_script=${project_root}/scripts/stop.sh
# Echo the value of pwd in the script so that it is clear what is being removed.
rm -rf ${project_root}/dist
mkdir dist
play_command $OPTS clean test compile dist
cd target/universal
ZIP_NAME=`/bin/ls *.zip`
unzip ${ZIP_NAME}
rm ${ZIP_NAME}
DIST_NAME=${ZIP_NAME%.zip}
chmod +x ${DIST_NAME}/bin/dr-elephant
# Append hadoop classpath and the ELEPHANT_CONF_DIR to the Classpath
sed -i.bak $'/declare -r app_classpath/s/.$/:`hadoop classpath`:${ELEPHANT_CONF_DIR}"/' ${DIST_NAME}/bin/dr-elephant
cp $start_script ${DIST_NAME}/bin/
cp $stop_script ${DIST_NAME}/bin/
zip -r ${DIST_NAME}.zip ${DIST_NAME}
mv ${DIST_NAME}.zip ${project_root}/dist/