-
Notifications
You must be signed in to change notification settings - Fork 7
/
start-smackstack.sh
executable file
·324 lines (270 loc) · 7.64 KB
/
start-smackstack.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/bin/bash
#
# SCRIPT: start-smackstack.sh
#
# USAGE: start-smackstack.sh <no of public agents>
#
#
if [ "$1" != "" ]
then
PUBLIC_NODE_COUNT=$1
else
PUBLIC_NODE_COUNT=1
fi
echo
echo " ####################################"
echo " ### Using No of Public Agents: $PUBLIC_NODE_COUNT ###"
echo " ####################################"
echo
echo " #################################"
echo " ### Verifying DC/OS CLI Setup ###"
echo " #################################"
echo
# Make sure the DC/OS CLI is available
result=$(which dcos 2>&1)
if [[ "$result" == *"no dcos in"* ]]
then
echo
echo " ERROR: The DC/OS CLI program is not installed. Please install it."
echo " Follow the instructions found here: https://docs.mesosphere.com/1.10/cli/install/"
echo " Exiting."
echo
exit 1
fi
# Get DC/OS Master Node URL
MASTER_URL=$(dcos config show core.dcos_url 2>&1)
if [[ $MASTER_URL != *"http"* ]]
then
echo
echo " ERROR: The DC/OS Master Node URL is not set."
echo " Please set it using the 'dcos cluster setup' command."
echo " Exiting."
echo
exit 1
fi
# Check if the CLI is logged in
result=$(dcos node list 2>&1)
if [[ "$result" == *"No cluster is attached"* ]]
then
echo
echo " ERROR: No cluster is attached. Please use the 'dcos cluster attach' command "
echo " or use the 'dcos cluster setup' command."
echo " Exiting."
echo
exit 1
fi
if [[ "$result" == *"Authentication failed"* ]]
then
echo
echo " ERROR: Not logged in. Please log into the DC/OS cluster with the "
echo " command 'dcos auth login'"
echo " Exiting."
echo
exit 1
fi
if [[ "$result" == *"is unreachable"* ]]
then
echo
echo " ERROR: The DC/OS master node is not reachable. Is core.dcos_url set correctly?"
echo " Please set it using the 'dcos cluster setup' command."
echo " Exiting."
echo
exit 1
fi
echo
echo " DC/OS CLI Setup Correctly "
echo
echo
echo " #################################################"
echo " ### Checking for at least 8 Private Agents ###"
echo " #################################################"
echo
# Get the number of private agent nodes (total nodes - 1)
PRIV_NODE_COUNT=$(dcos node list | grep agent | wc -l)
if [ "$PRIV_NODE_COUNT" == "" ]
then
echo " ERROR: Number of private agent nodes was not found."
echo " Exiting."
echo
exit 1
fi
PRIV_NODE_COUNT=$((PRIV_NODE_COUNT-$PUBLIC_NODE_COUNT))
if [ "$PRIV_NODE_COUNT" -lt 8 ]
then
echo " ERROR: Number of private agent nodes must be 8 or more."
echo " Only showing $PRIV_NODE_COUNT private agent nodes."
echo " Exiting."
echo
exit 1
fi
echo
echo " DC/OS Agent Node Count is Sufficient."
echo
echo " ##############################"
echo " ### Starting Cassandra ###"
echo " ##############################"
echo
dcos package install --options=config/cassandra-options.json cassandra --yes
echo
echo " ##############################"
echo " ### Starting Kafka ###"
echo " ##############################"
echo
dcos package install --options=config/kafka-options.json kafka --yes
echo
echo " ##############################"
echo " ### Starting HDFS ###"
echo " ##############################"
echo
dcos package install --options=config/hdfs-options.json hdfs --yes
# Wait for all HDFS data node task to show status of R for running
echo
echo " Waiting for HDFS service to start. "
while true
do
# Get the number of data nodes
datanode_count=$(dcos task | grep hdfs__data- | wc -l)
if [ "$datanode_count" -gt 0 ]
then
last_datanode=$(($datanode_count-1))
task_status=$(dcos task |grep hdfs__data-${last_datanode}-node | awk '{print $4}')
if [ "$task_status" != "R" ]
then
printf "."
else
echo
echo " HDFS service is running."
break
fi
else
printf "."
fi
sleep 10
done
echo
echo " #################################"
echo " ### Creating HDFS directories ###"
echo " ### and test data ###"
echo " #################################"
echo
sleep 10
dcos marathon app add config/hdfs-setup-commands.json
echo
echo " Waiting for HDFS setup commands to complete. "
while true
do
std_out=$(dcos task log hdfs-setup-commands stdout 2>&1 | grep 'test-data.txt')
std_err=$(dcos task log hdfs-setup-commands stderr 2>&1 | grep 'test-data.txt')
if [[ $std_out == *"test-data.txt"* ]] || [[ $std_err == *"File exists"* ]]
then
echo " HDFS setup commands completed successfully."
break
else
printf "."
fi
sleep 10
done
dcos marathon app remove hdfs-setup-commands
echo
echo " #####################################"
echo " ### Starting Spark History Server ###"
echo " #####################################"
echo
sleep 2
dcos package install --options=config/spark-history-options.json spark-history --yes
echo
echo " Waiting for Spark History server to start. "
while true
do
task_status=$(dcos task |grep spark-history | awk '{print $4}')
if [ "$task_status" != "R" ]
then
printf "."
else
echo " Spark History server is running."
break
fi
sleep 10
done
echo
echo " ###############################################"
echo " ### Starting Spark External Shuffle Service ###"
echo " ###############################################"
echo
# Set the instance count as the number private agent nodes
sed "s/256/$PRIV_NODE_COUNT/" config/spark-shuffle.json > /tmp/spark-shuffle.json
# Start the service
dcos marathon app add /tmp/spark-shuffle.json
echo
echo " WPRIV_NODE_COUNT/aiting for Spark External Shuffle Service to start. "
while true
do
task_status=$(dcos task |grep spark-shuffle | awk '{print $4}' | grep R | wc -l)
if [ "$task_status" -ne $PRIV_NODE_COUNT ]
then
printf "."
else
echo " Spark External Shuffle Service is running."
break
fi
sleep 10
done
echo
echo " ##############################"
echo " ### Starting Spark Service ###"
echo " ##############################"
echo
# Start the spark service
dcos package install spark --options=config/spark-options.json --yes
# Wait for the spark service to get a running status
echo
echo " Waiting for Spark service to start. "
while true
do
task_status=$(dcos task |grep 'spark ' | awk '{print $4}')
if [ "$task_status" != "R" ]
then
printf "."
else
echo " Spark service is running."
break
fi
sleep 10
done
echo
echo " #############################################"
echo " ### Starting Kafka Producer and Consumer ###"
echo " #############################################"
echo
echo
echo " Waiting for Kafka service to start. "
while true
do
task_status=$(dcos task |grep 'kafka-0-broker ' | awk '{print $4}')
if [ "$task_status" != "R" ]
then
printf "."
else
echo " Kafka service is running."
break
fi
sleep 10
done
dcos kafka topic create my-topic --partitions=3 --replication=3
sleep 2
dcos marathon app add config/kafka-consumer.json
sleep 10
dcos kafka topic producer_test my-topic 100
echo
echo " #############################################################"
echo " ### SMACK Stack start up complete. ###"
echo " ### If you would like to run a Spark jobs that read ###"
echo " ### from the HDFS file system or from a Kafka queue, ###"
echo " ### run the following commands: ###"
echo " #############################################################"
echo
echo " $ scripts/run-sample-spark-hdfs-job.sh "
echo
echo " $ scripts/run-sample-spark-kafka-job.sh "
echo
# End of Script