-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsavi-create-data-sources
executable file
·168 lines (140 loc) · 4.33 KB
/
savi-create-data-sources
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
160
161
162
163
164
165
166
167
168
#!/bin/bash -f
#
# This script creates the data source objects that store the location of the
# specified input and output data.
#
# Prerequisite:
# * Your Testbed's credentials was exported.
desc="This script creates the data source objects that store the location of the
specified input and output data.
"
script_name=`basename $0`
usage="Usage:
1. ${script_name} swift <container> <input_object> <output_object>
2. ${script_name} hdfs <cluster_name> <input_path> <output_path>
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
ds_type=$1
shift
else
ERR=1
fi
if [ -n "$1" ]; then
second_param=$1
shift
else
ERR=1
fi
if [ -n "$1" ]; then
input_path=$1
shift
else
ERR=1
fi
if [ -n "$1" ]; then
output_path=$1
shift
else
ERR=1
fi
if [ -n "$ERR" ]; then
echo "One or multiple arguments were missing."
echo ""
echo "${usage}"
exit 1
fi
# Remove the leading character '/' at path if any.
# For example, convert '/path/to/file' to 'path/to/file'.
input_path=`echo ${input_path} | sed 's/^\///'`
output_path=`echo ${output_path} | sed 's/^\///'`
input_file=`basename ${input_path}`
output_file=`basename ${output_path}`
blue_desc_title " Creating data sources"
if [ $ds_type = "swift" ]; then
container_name="${second_param}"
input_url="swift://${container_name}.sahara/${input_path}"
output_url="swift://${container_name}.sahara/${output_path}"
green_desc_title "1. Creating the input data source object ..."
# Create the data source object that store the location of the input data.
command="sahara data-source-create --name ${input_file} --type ${ds_type} --user ${OS_USERNAME} --password ${OS_PASSWORD}
--url ${input_url}"
yellow_desc "${command}"
output=`eval ${command}`
command_output_desc "${output}"
green_desc_title "2. Creating the output data source object ..."
# Create the data source object that store the location of the output data.
command="sahara data-source-create --name ${output_file} --type ${ds_type} --user ${OS_USERNAME} --password ${OS_PASSWORD}
--url ${output_url}"
yellow_desc "${command}"
output=`eval ${command}`
command_output_desc "${output}"
elif [ $ds_type = "hdfs" ]; then
cluster_name="${second_param}"
# Retrieve the IP address of the master node of the cluster.
master_ip=`sahara cluster-show --name ${cluster_name} 2>/dev/null | awk -F'[:/]' '/Oozie/{print $5}'`
if [ -z "$master_ip" ]; then
echo "Error: cannot find cluster '${cluster_name}'."
exit 1
fi
input_url="hdfs://${master_ip}:9000/${input_path}"
output_url="hdfs://${master_ip}:9000/${output_path}"
green_desc_title "1. Creating the input data source object ..."
# Create the data source object that store the location of the input data.
command="sahara data-source-create --name ${input_file} --type ${ds_type} --url ${input_url}"
yellow_desc "${command}"
output=`eval ${command}`
command_output_desc "${output}"
green_desc_title "2. Creating the output data source object ..."
# Create the data source object that store the location of the output data.
command="sahara data-source-create --name ${output_file} --type ${ds_type} --url ${output_url}"
yellow_desc "${command}"
output=`eval ${command}`
command_output_desc "${output}"
else
echo "Invalid data source type '${ds_type}'."
echo ""
echo "${usage}"
exit 1
fi
echo ""
blue_desc "Data sources were created."