-
Notifications
You must be signed in to change notification settings - Fork 0
/
cosmo.sh
233 lines (181 loc) · 5.39 KB
/
cosmo.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
#!/bin/bash -e
#########################################################
# MAPD module B // University of Padua, AY 2021/22
# Group 10 / Barone Nagaro Ninni Valentini
#
# This is a cluster manager for our MAPD project about
# streaming analysis of cosmic rays.
#
# --------------------------------------------------
# [!] please add to .bashrc the following lines:
#
# COSMO_CONFIG_PATH='config/localhost'
# cosmo() {
# YOUR_ABSOLUTE_PATH/cosmo.sh "$@"
# }
# export -f cosmo
# export COSMO_CONFIG_PATH
#
#--------------------------------------------------------
# coder: Barone Francesco, last edit: 19 jun 2022
# Open Access licence
#--------------------------------------------------------
# the binaries to use
COSMO_BINARIES='bin/cosmo'
cd $(dirname $0)
source $COSMO_BINARIES/general.sh
# select a config directory, this script will manage the rest
if [ -z "${COSMO_CONFIG_PATH+xxx}" ]; then
echo "config not set, using default";
COSMO_CONFIG_PATH='config/cloud'
fi
###########################
echo -e " ${cbBLUE}** COSMO **${cNC} - ver 1.0"
export COSMO_CONFIG_PATH
echo "loaded configuration: $COSMO_CONFIG_PATH"
echo -e "*****************************\n"
###########################
help() {
echo " routines _____"
echo " init | start Spark & Kafka cluster"
echo " run | execute the streaming analysis"
echo " halt | stop the streaming analysis"
echo " dismiss | stop cluster"
echo ""
echo " beat | heartbeat"
echo ""
echo " - alternatively, insert a specific function name (dev)"
echo " - type help_kafka to navigate the Kafka sources"
echo " - type wanda to ask for a fairly oddparent"
echo "-------------------------------------------------------"
echo " MAPD B: Group 10 // Barone, Nagaro, Ninni, Valentini"
echo " coded by Barone Francesco - @github.com/baronefr"
}
#####################
# general config #
#####################
read_ini
LAST_BCKPID=none
LOG_HIDDEN1='log/nohup1.log'
LOG_HIDDEN2='log/nohup2.log'
COSMO_SESSION='log/session.cosmo'
#####################
# dev functions #
#####################
kafka_deploy() {
$COSMO_BINARIES/kafka-deploy.sh
}
kafka_stop() {
$COSMO_BINARIES/kafka-stop.sh
}
kafka_status() {
$COSMO_BINARIES/kafka-status.sh "$@"
}
kafka_interact() {
$COSMO_BINARIES/kafka-interact.sh "$@"
}
dashboard() {
bokeh serve --show $DBOARD_BIN --port $DBOARD_UI --allow-websocket-origin=$SSH_HOSTNAME:$DBOARD_UI\
--args $COSMO_CONFIG_PATH/main.ini
}
dashboard_hidden() {
nohup bokeh serve --show $DBOARD_BIN --port $DBOARD_UI --allow-websocket-origin=$SSH_HOSTNAME:$DBOARD_UI\
--args $COSMO_CONFIG_PATH/main.ini > $LOG_HIDDEN1 2>&1 &
LAST_BCKPID=$!
}
stream_minidt() {
$DSTR_BIN $COSMO_CONFIG_PATH/main.ini
}
stream_minidt_hidden() {
nohup $DSTR_BIN $COSMO_CONFIG_PATH/main.ini > $LOG_HIDDEN1 2>&1 &
LAST_BCKPID=$!
}
stream_fake_analytics() {
echo -e "${cbRED}[ ERR ]: component deprecated${cNC} (development)"
#./bin/fake_analytics.py
}
spark_deploy() {
$SPARK_CLUSTER_ON
}
spark_stop() {
$SPARK_CLUSTER_OFF
}
spark_exe() {
$SPARK_EXE $COSMO_CONFIG_PATH/main.ini
}
spark_exe_hidden() {
nohup $SPARK_EXE $COSMO_CONFIG_PATH/main.ini > $LOG_HIDDEN2 2>&1 &
LAST_BCKPID=$!
}
#####################
# routines #
#####################
# no command prompted
if [ $# -eq 0 ]; then
help
exit 0
fi
# EXECUTE ROUTINES
if [ "$1" == "init" ]; then
### This routine initializes the Spark & Kafka servers
echo -e "${cbGREEN}deploy spark${cNC}"
spark_deploy
echo -e "\n${cbGREEN}deploy kafka${cNC}"
kafka_deploy
elif [ "$1" == "dismiss" ]; then
### This routine dismiss the clusters
echo -e "${cbRED}stop spark${cNC}"
spark_stop
echo -e "\n${cbRED}stop kafka${cNC}"
kafka_stop
elif [ "$1" == "run" ]; then
### This routine run the analysis
# create a session file (store the PIDs)
SESSION_ID="$(date)"
echo "spawn run on $SESSION_ID"
echo "COSMO | $SESSION_ID" > $COSMO_SESSION
echo -e "${cbYELLOW}spawn spark application${cNC}"
spark_exe_hidden
echo "spark/$LAST_BCKPID" >> $COSMO_SESSION
echo -e "${cbYELLOW}spawn dashboard${cNC}"
dashboard_hidden
echo "dashboard/$LAST_BCKPID" >> $COSMO_SESSION
echo 'wait spawn time...'
sleep $SPAWN_TIME
echo -e "\n${cbYELLOW}spawn minidt streamer${cNC}"
stream_minidt_hidden
echo "stream/$LAST_BCKPID" >> $COSMO_SESSION
elif [ "$1" == "halt" ]; then
### This routine stops the analysis
set +e
get_pid stream
echo -e "killing ${cbRED}stream${cNC} @ $READ_PID"
kill -9 $READ_PID
get_pid spark
echo -e "killing ${cbRED}spark${cNC} @ $READ_PID"
kill -9 $READ_PID
get_pid dashboard
echo -e "killing ${cbRED}dashboard${cNC} @ $READ_PID"
kill -9 $READ_PID
set -e
echo "halted $(date)" >> $COSMO_SESSION
elif [ "$1" == "beat" ]; then
# heartbeat routine
get_pid stream
check_pid 'stream' $READ_PID
get_pid spark
check_pid 'spark ' $READ_PID
get_pid dashboard
check_pid 'dash ' $READ_PID
elif [ "$1" == "help" ]; then
help
elif [ "$1" == "-h" ]; then
help
elif [ "$1" == "wanda" ]; then
cat $COSMO_BINARIES/fairy.ans
else
echo -e "${cYELLOW}dev mode${cNC}"
# execute function by name
$1 "${@:2}"
fi
exit 0