-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlaunch-admin-training-cluster.sh
executable file
·208 lines (175 loc) · 4.84 KB
/
launch-admin-training-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
#!/bin/bash
#
# Script to launch a cluster in the Google Cloud Environment for
# use in the On-Demand Training regiman.
#
# This is simply a short-circuit of the usual launch-mapr-cluster.sh
# logic, since all that needs to be done is initialize the nodes for
# manual software installation/configuration. We have kept the
# same basic structure just to simplify the user experience.
#
# Assumptions:
# gcloud tool is in the PATH
#
#
PROGRAM=$0
NODE_NAME_ROOT=node # used in config file to define nodes for deployment
usage() {
echo "
Usage:
$PROGRAM
--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 ]
"
echo ""
echo "EXAMPLES"
echo "$0 --config-file 3node.lst --node-name odt --image centos-6 --machine-type n1-highmem-2 --persistent-disks 2x256"
}
# 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
echo CHECK: -----
echo " project-id ${project:-default}"
echo " config-file $configFile"
echo " image $maprimage"
echo " machine $machinetype"
echo " zone $zone"
echo OPTIONAL: -----
echo " node-name ${nodeName:-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"
# 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"
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=prepare-mapr-image.sh \
--metadata \
maprversion=${maprversion} \
maprpackages=none \
--scopes storage-full &
done
wait
echo ""
gcloud compute instances list ${project_arg:-} --zone $zone \
| grep ^${host%${idx}}