blob: 2981afa49dd06a7c52139a4acb02bb7e5897b69a [file] [log] [blame]
Yuli Shlosbergd6680b22018-02-25 10:08:06 +02001#!/bin/bash
2
3CS_PASSWORD="onap123#@!"
4SDC_USER="asdc_user"
5SDC_PASSWORD="Aa1234%^!"
6JETTY_BASE="/var/lib/jetty"
7BE_JAVA_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=4000,server=y,suspend=n -Xmx2g -Xms2g"
8FE_JAVA_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=6000,server=y,suspend=n -Xmx512m -Xms512m"
9
10
11function usage {
12 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 ]"
13}
14
15
16function cleanup {
17 echo "performing old dockers cleanup"
18
19 if [ "$1" == "all" ] ; then
20 docker_ids=`docker ps -a | egrep -v "openecomp/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit" | awk '{print $1}'`
21 for X in ${docker_ids}
22 do
23 docker rm -f ${X}
24 done
25 else
26 echo "performing $1 docker cleanup"
27 tmp=`docker ps -a -q --filter="name=$1"`
28 if [[ ! -z "$tmp" ]]; then
29 docker rm -f ${tmp}
30 fi
31 fi
32}
33
34
35function dir_perms {
36 mkdir -p ${WORKSPACE}/data/logs/BE/SDC/SDC-BE
37 mkdir -p ${WORKSPACE}/data/logs/FE/SDC/SDC-FE
38 chmod -R 777 ${WORKSPACE}/data/logs
39}
40function probe_cs {
41
42cs_stat=false
43docker exec -it $1 /var/lib/ready-probe.sh > /dev/null 2>&1
44rc=$?
45if [[ $rc == 0 ]]; then
46 echo DOCKER start finished in $2 seconds
47 cs_stat=true
48fi
49
50}
51
52function probe_be {
53
54be_stat=false
55docker exec -it $1 /var/lib/ready-probe.sh > /dev/null 2>&1
56rc=$?
57if [[ $rc == 200 ]]; then
58 echo DOCKER start finished in $2 seconds
59 be_stat=true
60fi
61
62}
63
64function probe_fe {
65
66fe_stat=false
67docker exec -it $1 /var/lib/ready-probe.sh > /dev/null 2>&1
68rc=$?
69if [[ $rc == 200 ]]; then
70 echo DOCKER start finished in $2 seconds
71 fe_stat=true
72fi
73
74}
75
76function probe_es {
77
78es_stat=false
79health_Check_http_code=$(curl -o /dev/null -w '%{http_code}' http://${IP}:9200/_cluster/health?wait_for_status=yellow&timeout=120s)
80if [[ "$health_Check_http_code" -eq 200 ]]
81 then
82 echo DOCKER start finished in $2 seconds
83 es_stat=true
84 fi
85
86}
87
88function probe_docker {
89
90match_result=false
91MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
92echo MATCH is -- $MATCH
93
94if [ -n "$MATCH" ]; then
95 echo DOCKER start finished in $2 seconds
96 match_result=true
97fi
98}
99function monitor_docker {
100
101 echo monitor $1 Docker
102 sleep 5
103 TIME_OUT=900
104 INTERVAL=20
105 TIME=0
106 while [ "$TIME" -lt "$TIME_OUT" ]; do
107 if [ "$1" == "sdc-cs" ]; then
108 probe_cs $1 $TIME
109 if [[ $cs_stat == true ]]; then break; fi
110 elif [ "$1" == "sdc-es" ]; then
111 probe_es $1 $TIME
112 if [[ $es_stat == true ]]; then break; fi
113 elif [ "$1" == "sdc-BE" ]; then
114 probe_be $1 $TIME
115 if [[ $be_stat == true ]]; then break; fi
116 elif [ "$1" == "sdc-FE" ]; then
117 probe_fe $1 $TIME
118 if [[ $fe_stat == true ]]; then break; fi
119 else
120 probe_docker $1 $TIME
121 if [[ $match_result == true ]]; then break; fi
122 fi
123 echo Sleep: $INTERVAL seconds before testing if $1 DOCKER is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds
124 sleep $INTERVAL
125 TIME=$(($TIME+$INTERVAL))
126 done
127
128 if [ "$TIME" -ge "$TIME_OUT" ]; then
129 echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
130 fi
131
132}
133
134function healthCheck {
135 curl ${IP}:9200/_cluster/health?pretty=true
136
137 echo "BE health-Check:"
138 curl http://${IP}:8080/sdc2/rest/healthCheck
139
140 echo ""
141 echo ""
142 echo "FE health-Check:"
143 curl http://${IP}:8181/sdc1/rest/healthCheck
144
145
146 echo ""
147 echo ""
148 healthCheck_http_code=$(curl -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;)
149 if [[ ${healthCheck_http_code} != 200 ]]
150 then
151 echo "Error [${healthCheck_http_code}] while user existance check"
152 return ${healthCheck_http_code}
153 fi
154 echo "check user existance: OK"
155 return ${healthCheck_http_code}
156}
157
158function elasticHealthCheck {
159 echo "Elastic Health-Check:"
160
161 COUNTER=0
162 while [ $COUNTER -lt 20 ]; do
163 echo "Waiting ES docker to start"
164 health_Check_http_code=$(curl -o /dev/null -w '%{http_code}' http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=120s)
165 if [[ "$health_Check_http_code" -eq 200 ]]
166 then
167 break
168 fi
169 let COUNTER=COUNTER+1
170 sleep 4
171 done
172
173 healthCheck_http_code=$(curl -o /dev/null -w '%{http_code}' http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=120s)
174 if [[ "$health_Check_http_code" != 200 ]]
175 then
176 echo "Error [${healthCheck_http_code}] ES NOT started correctly"
177 exit ${healthCheck_http_code}
178 fi
179 echo "ES started correctly"
180 curl ${IP}:9200/_cluster/health?pretty=true
181 return ${healthCheck_http_code}
182}
183
184RELEASE=latest
185LOCAL=false
186RUNTESTS=false
187DEBUG_PORT="--publish 4000:4000"
188
189while [ $# -gt 0 ]; do
190 case $1 in
191 # -r | --release - The specific docker version to pull and deploy
192 -r | --release )
193 shift 1 ;
194 RELEASE=$1;
195 shift 1;;
196 # -e | --environment - The environment name you want to deploy
197 -e | --environment )
198 shift 1;
199 DEP_ENV=$1;
200 shift 1 ;;
201 # -p | --port - The port from which to connect to the docker nexus
202 -p | --port )
203 shift 1 ;
204 PORT=$1;
205 shift 1 ;;
206 # -l | --local - Use this for deploying your local dockers without pulling them first
207 -l | --local )
208 LOCAL=true;
209 shift 1;;
210 # -t | --runTests - Use this for running the sanity tests docker after all other dockers have been deployed
211 -t | --runTests )
212 RUNTESTS=true;
213 shift 1 ;;
214 # -d | --docker - The init specified docker
215 -d | --docker )
216 shift 1 ;
217 DOCKER=$1;
218 shift 1 ;;
219 # -h | --help - Display the help message with all the available run options
220 -h | --help )
221 usage;
222 exit 0;;
223 * )
224 usage;
225 exit 1;;
226 esac
227done
228
229
230[ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || echo ${DEP_ENV}
231[ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) || NEXUS_USERNAME=release
232[ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
233[ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=nexus3.onap.org:${PORT}
234[ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
235
236export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
237export PREFIX=${NEXUS_DOCKER_REPO}'/onap'
238
239if [ ${LOCAL} = true ]; then
240 PREFIX='onap'
241fi
242
243echo ""
244
245
246
247function sdc-es {
248
249# Elastic-Search
250echo "docker run sdc-elasticsearch..."
251if [ ${LOCAL} = false ]; then
252 echo "pulling code"
253 docker pull ${PREFIX}/sdc-elasticsearch:${RELEASE}
254fi
255docker 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
256
257echo "please wait while ES is starting..."
258monitor_docker sdc-es
259}
260
261function sdc-init-es {
262# Init-Elastic-Search
263echo "docker run sdc-init-elasticsearch..."
264if [ ${LOCAL} = false ]; then
265 echo "pulling code"
266 docker pull ${PREFIX}/sdc-init-elasticsearch:${RELEASE}
267fi
268docker 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}
269rc=$?
270if [[ $rc != 0 ]]; then exit $rc; fi
271
272}
273
274function sdc-cs {
275# Cassandra
276echo "docker run sdc-cassandra..."
277if [ ${LOCAL} = false ]; then
278 docker pull ${PREFIX}/sdc-cassandra:${RELEASE}
279fi
280docker 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
281
282
283echo "please wait while CS is starting..."
284monitor_docker sdc-cs
285}
286
287function sdc-cs-init {
288# cassandra-init
289echo "docker run sdc-cassandra-init..."
290if [ ${LOCAL} = false ]; then
291 docker pull ${PREFIX}/sdc-cassandra-init:${RELEASE}
292fi
293docker 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}
294rc=$?
295if [[ $rc != 0 ]]; then exit $rc; fi
296}
297
298function sdc-kbn {
299# kibana
300echo "docker run sdc-kibana..."
301if [ ${LOCAL} = false ]; then
302 docker pull ${PREFIX}/sdc-kibana:${RELEASE}
303docker 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}
304fi
305
306}
307
308
309function sdc-BE {
310
311dir_perms
312# Back-End
313echo "docker run sdc-backend..."
314if [ ${LOCAL} = false ]; then
315 docker pull ${PREFIX}/sdc-backend:${RELEASE}
316else
317 ADDITIONAL_ARGUMENTS=${DEBUG_PORT}
318fi
319docker run --detach --name sdc-BE --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --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}
320
321echo "please wait while BE is starting..."
322monitor_docker sdc-BE
323}
324
325function sdc-BE-init {
326
327dir_perms
328# Back-End-Init
329echo "docker run sdc-backend-init..."
330if [ ${LOCAL} = false ]; then
331 docker pull ${PREFIX}/sdc-backend-init:${RELEASE}
332fi
333docker 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}
334rc=$?
335if [[ $rc != 0 ]]; then exit $rc; fi
336}
337
338function sdc-FE {
339dir_perms
340# Front-End
341echo "docker run sdc-frontend..."
342if [ ${LOCAL} = false ]; then
343 docker pull ${PREFIX}/sdc-frontend:${RELEASE}
344fi
345docker run --detach --name sdc-FE --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --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}
346
347echo "please wait while FE is starting....."
348monitor_docker sdc-FE
349}
350
351
352
353function sdc-sanity {
354# sanityDocker
355if [[ (${RUNTESTS} = true) && (${healthCheck_http_code} == 200) ]]; then
356 echo "docker run sdc-sanity..."
357 echo "Triger sanity docker, please wait..."
358
359 if [ ${LOCAL} = false ]; then
360 docker pull ${PREFIX}/sdc-sanity:${RELEASE}
361 fi
362
363docker run --detach --name sdc-sanity --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --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-sanity/target:/var/lib/tests/target --volume ${WORKSPACE}/data/logs/sdc-sanity/ExtentReport:/var/lib/tests/ExtentReport --volume ${WORKSPACE}/data/logs/sdc-sanity/outputCsar:/var/lib/tests/outputCsar --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 9560:9560 ${PREFIX}/sdc-sanity:${RELEASE}
364echo "please wait while SANITY is starting....."
365monitor_docker sdc-sanity
366
367fi
368}
369
370if [ -z "${DOCKER}" ]; then
371 cleanup all
372 sdc-es
373 sdc-init-es
374 sdc-cs
375 sdc-cs-init
376 sdc-kbn
377 sdc-BE
378 sdc-BE-init
379 sdc-FE
380else
381 cleanup ${DOCKER}
382 ${DOCKER}
383fi
384
385# healthCheck
386healthCheck