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 # add well-known DCAE hostname aliases
27 echo "$(cat /opt/config/dcae_ip_addr.txt) consul" >>/etc/hosts
28 echo "$(cat /opt/config/dcae_ip_addr.txt) dockerhost" >>/etc/hosts
31 URL_ROOT='nexus.onap.org/service/local/repositories/raw/content'
32 REPO_BLUEPRINTS='org.onap.dcaegen2.platform.blueprints'
33 REPO_DEPLOYMENTS='org.onap.dcaegen2.deployments'
34 if [ -e /opt/config/dcae_deployment_profile.txt ]; then
35 DEPLOYMENT_PROFILE=$(cat /opt/config/dcae_deployment_profile.txt)
37 DEPLOYMENT_PROFILE=${DEPLOYMENT_PROFILE:-R3}
39 NEXUS_USER=$(cat /opt/config/nexus_username.txt)
40 NEXUS_PASSWORD=$(cat /opt/config/nexus_password.txt)
41 NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
42 DOCKER_VERSION=$(cat /opt/config/docker_version.txt)
44 MYFLOATIP=$(cat /opt/config/dcae_float_ip.txt)
45 MYLOCALIP=$(cat /opt/config/dcae_ip_addr.txt)
46 HTTP_PROXY=$(cat /opt/config/http_proxy.txt)
47 HTTPS_PROXY=$(cat /opt/config/https_proxy.txt)
49 if [ $HTTP_PROXY != "no_proxy" ]
51 export http_proxy=$HTTP_PROXY
52 export https_proxy=$HTTPS_PROXY
56 docker login -u "$NEXUS_USER" -p "$NEXUS_PASSWORD" "$NEXUS_DOCKER_REPO"
58 if [[ $DEPLOYMENT_PROFILE == R1* || $DEPLOYMENT_PROFILE == R2* ]]; then
59 echo "R1 and R2 deployment profiles are not supported in Casablanca Heat deployment"
60 elif [[ $DEPLOYMENT_PROFILE == R3* ]]; then
64 rm -rf /opt/app/inputs-templates
65 mkdir -p /opt/app/inputs-templates
66 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-1.yaml
67 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-2.yaml
68 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-3.yaml
69 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-4.yaml
70 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/register.sh
71 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/setup.sh
72 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/teardown.sh
74 pip install --upgrade jinja2
75 wget https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/scripts/detemplate-bpinputs.py \
77 (python detemplate-bpinputs.py /opt/config /opt/app/inputs-templates /opt/app/config; \
78 rm detemplate-bpinputs.py)
80 if [ -e /opt/app/config/register.sh ]; then
81 chmod +x /opt/app/config/register.sh
83 if [ -e /opt/app/config/setup.sh ]; then
84 chmod +x /opt/app/config/setup.sh
86 if [ -e /opt/app/config/build-plugins.sh ]; then
87 chmod +x /opt/app/config/build-plugins.sh
93 /opt/docker/docker-compose -f docker-compose-1.yaml up -d
95 # wait for essentials to become ready
96 echo "Waiting for Consul to come up ready"
97 while ! nc -z localhost 8500; do sleep 1; done
98 echo "Waiting for Postgres DB to come up ready"
99 while ! nc -z localhost 5432; do sleep 1; done
100 echo "Waiting for CBS to come up ready"
101 while ! nc -z localhost 10000; do sleep 1; done
102 echo "All dependencies are up, proceed to the next phase"
105 echo "Setup CloudifyManager and Registrator"
110 export https_proxy=""
114 echo "Bring up DCAE MIN service components for R2 use cases"
115 /opt/docker/docker-compose -f docker-compose-2.yaml up -d
117 if [[ "$DEPLOYMENT_PROFILE" == "R3" || "$DEPLOYMENT_PROFILE" == "R3PLUS" ]]; then
118 echo "Bring up DCAE platform components"
119 /opt/docker/docker-compose -f docker-compose-3.yaml up -d
121 if [[ "$DEPLOYMENT_PROFILE" == "R3PLUS" ]]; then
122 echo "Bring up additional (plus) DCAE service components"
123 /opt/docker/docker-compose -f docker-compose-4.yaml up -d
127 # start proxy for consul's health check
128 CONSULIP=$(cat /opt/config/dcae_ip_addr.txt)
129 echo "Consul is available at $CONSULIP"
132 cat >./nginx.conf <<EOL
135 server_name dcae.simpledemo.onap.org;
136 root /www/healthcheck;
138 location /healthcheck {
139 try_files /services.yaml =404;
142 try_files /r3mvp_healthy.yaml =404;
145 try_files /r3_healthy.yaml =404;
148 try_files /r3plus_healthy.yaml =404;
156 -p ${HEALTHPORT}:80 \
157 -v "$(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf" \
158 -v "/tmp/healthcheck:/www/healthcheck" \
159 --label "SERVICE_80_NAME=dcae-health" \
160 --label "SERVICE_80_CHECK_HTTP=/healthcheck" \
161 --label "SERVICE_80_CHECK_INTERVAL=15s" \
162 --label "SERVICE_80_CHECK_INITIAL_STATUS=passing" \
165 echo "Healthcheck API available at http://${MYFLOATIP}:${HEALTHPORT}/healthcheck"
166 echo " http://${MYFLOATIP}:${HEALTHPORT}/R3"
167 echo " http://${MYFLOATIP}:${HEALTHPORT}/R3MIN"
168 echo " http://${MYFLOATIP}:${HEALTHPORT}/R3PLUS"
170 # run forever for updating health status based on consul
174 rm -rf /tmp/healthcheck/*
175 # all registered services
176 SERVICES=$(curl -s http://consul:8500/v1/agent/services |jq '. | to_entries[] | .value.Service')
178 SERVICES=$(curl -s http://consul:8500/v1/health/state/passing | jq '.[] | .ServiceName')
180 # remove empty lines/entries
181 SERVICES=$(echo "$SERVICES" | sed '/^\s*\"\"\s*$/d' |sed '/^\s*$/d')
183 SERVICES_JSON=$(echo "$SERVICES" | sed 's/\"$/\",/g' | sed '$ s/.$//')
185 echo "$(date): running healthy services:"
187 PLT_CONSUL=$(echo "$SERVICES" |grep "consul")
188 PLT_CBS=$(echo "$SERVICES" |grep "config_binding_service")
189 MVP_PG_HOLMES=$(echo "$SERVICES" |grep "pgHolmes")
190 MVP_VES=$(echo "$SERVICES" |grep "mvp.*ves")
191 MVP_TCA=$(echo "$SERVICES" |grep "mvp.*tca")
192 MVP_HR=$(echo "$SERVICES" |grep "mvp.*holmes-rule")
193 MVP_HE=$(echo "$SERVICES" |grep "mvp.*holmes-engine")
195 PLT_CM=$(echo "$SERVICES" |grep "cloudify.*manager")
196 PLT_DH=$(echo "$SERVICES" |grep "deployment.*handler")
197 PLT_PH=$(echo "$SERVICES" |grep "policy.*handler")
198 PLT_SCH=$(echo "$SERVICES" |grep "service.*change.*handler")
199 PLT_INV=$(echo "$SERVICES" |grep "inventory")
200 PLT_PG_INVENTORY=$(echo "$SERVICES" |grep "pgInventory")
202 PLUS_MHB=$(echo "$SERVICES" |grep "heartbeat")
203 PLUS_PRH=$(echo "$SERVICES" |grep "prh")
204 PLUS_MPR=$(echo "$SERVICES" |grep "mapper")
205 PLUS_TRAP=$(echo "$SERVICES" |grep "snmptrap")
207 DATA="{\"healthy\" : \"$(date)\", \"healthy_services\": [${SERVICES_JSON}]}"
208 if [[ -n "$PLT_CONSUL" && -n "$PLT_CBS" && -n "$MVP_PG_HOLMES" && -n "$MVP_VES" && \
209 -n "$MVP_TCA" ]]; then
210 echo "${DATA}" > /tmp/healthcheck/r3mvp_healthy.yaml
211 echo "${DATA}" > /tmp/healthcheck/services.yaml
212 echo ">>>>>> enough services satisfying R3MIN service deployment"
214 echo ">>>>>> not enough services satisfying R3MIN service deployment"
217 if [[ -n "$PLT_CONSUL" && -n "$PLT_CBS" && -n "$PLT_CM" && -n "$PLT_DH" && \
218 -n "$PLT_PH" && -n "$PLT_SCH" && -n "$PLT_INV" && -n "$PLT_PG_INVENTORY" ]]; then
219 echo ">>>>>> enough services satisfying R3 platform deployment"
220 echo "${DATA}" > /tmp/healthcheck/r3_healthy.yaml
222 if [[ -n "$PLUS_MHB" && -n "$PLUS_PRH" && -n "$PLUS_MPR" && -n "$PLUS_TRAP" && -n "$MVP_HR" && -n "$MVP_HE" ]]; then
223 echo ">>>>>> enough services satisfying R3PLUS deployment"
224 echo "${DATA}" > /tmp/healthcheck/r3plus_healthy.yaml
226 echo ">>>>>> not enough services satisfying R3PLUS service deployment"
229 echo ">>>>>> not enough services satisfying R3 platform or R3PLUS service deployment"