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=
54 # Other variables used in this script
60 if [ ${#line} -gt 0 ] && [ ${line:0:1} != "#" ] && [ ${line:0:1} != "[" ];then
64 client_servers=${line[1]};;
66 web_servers=${line[1]};;
68 app_servers=${line[1]};;
70 cjdbc_controller=${line[1]};;
72 database_servers=${line[1]};;
74 database_port=${line[1]};;
76 db_username=${line[1]};;
78 db_password=${line[1]};;
80 clients_per_node=${line[@]:1:${#line[@]-1}};;
82 rubbos_app=${line[1]};;
84 rubbos_app_tools=${line[1]};;
86 rubbos_home=${line[1]};;
89 done < $local_cfg_path
91 clients_arr=(${client_servers//,/ })
92 clients_per_node_arr=(${clients_per_node})
93 webservers_arr=(${web_servers//,/ })
94 appservers_arr=(${app_servers//,/ })
95 dbservers_arr=(${database_servers//,/ })
96 all_agents_arr=("${clients_arr[@]}" "${webservers_arr[@]}" "${appservers_arr[@]}" "${dbservers_arr[@]}")
97 bench_client=${clients_arr[0]}
98 len=${#clients_arr[@]}
99 if [ $len -gt 1 ]; then
100 remote_clients_arr=(${clients_arr[@]:1:$len-1})
101 remote_client_servers=${client_servers#*,}
104 echo "-------------Main conf info:----------"
105 echo "clients_arr: "${clients_arr[@]}
106 echo "bench_client: "$bench_client
107 echo "remote_client_servers: "$remote_client_servers
108 echo "remote_clients_arr: "${remote_clients_arr[@]}
109 echo "clients_per_node_arr: "${clients_per_node_arr[@]}
110 echo "webservers_arr: "${webservers_arr[@]}
111 echo "appservers_arr: "${appservers_arr[@]}
112 echo "dbservers_arr: "${dbservers_arr[@]}
113 echo "all agents: "${all_agents_arr[@]}
116 fetch_remote_resources() {
117 if [ -d $LOCAL_GIT_REPO ];then
118 rm -rf $LOCAL_GIT_REPO
120 mkdir -p $LOCAL_GIT_REPO
121 sudo apt-get install -y git
123 git clone ${REMOTE_GIT_REPO}
125 if [ -d $LOCAL_ARTIFACTS_REPO ];then
126 rm -rf $LOCAL_ARTIFACTS_REPO
128 mkdir -p $LOCAL_ARTIFACTS_REPO
129 cd $LOCAL_ARTIFACTS_REPO
130 wget ${REMOTE_ARTIFACTS_REPO}
131 tar xvzf rubbos_files.tar.gz
133 if [ -d $local_results_dir ];then
134 rm -rf $local_results_dir
136 mkdir -p $local_results_dir
140 # It requires one local file path which needs to be replaced
142 echo "_replace file: "$1
143 sed -i 's#REPLACED_RUBBOS_APP_TOOLS#'${rubbos_app_tools}'#g' $1
144 sed -i 's#REPLACED_RUBBOS_APP#'${rubbos_app}'#g' $1
145 sed -i 's#REPLACED_RUBBOS_HOME#'${rubbos_home}'#g' $1
146 local mysql_jdbc_url="jdbc:mysql://"${database_servers}":"${database_port}"/rubbos"
147 sed -i 's#REPLACED_MYSQL_JDBC_DB_URL#'${mysql_jdbc_url}'#g' $1
148 sed -i 's/REPLACED_MYSQL_USERNAME/'${db_username}'/g' $1
149 sed -i 's/REPLACED_MYSQL_PASSWORD/'${db_password}'/g' $1
153 while [ $i -lt ${#appservers_arr} ];do
155 handlers=${handlers}${handler_name}","
156 handler_details=${handler_details}"worker."${handler_name}".port=8009\n"
157 handler_details=${handler_details}"worker."${handler_name}".host="${appservers_arr[$i]}"\n"
158 handler_details=${handler_details}"worker."${handler_name}".type=ajp13\n"
159 handler_details=${handler_details}"worker."${handler_name}".lbfactor=1\n"
162 handlers=${handlers%,}
163 sed -i 's/REPLACED_HANDLERS_DETAILS/'${handler_details}'/g' $1
164 sed -i 's/REPLACED_HANDLERS/'${handlers}'/g' $1
166 sed -i 's/REPLACED_WEB_SERVER/'${web_servers}'/g' $1
167 sed -i 's/REPLACED_APPLICATION_SERVER/'${app_servers}'/g' $1
168 sed -i 's/REPLACED_DB_SERVER/'${database_servers}'/g' $1
169 sed -i 's/REPLACED_CLIENT_SERVERS/'${remote_client_servers}'/g' $1
173 # it requires one input string
174 _to_puppet_class_nodes() {
175 echo "_to_puppet_class_nodes "$1
177 nodes_arr=(${1//,/ })
179 while [ $i -lt ${#nodes_arr[@]} ];do
180 class_nodes=${class_nodes}"'"${nodes_arr[$i]}"',"
183 class_nodes=${class_nodes%,}
188 # use *class_nodes* to receive return vale
189 _to_puppet_class_nodes ${client_servers}
190 sed -i 's/REPLACED_CLIENT_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
192 _to_puppet_class_nodes ${web_servers}
193 sed -i 's/REPLACED_HTTPD_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
195 _to_puppet_class_nodes ${app_servers}
196 sed -i 's/REPLACED_TOMCAT_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
198 _to_puppet_class_nodes ${database_servers}
199 sed -i 's/REPLACED_MYSQL_NODES/'${class_nodes}'/g' /etc/puppet/manifests/site.pp
201 for host in "${clients_arr[@]}"; do
202 ssh ubuntu@${host} 'sudo puppet agent -t' &
204 for host in "${webservers_arr[@]}"; do
205 ssh ubuntu@${host} 'sudo puppet agent -t'
207 for host in "${appservers_arr[@]}"; do
208 ssh ubuntu@${host} 'sudo puppet agent -t'
210 for host in "${dbservers_arr[@]}"; do
211 ssh ubuntu@${host} 'sudo puppet agent -t'
215 prepare_manifests() {
217 sudo cp -r ${LOCAL_RUBBOS_MANIFESTS_HOME}/modules/* /etc/puppet/modules/
220 sudo cp -r ${LOCAL_ARTIFACTS_RUBBOS_HOME}/modules/* /etc/puppet/modules/
222 # adjust corresponding configuration files (pre-catalog)
223 _replace_text /etc/puppet/modules/rubbos_tomcat/files/tomcat_sl/build.properties
224 _replace_text /etc/puppet/modules/rubbos_tomcat/files/tomcat_sl/Config.java
225 _replace_text /etc/puppet/modules/rubbos_tomcat/files/tomcat_sl/mysql.properties
226 _replace_text /etc/puppet/modules/rubbos_httpd/files/apache_conf/workers.properties
227 _replace_text /etc/puppet/modules/rubbos_httpd/files/apache_conf/httpd.conf
228 _replace_text /etc/puppet/modules/rubbos_client/files/build.properties
229 _replace_text /etc/puppet/modules/rubbos_client/files/rubbos.properties.template
230 _replace_text /etc/puppet/modules/rubbos_client/files/run_emulator.sh
234 # start all (exec catalog)
235 echo "--> Cleanup all agents..."
236 sudo cp ${LOCAL_RUBBOS_MANIFESTS_HOME}/site_off.pp /etc/puppet/manifests/site.pp
241 echo "--> Start to execute catalogs in all agents..."
242 sudo cp ${LOCAL_RUBBOS_MANIFESTS_HOME}/site_on.pp /etc/puppet/manifests/site.pp
244 echo "--> Finish to execute catalogs in all agents."
248 # prepare data in db servers
249 for host in "${dbservers_arr[@]}"; do
250 ssh ubuntu@${host} 'sudo scp ubuntu@'${controller_host}':/etc/puppet/modules/rubbos_mysql/files/rubbos_data_sql.tar.gz '${rubbos_home}''
251 ssh ubuntu@${host} 'cd '${rubbos_home}' && sudo ./prepare_rubbos_mysql_db.sh ./rubbos_data_sql.tar.gz ./rubbos_data_sql_dir'
254 # run emulator.sh ( Modify rubbos.properties file first)
255 ssh ubuntu@${bench_client} 'sudo rm -rf '${rubbos_home}'/bench/bench'
256 for x in "${clients_per_node_arr[@]}";do
257 echo "run emulator with clients_per_node="$x
258 for host in "${clients_arr[@]}";do
259 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 "
261 ssh ubuntu@${bench_client} 'cd '${rubbos_home}'/bench && ./run_emulator.sh'
266 # collect results, from bench_host to controller
267 scp -r ubuntu@${bench_client}:${rubbos_home}/bench/bench/* ${local_results_dir}
271 # post-process results and push to the database of dashboard
272 python ${LOCAL_GIT_REPO}/bottlenecks/utils/dashboard/process_data.py -i ${local_results_dir} \
273 -c ${LOCAL_GIT_REPO}/bottlenecks/utils/dashboard/dashboard.yaml \
275 -o ${local_results_dir}/rubbos.out \
280 echo "==> read_conf:"
282 echo "==> fetch_remote_resources:"
283 fetch_remote_resources
284 echo "==> prepare_manifests:"
286 echo "==> execute_catalog:"
288 echo "==> run_emulator:"
290 echo "==> collect_results (to controller:${local_results_dir}):"
292 echo "==> process_results:"