blob: 503cec2a534cef9abdf03270858b1fda1776293f [file] [log] [blame]
Jack Lucas230ae892018-03-27 00:04:46 -04001#!/bin/bash
Jack Lucas5b12c6d2018-04-04 21:47:28 +00002# ================================================================================
Jack Lucas5caf1652019-02-08 14:21:58 -05003# Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved.
Jack Lucas5b12c6d2018-04-04 21:47:28 +00004# ================================================================================
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16# ============LICENSE_END=========================================================
17
Jack Lucas230ae892018-03-27 00:04:46 -040018# Install DCAE via Cloudify Manager
19# Expects:
20# CM address (IP or DNS) in CMADDR environment variable
21# CM password in CMPASS environment variable (assumes user is "admin")
Jack Lucas0a48eea2018-05-10 20:50:54 +000022# ONAP common Kubernetes namespace in ONAP_NAMESPACE environment variable
23# If DCAE components are deployed in a separate Kubernetes namespace, that namespace in DCAE_NAMESPACE variable.
Jack Lucas53f31102018-04-02 20:55:04 +000024# Consul address with port in CONSUL variable
Jack Lucas230ae892018-03-27 00:04:46 -040025# Plugin wagon files in /wagons
Jack Lucas53f31102018-04-02 20:55:04 +000026# Blueprints for components to be installed in /blueprints
27# Input files for components to be installed in /inputs
28# Configuration JSON files that need to be loaded into Consul in /dcae-configs
Jack Lucasb3350fa2018-08-17 12:58:51 +000029# Consul is installed in /opt/consul/bin/consul, with base config in /opt/consul/config/00consul.json
Jack Lucas230ae892018-03-27 00:04:46 -040030
Jack Lucasb3350fa2018-08-17 12:58:51 +000031### FUNCTION DEFINITIONS ###
32
33# keep_running: Keep running after bootstrap finishes or after error
34keep_running() {
35 echo $1
36 sleep infinity &
37 wait
38}
39
40# cm_hasany: Query Cloudify Manager and return 0 (true) if there are any entities matching the query
41# Used to see if something is already present on CM
42# $1 -- query fragment, for instance "plugins?archive_name=xyz.wgn" to get
43# the number of plugins that came from the archive file "xyz.wgn"
44function cm_hasany {
45 # We use _include=id to limit the amount of data the CM sends back
46 # We rely on the "metadata.pagination.total" field in the response
47 # for the total number of matching entities
48 COUNT=$(curl -Ss -H "Tenant: default_tenant" --user admin:${CMPASS} "${CMADDR}/api/v3.1/$1&_include=id" \
49 | /bin/jq .metadata.pagination.total)
50 if (( $COUNT > 0 ))
51 then
52 return 0
53 else
54 return 1
55 fi
56}
57
58# deploy: Deploy components if they're not already deployed
59# $1 -- name (for bp and deployment)
60# $2 -- blueprint file name
61# $3 -- inputs file name (optional)
62function deploy {
63 # Don't crash the script on error
64 set +e
65
66 # Upload blueprint if it's not already there
67 if cm_hasany "blueprints?id=$1"
68 then
69 echo blueprint $1 is already installed on ${CMADDR}
70 else
71 cfy blueprints upload -b $1 /blueprints/$2
72 fi
73
74 # Create deployment if it doesn't already exist
75 if cm_hasany "deployments?id=$1"
76 then
77 echo deployment $1 has already been created on ${CMADDR}
78 else
79 INPUTS=
80 if [ -n "$3" ]
81 then
82 INPUTS="-i/inputs/$3"
83 fi
84 cfy deployments create -b $1 ${INPUTS} $1
85 fi
86
87 # Run the install workflow if it hasn't been run already
88 # We don't have a completely certain way of determining this.
89 # We check to see if the deployment has any node instances
90 # that are in the 'uninitialized' or 'deleted' states. (Note that
91 # the & in the query acts as a logical OR for the multiple state values.)
92 # We'll try to install when a deployment has node instances in those states
93 if cm_hasany "node-instances?deployment_id=$1&state=uninitialized&state=deleted"
94 then
95 cfy executions start -d $1 install
96 else
97 echo deployment $1 appears to have had an install workflow executed already or is not ready for an install
98 fi
99}
100
101# Install plugin if it's not already installed
102# $1 -- path to wagon file for plugin
103function install_plugin {
104 ARCHIVE=$(basename $1)
105 # See if it's already installed
106 if cm_hasany "plugins?archive_name=$ARCHIVE"
107 then
108 echo plugin $1 already installed on ${CMADDR}
109 else
110 cfy plugin upload $1
111 fi
112}
113
114### END FUNCTION DEFINTIONS ###
115
116set -x
117
118# Make sure we keep the container alive after an error
119trap keep_running ERR
120
121set -e
Jack Lucas230ae892018-03-27 00:04:46 -0400122
Jack Lucas5b12c6d2018-04-04 21:47:28 +0000123# Consul service registration data
Jack Lucas53f31102018-04-02 20:55:04 +0000124CBS_REG='{"ID": "dcae-cbs0", "Name": "config_binding_service", "Address": "config-binding-service", "Port": 10000}'
Jack Lucas5b12c6d2018-04-04 21:47:28 +0000125CBS_REG1='{"ID": "dcae-cbs1", "Name": "config-binding-service", "Address": "config-binding-service", "Port": 10000}'
Jack Lucas5867fe12018-05-17 01:53:45 +0000126HE_REG='{"ID": "dcae-he0", "Name": "holmes-engine-mgmt", "Address": "holmes-engine-mgmt", "Port": 9102}'
127HR_REG='{"ID": "dcae-hr0", "Name": "holmes-rule-mgmt", "Address": "holmes-rule-mgmt", "Port": 9101}'
Jack Lucas0a48eea2018-05-10 20:50:54 +0000128PH_REG='{"ID": "dcae-ph0", "Name": "policy_handler", "Port": 25577, "Address": "policy-handler'
Jack Lucasbb206c72018-05-10 18:55:45 +0000129if [ ! -z "${DCAE_NAMESPACE}" ]
130then
131 PH_REG="${PH_REG}.${DCAE_NAMESPACE}"
132fi
133PH_REG="${PH_REG}\"}"
Jack Lucas5b12c6d2018-04-04 21:47:28 +0000134
Jack Lucas5b12c6d2018-04-04 21:47:28 +0000135# Set up profile to access Cloudify Manager
Jack Lucas230ae892018-03-27 00:04:46 -0400136cfy profiles use -u admin -t default_tenant -p "${CMPASS}" "${CMADDR}"
137
138# Output status, for debugging purposes
139cfy status
140
Jack Lucasb3350fa2018-08-17 12:58:51 +0000141# Check Consul readiness
142# The readiness container waits for a "consul-server" container to be ready,
143# but this isn't always enough. We need the Consul API to be up and for
144# the cluster to be formed, otherwise our Consul accesses might fail.
145# (Note in ONAP R2, we never saw a problem, but occasionally in R3 we
146# have seen Consul not be fully ready, so we add these checks, originally
147# used in the R1 HEAT-based deployment.)
148# Wait for Consul API to come up
149until curl http://${CONSUL}/v1/agent/services
150do
151 echo Waiting for Consul API
152 sleep 60
153done
154# Wait for a leader to be elected
155until [[ "$(curl -Ss http://{$CONSUL}/v1/status/leader)" != '""' ]]
156do
157 echo Waiting for leader
158 sleep 30
159done
160
161# Load configurations into Consul KV store
Jack Lucas53f31102018-04-02 20:55:04 +0000162for config in /dcae-configs/*.json
163do
164 # The basename of the file is the Consul key
165 key=$(basename ${config} .json)
166 # Strip out comments, empty lines
167 egrep -v "^#|^$" ${config} > /tmp/dcae-upload
168 curl -v -X PUT -H "Content-Type: application/json" --data-binary @/tmp/dcae-upload ${CONSUL}/v1/kv/${key}
169done
170
Jack Lucasb3350fa2018-08-17 12:58:51 +0000171# Put service registrations into the local Consul configuration directory
Jack Lucas5caf1652019-02-08 14:21:58 -0500172for sr in CBS_REG CBS_REG1 HE_REG HR_REG PH_REG
Jack Lucasb3350fa2018-08-17 12:58:51 +0000173do
174 echo '{"service" : ' ${!sr} ' }'> /opt/consul/config/${sr}.json
175done
176
177# Start the local consul agent instance
178/opt/consul/bin/consul agent --config-dir /opt/consul/config 2>&1 | tee /opt/consul/consul.log &
Jack Lucas5b12c6d2018-04-04 21:47:28 +0000179
180# Store the CM password into a Cloudify secret
181cfy secret create -s ${CMPASS} cmpass
Jack Lucas53f31102018-04-02 20:55:04 +0000182
Jack Lucas230ae892018-03-27 00:04:46 -0400183# Load plugins onto CM
184for wagon in /wagons/*.wgn
185do
Jack Lucasb3350fa2018-08-17 12:58:51 +0000186 install_plugin ${wagon}
Jack Lucas230ae892018-03-27 00:04:46 -0400187done
188
Jack Lucas45cb8992018-08-22 19:29:40 +0000189# After this point, failures should not stop the script or block later commands
190trap - ERR
Lusheng Jidda9b822018-05-04 16:02:38 -0400191set +e
Jack Lucasb3350fa2018-08-17 12:58:51 +0000192
Jack Lucas230ae892018-03-27 00:04:46 -0400193# Deploy platform components
Jack Lucasb3350fa2018-08-17 12:58:51 +0000194# Allow for some parallelism to speed up the process. Probably could be somewhat more aggressive.
Jack Lucasb3350fa2018-08-17 12:58:51 +0000195deploy pgaas_initdb k8s-pgaas-initdb.yaml k8s-pgaas-initdb-inputs.yaml &
Vijay Venkatesh Kumard2c82122019-04-05 00:38:59 +0000196deploy dashboard k8s-dashboard.yaml k8s-dashboard-inputs.yaml &
Jack Lucasb3350fa2018-08-17 12:58:51 +0000197PG_PID=$!
Jack Lucas0025fda2019-01-17 13:53:56 -0500198wait ${PG_PID}
Jack Lucasbac8d422018-04-27 22:11:51 +0000199
200# Deploy service components
wasala42517302018-09-19 13:51:36 +0200201# tca, ves, prh, hv-ves, datafile-collector can be deployed simultaneously
Jack Lucasb3350fa2018-08-17 12:58:51 +0000202deploy tca k8s-tca.yaml k8s-tca-inputs.yaml &
203deploy ves k8s-ves.yaml k8s-ves-inputs.yaml &
vagrant6ccc5602018-09-16 07:00:06 +0000204deploy snmptrap k8s-snmptrap.yaml k8s-snmptrap-inputs.yaml &
205deploy prh k8s-prh.yaml k8s-prh-inputs.yaml &
206deploy hv-ves k8s-hv-ves.yaml k8s-hv_ves-inputs.yaml &
Paul Dennehy1fe9e4d2018-10-01 15:46:28 +0100207deploy datafile-collector k8s-datafile-collector.yaml k8s-datafile-collector-inputs.yaml &
Jack Lucasb3350fa2018-08-17 12:58:51 +0000208# holmes_rules must be deployed before holmes_engine, but holmes_rules can go in parallel with other service components
Jack Lucas2415db82018-04-30 01:23:45 +0000209deploy holmes_rules k8s-holmes-rules.yaml k8s-holmes_rules-inputs.yaml
210deploy holmes_engine k8s-holmes-engine.yaml k8s-holmes_engine-inputs.yaml
Jack Lucas230ae892018-03-27 00:04:46 -0400211
Jack Lucas53f31102018-04-02 20:55:04 +0000212# Display deployments, for debugging purposes
213cfy deployments list
Jack Lucasb3350fa2018-08-17 12:58:51 +0000214
215# Continue running
216keep_running "Finished bootstrap steps."
vagrant6ccc5602018-09-16 07:00:06 +0000217echo "Exiting!"