Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # ============LICENSE_START======================================================= |
| 4 | # ONAP DMAAP MR |
| 5 | # ================================================================================ |
| 6 | # Copyright (C) 2018 AT&T Intellectual Property. All rights |
| 7 | # reserved. |
| 8 | # ================================================================================ |
| 9 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | # you may not use this file except in compliance with the License. |
| 11 | # You may obtain a copy of the License at |
| 12 | # |
| 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | # |
| 15 | # Unless required by applicable law or agreed to in writing, software |
| 16 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | # See the License for the specific language governing permissions and |
| 19 | # limitations under the License. |
| 20 | # ============LICENSE_END============================================ |
| 21 | # =================================================================== |
| 22 | # ECOMP is a trademark and service mark of AT&T Intellectual Property. |
| 23 | # |
| 24 | # This script is a copy of plans/dmaap/mrpubsub/setup.sh, placed in the scripts |
| 25 | # dir, and edited to be a callable function from other plans. e.g. dmaap-buscontroller needs it. |
| 26 | # |
| 27 | source ${SCRIPTS}/common_functions.sh |
| 28 | |
| 29 | # function to launch DMaaP MR docker containers. |
| 30 | # sets global var IP with assigned IP address of MR container. |
| 31 | # (kafka and zk containers are not called externally) |
| 32 | |
| 33 | function dmaap_mr_launch() { |
| 34 | # |
| 35 | # the default prefix for docker containers is the directory name containing the docker-compose.yml file. |
| 36 | # It can be over-written by an env variable COMPOSE_PROJECT_NAME. This env var seems to be set in the Jenkins CSIT environment |
Dominic Lunanuova | c078eea | 2018-10-01 20:21:48 +0000 | [diff] [blame] | 37 | COMPOSE_PREFIX=${COMPOSE_PROJECT_NAME:-dockercompose} |
| 38 | export COMPOSE_PROJECT_NAME=$COMPOSE_PREFIX |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 39 | echo "COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME" |
| 40 | echo "COMPOSE_PREFIX=$COMPOSE_PREFIX" |
| 41 | |
| 42 | # Clone DMaaP Message Router repo |
| 43 | mkdir -p $WORKSPACE/archives/dmaapmr |
| 44 | cd $WORKSPACE/archives/dmaapmr |
| 45 | #unset http_proxy https_proxy |
| 46 | git clone --depth 1 http://gerrit.onap.org/r/dmaap/messagerouter/messageservice -b master |
| 47 | cd messageservice |
| 48 | git pull |
| 49 | cd $WORKSPACE/archives/dmaapmr/messageservice/src/main/resources/docker-compose |
| 50 | cp $WORKSPACE/archives/dmaapmr/messageservice/bundleconfig-local/etc/appprops/MsgRtrApi.properties /var/tmp/ |
| 51 | |
| 52 | |
| 53 | # start DMaaP MR containers with docker compose and configuration from docker-compose.yml |
| 54 | docker login -u docker -p docker nexus3.onap.org:10001 |
| 55 | docker-compose up -d |
| 56 | docker ps |
| 57 | |
| 58 | # Wait for initialization of Docker contaienr for DMaaP MR, Kafka and Zookeeper |
| 59 | for i in {1..50}; do |
| 60 | if [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_dmaap_1) ] && \ |
| 61 | [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_zookeeper_1) ] && \ |
| 62 | [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_dmaap_1) ] |
| 63 | then |
| 64 | echo "DMaaP Service Running" |
| 65 | break |
| 66 | else |
| 67 | echo sleep $i |
| 68 | sleep $i |
| 69 | fi |
| 70 | done |
| 71 | |
| 72 | |
| 73 | DMAAP_MR_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${COMPOSE_PREFIX}_dmaap_1) |
| 74 | IP=${DMAAP_MR_IP} |
| 75 | KAFKA_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${COMPOSE_PREFIX}_kafka_1) |
| 76 | ZOOKEEPER_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${COMPOSE_PREFIX}_zookeeper_1) |
| 77 | |
| 78 | echo DMAAP_MR_IP=${DMAAP_MR_IP} |
| 79 | echo IP=${IP} |
| 80 | echo KAFKA_IP=${KAFKA_IP} |
| 81 | echo ZOOKEEPER_IP=${ZOOKEEPER_IP} |
| 82 | |
| 83 | # Initial docker-compose up and down is for populating kafka and zookeeper IPs in /var/tmp/MsgRtrApi.properites |
| 84 | docker-compose down |
| 85 | |
| 86 | # Update kafkfa and zookeeper properties in MsgRtrApi.propeties which will be copied to DMaaP Container |
| 87 | sed -i -e 's/<zookeeper_host>/'$ZOOKEEPER_IP'/' /var/tmp/MsgRtrApi.properties |
| 88 | sed -i -e 's/<kafka_host>:<kafka_port>/'$KAFKA_IP':9092/' /var/tmp/MsgRtrApi.properties |
| 89 | |
| 90 | docker-compose build |
| 91 | docker login -u docker -p docker nexus3.onap.org:10001 |
| 92 | docker-compose up -d |
| 93 | |
| 94 | # Wait for initialization of Docker containers |
| 95 | for i in {1..50}; do |
| 96 | if [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_dmaap_1) ] && \ |
| 97 | [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_zookeeper_1) ] && \ |
| 98 | [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_dmaap_1) ] |
| 99 | then |
| 100 | echo "DMaaP Service Running" |
| 101 | break |
| 102 | else |
| 103 | echo sleep $i |
| 104 | sleep $i |
| 105 | fi |
| 106 | done |
| 107 | |
| 108 | # Wait for initialization of docker services |
| 109 | for i in {1..50}; do |
| 110 | curl -sS -m 1 ${DMAAP_MR_IP}:3904/events/TestTopic && break |
| 111 | echo sleep $i |
| 112 | sleep $i |
| 113 | done |
| 114 | } |
| 115 | |