-
Notifications
You must be signed in to change notification settings - Fork 4
/
uploadHeatmaps.sh
executable file
·250 lines (235 loc) · 6.37 KB
/
uploadHeatmaps.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/bin/bash
#---------------------------------------------------
# bash uploadHeatmaps.sh <options>
# Description: This script manages the conversion and
# upload of heatmaps to a containerized
# pathdb instance of quip.
# Author(s): Joseph Balsamo
#---------------------------------------------------
#---------------------------------------------------
# Source Function Libraries
#---------------------------------------------------
source helpers.sh
source readpass.sh
#---------------------------------------------------
# Function Definitions
#---------------------------------------------------
#---------------------------------------------------
# Function: usage(brief)
# Description: Display help message. When true is passed
# it will show a brief version showing the
# bare minimum flags needed.
# parameters: brief
# usage: usage [true | false]
#---------------------------------------------------
function usage() {
echo "Usage: $ uploadHeatmaps.sh [options] -c <pathDB_collection>"
if [ $1 == false ]
then
echo " Options:"
echo " -c, --collection <pathDB_collection>: PathDB Collection for heatmaps (*this parameter required)"
echo " -i, --input <input_folder>: Folder where heatmaps are loaded from (default: /mnt/data/xfer/input)"
echo " -o, --output <output_folder>: Folder where converted heatmaps are imported from (default: /mnt/data/xfer/output)"
echo " -q, --quip-host <host>: ip or hostname of PathDB Server (default: quip-pathdb)"
echo " -h, --data-host <host>: ip or hostname of database (default: ca-mongo)"
echo " -m, --manifest <manifest name> (default: manifest.csv)"
echo " -d, --database <database name> (default: camic)"
echo " -p, --port <database port> (default: 27017)"
echo ""
echo " --help Display full help usage."
echo " Notes: requires mongoDB client tools installed on running server"
fi
}
#-----------------------------------------------------------------------
# End usage
#-----------------------------------------------------------------------
#---------------------------------------------------
# End Function Definitions
#---------------------------------------------------
#-----------------------------------------------------------------------
# Main Script
#-----------------------------------------------------------------------
# Set Default variables.
database="camic"
port="27017"
HOST="ca-mongo"
errcode=0
brief=true
# Loop through all command-line arguments.
while [ -n "$1" ]
# while loop starts
do
# Process command-line flags
# Start Case
case "$1" in
-q | --quip-host)
opterr="$(chk_opt ${2})"
if [ $opterr == 'true' ]
then
echo "Error: Missing parameter."
exit 5
else
qhost="$2"
shift
fi;;
-h | --data-host)
opterr="$(chk_opt ${2})"
if [ $opterr == 'true' ]
then
echo "Error: Missing parameter."
exit 5
else
host="$2"
shift
fi;;
-p | --port)
opterr="$(chk_opt ${2})"
if [ $opterr == 'true' ]
then
echo "Error: Missing parameter."
exit 5
else
port="$2"
shift
fi;;
-c | --collection)
opterr="$(chk_opt ${2})"
if [ $opterr == 'true' ]
then
echo "Error: Missing parameter."
exit 5
else
collection="$2"
shift
fi;;
-m | --manifest)
opterr="$(chk_opt ${2})"
if [ $opterr == 'true' ]
then
echo "Error: Missing parameter."
exit 5
else
manifest="$2"
shift
fi;;
-i | --input)
opterr="$(chk_opt ${2})"
if [ $opterr == 'true' ]
then
echo "Error: Missing parameter."
exit 5
else
in="$2"
shift
fi;;
-o | --output)
opterr="$(chk_opt ${2})"
if [ $opterr == 'true' ]
then
echo "Error: Missing parameter."
exit 5
else
out=${2}
shift
fi;;
-d | --database)
opterr="$(chk_opt ${2})"
if [ $opterr == 'true' ]
then
echo "Error: Missing parameter."
exit 5
else
database=${2}
shift
fi;;
--help)
usage false
exit 0;;
*) usage true;;
esac
# End of Case
shift
done
# End of While
if [ -z "${collection}" ]
then
echo "Missing required parameter"
usage true
exit 1
fi
# Set default values for unprovided options.
if [ -z "${host}" ]
then
host="ca-mongo"
fi
if [ -z "${qhost}" ]
then
qhost="quip-pathdb"
fi
if [ -z "${manifest}" ]
then
manifest="manifest.csv"
fi
if [ -z "${in}" ]
then
in="/mnt/data/heatmaps/input"
fi
if [ -z "${out}" ]
then
out="/mnt/data/heatmaps/output"
fi
if [ -z "${port}" ]
then
port="27017"
fi
if [ -z "${database}" ]
then
database="camic"
fi
# Check that input and output folders exist.
if [ ! -d "/mnt/data/heatmaps/${in}" ]
then
echo "Error: Input folder does not exist."
exit 2
fi
if [ ! -d "/mnt/data/heatmaps/${out}" ]
then
echo "Error: Output folder does not exist."
exit 3
fi
# Check that manifest file exists
if [ ! -f "/mnt/data/heatmaps/${in}/${manifest}" ]
then
echo "Error: Manifest does not exist."
exit 2
fi
# Request username and password for upload.
uname="$(getPrompt 'Username:')"
passw="$(getPass 'Password:')"
echo
echo
# Verify that PathDB Server is reachable using current username/password combo
ret_code="$(curl -Is http://${qhost}/user | head -1 | awk '{ print $2 }')"
if [ ! $ret_code -lt 400 ]
then
echo "Error: PathDB Server is unreachable."
exit 100
fi
# Convert heatmap data in the 'in' folder into uploadable json in the 'out' folder.
node --max_old_space_size=16384 /usr/local/bin/convert_heatmaps.js -h ${qhost} -c ${collection} -m ${manifest} -i ${in} -o ${out} -u ${uname} -p ${passw}
exitStatus=$?
uploadDir="/mnt/data/heatmaps/${out}"
# Check to see conversion process succeeded.
if [[ $exitStatus -eq 0 ]]
then
# Import into the quip database
for filename in ${uploadDir}/*.json ; do
mongoimport --port ${port} --host ${host} -d ${database} -c heatmap ${filename}
done
else
# Slightly safer delete
rm -f ${uploadDir}/*.json
exit $exitStatus
fi
# exit normally
exit 0