blob: 36d316890dedd0c3e6ca9cfdbe51b7e5a53806d6 [file] [log] [blame]
Gary Wu9abb61c2018-09-27 10:38:50 -07001#!/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#
27source ${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
33function 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
37 COMPOSE_PREFIX=${COMPOSE_PROJECT_NAME:-docker-compose}
38 echo "COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME"
39 echo "COMPOSE_PREFIX=$COMPOSE_PREFIX"
40
41 # Clone DMaaP Message Router repo
42 mkdir -p $WORKSPACE/archives/dmaapmr
43 cd $WORKSPACE/archives/dmaapmr
44 #unset http_proxy https_proxy
45 git clone --depth 1 http://gerrit.onap.org/r/dmaap/messagerouter/messageservice -b master
46 cd messageservice
47 git pull
48 cd $WORKSPACE/archives/dmaapmr/messageservice/src/main/resources/docker-compose
49 cp $WORKSPACE/archives/dmaapmr/messageservice/bundleconfig-local/etc/appprops/MsgRtrApi.properties /var/tmp/
50
51
52 # start DMaaP MR containers with docker compose and configuration from docker-compose.yml
53 docker login -u docker -p docker nexus3.onap.org:10001
54 docker-compose up -d
55 docker ps
56
57 # Wait for initialization of Docker contaienr for DMaaP MR, Kafka and Zookeeper
58 for i in {1..50}; do
59 if [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_dmaap_1) ] && \
60 [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_zookeeper_1) ] && \
61 [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_dmaap_1) ]
62 then
63 echo "DMaaP Service Running"
64 break
65 else
66 echo sleep $i
67 sleep $i
68 fi
69 done
70
71
72 DMAAP_MR_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${COMPOSE_PREFIX}_dmaap_1)
73 IP=${DMAAP_MR_IP}
74 KAFKA_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${COMPOSE_PREFIX}_kafka_1)
75 ZOOKEEPER_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${COMPOSE_PREFIX}_zookeeper_1)
76
77 echo DMAAP_MR_IP=${DMAAP_MR_IP}
78 echo IP=${IP}
79 echo KAFKA_IP=${KAFKA_IP}
80 echo ZOOKEEPER_IP=${ZOOKEEPER_IP}
81
82 # Initial docker-compose up and down is for populating kafka and zookeeper IPs in /var/tmp/MsgRtrApi.properites
83 docker-compose down
84
85 # Update kafkfa and zookeeper properties in MsgRtrApi.propeties which will be copied to DMaaP Container
86 sed -i -e 's/<zookeeper_host>/'$ZOOKEEPER_IP'/' /var/tmp/MsgRtrApi.properties
87 sed -i -e 's/<kafka_host>:<kafka_port>/'$KAFKA_IP':9092/' /var/tmp/MsgRtrApi.properties
88
89 docker-compose build
90 docker login -u docker -p docker nexus3.onap.org:10001
91 docker-compose up -d
92
93 # Wait for initialization of Docker containers
94 for i in {1..50}; do
95 if [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_dmaap_1) ] && \
96 [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_zookeeper_1) ] && \
97 [ $(docker inspect --format '{{ .State.Running }}' ${COMPOSE_PREFIX}_dmaap_1) ]
98 then
99 echo "DMaaP Service Running"
100 break
101 else
102 echo sleep $i
103 sleep $i
104 fi
105 done
106
107 # Wait for initialization of docker services
108 for i in {1..50}; do
109 curl -sS -m 1 ${DMAAP_MR_IP}:3904/events/TestTopic && break
110 echo sleep $i
111 sleep $i
112 done
113}
114