Enable different version for DCAE
[sdc.git] / sdc-os-chef / scripts / docker_run.sh
1 #!/bin/bash
2
3 #
4 # Constants:
5 #
6
7 WORKSPACE="${WORKSPACE:-}"
8 SUCCESS=0
9 FAILURE=1
10
11 CS_PASSWORD="onap123#@!"
12 SDC_USER="asdc_user"
13 SDC_PASSWORD="Aa1234%^!"
14
15 JETTY_BASE="/var/lib/jetty"
16 SDC_CERT_DIR="onap/cert"
17
18 RELEASE=latest
19 DCAE_RELEASE=latest
20 LOCAL=false
21 RUNTESTS=false
22 BE_DEBUG_PORT="--publish 4000:4000"
23 FE_DEBUG_PORT="--publish 6000:6000"
24 ONBOARD_DEBUG_PORT="--publish 4001:4001"
25
26
27 # Java Options:
28 BE_JAVA_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=4000,server=y,suspend=n -Xmx1536m -Xms1536m"
29 FE_JAVA_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=6000,server=y,suspend=n -Xmx256m -Xms256m"
30 ONBOARD_BE_JAVA_OPTIONS="-Xdebug -agentlib:jdwp=transport=dt_socket,address=4001,server=y,suspend=n -Xmx1g -Xms1g"
31 DCAE_BE_JAVA_OPTIONS="-XX:MaxPermSize=256m -Xmx1024m -Dconfig.home=config -Dlog.home=/var/lib/jetty/logs/ -Dlogging.config=config/dcae-be/logback-spring.xml"
32 DCAE_FE_JAVA_OPTIONS="-XX:MaxPermSize=256m -Xmx1024m -Dconfig.home=config -Dlog.home=/var/lib/jetty/logs/ -Dlogging.config=config/dcae-fe/logback-spring.xml"
33 SIM_JAVA_OPTIONS=" -Xmx128m -Xms128m -Xss1m -Dlog4j.configuration=file:///${JETTY_BASE}/config/sdc-simulator/log4j.properties"
34 API_TESTS_JAVA_OPTIONS="-Xmx512m -Xms512m"
35 UI_TESTS_JAVA_OPTIONS="-Xmx1024m -Xms1024m"
36 #Define this as variable, so it can be excluded in run commands on Docker for OSX, as /etc/localtime cant be mounted there.
37 LOCAL_TIME_MOUNT_CMD="--volume /etc/localtime:/etc/localtime:ro"
38 # If os is OSX, unset this, so /etc/localtime is not mounted, otherwise leave it be
39 if [[ "$OSTYPE" == "darwin"* ]]; then
40   LOCAL_TIME_MOUNT_CMD=""
41 fi
42
43
44 #
45 # Functions:
46 #
47
48
49 function usage {
50     echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ] [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -l|--local <Run-without-pull>] [ -sim|--simulator <Run-with-simulator>] [ -ta <run api tests with the supplied test suit>] [ -tu <run ui tests with the supplied test suit>] [ -ta <run api tests with the supplied test suit>] [ -tu <run ui tests with the supplied test suit>] [ -tad <run api tests with the default test suit>] [ -tu <run ui tests with the default test suit>] [ -dcae|--dcae <Run-with DCAE using label DCAE-RELEASE-NAME>][ -h|--help ]"
51     echo "start dockers built locally example: docker_run.sh -l"
52     echo "start dockers built locally and simulator example: docker_run.sh -l -sim"
53     echo "start dockers, pull from onap nexus according to release and simulator example: docker_run.sh -r 1.5-STAGING-latest -sim"
54     echo "start dockers with DCAE, pull from onap nexus according to respective releases: docker_run.sh -r 1.5-STAGING-latest -dcae 1.3-STAGING-latest"
55     echo "start dockers built locally and run api tests docker example: docker_run.sh -l -tad"
56     echo "start dockers built locally and run only the catalog be example: docker_run.sh -l -d sdc-BE "
57 }
58 #
59
60
61 function cleanup {
62     echo "Performing old dockers cleanup"
63
64         if [ "$1" == "all" ] ; then
65                 docker_ids=`docker ps -a | egrep -v "onap/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit}|dcae" | awk '{print $1}'`
66                 for X in ${docker_ids}
67                 do
68                         docker rm -f ${X}
69                 done
70         else
71             echo "performing $1 docker cleanup"
72             tmp=`docker ps -a -q --filter="name=$1"`
73             if [[ ! -z "$tmp" ]]; then
74                 docker rm -f ${tmp}
75         fi
76         fi
77 }
78 #
79
80
81 function dir_perms {
82     mkdir -p ${WORKSPACE}/data/logs/BE/SDC/SDC-BE
83     mkdir -p ${WORKSPACE}/data/logs/FE/SDC/SDC-FE
84
85     mkdir -p ${WORKSPACE}/data/logs/DCAE-BE/DCAE
86     mkdir -p ${WORKSPACE}/data/logs/DCAE-FE/DCAE
87
88     mkdir -p ${WORKSPACE}/data/logs/sdc-api-tests/ExtentReport
89     mkdir -p ${WORKSPACE}/data/logs/ONBOARD/SDC/ONBOARD-BE
90         mkdir -p ${WORKSPACE}/data/logs/sdc-api-tests/target
91         mkdir -p ${WORKSPACE}/data/logs/sdc-ui-tests/ExtentReport
92         mkdir -p ${WORKSPACE}/data/logs/sdc-ui-tests/target
93         mkdir -p ${WORKSPACE}/data/logs/docker_logs
94         mkdir -p ${WORKSPACE}/data/logs/WS
95         echo "create dir"
96         echo "${WORKSPACE}/data/${SDC_CERT_DIR}"
97         mkdir -p ${WORKSPACE}/data/${SDC_CERT_DIR}
98     chmod -R 777 ${WORKSPACE}/data/logs
99 }
100 #
101
102
103 function docker_logs {
104     docker logs $1 > ${WORKSPACE}/data/logs/docker_logs/$1_docker.log
105 }
106 #
107
108
109 #
110 # Readiness Prob
111 #
112
113 function ready_probe {
114     docker exec $1 /var/lib/ready-probe.sh > /dev/null 2>&1
115     rc=$?
116     if [[ ${rc} == 0 ]]; then
117         echo DOCKER $1 start finished in $2 seconds
118         return ${SUCCESS}
119     fi
120     return ${FAILURE}
121 }
122 #
123
124
125 function probe_docker {
126     MATCH=`docker logs --tail 30 $1 | grep "DOCKER STARTED"`
127     echo MATCH is -- ${MATCH}
128
129     if [ -n "$MATCH" ] ; then
130         echo DOCKER start finished in $2 seconds
131         return ${SUCCESS}
132     fi
133     return ${FAILURE}
134 }
135 #
136
137
138 function probe_es {
139     health_Check_http_code=$(curl --noproxy "*" -o /dev/null -w '%{http_code}' http://${IP}:9200/_cluster/health?wait_for_status=yellow&timeout=120s)
140     if [[ "$health_Check_http_code" -eq 200 ]] ; then
141         echo DOCKER start finished in $1 seconds
142         return ${SUCCESS}
143     fi
144     return ${FAILURE}
145 }
146 #
147
148
149 function probe_sim {
150     if lsof -Pi :8285 -sTCP:LISTEN -t >/dev/null ; then
151         echo "Already running"
152         return ${SUCCESS}
153     else
154         echo "Not running"
155         return ${FAILURE}
156     fi
157 }
158 #
159
160
161 function probe_dcae_be {
162     health_check_http_code=$(curl -i -o /dev/null -w '%{http_code}' http://${IP}:8082/dcae/conf/composition)
163     if [[ "${health_check_http_code}" -eq 200 ]] ; then
164         echo DOCKER start finished in $1 seconds
165         return ${SUCCESS}
166     fi
167     return ${FAILURE}
168 }
169 #
170
171 function probe_dcae_fe {
172     health_check_http_code=$(curl -i -o /dev/null -w '%{http_code}' http://${IP}:8183/dcaed/healthCheck)
173     if [[ "${health_check_http_code}" -eq 200 ]] ; then
174         echo DOCKER start finished in $1 seconds
175         return ${SUCCESS}
176     fi
177     return ${FAILURE}
178 }
179 #
180
181
182 # Not applicable for current release. Return Success in any case
183 function probe_dcae_tools {
184    health_check_http_code=$(curl -i -o /dev/null -w '%{http_code}'  http://${IP}:8082/dcae/getResourcesByMonitoringTemplateCategory)
185     if [[ "${health_check_http_code}" -eq 200 ]] ; then
186         echo DOCKER start finished in $1 seconds
187         return ${SUCCESS}
188     fi
189     return ${SUCCESS}
190 }
191 #
192
193
194 function monitor_docker {
195     DOCKER_NAME=$1
196     echo "Monitor ${DOCKER_NAME} Docker"
197     sleep 5
198     TIME_OUT=900
199     INTERVAL=20
200     TIME=0
201
202     while [ "$TIME" -lt "$TIME_OUT" ]; do
203
204         case ${DOCKER_NAME} in
205
206             sdc-cs)
207                 ready_probe ${DOCKER_NAME} ${TIME} ;
208                 status=$? ;
209             ;;
210             sdc-es)
211                 probe_es ${TIME} ;
212                 status=$? ;
213             ;;
214             sdc-BE)
215                     ready_probe ${DOCKER_NAME} ${TIME} ;
216                 status=$? ;
217             ;;
218             sdc-FE)
219                 ready_probe ${DOCKER_NAME} ${TIME} ;
220                 status=$? ;
221             ;;
222             sdc-onboard-BE)
223                 ready_probe ${DOCKER_NAME} ${TIME} ;
224                 status=$? ;
225             ;;
226             dcae-be)
227                 probe_dcae_be ${TIME} ;
228                 status=$? ;
229             ;;
230             dcae-fe)
231                 probe_dcae_fe ${TIME} ;
232                 status=$? ;
233             ;;
234             dcae-tools)
235                 probe_dcae_tools ;
236                 status=$? ;
237             ;;
238             *)
239                 probe_docker ${DOCKER_NAME} ${TIME};
240                 status=$? ;
241             ;;
242
243         esac
244
245         if [ ${status} == ${SUCCESS} ] ; then
246             break;
247         fi
248
249         echo "Sleep: ${INTERVAL} seconds before testing if ${DOCKER_NAME} DOCKER is up. Total wait time up now is: ${TIME} seconds. Timeout is: ${TIME_OUT} seconds"
250         sleep ${INTERVAL}
251         TIME=$(($TIME+$INTERVAL))
252     done
253
254     docker_logs ${DOCKER_NAME}
255
256     if [ "$TIME" -ge "$TIME_OUT" ]; then
257         echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
258     fi
259 }
260 #
261
262
263 function healthCheck {
264         curl --noproxy "*" ${IP}:9200/_cluster/health?pretty=true
265
266         echo "BE health-Check:"
267         curl --noproxy "*" http://${IP}:8080/sdc2/rest/healthCheck
268
269         echo ""
270         echo ""
271         echo "FE health-Check:"
272         curl --noproxy "*" http://${IP}:8181/sdc1/rest/healthCheck
273
274
275         echo ""
276         echo ""
277         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;)
278         if [[ ${healthCheck_http_code} != 200 ]]; then
279                 echo "Error [${healthCheck_http_code}] while user existance check"
280                 return ${healthCheck_http_code}
281         fi
282         echo "check user existance: OK"
283         return ${healthCheck_http_code}
284 }
285 #
286
287
288 function command_exit_status {
289     status=$1
290     docker=$2
291     if [ "${status}" != "0" ] ; then
292         echo "[  ERROR  ] Docker ${docker} run command exit with status [${status}]"
293     fi
294 }
295 #
296
297
298 #
299 # Run Containers
300 #
301
302 #Elastic-Search
303 function sdc-es {
304     DOCKER_NAME="sdc-es"
305     echo "docker run sdc-elasticsearch..."
306     if [ ${LOCAL} = false ]; then
307         echo "pulling code"
308         docker pull ${PREFIX}/sdc-elasticsearch:${RELEASE}
309     fi
310     docker run -dit --name ${DOCKER_NAME} --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 ${LOCAL_TIME_MOUNT_CMD} --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
311     command_exit_status $? ${DOCKER_NAME}
312     echo "please wait while ES is starting..."
313     monitor_docker ${DOCKER_NAME}
314 }
315 #
316
317
318 #Init-Elastic-Search
319 function sdc-init-es {
320     DOCKER_NAME="sdc-init-es"
321     echo "docker run sdc-init-elasticsearch..."
322     if [ ${LOCAL} = false ]; then
323         echo "pulling code"
324         docker pull ${PREFIX}/sdc-init-elasticsearch:${RELEASE}
325     fi
326     echo "Running sdc-init-es"
327     docker run --name ${DOCKER_NAME} --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 ${LOCAL_TIME_MOUNT_CMD} --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments ${PREFIX}/sdc-init-elasticsearch:${RELEASE} > /dev/null 2>&1
328     rc=$?
329     docker_logs ${DOCKER_NAME}
330     if [[ ${rc} != 0 ]]; then exit ${rc}; fi
331 }
332 #
333
334
335 #Cassandra
336 function sdc-cs {
337     DOCKER_NAME="sdc-cs"
338     echo "docker run sdc-cassandra..."
339     if [ ${LOCAL} = false ]; then
340         docker pull ${PREFIX}/sdc-cassandra:${RELEASE}
341     fi
342     docker run -dit --name ${DOCKER_NAME} --env RELEASE="${RELEASE}" --env CS_PASSWORD="${CS_PASSWORD}" --env ENVNAME="${DEP_ENV}" --env HOST_IP=${IP} --env MAX_HEAP_SIZE="1536M" --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 ${LOCAL_TIME_MOUNT_CMD} --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
343     command_exit_status $? ${DOCKER_NAME}
344     echo "please wait while CS is starting..."
345     monitor_docker ${DOCKER_NAME}
346 }
347 #
348
349
350 #Cassandra-init
351 function sdc-cs-init {
352     DOCKER_NAME="sdc-cs-init"
353     echo "docker run sdc-cassandra-init..."
354     if [ ${LOCAL} = false ]; then
355         docker pull ${PREFIX}/sdc-cassandra-init:${RELEASE}
356     fi
357     docker run --name ${DOCKER_NAME} --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 ${LOCAL_TIME_MOUNT_CMD} --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
358     rc=$?
359     docker_logs ${DOCKER_NAME}
360     if [[ ${rc} != 0 ]]; then exit ${rc}; fi
361 }
362 #
363
364
365 #Onboard Cassandra-init
366 function sdc-cs-onboard-init {
367     DOCKER_NAME="sdc-cs-onboard-init"
368     echo "docker run sdc-cs-onboard-init..."
369     if [ ${LOCAL} = false ]; then
370         docker pull ${PREFIX}/sdc-onboard-cassandra-init:${RELEASE}
371     fi
372     docker run --name ${DOCKER_NAME} --env RELEASE="${RELEASE}" --env CS_HOST_IP=${IP}  --env SDC_USER="${SDC_USER}" --env SDC_PASSWORD="${SDC_PASSWORD}" --env CS_PASSWORD="${CS_PASSWORD}" --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 ${LOCAL_TIME_MOUNT_CMD} --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-onboard-cassandra-init:${RELEASE}
373     rc=$?
374     docker_logs ${DOCKER_NAME}
375     if [[ ${rc} != 0 ]]; then exit ${rc}; fi
376 }
377 #
378
379
380 #Kibana
381 function sdc-kbn {
382     DOCKER_NAME="sdc-kbn"
383     echo "docker run sdc-kibana..."
384     if [ ${LOCAL} = false ]; then
385         docker pull ${PREFIX}/sdc-kibana:${RELEASE}
386         docker run --detach --name ${DOCKER_NAME} --env ENVNAME="${DEP_ENV}" --env NODE_OPTIONS="--max-old-space-size=200" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 ${LOCAL_TIME_MOUNT_CMD} --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 5601:5601 ${PREFIX}/sdc-kibana:${RELEASE}
387         command_exit_status $? ${DOCKER_NAME}
388     fi
389 }
390 #
391
392
393 #Back-End
394 function sdc-BE {
395     DOCKER_NAME="sdc-BE"
396     echo "docker run sdc-backend..."
397     if [ ${LOCAL} = false ]; then
398         docker pull ${PREFIX}/sdc-backend:${RELEASE}
399     else
400         ADDITIONAL_ARGUMENTS=${BE_DEBUG_PORT}
401     fi
402     docker run --detach --name ${DOCKER_NAME} --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env cassandra_ssl_enabled="false" --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 ${LOCAL_TIME_MOUNT_CMD} --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}
403     command_exit_status $? ${DOCKER_NAME}
404     echo "please wait while BE is starting..."
405     monitor_docker ${DOCKER_NAME}
406 }
407 #
408
409
410 # Back-End-Init
411 function sdc-BE-init {
412     DOCKER_NAME="sdc-BE-init"
413     echo "docker run sdc-backend-init..."
414     if [ ${LOCAL} = false ]; then
415         docker pull ${PREFIX}/sdc-backend-init:${RELEASE}
416     fi
417     docker run --name ${DOCKER_NAME} --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 ${LOCAL_TIME_MOUNT_CMD} --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
418     rc=$?
419     docker_logs ${DOCKER_NAME}
420     if [[ ${rc} != 0 ]]; then exit ${rc}; fi
421 }
422 #
423
424
425 # Onboard Back-End
426 function sdc-onboard-BE {
427     DOCKER_NAME="sdc-onboard-BE"
428     echo "docker run  sdc-onboard-BE ..."
429 #    TODO Check the dir_perms action . do we need it here ??
430 #    dir_perms
431     if [ ${LOCAL} = false ]; then
432         docker pull ${PREFIX}/sdc-onboard-backend:${RELEASE}
433     else
434         ADDITIONAL_ARGUMENTS=${ONBOARD_DEBUG_PORT}
435     fi
436     docker run --detach --name ${DOCKER_NAME} --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env cassandra_ssl_enabled="false" --env SDC_CLUSTER_NAME="SDC-CS-${DEP_ENV}" --env SDC_USER="${SDC_USER}" --env SDC_PASSWORD="${SDC_PASSWORD}" --env SDC_CERT_DIR="${SDC_CERT_DIR}" --env JAVA_OPTIONS="${ONBOARD_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 ${LOCAL_TIME_MOUNT_CMD} --volume ${WORKSPACE}/data/${SDC_CERT_DIR}:/var/lib/jetty/onap/cert --volume ${WORKSPACE}/data/logs/ONBOARD:/var/lib/jetty/logs --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --publish 8445:8445 --publish 8081:8081 ${ADDITIONAL_ARGUMENTS} ${PREFIX}/sdc-onboard-backend:${RELEASE}
437     command_exit_status $? ${DOCKER_NAME}
438     echo "please wait while sdc-onboard-BE is starting..."
439     monitor_docker ${DOCKER_NAME}
440 }
441 #
442
443
444 # Front-End
445 function sdc-FE {
446     DOCKER_NAME="sdc-FE"
447     echo "docker run sdc-frontend..."
448     if [ ${LOCAL} = false ]; then
449         docker pull ${PREFIX}/sdc-frontend:${RELEASE}
450     else
451         ADDITIONAL_ARGUMENTS=${FE_DEBUG_PORT}
452     fi
453     docker run --detach --name ${DOCKER_NAME} --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 ${LOCAL_TIME_MOUNT_CMD}  --volume ${WORKSPACE}/data/logs/FE/:/var/lib/jetty/logs --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments --volume ${WORKSPACE}/data/environments/plugins-configuration.yaml:${JETTY_BASE}/config/catalog-fe/plugins-configuration.yaml --publish 9443:9443 --publish 8181:8181 ${ADDITIONAL_ARGUMENTS} ${PREFIX}/sdc-frontend:${RELEASE}
454     command_exit_status $? ${DOCKER_NAME}
455     echo "please wait while FE is starting....."
456     monitor_docker ${DOCKER_NAME}
457 }
458 #
459
460
461 # DCAE BackEnd
462 function dcae-be {
463     if [ ! ${DCAE_ENABLE} ] ; then
464         return
465     fi
466     DOCKER_NAME="dcae-be"
467     echo "docker run ${DOCKER_NAME}..."
468     if [ ${LOCAL} = false ]; then
469             docker pull ${PREFIX}/${DOCKER_NAME}:${DCAE_RELEASE}
470     fi
471     docker run --detach --name ${DOCKER_NAME} --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env JAVA_OPTIONS="${DCAE_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 ${LOCAL_TIME_MOUNT_CMD}  --volume ${WORKSPACE}/data/logs/DCAE-BE/:/var/lib/jetty/logs --volume ${WORKSPACE}/data/environments:/var/opt/dcae-be/chef-solo/environments --publish 8444:8444 --publish 8082:8082 ${PREFIX}/${DOCKER_NAME}:${DCAE_RELEASE}
472     command_exit_status $? ${DOCKER_NAME}
473     echo "please wait while ${DOCKER_NAME^^} is starting....."
474     monitor_docker ${DOCKER_NAME}
475 }
476 #
477
478
479 # DCAE Configuration
480 function dcae-tools {
481     if [ ! ${DCAE_ENABLE} ] ; then
482         return
483     fi
484     DOCKER_NAME="dcae-tools"
485     echo "docker run ${DOCKER_NAME}..."
486     if [ ${LOCAL} = false ]; then
487             docker pull ${PREFIX}/${DOCKER_NAME}:${DCAE_RELEASE}
488     fi
489     docker run --detach --name ${DOCKER_NAME} --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" ${LOCAL_TIME_MOUNT_CMD}  --volume ${WORKSPACE}/data/logs/BE/:/var/lib/jetty/logs --volume ${WORKSPACE}/data/environments:/var/opt/dcae-tools/chef-solo/environments  ${PREFIX}/${DOCKER_NAME}:${DCAE_RELEASE}
490     command_exit_status $? ${DOCKER_NAME}
491     echo "please wait while ${DOCKER_NAME^^} is starting....."
492     monitor_docker ${DOCKER_NAME}
493
494 }
495 #
496
497
498 # DCAE FrontEnd
499 function dcae-fe {
500     if [ ! ${DCAE_ENABLE} ] ; then
501         return
502     fi
503     DOCKER_NAME="dcae-fe"
504     echo "docker run ${DOCKER_NAME}..."
505     if [ ${LOCAL} = false ]; then
506             docker pull ${PREFIX}/${DOCKER_NAME}:${DCAE_RELEASE}
507     fi
508     docker run --detach --name ${DOCKER_NAME} --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env JAVA_OPTIONS="${DCAE_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 ${LOCAL_TIME_MOUNT_CMD}  --volume ${WORKSPACE}/data/logs/DCAE-FE/:/var/lib/jetty/logs --volume ${WORKSPACE}/data/environments:/var/opt/dcae-fe/chef-solo/environments/ --publish 9444:9444 --publish 8183:8183 ${PREFIX}/${DOCKER_NAME}:${DCAE_RELEASE}
509     command_exit_status $? ${DOCKER_NAME}
510     echo "please wait while ${DOCKER_NAME^^} is starting....."
511     monitor_docker ${DOCKER_NAME}
512
513 }
514 #
515
516
517 # apis-sanity
518 function sdc-api-tests {
519     if [[ ${RUN_API_TESTS} = true ]] ; then
520         healthCheck
521         healthCheck_http_code=$?
522         if [[ ${healthCheck_http_code} == 200 ]] ; then
523             echo "docker run sdc-api-tests..."
524             echo "Trigger sdc-api-tests docker, please wait..."
525
526             if [ ${LOCAL} = false ]; then
527                 docker pull ${PREFIX}/sdc-api-tests:${RELEASE}
528             fi
529
530             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 ${LOCAL_TIME_MOUNT_CMD} --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 --volume ${WORKSPACE}/data/${SDC_CERT_DIR}:/var/lib/tests/cert --publish 9560:9560 ${PREFIX}/sdc-api-tests:${RELEASE} echo "please wait while SDC-API-TESTS is starting....."
531             monitor_docker sdc-api-tests
532         fi
533     fi
534 }
535 #
536
537
538 # ui-sanity
539 function sdc-ui-tests {
540
541     if [[ ${RUN_UI_TESTS} = true ]] ; then
542                 healthCheck
543         healthCheck_http_code=$?
544         if [[ ${healthCheck_http_code} == 200 ]]; then
545             echo "docker run sdc-ui-tets..."
546             echo "Trigger sdc-ui-tests docker, please wait..."
547
548             if [ ${LOCAL} = false ]; then
549                 docker pull ${PREFIX}/sdc-ui-tests:${RELEASE}
550             fi
551             RUN_SIMULATOR=true;
552             sdc-sim
553             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 ${LOCAL_TIME_MOUNT_CMD} --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}
554             echo "please wait while SDC-UI-TESTS is starting....."
555             monitor_docker sdc-ui-tests
556         fi
557     fi
558 }
559 #
560
561
562 # SDC-Simulator
563 function sdc-sim {
564     if [ "${RUN_SIMULATOR}" == true ]; then
565         echo "docker run sdc-webSimulator..."
566         if [ ${LOCAL} = false ]; then
567             docker pull ${PREFIX}/sdc-simulator:${RELEASE}
568         fi
569
570         probe_sim
571         sim_stat=$?
572         if [ ${sim_stat} == 1 ]; then
573             docker run \
574                 --detach \
575                 --name sdc-sim \
576                 --env FE_URL="${FE_URL}" \
577                 --env JAVA_OPTIONS="${SIM_JAVA_OPTIONS}" \
578                 --env ENVNAME="${DEP_ENV}" \
579                 ${LOCAL_TIME_MOUNT_CMD} \
580                 --volume ${WORKSPACE}/data/logs/WS/:/var/lib/jetty/logs \
581                 --volume ${WORKSPACE}/data/environments:/root/chef-solo/environments \
582                 --publish 8285:8080 \
583                 --publish 8286:8443 ${PREFIX}/sdc-simulator:${RELEASE}
584             echo "please wait while SDC-WEB-SIMULATOR is starting....."
585             monitor_docker sdc-sim
586         fi
587     fi
588 }
589 #
590
591
592 #
593 # Main
594 #
595
596 # Handle command line arguments
597 while [ $# -gt 0 ]; do
598     case $1 in
599
600         # -r | --release - The specific docker version to pull and deploy
601     -r | --release )
602           shift 1 ;
603           RELEASE=$1;
604           shift 1;;
605
606         # -e | --environment - The environment name you want to deploy
607     -e | --environment )
608           shift 1;
609           DEP_ENV=$1;
610           shift 1 ;;
611
612         # -p | --port - The port from which to connect to the docker nexus
613     -p | --port )
614           shift 1 ;
615           PORT=$1;
616           shift 1 ;;
617
618         # -l | --local - Use this for deploying your local dockers without pulling them first
619     -l | --local )
620           LOCAL=true;
621           shift 1;;
622
623         # -ta - Use this for running the APIs sanity docker after all other dockers have been deployed
624     -ta  )
625           shift 1 ;
626           API_SUITE=$1;
627           RUN_API_TESTS=true;
628           shift 1 ;;
629
630         # -tu - Use this for running the UI sanity docker after all other dockers have been deployed
631     -tu  )
632           shift 1 ;
633               UI_SUITE=$1;
634           RUN_UI_TESTS=true;
635           shift 1 ;;
636
637     # -tad - Use this for running the DEFAULT suite of tests in APIs sanity docker after all other dockers have been deployed
638     -tad | -t )
639           API_SUITE="onapApiSanity";
640           RUN_API_TESTS=true;
641           shift 1 ;;
642
643         # -tud - Use this for running the DEFAULT suite of tests in UI sanity docker after all other dockers have been deployed
644     -tud   )
645           UI_SUITE="onapUiSanity";
646           RUN_UI_TESTS=true;
647           shift 1 ;;
648
649     # -d | --docker - The init specified docker
650     -d | --docker )
651           shift 1 ;
652           DOCKER=$1;
653           shift 1 ;;
654     # -sim | --simulator run the simulator
655     -sim | --simulator )
656           RUN_SIMULATOR=true;
657           shift 1 ;;
658     # -sim | --simulator run the simulator
659     -u | --fe_url )
660           shift 1 ;
661           FE_URL=$1;
662           shift 1 ;;
663     # -dcae | --dcae - Use this to deploy DCAE upon SDC
664     -dcae | --dcae )
665           shift 1 ;
666           DCAE_RELEASE=$1;
667           shift 1;
668           DCAE_ENABLE='True';;
669
670         # -h | --help - Display the help message with all the available run options
671     -h | --help )
672           usage;
673           exit  ${SUCCESS};;
674
675          * )
676           usage;
677           exit  ${FAILURE};;
678     esac
679 done
680
681
682 #Prefix those with WORKSPACE so it can be set to something other than /opt
683 [ -f ${WORKSPACE}/opt/config/env_name.txt ] && DEP_ENV=$(cat ${WORKSPACE}/opt/config/env_name.txt) || echo ${DEP_ENV}
684 [ -f ${WORKSPACE}/opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat ${WORKSPACE}/opt/config/nexus_username.txt)    || NEXUS_USERNAME=release
685 [ -f ${WORKSPACE}/opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat ${WORKSPACE}/opt/config/nexus_password.txt)      || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
686 [ -f ${WORKSPACE}/opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat ${WORKSPACE}/opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=nexus3.onap.org:${PORT}
687 [ -f ${WORKSPACE}/opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
688
689
690 export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
691 #If OSX, then use this to get IP
692 if [[ "$OSTYPE" == "darwin"* ]]; then
693     export IP=$(ipconfig getifaddr en0)
694 fi
695 export PREFIX=${NEXUS_DOCKER_REPO}'/onap'
696
697 if [ ${LOCAL} = true ]; then
698         PREFIX='onap'
699 fi
700
701 echo ""
702
703 if [ -z "${DOCKER}" ]; then
704     cleanup all
705         dir_perms
706         sdc-es
707         sdc-init-es
708         sdc-cs
709         sdc-cs-init
710 #       sdc-kbn
711         sdc-cs-onboard-init
712         sdc-onboard-BE
713         sdc-BE
714         sdc-BE-init
715         sdc-FE
716         dcae-be
717         dcae-tools
718         dcae-fe
719         healthCheck
720     sdc-sim
721         sdc-api-tests
722         sdc-ui-tests
723 else
724         cleanup ${DOCKER}
725         dir_perms
726         ${DOCKER}
727     healthCheck
728 fi