-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathmy-functions.sh
304 lines (276 loc) · 10.1 KB
/
my-functions.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
#!/usr/bin/env bash
TIMEOUT=120
# -- wait_for_container_log --
# $1: docker container name
# S2: spring value to wait to appear in container logs
# wait_for_container_log_exec_time: global variable that contains the execution time needed to wait for the string to appear
# wait_for_container_log_matched_row: global variable that contains the log row matched
function wait_for_container_log() {
local log_waiting="Waiting for string '$2' in the $1 logs ..."
echo "${log_waiting} It will timeout in ${TIMEOUT}s"
SECONDS=0
while true ; do
local log=$(docker logs $1 2>&1 | grep "$2")
if [ -n "$log" ] ; then
echo $log
wait_for_container_log_exec_time="${SECONDS}s"
wait_for_container_log_matched_row=$log
break
fi
if [ $SECONDS -ge $TIMEOUT ] ; then
echo "${log_waiting} TIMEOUT"
wait_for_container_log_exec_time="999999"
wait_for_container_log_matched_row=""
break
fi
sleep 1
done
}
# -- extract_startup_time_from_log --
# $1: log row
# $2: awk command to parse the log and extract the time
function extract_startup_time_from_log() {
echo "$1" | awk "$2"
}
# -- get_container_memory_usage --
# $1: docker container name
function get_container_memory_usage() {
while true ; do
local log=$(docker stats --no-stream 2>&1 | grep $1)
if [ -n "$log" ] ; then
echo $log | awk '{print $4"/"$6"("$7")"}'
break
fi
sleep 1
done
}
# -- wait_for_container_status_healthy --
# $1: docker container port
function wait_for_container_status_healthy() {
echo "Waiting for container with port $1 to be 'healthy' ..."
while true ; do
local log=$(docker ps | grep -E "healthy.*$1")
if [ -n "$log" ] ; then
echo $log
break
fi
sleep 1
done
}
# -- run_command --
# $1: command to run
# $run_command_exec_time: global variable that contains the last execution time of the function
function run_command() {
SECONDS=0 ; eval $1 ; run_command_exec_time="${SECONDS}s"
}
# -- convert_seconds_to_millis --
# $1: value number in seconds without any suffix
function convert_seconds_to_millis() {
echo "scale=0 ; ($1 * 1000)/1" | bc -l
}
# -- get_docker_size --
# $1: docker container name
function get_docker_size() {
echo $(docker images $1 --format='{{println .Size}}')
}
# -- get_folder_file_size --
# $1: file path
function get_folder_file_size() {
echo $(du -hs "$1" | awk '{ print $1 }')
}
# -- package_jar_build_image --
# $1: jar clean command
# $2: jar package/assemble command
# $3: output jar file path
# $4: docker command
# $5: docker image
function package_jar_build_image() {
eval "$1"
run_command "$2"
package_jar_build_image_packaging_time=$run_command_exec_time
package_jar_build_image_jar_size=$(get_folder_file_size "$3")
run_command "$4"
package_jar_build_image_building_time=$run_command_exec_time
package_jar_build_image_docker_image_size=$(get_docker_size $5)
}
# -- warm_up --
# $1: number of times
# $2: command to run
function warm_up() {
echo
echo "-- Begin: ab test warm-up"
x=$1
while [ $x -gt 0 ]; do
eval $2
x=$(($x-1))
done
echo "-- End: ab test warm-up"
echo
}
# -- check_docker_manager_script_input_parameter --
# $1: input parameter
function check_docker_manager_script_input_parameter() {
if [ "$1" != "all" ] &&
[ "$1" != "quarkus" ] &&
[ "$1" != "micronaut" ] &&
[ "$1" != "springboot" ] &&
[ "$1" != "simple-api" ] &&
[ "$1" != "jpa-mysql" ] &&
[ "$1" != "kafka" ] &&
[ "$1" != "elasticsearch" ] &&
[ "$1" != "quarkus-simple-api" ] &&
[ "$1" != "micronaut-simple-api" ] &&
[ "$1" != "springboot-simple-api" ] &&
[ "$1" != "quarkus-jpa-mysql" ] &&
[ "$1" != "micronaut-jpa-mysql" ] &&
[ "$1" != "springboot-jpa-mysql" ] &&
[ "$1" != "quarkus-kafka" ] &&
[ "$1" != "micronaut-kafka" ] &&
[ "$1" != "springboot-kafka" ] &&
[ "$1" != "quarkus-kafka-producer" ] &&
[ "$1" != "quarkus-kafka-consumer" ] &&
[ "$1" != "micronaut-kafka-producer" ] &&
[ "$1" != "micronaut-kafka-consumer" ] &&
[ "$1" != "springboot-kafka-producer" ] &&
[ "$1" != "springboot-kafka-consumer" ] &&
[ "$1" != "quarkus-elasticsearch" ] &&
[ "$1" != "micronaut-elasticsearch" ] &&
[ "$1" != "springboot-elasticsearch" ];
then
printf "Invalid Java Framework, application name or type provided!"
printf "\nValid Parameters:"
printf "\n\tall"
printf "\n\tsimple-api\tjpa-mysql\tkafka\telasticsearch"
printf "\n\tquarkus"
printf "\n\t\tquarkus-simple-api"
printf "\n\t\tquarkus-jpa-mysql"
printf "\n\t\tquarkus-kafka"
printf "\n\t\t\tquarkus-kafka-producer"
printf "\n\t\t\tquarkus-kafka-consumer"
printf "\n\t\tquarkus-elasticsearch"
printf "\n\tmicronaut"
printf "\n\t\tmicronaut-simple-api"
printf "\n\t\tmicronaut-jpa-mysql"
printf "\n\t\tmicronaut-kafka"
printf "\n\t\t\tmicronaut-kafka-producer"
printf "\n\t\t\tmicronaut-kafka-consumer"
printf "\n\t\tmicronaut-elasticsearch"
printf "\n\tspringboot"
printf "\n\t\tspringboot-simple-api"
printf "\n\t\tspringboot-jpa-mysql"
printf "\n\t\tspringboot-kafka"
printf "\n\t\t\tspringboot-kafka-producer"
printf "\n\t\t\tspringboot-kafka-consumer"
printf "\n\t\tspringboot-elasticsearch"
printf "\n"
exit 1
fi
}
# -- check_runner_script_input_parameter --
# $1: input parameter
function check_runner_script_input_parameter() {
if [ "$1" != "all" ] &&
[ "$1" != "jvm" ] &&
[ "$1" != "native" ] &&
[ "$1" != "quarkus" ] &&
[ "$1" != "micronaut" ] &&
[ "$1" != "springboot" ] &&
[ "$1" != "quarkus-jvm" ] &&
[ "$1" != "micronaut-jvm" ] &&
[ "$1" != "springboot-jvm" ] &&
[ "$1" != "quarkus-native" ] &&
[ "$1" != "micronaut-native" ] &&
[ "$1" != "springboot-native" ] &&
[ "$1" != "simple-api" ] &&
[ "$1" != "jpa-mysql" ] &&
[ "$1" != "kafka" ] &&
[ "$1" != "elasticsearch" ] &&
[ "$1" != "simple-api-jvm" ] &&
[ "$1" != "jpa-mysql-jvm" ] &&
[ "$1" != "kafka-jvm" ] &&
[ "$1" != "elasticsearch-jvm" ] &&
[ "$1" != "simple-api-native" ] &&
[ "$1" != "jpa-mysql-native" ] &&
[ "$1" != "kafka-native" ] &&
[ "$1" != "elasticsearch-native" ] &&
[ "$1" != "quarkus-simple-api" ] &&
[ "$1" != "micronaut-simple-api" ] &&
[ "$1" != "springboot-simple-api" ] &&
[ "$1" != "quarkus-jpa-mysql" ] &&
[ "$1" != "micronaut-jpa-mysql" ] &&
[ "$1" != "springboot-jpa-mysql" ] &&
[ "$1" != "quarkus-kafka" ] &&
[ "$1" != "micronaut-kafka" ] &&
[ "$1" != "springboot-kafka" ] &&
[ "$1" != "quarkus-elasticsearch" ] &&
[ "$1" != "micronaut-elasticsearch" ] &&
[ "$1" != "springboot-elasticsearch" ] &&
[ "$1" != "quarkus-simple-api-jvm" ] && [ "$1" != "quarkus-simple-api-native" ] &&
[ "$1" != "micronaut-simple-api-jvm" ] && [ "$1" != "micronaut-simple-api-native" ] &&
[ "$1" != "springboot-simple-api-jvm" ] && [ "$1" != "springboot-simple-api-native" ] &&
[ "$1" != "quarkus-jpa-mysql-jvm" ] && [ "$1" != "quarkus-jpa-mysql-native" ] &&
[ "$1" != "micronaut-jpa-mysql-jvm" ] && [ "$1" != "micronaut-jpa-mysql-native" ] &&
[ "$1" != "springboot-jpa-mysql-jvm" ] && [ "$1" != "springboot-jpa-mysql-native" ] &&
[ "$1" != "quarkus-kafka-jvm" ] && [ "$1" != "quarkus-kafka-native" ] &&
[ "$1" != "micronaut-kafka-jvm" ] && [ "$1" != "micronaut-kafka-native" ] &&
[ "$1" != "springboot-kafka-jvm" ] && [ "$1" != "springboot-kafka-native" ] &&
[ "$1" != "quarkus-elasticsearch-jvm" ] && [ "$1" != "quarkus-elasticsearch-native" ] &&
[ "$1" != "micronaut-elasticsearch-jvm" ] && [ "$1" != "micronaut-elasticsearch-native" ] &&
[ "$1" != "springboot-elasticsearch-jvm" ] && [ "$1" != "springboot-elasticsearch-native" ];
then
printf "Invalid Java Framework, application name or type provided!"
printf "\nValid Parameters:"
printf "\n\tall"
printf "\n\tjvm\tnative"
printf "\n\tsimple-api\tjpa-mysql\tkafka\telasticsearch"
printf "\n\tsimple-api-jvm\tjpa-mysql-jvm\tkafka-jvm\telasticsearch-jvm"
printf "\n\tsimple-api-native\tjpa-mysql-native\tkafka-native\telasticsearch-native"
printf "\n\tquarkus"
printf "\n\t\tquarkus-jvm"
printf "\n\t\tquarkus-native"
printf "\n\t\t\tquarkus-simple-api"
printf "\n\t\t\t\tquarkus-simple-api-jvm"
printf "\n\t\t\t\tquarkus-simple-api-native"
printf "\n\t\t\tquarkus-jpa-mysql"
printf "\n\t\t\t\tquarkus-jpa-mysql-jvm"
printf "\n\t\t\t\tquarkus-jpa-mysql-native"
printf "\n\t\t\tquarkus-kafka"
printf "\n\t\t\t\tquarkus-kafka-jvm"
printf "\n\t\t\t\tquarkus-kafka-native"
printf "\n\t\t\tquarkus-elasticsearch"
printf "\n\t\t\t\tquarkus-elasticsearch-jvm"
printf "\n\t\t\t\tquarkus-elasticsearch-native"
printf "\n\tmicronaut"
printf "\n\t\tmicronaut-jvm"
printf "\n\t\tmicronaut-native"
printf "\n\t\t\tmicronaut-simple-api"
printf "\n\t\t\t\tmicronaut-simple-api-jvm"
printf "\n\t\t\t\tmicronaut-simple-api-native"
printf "\n\t\t\tmicronaut-jpa-mysql"
printf "\n\t\t\t\tmicronaut-jpa-mysql-jvm"
printf "\n\t\t\t\tmicronaut-jpa-mysql-native"
printf "\n\t\t\tmicronaut-kafka"
printf "\n\t\t\t\tmicronaut-kafka-jvm"
printf "\n\t\t\t\tmicronaut-kafka-native"
printf "\n\t\t\tmicronaut-elasticsearch"
printf "\n\t\t\t\tmicronaut-elasticsearch-jvm"
printf "\n\t\t\t\tmicronaut-elasticsearch-native"
printf "\n\tspringboot"
printf "\n\t\tspringboot-jvm"
printf "\n\t\tspringboot-native"
printf "\n\t\t\tspringboot-simple-api"
printf "\n\t\t\t\tspringboot-simple-api-jvm"
printf "\n\t\t\t\tspringboot-simple-api-native"
printf "\n\t\t\tspringboot-jpa-mysql"
printf "\n\t\t\t\tspringboot-jpa-mysql-jvm"
printf "\n\t\t\t\tspringboot-jpa-mysql-native"
printf "\n\t\t\tspringboot-kafka"
printf "\n\t\t\t\tspringboot-kafka-jvm"
printf "\n\t\t\t\tspringboot-kafka-native"
printf "\n\t\t\tspringboot-elasticsearch"
printf "\n\t\t\t\tspringboot-elasticsearch-jvm"
printf "\n\t\t\t\tspringboot-elasticsearch-native"
printf "\n"
exit 1
fi
}