2 #############################################################################
4 # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 #############################################################################
22 ################################## start of vm_init #####################################
26 URL_ROOT='nexus.onap.org/service/local/repositories/raw/content'
27 REPO_BLUEPRINTS='org.onap.dcaegen2.platform.blueprints'
28 REPO_DEPLOYMENTS='org.onap.dcaegen2.deployments'
29 if [ -e /opt/config/dcae_deployment_profile.txt ]; then
30 DEPLOYMENT_PROFILE=$(cat /opt/config/dcae_deployment_profile.txt)
32 DEPLOYMENT_PROFILE=${DEPLOYMENT_PROFILE:-R3}
34 NEXUS_USER=$(cat /opt/config/nexus_username.txt)
35 NEXUS_PASSWORD=$(cat /opt/config/nexus_password.txt)
36 NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
37 DOCKER_VERSION=$(cat /opt/config/docker_version.txt)
39 MYFLOATIP=$(cat /opt/config/dcae_float_ip.txt)
40 MYLOCALIP=$(cat /opt/config/dcae_ip_addr.txt)
41 HTTP_PROXY=$(cat /opt/config/http_proxy.txt)
42 HTTPS_PROXY=$(cat /opt/config/https_proxy.txt)
44 if [ $HTTP_PROXY != "no_proxy" ]
46 export http_proxy=$HTTP_PROXY
47 export https_proxy=$HTTPS_PROXY
50 # clean up old network configuration in docker engine
52 if [ -n "$(docker ps -q -a)" ]; then
53 docker stop $(docker ps -q -a)
54 docker update --restart=no $(docker ps -a -q)
55 systemctl restart docker
56 docker rm $(docker ps -q -a)
57 if [ -n "$(docker network ls | grep 'config_default')" ]; then
58 docker network rm config_default
64 docker login -u "$NEXUS_USER" -p "$NEXUS_PASSWORD" "$NEXUS_DOCKER_REPO"
66 if [[ $DEPLOYMENT_PROFILE == R1* || $DEPLOYMENT_PROFILE == R2* ]]; then
67 echo "R1 and R2 deployment profiles are not supported in Casablanca Heat deployment"
68 elif [[ $DEPLOYMENT_PROFILE == R3* ]]; then
72 rm -rf /opt/app/inputs-templates
73 mkdir -p /opt/app/inputs-templates
74 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-1.yaml
75 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-2.yaml
76 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-3.yaml
77 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-4.yaml
78 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/register.sh
79 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/setup.sh
80 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/teardown.sh
82 pip install --upgrade jinja2
83 wget https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/scripts/detemplate-bpinputs.py \
85 (python detemplate-bpinputs.py /opt/config /opt/app/inputs-templates /opt/app/config; \
86 rm detemplate-bpinputs.py)
88 if [ -e /opt/app/config/register.sh ]; then
89 chmod +x /opt/app/config/register.sh
91 if [ -e /opt/app/config/setup.sh ]; then
92 chmod +x /opt/app/config/setup.sh
94 if [ -e /opt/app/config/build-plugins.sh ]; then
95 chmod +x /opt/app/config/build-plugins.sh
101 /opt/docker/docker-compose -f docker-compose-1.yaml up -d
103 # wait for essentials to become ready
104 echo "Waiting for Consul to come up ready"
105 while ! nc -z localhost 8500; do sleep 1; done
106 echo "Waiting for Postgres DB to come up ready"
107 while ! nc -z localhost 5432; do sleep 1; done
108 echo "Waiting for CBS to come up ready"
109 while ! nc -z localhost 10000; do sleep 1; done
110 echo "All dependencies are up, proceed to the next phase"
113 echo "Setup CloudifyManager and Registrator"
118 export https_proxy=""
122 echo "Bring up DCAE MIN service components for R2 use cases"
123 /opt/docker/docker-compose -f docker-compose-2.yaml up -d
125 if [[ "$DEPLOYMENT_PROFILE" == "R3" || "$DEPLOYMENT_PROFILE" == "R3PLUS" ]]; then
126 echo "Bring up DCAE platform components"
127 /opt/docker/docker-compose -f docker-compose-3.yaml up -d
129 if [[ "$DEPLOYMENT_PROFILE" == "R3PLUS" ]]; then
130 echo "Bring up additional (plus) DCAE service components"
131 /opt/docker/docker-compose -f docker-compose-4.yaml up -d
135 # start proxy for consul's health check
136 CONSULIP=$(cat /opt/config/dcae_ip_addr.txt)
137 echo "Consul is available at $CONSULIP"
140 cat >./nginx.conf <<EOL
143 server_name dcae.simpledemo.onap.org;
144 root /www/healthcheck;
146 location /healthcheck {
147 try_files /services.yaml =404;
150 try_files /r3mvp_healthy.yaml =404;
153 try_files /r3_healthy.yaml =404;
156 try_files /r3plus_healthy.yaml =404;
164 -p ${HEALTHPORT}:80 \
165 -v "$(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf" \
166 -v "/tmp/healthcheck:/www/healthcheck" \
167 --label "SERVICE_80_NAME=dcae-health" \
168 --label "SERVICE_80_CHECK_HTTP=/healthcheck" \
169 --label "SERVICE_80_CHECK_INTERVAL=15s" \
170 --label "SERVICE_80_CHECK_INITIAL_STATUS=passing" \
173 echo "Healthcheck API available at http://${MYFLOATIP}:${HEALTHPORT}/healthcheck"
174 echo " http://${MYFLOATIP}:${HEALTHPORT}/R3"
175 echo " http://${MYFLOATIP}:${HEALTHPORT}/R3MIN"
176 echo " http://${MYFLOATIP}:${HEALTHPORT}/R3PLUS"
178 # run forever for updating health status based on consul
182 rm -rf /tmp/healthcheck/*
183 # all registered services
184 SERVICES=$(curl -s http://consul:8500/v1/agent/services |jq '. | to_entries[] | .value.Service')
186 SERVICES=$(curl -s http://consul:8500/v1/health/state/passing | jq '.[] | .ServiceName')
188 # remove empty lines/entries
189 SERVICES=$(echo "$SERVICES" | sed '/^\s*\"\"\s*$/d' |sed '/^\s*$/d')
191 SERVICES_JSON=$(echo "$SERVICES" | sed 's/\"$/\",/g' | sed '$ s/.$//')
193 echo "$(date): running healthy services:"
195 PLT_CONSUL=$(echo "$SERVICES" |grep "consul")
196 PLT_CBS=$(echo "$SERVICES" |grep "config_binding_service")
197 MVP_PG_HOLMES=$(echo "$SERVICES" |grep "pgHolmes")
198 MVP_VES=$(echo "$SERVICES" |grep "mvp.*ves")
199 MVP_TCA=$(echo "$SERVICES" |grep "mvp.*tca")
200 MVP_HR=$(echo "$SERVICES" |grep "mvp.*holmes-rule")
201 MVP_HE=$(echo "$SERVICES" |grep "mvp.*holmes-engine")
203 PLT_CM=$(echo "$SERVICES" |grep "cloudify.*manager")
204 PLT_DH=$(echo "$SERVICES" |grep "deployment.*handler")
205 PLT_PH=$(echo "$SERVICES" |grep "policy.*handler")
206 PLT_SCH=$(echo "$SERVICES" |grep "service.*change.*handler")
207 PLT_INV=$(echo "$SERVICES" |grep "inventory")
208 PLT_PG_INVENTORY=$(echo "$SERVICES" |grep "pgInventory")
210 PLUS_MHB=$(echo "$SERVICES" |grep "heartbeat")
211 PLUS_PRH=$(echo "$SERVICES" |grep "prh")
212 PLUS_MPR=$(echo "$SERVICES" |grep "mapper")
213 PLUS_TRAP=$(echo "$SERVICES" |grep "snmptrap")
215 DATA="{\"healthy\" : \"$(date)\", \"healthy_services\": [${SERVICES_JSON}]}"
216 if [[ -n "$PLT_CONSUL" && -n "$PLT_CBS" && -n "$MVP_PG_HOLMES" && -n "$MVP_VES" && \
217 -n "$MVP_TCA" ]]; then
218 echo "${DATA}" > /tmp/healthcheck/r3mvp_healthy.yaml
219 echo "${DATA}" > /tmp/healthcheck/services.yaml
220 echo ">>>>>> enough services satisfying R3MIN service deployment"
222 echo ">>>>>> not enough services satisfying R3MIN service deployment"
225 if [[ -n "$PLT_CONSUL" && -n "$PLT_CBS" && -n "$PLT_CM" && -n "$PLT_DH" && \
226 -n "$PLT_PH" && -n "$PLT_SCH" && -n "$PLT_INV" && -n "$PLT_PG_INVENTORY" ]]; then
227 echo ">>>>>> enough services satisfying R3 platform deployment"
228 echo "${DATA}" > /tmp/healthcheck/r3_healthy.yaml
230 if [[ -n "$PLUS_MHB" && -n "$PLUS_PRH" && -n "$PLUS_MPR" && -n "$PLUS_TRAP" && -n "$MVP_HR" && -n "$MVP_HE" ]]; then
231 echo ">>>>>> enough services satisfying R3PLUS deployment"
232 echo "${DATA}" > /tmp/healthcheck/r3plus_healthy.yaml
234 echo ">>>>>> not enough services satisfying R3PLUS service deployment"
237 echo ">>>>>> not enough services satisfying R3 platform or R3PLUS service deployment"