2 ##############################################################################
3 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
12 ## run_rubbos_interlnal.sh is executed in rubbos-controller
13 ## Usage: run_rubbos_internal.sh rubbos.conf local_result_dir
15 echo "Need Two argument!"
20 controller_host=`hostname`
22 REMOTE_GIT_REPO=git://git.opnfv.org/bottlenecks
23 REMOTE_ARTIFACTS_REPO=http://artifacts.opnfv.org/bottlenecks/rubbos/rubbos_files.tar.gz
24 LOCAL_GIT_REPO=/btnks-git
25 LOCAL_ARTIFACTS_REPO=/btnks-artifacts
26 LOCAL_RUBBOS_MANIFESTS_HOME=/btnks-git/bottlenecks/testsuites/rubbos/puppet_manifests
27 LOCAL_ARTIFACTS_RUBBOS_HOME=/btnks-artifacts/rubbos_files
29 # conf properties from the input config file
43 # conf info used in this script
47 remote_client_servers=
56 # Other variables used in this script
62 if [ ${#line} -gt 0 ] && [ ${line:0:1} != "#" ] && [ ${line:0:1} != "[" ];then
66 e_arr=(${line[1]//:/ })
67 controller_host=${e_arr[0]}
68 controller_ip=${e_arr[2]}
69 hostname_arr=("${hostname_arr[@]}" "${e_arr[0]}")
70 hostip_arr=("${hostip_arr[@]}" "${e_arr[2]}");;
72 elems=(${line[1]//,/ })
73 for e in "${elems[@]}";do
75 client_servers=${client_servers}${e_arr[0]}","
76 hostname_arr=("${hostname_arr[@]}" "${e_arr[0]}")
77 hostip_arr=("${hostip_arr[@]}" "${e_arr[1]}")
79 client_servers=${client_servers%,};;
81 e_arr=(${line[1]//:/ })
82 web_servers=${web_servers}${e_arr[0]}","
83 hostname_arr=("${hostname_arr[@]}" "${e_arr[0]}")
84 hostip_arr=("${hostip_arr[@]}" "${e_arr[1]}")
85 web_servers=${e_arr[0]};;
87 elems=(${line[1]//,/ })
88 for e in "${elems[@]}";do
90 app_servers=${app_servers}${e_arr[0]}","
91 hostname_arr=("${hostname_arr[@]}" "${e_arr[0]}")
92 hostip_arr=("${hostip_arr[@]}" "${e_arr[1]}")
94 app_servers=${app_servers%,};;
96 if [ "x"${line[1]} != "x" ]; then
97 e_arr=(${line[1]//:/ })
98 hostname_arr=("${hostname_arr[@]}" "${e_arr[0]}")
99 hostip_arr=("${hostip_arr[@]}" "${e_arr[1]}")
100 cjdbc_controller=${e_arr[0]}
104 elems=(${line[1]//,/ })
105 for e in "${elems[@]}";do
107 database_servers=${database_servers}${e_arr[0]}","
108 hostname_arr=("${hostname_arr[@]}" "${e_arr[0]}")
109 hostip_arr=("${hostip_arr[@]}" "${e_arr[1]}")
111 database_servers=${database_servers%,};;
113 database_port=${line[1]};;
115 db_username=${line[1]};;
117 db_password=${line[1]};;
119 clients_per_node=${line[@]:1:${#line[@]-1}};;
121 rubbos_app=${line[1]};;
123 rubbos_app_tools=${line[1]};;
125 rubbos_home=${line[1]};;
128 done < $local_cfg_path
130 clients_arr=(${client_servers//,/ })
131 clients_per_node_arr=(${clients_per_node})
132 webservers_arr=(${web_servers//,/ })
133 appservers_arr=(${app_servers//,/ })
134 dbservers_arr=(${database_servers//,/ })
135 all_agents_arr=("${clients_arr[@]}" "${webservers_arr[@]}" "${appservers_arr[@]}" "${dbservers_arr[@]}")
136 bench_client=${clients_arr[0]}
137 len=${#clients_arr[@]}
138 if [ $len -gt 1 ]; then
139 remote_clients_arr=(${clients_arr[@]:1:$len-1})
140 remote_client_servers=${client_servers#*,}
143 echo "-------------Main conf info:----------"
145 while [ $i -lt ${#hostname_arr[@]} ]; do
146 echo ${hostip_arr[$i]}" "${hostname_arr[$i]}
149 echo "clients_arr: "${clients_arr[@]}
150 echo "bench_client: "$bench_client
151 echo "remote_client_servers: "$remote_client_servers
152 echo "remote_clients_arr: "${remote_clients_arr[@]}
153 echo "clients_per_node_arr: "${clients_per_node_arr[@]}
154 echo "webservers_arr: "${webservers_arr[@]}
155 echo "appservers_arr: "${appservers_arr[@]}
156 echo "dbservers_arr: "${dbservers_arr[@]}
157 echo "all agents: "${all_agents_arr[@]}
160 fetch_remote_resources() {
161 if [ -d $LOCAL_GIT_REPO ];then
162 rm -rf $LOCAL_GIT_REPO
164 mkdir -p $LOCAL_GIT_REPO
165 sudo apt-get install -y git
167 git clone ${REMOTE_GIT_REPO}
169 if [ -d $LOCAL_ARTIFACTS_REPO ];then
170 rm -rf $LOCAL_ARTIFACTS_REPO
172 mkdir -p $LOCAL_ARTIFACTS_REPO
173 cd $LOCAL_ARTIFACTS_REPO
174 wget ${REMOTE_ARTIFACTS_REPO}
175 tar xvzf rubbos_files.tar.gz
177 if [ -d $local_results_dir ];then
178 rm -rf $local_results_dir
180 mkdir -p $local_results_dir
183 # ssh all vms/instances once only after first creation
185 sudo cp ${LOCAL_GIT_REPO}/bottlenecks/utils/infra_setup/bottlenecks_key/bottlenecks_key /home/ubuntu/.ssh/id_rsa
186 sudo chmod 0600 /home/ubuntu/.ssh/id_rsa
187 echo 'StrictHostKeyChecking no' > /home/ubuntu/.ssh/config
188 sudo cp /home/ubuntu/.ssh/id_rsa /root/.ssh/
189 sudo cp /home/ubuntu/.ssh/config /root/.ssh/
190 local ssh_args="-o StrictHostKeyChecking=no -o BatchMode=yes -i /home/ubuntu/.ssh/id_rsa"
192 while [ $i -lt ${#hostname_arr[@]} ]; do
193 echo ${hostip_arr[$i]}" "${hostname_arr[$i]}
194 if [ ${hostname_arr[$i]} == ${controller_host} ];then
198 echo ${hostip_arr[$i]}" "${hostname_arr[$i]} >> /etc/hosts
199 ssh ${ssh_args} ubuntu@${hostname_arr[$i]} "echo 'StrictHostKeyChecking no' > /home/ubuntu/.ssh/config"
200 ssh ${ssh_args} ubuntu@${hostname_arr[$i]} "sudo cp /home/ubuntu/.ssh/config /root/.ssh/"
201 scp ${ssh_args} /home/ubuntu/.ssh/id_rsa ubuntu@${hostname_arr[$i]}:/home/ubuntu/.ssh/
202 ssh ${ssh_args} ubuntu@${hostname_arr[$i]} "sudo cp /home/ubuntu/.ssh/id_rsa /root/.ssh/"
203 echo "Append hosts for "${hostname_arr[$i]}
204 ssh ${ssh_args} ubuntu@${hostname_arr[$i]} "sudo cp /etc/hosts /home/ubuntu/ && sudo chmod 646 /home/ubuntu/hosts"
206 while [ $j -lt ${#hostname_arr[@]} ];do
207 local host_item=${hostip_arr[$j]}" "${hostname_arr[$j]}
208 ssh ${ssh_args} ubuntu@${hostname_arr[$i]} "sudo echo ${host_item} >> /home/ubuntu/hosts"
211 ssh ${ssh_args} ubuntu@${hostname_arr[$i]} "sudo chmod 644 /home/ubuntu/hosts && sudo cp /home/ubuntu/hosts /etc/ && sudo rm -rf /home/ubuntu/hosts"
217 # It requires one local file path which needs to be replaced
219 echo "_replace file: "$1
220 sed -i 's#REPLACED_RUBBOS_APP_TOOLS#'${rubbos_app_tools}'#g' $1
221 sed -i 's#REPLACED_RUBBOS_APP#'${rubbos_app}'#g' $1
222 sed -i 's#REPLACED_RUBBOS_HOME#'${rubbos_home}'#g' $1
223 local mysql_jdbc_url="jdbc:mysql://"${database_servers}":"${database_port}"/rubbos"
224 sed -i 's#REPLACED_MYSQL_JDBC_DB_URL#'${mysql_jdbc_url}'#g' $1
225 sed -i 's/REPLACED_MYSQL_USERNAME/'${db_username}'/g' $1
226 sed -i 's/REPLACED_MYSQL_PASSWORD/'${db_password}'/g' $1
230 while [ $i -lt ${#appservers_arr} ];do
232 handlers=${handlers}${handler_name}","
233 handler_details=${handler_details}"worker."${handler_name}".port=8009\n"
234 handler_details=${handler_details}"worker."${handler_name}".host="${appservers_arr[$i]}"\n"
235 handler_details=${handler_details}"worker."${handler_name}".type=ajp13\n"
236 handler_details=${handler_details}"worker."${handler_name}".lbfactor=1\n"
239 handlers=${handlers%,}
240 sed -i 's/REPLACED_HANDLERS_DETAILS/'${handler_details}'/g' $1
241 sed -i 's/REPLACED_HANDLERS/'${handlers}'/g' $1
243 sed -i 's/REPLACED_WEB_SERVER/'${web_servers}'/g' $1
244 sed -i 's/REPLACED_APPLICATION_SERVER/'${app_servers}'/g' $1
245 sed -i 's/REPLACED_DB_SERVER/'${database_servers}'/g' $1
246 sed -i 's/REPLACED_CLIENT_SERVERS/'${remote_client_servers}'/g' $1
250 # it requires one input string
251 _to_puppet_class_nodes() {
252 echo "_to_puppet_class_nodes "$1
254 nodes_arr=(${1//,/ })
256 while [ $i -lt ${#nodes_arr[@]} ];do
257 class_nodes=${class_nodes}"'"${nodes_arr[$i]}"',"
260 class_nodes=${class_nodes%,}
265 # use *class_nodes* to receive return vale
266 _to_puppet_class_nodes ${client_servers}
267 sed -i 's/REPLACED_CLIENT_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
269 _to_puppet_class_nodes ${web_servers}
270 sed -i 's/REPLACED_HTTPD_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
272 _to_puppet_class_nodes ${app_servers}
273 sed -i 's/REPLACED_TOMCAT_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
275 _to_puppet_class_nodes ${database_servers}
276 sed -i 's/REPLACED_MYSQL_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
278 for host in "${clients_arr[@]}"; do
279 ssh ubuntu@${host} 'sudo puppet agent -t' &
281 for host in "${webservers_arr[@]}"; do
282 ssh ubuntu@${host} 'sudo puppet agent -t'
284 for host in "${appservers_arr[@]}"; do
285 ssh ubuntu@${host} 'sudo puppet agent -t'
287 for host in "${dbservers_arr[@]}"; do
288 ssh ubuntu@${host} 'sudo puppet agent -t'
292 prepare_manifests() {
294 sudo cp -r ${LOCAL_RUBBOS_MANIFESTS_HOME}/modules/* /etc/puppet/modules/
297 sudo cp -r ${LOCAL_ARTIFACTS_RUBBOS_HOME}/modules/* /etc/puppet/modules/
299 # adjust corresponding configuration files (pre-catalog)
300 _replace_text /etc/puppet/modules/rubbos_tomcat/files/tomcat_sl/build.properties
301 _replace_text /etc/puppet/modules/rubbos_tomcat/files/tomcat_sl/Config.java
302 _replace_text /etc/puppet/modules/rubbos_tomcat/files/tomcat_sl/mysql.properties
303 _replace_text /etc/puppet/modules/rubbos_httpd/files/apache_conf/workers.properties
304 _replace_text /etc/puppet/modules/rubbos_httpd/files/apache_conf/httpd.conf
305 _replace_text /etc/puppet/modules/rubbos_client/files/build.properties
306 _replace_text /etc/puppet/modules/rubbos_client/files/rubbos.properties.template
307 _replace_text /etc/puppet/modules/rubbos_client/files/run_emulator.sh
311 # start all (exec catalog)
312 if [ "x"$1 == "xstart" ];then
313 echo "--> Start to execute catalogs in all agents..."
314 sudo cp ${LOCAL_RUBBOS_MANIFESTS_HOME}/site_on.pp /etc/puppet/manifests/site.pp
316 echo "--> Finish to execute catalogs in all agents."
317 elif [ "x"$1 == "xclean" ];then
318 echo "--> Cleanup all agents..."
319 sudo cp ${LOCAL_RUBBOS_MANIFESTS_HOME}/site_off.pp /etc/puppet/manifests/site.pp
321 echo "--> Finish to cleanup all agents."
326 # prepare data in db servers
327 for host in "${dbservers_arr[@]}"; do
328 ssh ubuntu@${host} 'sudo scp ubuntu@'${controller_host}':/etc/puppet/modules/rubbos_mysql/files/rubbos_data_sql.tar.gz '${rubbos_home}''
329 ssh ubuntu@${host} 'cd '${rubbos_home}' && sudo ./prepare_rubbos_mysql_db.sh ./rubbos_data_sql.tar.gz ./rubbos_data_sql_dir'
332 # run emulator.sh ( Modify rubbos.properties file first)
333 ssh ubuntu@${bench_client} 'sudo rm -rf '${rubbos_home}'/bench/bench'
334 for x in "${clients_per_node_arr[@]}";do
335 echo "run emulator with clients_per_node="$x
336 for host in "${clients_arr[@]}";do
337 ssh ubuntu@${host} "sed -e 's/REPLACED_NUMBER_OF_CLIENTS_PER_NODE/'${x}'/g' '${rubbos_home}'/Client/rubbos.properties.template > '${rubbos_home}'/Client/rubbos.properties "
339 ssh ubuntu@${bench_client} 'cd '${rubbos_home}'/bench && ./run_emulator.sh'
344 # collect results, from bench_host to controller
345 scp -r ubuntu@${bench_client}:${rubbos_home}/bench/bench/* ${local_results_dir}
349 # post-process results and push to the database of dashboard
350 python ${LOCAL_GIT_REPO}/bottlenecks/utils/dashboard/process_data.py -i ${local_results_dir} \
351 -c ${LOCAL_GIT_REPO}/bottlenecks/utils/dashboard/dashboard.yaml \
353 -o ${local_results_dir}/rubbos.out \
358 echo "==> read_conf:"
360 echo "==> fetch_remote_resources:"
361 fetch_remote_resources
362 echo "==> direct_ssh:"
364 echo "==> prepare_manifests:"
366 echo "==> execute_catalog start:"
367 execute_catalog start
368 echo "==> run_emulator:"
370 echo "==> collect_results (to controller:${local_results_dir}):"
372 echo "==> process_results:"
374 echo "==> execute_catalog clean:"
375 execute_catalog clean