-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsavi-create-job-template
executable file
·159 lines (132 loc) · 4.22 KB
/
savi-create-job-template
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash -f
#
# This script uploads the application artifacts to Sahara, and create
# the corresponding job binary objects and a job template.
#
# Prerequisite:
# * Your Testbed's credentials was exported.
desc="This script uploads the application artifacts to Sahara, and create
the corresponding job binary objects and the job template.
"
script_name=`basename $0`
usage="Usage:
1. ${script_name} Java <jar_file> [additional_library]
2. ${script_name} Pig <pig_script> [additional_library]
3. ${script_name} help
"
if [[ -n "$1" && $1 == "help" ]]; then
echo "${desc}"
echo "${usage}"
exit
fi
source /home/savitb/bin/functions
function command_output_desc() {
OUT=$?
if [ $OUT -eq 0 ];then
echo "Succeeded."
else
echo $1
blue_desc "Failed!"
exit 1
fi
}
# Check the prerequisite.
if [ -z "$OS_USERNAME" ]; then
echo "The environment variable OS_USERNAME is not set."
exit 1
fi
if [ -z "$OS_PASSWORD" ]; then
echo "The environment variable OS_PASSWORD is not set."
exit 1
fi
if [ -z "$OS_AUTH_URL" ]; then
echo "The environment variable OS_AUTH_URL is not set."
exit 1
fi
if [ -z "$OS_TENANT_NAME" ]; then
echo "The environment variable OS_TENANT_NAME is not set."
exit 1
fi
if [ -z "$OS_REGION_NAME" ]; then
echo "The environment variable OS_REGION_NAME is not set."
exit 1
fi
# Check parameters.
unset ERR
if [ -n "$1" ]; then
job_type=$1
shift
else
ERR=1
fi
if [ -n "$1" ]; then
main_binary=$1
shift
else
ERR=1
fi
if [ -n "$1" ]; then
additional_binary=$1
shift
fi
if [ -n "$ERR" ]; then
echo "One or multiple arguments were missing."
echo ""
echo "${usage}"
exit 1
fi
if [[ "$job_type" != "Java" && "$job_type" != "Pig" ]]; then
echo "Error: '${job_type}' is not a valid job type. Only 'Java' and 'Pig' are allowed."
exit 1
fi
blue_desc_title " Create job template"
# Thhis step uploads application artifacts to Sahara, and creates job binary
# objects that store their location.
green_desc_title "1. Creating job binaries ..."
# Upload the main binary file to Sahara.
command="sahara job-binary-data-create --file ${main_binary}"
yellow_desc "${command}"
output=`eval ${command}`
command_output_desc "$output"
binary_data_id=`echo ${output} | awk '/ id / {print $9}'`
binary_name=`basename ${main_binary}`
# Create a job binary object that stores the location of the uploaded file.
command="sahara job-binary-create --name ${binary_name} --url internal-db://${binary_data_id}"
yellow_desc "${command}"
output=`eval ${command}`
command_output_desc "$output"
main_binary_id=`sahara job-binary-show --name ${binary_name} | awk '/ id /{print $4}'`
if [ -n "$additional_binary" ]; then
# If user specified an additoinal binary file, we process it as well.
command="sahara job-binary-data-create --file ${additional_binary}"
yellow_desc "${command}"
output=`eval ${command}`
command_output_desc "$output"
binary_data_id=`echo ${output} | awk '/ id /{print $9}'`
binary_name=`basename ${additional_binary}`
command="sahara job-binary-create --name ${binary_name} --url internal-db://${binary_data_id}"
yellow_desc "${command}"
output=`eval ${command}`
command_output_desc "$output"
additional_binary_id=`sahara job-binary-show --name ${binary_name} | awk '/ id /{print $4}'`
fi
green_desc_title "2. Creating a job template ..."
# We choose the name of the job template based on the name of the main binary.
# E.g. if the main binary is "path/to/myapp.jar", the job template name will be "myapp".
template_name=`basename ${main_binary} | sed 's/\.[^.]*$//'`
if [ $job_type = "Java" ]; then
command="sahara job-template-create --name ${template_name} --type ${job_type} --lib ${main_binary_id}"
if [ -n "$additional_binary_id" ]; then
command="${command} --lib ${additional_binary_id}"
fi
elif [ $job_type = "Pig" ]; then
command="sahara job-template-create --name ${template_name} --type ${job_type} --main ${main_binary_id}"
if [ -n "$additional_binary_id" ]; then
command="${command} --lib ${additional_binary_id}"
fi
fi
yellow_desc "${command}"
output=`eval ${command}`
command_output_desc "$output"
echo ""
blue_desc "Job template was created."