new ui sanity docker
[sdc.git] / sdc-os-chef / scripts / docker_run.sh
1 #!/bin/bash
2
3 CS_PASSWORD="onap123#@!"
4 SDC_USER="asdc_user"
5 SDC_PASSWORD="Aa1234%^!"
6 JETTY_BASE="/var/lib/jetty"
7 BE_JAVA_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=4000,server=y,suspend=n -Xmx2g -Xms2g"
8 FE_JAVA_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=6000,server=y,suspend=n -Xmx512m -Xms512m"
9 SIM_JAVA_OPTIONS=" -Xmx128m -Xms128m -Xss1m"
10 API_TESTS_JAVA_OPTIONS="-Xmx512m -Xms512m"
11 UI_TESTS_JAVA_OPTIONS="-Xmx1024m -Xms1024m"
12
13 function usage {
14     echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ]  [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -l|--local <Run-without-pull>] [ -t|--runTests <Run-with-sanityDocker>] [ -h|--help ]"
15 }
16
17
18 function cleanup {
19     echo "performing old dockers cleanup"
20
21         if [ "$1" == "all" ] ; then
22                 docker_ids=`docker ps -a | egrep -v "onap/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit" | awk '{print $1}'`
23                 for X in ${docker_ids}
24                 do
25                         docker rm -f ${X}
26                 done
27         else
28             echo "performing $1 docker cleanup"
29             tmp=`docker ps -a -q --filter="name=$1"`
30             if [[ ! -z "$tmp" ]]; then
31                 docker rm -f ${tmp}
32             fi
33         fi
34 }
35
36
37 function dir_perms {
38     mkdir -p ${WORKSPACE}/data/logs/BE/SDC/SDC-BE
39     mkdir -p ${WORKSPACE}/data/logs/FE/SDC/SDC-FE
40     mkdir -p ${WORKSPACE}/data/logs/sdc-api-tests/ExtentReport
41         mkdir -p ${WORKSPACE}/data/logs/sdc-api-tests/target
42         mkdir -p ${WORKSPACE}/data/logs/sdc-ui-tests/ExtentReport
43         mkdir -p ${WORKSPACE}/data/logs/sdc-ui-tests/target
44         mkdir -p ${WORKSPACE}/data/logs/docker_logs
45     chmod -R 777 ${WORKSPACE}/data/logs
46 }
47
48 function docker_logs {
49
50 docker logs $1 > ${WORKSPACE}/data/logs/docker_logs/$1_docker.log
51
52 }
53
54 function probe_cs {
55
56 cs_stat=false
57 docker exec $1 /var/lib/ready-probe.sh > /dev/null 2>&1
58 rc=$?
59 if [[ $rc == 0 ]]; then
60   echo DOCKER start finished in $2 seconds
61   cs_stat=true
62 fi
63
64 }
65
66 function probe_be {
67
68 be_stat=false
69 docker exec $1 /var/lib/ready-probe.sh > /dev/null 2>&1
70 rc=$?
71 if [[ $rc == 200 ]]; then
72   echo DOCKER start finished in $2 seconds
73   be_stat=true
74 fi
75
76 }
77
78 function probe_fe {
79
80 fe_stat=false
81 docker exec $1 /var/lib/ready-probe.sh > /dev/null 2>&1
82 rc=$?
83 if [[ $rc == 200 ]]; then
84   echo DOCKER start finished in $2 seconds
85   fe_stat=true
86 fi
87
88 }
89
90 function probe_es {
91
92 es_stat=false
93 health_Check_http_code=$(curl --noproxy "*" -o /dev/null -w '%{http_code}' http://${IP}:9200/_cluster/health?wait_for_status=yellow&timeout=120s)
94 if [[ "$health_Check_http_code" -eq 200 ]]
95  then
96    echo DOCKER start finished in $2 seconds
97    es_stat=true
98  fi
99
100 }
101
102 function probe_sim {
103
104 if lsof -Pi :8285 -sTCP:LISTEN -t >/dev/null ; then
105     echo "running"
106     sim_stat=true
107 else
108     echo "not running"
109     sim_stat=false
110 fi
111
112
113 }
114
115 function probe_docker {
116
117 match_result=false
118 MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
119 echo MATCH is -- $MATCH
120
121 if [ -n "$MATCH" ]; then
122    echo DOCKER start finished in $2 seconds
123    match_result=true
124 fi
125 }
126 function monitor_docker {
127
128     echo monitor $1 Docker
129     sleep 5
130     TIME_OUT=900
131     INTERVAL=20
132     TIME=0
133     while [ "$TIME" -lt "$TIME_OUT" ]; do
134        if [ "$1" == "sdc-cs" ]; then
135                     probe_cs $1 $TIME
136                 if [[ $cs_stat == true ]]; then break; fi
137                 elif [ "$1" == "sdc-es" ]; then
138                     probe_es $1 $TIME
139                         if [[ $es_stat == true ]]; then break; fi
140                 elif [ "$1" == "sdc-BE" ]; then
141                     probe_be $1 $TIME
142                         if [[ $be_stat == true ]]; then break; fi
143                 elif [ "$1" == "sdc-FE" ]; then
144                     probe_fe $1 $TIME
145                         if [[ $fe_stat == true ]]; then break; fi
146         else
147             probe_docker $1 $TIME
148             if [[ $match_result == true ]]; then break; fi
149         fi
150         echo Sleep: $INTERVAL seconds before testing if $1 DOCKER is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
151         sleep $INTERVAL
152         TIME=$(($TIME+$INTERVAL))
153     done
154
155     docker_logs $1
156
157     if [ "$TIME" -ge "$TIME_OUT" ]; then
158         echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
159     fi
160
161 }
162
163 function healthCheck {
164         curl --noproxy "*" ${IP}:9200/_cluster/health?pretty=true
165
166         echo "BE health-Check:"
167         curl --noproxy "*" http://${IP}:8080/sdc2/rest/healthCheck
168
169         echo ""
170         echo ""
171         echo "FE health-Check:"
172         curl --noproxy "*" http://${IP}:8181/sdc1/rest/healthCheck
173
174
175         echo ""
176         echo ""
177         healthCheck_http_code=$(curl --noproxy "*" -o /dev/null -w '%{http_code}' -H "Accept: application/json" -H "Content-Type: application/json" -H "USER_ID: jh0003" http://${IP}:8080/sdc2/rest/v1/user/demo;)
178         if [[ ${healthCheck_http_code} != 200 ]]
179         then
180                 echo "Error [${healthCheck_http_code}] while user existance check"
181                 return ${healthCheck_http_code}
182         fi
183         echo "check user existance: OK"
184         return ${healthCheck_http_code}
185 }
186
187 RELEASE=latest
188 LOCAL=false
189 RUNTESTS=false
190 DEBUG_PORT="--publish 4000:4000"
191
192 while [ $# -gt 0 ]; do
193     case $1 in
194         # -r | --release - The specific docker version to pull and deploy
195     -r | --release )
196           shift 1 ;
197           RELEASE=$1;
198           shift 1;;
199         # -e | --environment - The environment name you want to deploy
200     -e | --environment )
201           shift 1;
202           DEP_ENV=$1;
203           shift 1 ;;
204         # -p | --port - The port from which to connect to the docker nexus
205     -p | --port )
206           shift 1 ;
207           PORT=$1;
208           shift 1 ;;
209         # -l | --local - Use this for deploying your local dockers without pulling them first
210     -l | --local )
211           LOCAL=true;
212           shift 1;;
213         # -ta - Use this for running the APIs sanity docker after all other dockers have been deployed
214     -ta  )
215           shift 1 ;
216           API_SUITE=$1;
217           RUN_API_TESTS=true;
218           shift 1 ;;
219         # -tu - Use this for running the UI sanity docker after all other dockers have been deployed
220     -tu  )
221           shift 1 ;
222               UI_SUITE=$1;
223           RUN_UI_TESTS=true;
224           shift 1 ;;
225     # -tad - Use this for running the DEFAULT suite of tests in APIs sanity docker after all other dockers have been deployed
226     -tad | -t )
227           API_SUITE="onapApiSanity";
228           RUN_API_TESTS=true;
229           shift 1 ;;
230         # -tud - Use this for running the DEFAULT suite of tests in UI sanity docker after all other dockers have been deployed
231     -tud   )
232           UI_SUITE="onapUiSanity";
233           RUN_UI_TESTS=true;
234           shift 1 ;;
235     # -d | --docker - The init specified docker
236     -d | --docker )
237           shift 1 ;
238           DOCKER=$1;
239           shift 1 ;;
240         # -h | --help - Display the help message with all the available run options
241     -h | --help )
242           usage;
243           exit  0;;
244          * )
245           usage;
246           exit  1;;
247     esac
248 done
249
250
251 [ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || echo ${DEP_ENV}
252 [ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt)    || NEXUS_USERNAME=release
253 [ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt)      || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
254 [ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=nexus3.onap.org:${PORT}
255 [ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
256
257 export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
258 export PREFIX=${NEXUS_DOCKER_REPO}'/onap'
259
260 if [ ${LOCAL} = true ]; then
261         PREFIX='onap'
262 fi
263
264 echo ""
265
266
267 #Elastic-Search
268 function sdc-es {
269 echo "docker run sdc-elasticsearch..."
270 if [ ${LOCAL} = false ]; then
271         echo "pulling code"
272         docker pull ${PREFIX}/sdc-elasticsearch:${RELEASE}
273 fi
274 docker run -dit --name sdc-es --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --env ES_JAVA_OPTS="-Xms512m -Xmx512m" --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --env ES_HEAP_SIZE=1024M --volume ${WORKSPACE}/data/ES:/usr/share/elasticsearch/data --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 9200:9200 --publish 9300:9300 ${PREFIX}/sdc-elasticsearch:${RELEASE} /bin/sh
275
276 echo "please wait while ES is starting..."
277 monitor_docker sdc-es
278 }
279
280
281 #Init-Elastic-Search
282 function sdc-init-es {
283 echo "docker run sdc-init-elasticsearch..."
284 if [ ${LOCAL} = false ]; then
285         echo "pulling code"
286         docker pull ${PREFIX}/sdc-init-elasticsearch:${RELEASE}
287 fi
288 echo "Running sdc-init-es"
289 docker run --name sdc-init-es --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments ${PREFIX}/sdc-init-elasticsearch:${RELEASE} > /dev/null 2>&1
290 rc=$?
291 docker_logs sdc-init-es
292 if [[ $rc != 0 ]]; then exit $rc; fi
293
294 }
295
296 #Cassandra
297 function sdc-cs {
298 echo "docker run sdc-cassandra..."
299 if [ ${LOCAL} = false ]; then
300         docker pull ${PREFIX}/sdc-cassandra:${RELEASE}
301 fi
302 docker run -dit --name sdc-cs --env RELEASE="${RELEASE}" --env CS_PASSWORD="${CS_PASSWORD}" --env ENVNAME="${DEP_ENV}" --env HOST_IP=${IP} --env MAX_HEAP_SIZE="2024M" --env HEAP_NEWSIZE="512M" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/CS:/var/lib/cassandra --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 9042:9042 --publish 9160:9160 ${PREFIX}/sdc-cassandra:${RELEASE} /bin/sh
303
304
305 echo "please wait while CS is starting..."
306 monitor_docker sdc-cs
307 }
308
309 #Cassandra-init
310 function sdc-cs-init {
311 echo "docker run sdc-cassandra-init..."
312 if [ ${LOCAL} = false ]; then
313         docker pull ${PREFIX}/sdc-cassandra-init:${RELEASE}
314 fi
315 docker run --name sdc-cs-init --env RELEASE="${RELEASE}" --env SDC_USER="${SDC_USER}" --env SDC_PASSWORD="${SDC_PASSWORD}" --env CS_PASSWORD="${CS_PASSWORD}" --env ENVNAME="${DEP_ENV}" --env HOST_IP=${IP} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/CS:/var/lib/cassandra --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --volume ${WORKSPACE}/data/CS-Init:/root/chef-solo/cache ${PREFIX}/sdc-cassandra-init:${RELEASE} > /dev/null 2>&1
316 rc=$?
317 docker_logs sdc-cs-init
318 if [[ $rc != 0 ]]; then exit $rc; fi
319 }
320
321 #Kibana
322 function sdc-kbn {
323 echo "docker run sdc-kibana..."
324 if [ ${LOCAL} = false ]; then
325         docker pull ${PREFIX}/sdc-kibana:${RELEASE}
326 docker run --detach --name sdc-kbn --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 5601:5601 ${PREFIX}/sdc-kibana:${RELEASE}
327 fi
328
329 }
330
331 #Back-End
332 function sdc-BE {
333 echo "docker run sdc-backend..."
334 if [ ${LOCAL} = false ]; then
335         docker pull ${PREFIX}/sdc-backend:${RELEASE}
336 else
337         ADDITIONAL_ARGUMENTS=${DEBUG_PORT}
338 fi
339 docker run --detach --name sdc-BE --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env JAVA_OPTIONS="${BE_JAVA_OPTIONS}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/logs/BE/:/var/lib/jetty/logs  --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 8443:8443 --publish 8080:8080 ${ADDITIONAL_ARGUMENTS} ${PREFIX}/sdc-backend:${RELEASE}
340
341 echo "please wait while BE is starting..."
342 monitor_docker sdc-BE
343 }
344
345 # Back-End-Init
346 function sdc-BE-init {
347 echo "docker run sdc-backend-init..."
348 if [ ${LOCAL} = false ]; then
349         docker pull ${PREFIX}/sdc-backend-init:${RELEASE}
350 fi
351 docker run --name sdc-BE-init --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/logs/BE/:/var/lib/jetty/logs  --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments ${PREFIX}/sdc-backend-init:${RELEASE} > /dev/null 2>&1
352 rc=$?
353 docker_logs sdc-BE-init
354 if [[ $rc != 0 ]]; then exit $rc; fi
355 }
356
357
358 # Front-End
359 function sdc-FE {
360 echo "docker run sdc-frontend..."
361 if [ ${LOCAL} = false ]; then
362         docker pull ${PREFIX}/sdc-frontend:${RELEASE}
363 fi
364 docker run --detach --name sdc-FE --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env JAVA_OPTIONS="${FE_JAVA_OPTIONS}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro  --volume ${WORKSPACE}/data/logs/FE/:/var/lib/jetty/logs --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 9443:9443 --publish 8181:8181 ${PREFIX}/sdc-frontend:${RELEASE}
365
366 echo "please wait while FE is starting....."
367 monitor_docker sdc-FE
368 }
369
370
371 # apis-sanity
372 function sdc-api-tests {
373 healthCheck
374 if [[ (${RUN_API_TESTS} = true) && (${healthCheck_http_code} == 200) ]]; then
375     echo "docker run sdc-api-tests..."
376     echo "Triger sdc-api-tests docker, please wait..."
377
378     if [ ${LOCAL} = false ]; then
379         docker pull ${PREFIX}/sdc-api-tests:${RELEASE}
380     fi
381
382 docker run --detach --name sdc-api-tests --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env JAVA_OPTIONS="${API_TESTS_JAVA_OPTIONS}" --env SUITE_NAME=${API_SUITE} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/logs/sdc-api-tests/target:/var/lib/tests/target --volume ${WORKSPACE}/data/logs/sdc-api-tests/ExtentReport:/var/lib/tests/ExtentReport --volume ${WORKSPACE}/data/logs/sdc-api-tests/outputCsar:/var/lib/tests/outputCsar --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 9560:9560 ${PREFIX}/sdc-api-tests:${RELEASE} echo "please wait while SDC-API-TESTS is starting....."
383 monitor_docker sdc-api-tests
384
385 fi
386 }
387
388 # ui-sanity
389 function sdc-ui-tests {
390 healthCheck
391 if [[ (${RUN_UI_TESTS} = true) && (${healthCheck_http_code} == 200) ]]; then
392     echo "docker run sdc-ui-tets..."
393     echo "Triger sdc-ui-tests docker, please wait..."
394
395     if [ ${LOCAL} = false ]; then
396         docker pull ${PREFIX}/sdc-ui-tests:${RELEASE}
397     fi
398
399 sdc-sim
400 docker run --detach --name sdc-ui-tests --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env JAVA_OPTIONS="${UI_TESTS_JAVA_OPTIONS}" --env SUITE_NAME=${UI_SUITE} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume ${WORKSPACE}/data/logs/sdc-ui-tests/target:/var/lib/tests/target --volume ${WORKSPACE}/data/logs/sdc-ui-tests/ExtentReport:/var/lib/tests/ExtentReport --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 5901:5901 --publish 6901:6901 ${PREFIX}/sdc-ui-tests:${RELEASE}
401 echo "please wait while SDC-UI-TESTS is starting....."
402 monitor_docker sdc-ui-tests
403
404 fi
405 }
406
407
408 # SDC-Simulator
409 function sdc-sim {
410 echo "docker run sdc-webSimulator..."
411 if [ ${LOCAL} = false ]; then
412         docker pull ${PREFIX}/sdc-sim:${RELEASE}
413 fi
414
415 probe_sim
416 if [ sim_stat=false ]; then
417
418 docker run --detach --name sdc-sim  --env JAVA_OPTIONS="${SIM_JAVA_OPTIONS}" --env ENVNAME="${DEP_ENV}" --volume /etc/localtime:/etc/localtime:ro --volume /data/logs/WS/:/var/lib/jetty/logs --volume /data/environments:/root/chef-solo/environments --publish 8285:8080 --publish 8286:8443 ${PREFIX}/sdc-simulator:${RELEASE}
419 echo "please wait while SDC-WEB-SIMULATOR is starting....."
420 monitor_docker sdc-sim
421
422 fi
423 }
424
425 if [ -z "${DOCKER}" ]; then
426     cleanup all
427         dir_perms
428         sdc-es
429         sdc-init-es
430         sdc-cs
431         sdc-cs-init
432 #       sdc-kbn
433         sdc-BE
434         sdc-BE-init
435         sdc-FE
436     healthCheck
437         sdc-api-tests
438         sdc-ui-tests
439 else
440         cleanup ${DOCKER}
441         dir_perms
442         ${DOCKER}
443     healthCheck
444 fi