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"
216 start_puppet_service() {
218 local ssh_args="-o StrictHostKeyChecking=no -o BatchMode=yes -i /home/ubuntu/.ssh/id_rsa"
219 sudo service puppetserver status
220 sudo service puppetserver start
221 # Start all puppet agents
222 for host in "${all_agents_arr[@]}";do
223 ssh ${ssh_args} ubuntu@${host} "sudo service puppet start --no-client"
225 sudo service puppetserver status
226 sudo puppet cert list --all
227 sudo puppet cert sign --all
228 sudo puppet cert list --all
232 # It requires one local file path which needs to be replaced
234 echo "_replace file: "$1
235 sed -i 's#REPLACED_RUBBOS_APP_TOOLS#'${rubbos_app_tools}'#g' $1
236 sed -i 's#REPLACED_RUBBOS_APP#'${rubbos_app}'#g' $1
237 sed -i 's#REPLACED_RUBBOS_HOME#'${rubbos_home}'#g' $1
238 local mysql_jdbc_url="jdbc:mysql://"${database_servers}":"${database_port}"/rubbos"
239 sed -i 's#REPLACED_MYSQL_JDBC_DB_URL#'${mysql_jdbc_url}'#g' $1
240 sed -i 's/REPLACED_MYSQL_USERNAME/'${db_username}'/g' $1
241 sed -i 's/REPLACED_MYSQL_PASSWORD/'${db_password}'/g' $1
245 while [ $i -lt ${#appservers_arr} ];do
247 handlers=${handlers}${handler_name}","
248 handler_details=${handler_details}"worker."${handler_name}".port=8009\n"
249 handler_details=${handler_details}"worker."${handler_name}".host="${appservers_arr[$i]}"\n"
250 handler_details=${handler_details}"worker."${handler_name}".type=ajp13\n"
251 handler_details=${handler_details}"worker."${handler_name}".lbfactor=1\n"
254 handlers=${handlers%,}
255 sed -i 's/REPLACED_HANDLERS_DETAILS/'${handler_details}'/g' $1
256 sed -i 's/REPLACED_HANDLERS/'${handlers}'/g' $1
258 sed -i 's/REPLACED_WEB_SERVER/'${web_servers}'/g' $1
259 sed -i 's/REPLACED_APPLICATION_SERVER/'${app_servers}'/g' $1
260 sed -i 's/REPLACED_DB_SERVER/'${database_servers}'/g' $1
261 sed -i 's/REPLACED_CLIENT_SERVERS/'${remote_client_servers}'/g' $1
265 # it requires one input string
266 _to_puppet_class_nodes() {
267 echo "_to_puppet_class_nodes "$1
269 nodes_arr=(${1//,/ })
271 while [ $i -lt ${#nodes_arr[@]} ];do
272 class_nodes=${class_nodes}"'"${nodes_arr[$i]}"',"
275 class_nodes=${class_nodes%,}
280 # use *class_nodes* to receive return vale
281 _to_puppet_class_nodes ${client_servers}
282 sed -i 's/REPLACED_CLIENT_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
284 _to_puppet_class_nodes ${web_servers}
285 sed -i 's/REPLACED_HTTPD_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
287 _to_puppet_class_nodes ${app_servers}
288 sed -i 's/REPLACED_TOMCAT_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
290 _to_puppet_class_nodes ${database_servers}
291 sed -i 's/REPLACED_MYSQL_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
293 for host in "${clients_arr[@]}"; do
294 ssh ubuntu@${host} 'sudo puppet agent -t' &
296 for host in "${webservers_arr[@]}"; do
297 ssh ubuntu@${host} 'sudo puppet agent -t'
299 for host in "${appservers_arr[@]}"; do
300 ssh ubuntu@${host} 'sudo puppet agent -t'
302 for host in "${dbservers_arr[@]}"; do
303 ssh ubuntu@${host} 'sudo puppet agent -t'
307 prepare_manifests() {
309 sudo cp -r ${LOCAL_RUBBOS_MANIFESTS_HOME}/modules/* /etc/puppet/modules/
312 sudo cp -r ${LOCAL_ARTIFACTS_RUBBOS_HOME}/modules/* /etc/puppet/modules/
314 # adjust corresponding configuration files (pre-catalog)
315 _replace_text /etc/puppet/modules/rubbos_tomcat/files/tomcat_sl/build.properties
316 _replace_text /etc/puppet/modules/rubbos_tomcat/files/tomcat_sl/Config.java
317 _replace_text /etc/puppet/modules/rubbos_tomcat/files/tomcat_sl/mysql.properties
318 _replace_text /etc/puppet/modules/rubbos_httpd/files/apache_conf/workers.properties
319 _replace_text /etc/puppet/modules/rubbos_httpd/files/apache_conf/httpd.conf
320 _replace_text /etc/puppet/modules/rubbos_client/files/build.properties
321 _replace_text /etc/puppet/modules/rubbos_client/files/rubbos.properties.template
322 _replace_text /etc/puppet/modules/rubbos_client/files/run_emulator.sh
326 # start all (exec catalog)
327 if [ "x"$1 == "xstart" ];then
328 echo "--> Start to execute catalogs in all agents..."
329 sudo cp ${LOCAL_RUBBOS_MANIFESTS_HOME}/site_on.pp /etc/puppet/manifests/site.pp
331 echo "--> Finish to execute catalogs in all agents."
332 elif [ "x"$1 == "xclean" ];then
333 echo "--> Cleanup all agents..."
334 sudo cp ${LOCAL_RUBBOS_MANIFESTS_HOME}/site_off.pp /etc/puppet/manifests/site.pp
336 echo "--> Finish to cleanup all agents."
341 # prepare data in db servers
342 for host in "${dbservers_arr[@]}"; do
343 ssh ubuntu@${host} 'sudo scp ubuntu@'${controller_host}':/etc/puppet/modules/rubbos_mysql/files/rubbos_data_sql.tar.gz '${rubbos_home}''
344 ssh ubuntu@${host} 'cd '${rubbos_home}' && sudo ./prepare_rubbos_mysql_db.sh ./rubbos_data_sql.tar.gz ./rubbos_data_sql_dir'
347 # run emulator.sh ( Modify rubbos.properties file first)
348 ssh ubuntu@${bench_client} 'sudo rm -rf '${rubbos_home}'/bench/bench'
349 for x in "${clients_per_node_arr[@]}";do
350 echo "run emulator with clients_per_node="$x
351 for host in "${clients_arr[@]}";do
352 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 "
354 ssh ubuntu@${bench_client} 'cd '${rubbos_home}'/bench && ./run_emulator.sh'
359 # collect results, from bench_host to controller
360 scp -r ubuntu@${bench_client}:${rubbos_home}/bench/bench/* ${local_results_dir}
364 # post-process results and push to the database of dashboard
365 python ${LOCAL_GIT_REPO}/bottlenecks/utils/dashboard/process_data.py -i ${local_results_dir} \
366 -c ${LOCAL_GIT_REPO}/bottlenecks/utils/dashboard/dashboard.yaml \
368 -o ${local_results_dir}/rubbos.out \
373 echo "==> read_conf:"
375 echo "==> fetch_remote_resources:"
376 fetch_remote_resources
377 echo "==> direct_ssh:"
379 echo "==> start_puppet_service:"
381 echo "==> prepare_manifests:"
383 echo "==> execute_catalog start:"
384 execute_catalog start
385 echo "==> run_emulator:"
387 echo "==> collect_results (to controller:${local_results_dir}):"
389 echo "==> process_results:"
391 echo "==> execute_catalog clean:"
392 execute_catalog clean