/
launch-mapr-cluster.sh
executable file
·311 lines (264 loc) · 8.29 KB
/
launch-mapr-cluster.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/bash
#
# Script to launch a MapR cluster in the Google Cloud Environment.
# Cluster configuration defined in simple file of the form
# ${NODE_NAME_ROOT}<index>:<packages>
# for all the nodes you desire. The 'mapr-' prefix is not necessary
# for the packages. Any line that does NOT start with ${NODE_NAME_ROOT}
# is treated as a comment.
#
# A sample config file is
# node0:zookeeper,cldb,fileserver,tasktracker,nfs,webserver
# node1:zookeeper,cldb,fileserver,tasktracker,nfs
# node2:zookeeper,jobtracker,fileserver,tasktracker,nfs
#
# By default, the nodes will be given hostnames equivalent to the
# name specification (eg "node0", "node1", "node2" in the above example).
# The base hostname can be overridden with the "--node-name" option.
#
# Data disks default to ephemeral, but persistent disks can
# be requested on the command line and automatically allocated.
#
# Assumptions:
# gcloud tool is in the PATH
#
# Tricks
# Pass in prepare-mapr-image.sh script as metadata ... to be used
# in case user selects an image WITHOUT the MapR software
# Downside: this prevents easy sharing of ssh keys between mapr users
#
PROGRAM=$0
NODE_NAME_ROOT=node # used in config file to define nodes for deployment
usage() {
echo "
Usage:
$PROGRAM
--cluster <clustername>
--mapr-version <version, eg 3.1.1, 4.1.0>
--config-file <cfg-file>
--image image_name
--machine-type <machine-type>
--persistent-disks <nxm> # N disks of M gigabytes
--zone zone
[ --project <GCE Project ID> # uses gcloud config default ]
[ --node-name <name-prefix> # hostname prefix for cluster nodes ]
[ --license-file <license to be installed> ]
"
echo ""
echo "EXAMPLES"
echo "$0 --cluster ProdCluster --mapr-version 3.0.3 --config-file 3node.lst --node-name prod --image debian-7-wheezy --machine-type n1-highmem-2 --persistent-disks 4x256"
}
# Build up the disk argument CAREFULLY ... the shell
# addition of extra ' and " characters really confuses the
# final invocation of gcloud
#
# We could be smarter about error handling, but it's safer
# to simply ignore any disk where there is a problem creating
# it (since the most common error during our development was
# that the disk had already been created).
create_persistent_data_disks() {
targetNode=$1
# Compute the disk specifications ...
# N disks of size S from the pdisk parameter
ndisk="${pdisk%x*}"
dsize="${pdisk#*x}"
[ -z "${dsize:-}" -o "${dsize:-0}" -le 0 ] && ndisk=""
[ -z "${targetNode}" ] && return 1
[ -z "${ndisk:-}" -o "${ndisk:-0}" -le 0 ] && return 1
pdisk_args=""
for d in $(seq 1 $ndisk)
do
diskname=${targetNode}-pdisk-${d}
gcloud compute disks list ${project_arg:-} --zone $zone \
--regexp "$diskname" \
| grep -q $diskname
if [ $? -eq 0 ] ; then
pdisk_args=${pdisk_args}' '--disk' 'name=$diskname' 'mode=rw
else
gcloud compute disks create \
$diskname \
${project_arg:-} \
--zone $zone \
--size ${dsize}GB
if [ $? -eq 0 ] ; then
pdisk_args=${pdisk_args}' '--disk' 'name=$diskname' 'mode=rw
fi
fi
done
export pdisk_args
}
#
# MAIN
#
if [ $# -lt 4 ]
then
usage
exit 1
fi
while [ $# -gt 0 ]
do
case $1 in
--cluster) cluster=$2 ;;
--mapr-version) maprversion=$2 ;;
--config-file) configFile=$2 ;;
--node-name) nodeName=$2 ;;
--project) project=$2 ;;
--zone) zone=$2 ;;
--image) image=$2 ;;
--machine-type) machinetype=$2 ;;
--license-file) licenseFile=$2 ;;
--persistent-disks) pdisk=$2 ;;
*)
echo "****" Bad argument: $1
usage
exit ;;
esac
shift 2
done
echo ""
# Defaults
maprversion=${maprversion:-"4.1.0"}
machinetype=${machinetype:-"n1-standard-2"}
zone=${zone:-"us-central1-b"}
if [ -n "${image:-}" ] ; then
maprimage=$image
else
echo "ERROR: No image specified; aborting cluster creation"
exit 1
fi
if [ "${machinetype%-d}" = "${machinetype}" ] ; then
if [ -z "${pdisk:-}" ] ; then
echo "ERROR: No persistent disks specified for diskless machine type ($machinetype);"
echo " aborting cluster creation"
exit 1
fi
fi
# TBD
# Validate the presense/accessibility of the image
# TBD
# Error check input parameters
# Assemble the data we'll need to pass in to each node
#
# The ZK and CLDB host settings are easy, since GCE will set up
# micro-dns to make our assigned hostnames consistent across the deployed
# nodes.
#
# ResourceManager and History server nodes are necessary only for
# MapR 4.0 and later; we'll look for them for every cluster, though.
#
# DOWNSIDE : be careful not to launch multiple clusters with the same
# hostname defaults.
#
zknodes=`grep ^$NODE_NAME_ROOT $configFile | grep zookeeper | cut -f1 -d:`
for zkh in `echo $zknodes` ; do
zkidx=${zkh#${NODE_NAME_ROOT}}
[ -n "${nodeName:-}" ] && zkh=${nodeName}$zkidx
if [ -n "${zkhosts:-}" ] ; then zkhosts=$zkhosts','$zkh
else zkhosts=$zkh
fi
done
cldbnodes=`grep ^$NODE_NAME_ROOT $configFile | grep cldb | cut -f1 -d:`
for cldbh in `echo $cldbnodes` ; do
cldbidx=${cldbh#${NODE_NAME_ROOT}}
[ -n "${nodeName:-}" ] && cldbh=${nodeName}$cldbidx
if [ -n "${cldbhosts:-}" ] ; then cldbhosts=$cldbhosts','$cldbh
else cldbhosts=$cldbh
fi
done
rmnodes=`grep ^$NODE_NAME_ROOT $configFile | grep resourcemanager | cut -f1 -d:`
for rmh in `echo $rmnodes` ; do
rmidx=${rmh#${NODE_NAME_ROOT}}
[ -n "${nodeName:-}" ] && rmh=${nodeName}$rmidx
if [ -n "${rmhosts:-}" ] ; then rmhosts=$rmhosts','$rmh
else rmhosts=$rmh
fi
done
hsnode=`grep ^$NODE_NAME_ROOT $configFile | grep historyserver | head -1 | cut -f1 -d:`
if [ -n "$hsnode" ] ; then
hsidx=${hsnode#${NODE_NAME_ROOT}}
[ -n "${nodeName:-}" ] && hsnode=${nodeName}$hsidx
fi
# Grab just one metrics node to run the MySQL service
metricsnode=`grep ^$NODE_NAME_ROOT $configFile | grep metrics | head -1 | cut -f1 -d:`
if [ -n "$metricsnode" ] ; then
metricsidx=${metricsnode#${NODE_NAME_ROOT}}
[ -n "${nodeName:-}" ] && metricsnode=${nodeName}$metricsidx
fi
# TBD
# Make sure there are an odd number of zookeepers and at least one CLDB
echo CHECK: -----
echo " project-id ${project:-default}"
echo " cluster $cluster"
echo " mapr-version $maprversion"
echo " config-file $configFile"
echo " cldb: $cldbhosts"
echo " zk: $zkhosts"
echo " image $maprimage"
echo " machine $machinetype"
echo " zone $zone"
echo OPTIONAL: -----
echo " node-name ${nodeName:-none}"
echo " licenseFile ${licenseFile:-none}"
echo " persistent-disks ${pdisk:-none}"
echo -----
echo "Proceed {y/N} ? "
read YoN
if [ -z "${YoN:-}" -o -n "${YoN%[yY]*}" ] ; then
exit 1
fi
# Set gcloud args based on input
[ -n "$project" ] && project_arg="--project $project"
# Only add metadata for metrics if we have Metrics configured
if [ -n "${metricsnode:-}" ] ; then
metrics_args="maprmetricsserver=${metricsnode:-} maprmetricsdb=maprmetrics"
fi
# Only add license arg if file exists
if [ -n "${licenseFile}" ] ; then
[ -f "${licenseFile}" ] && \
license_args="maprlicense=${licenseFile}"
fi
# Since the format of each hostline is so simple (<node>:<packages>),
# it's safer to simply parse it ourselves.
grep ^$NODE_NAME_ROOT $configFile | \
while read hostline
do
host="${hostline%:*}"
packages="${hostline#*:}"
idx=${host#${NODE_NAME_ROOT}}
[ -n "${nodeName:-}" ] && host=${nodeName}$idx
echo "Launch $host with $packages"
if [ -n "${pdisk:-}" ] ; then
echo ""
echo " Creating persistent data volumes first ($pdisk)"
create_persistent_data_disks $host
# Side effect ... pdisk_args is set
#
# An empty "pdisk_args" implies failed storage creation ...
# so don't proceed with instance creation.
[ -z "$pdisk_args" ] && continue
fi
gcloud compute instances create $host \
${project_arg:-} \
--image $maprimage \
--machine-type $machinetype \
--zone $zone \
${pdisk_args:-} \
--metadata-from-file \
startup-script=configure-mapr-instance.sh \
maprimagerscript=prepare-mapr-image.sh \
${license_args:-} \
--metadata \
maprversion=${maprversion} \
maprpackages=${packages//,/:} \
${metrics_args:-} \
cluster=${cluster} \
zknodes=${zkhosts//,/:} \
cldbnodes=${cldbhosts//,/:} \
rmnodes=${rmhosts//,/:} \
hsnode=${hsnode} \
--scopes storage-full &
done
wait
echo ""
gcloud compute instances list ${project_arg:-} --zone $zone \
| grep ^${host%${idx}}