blob: 9cd69c8c3955b3e88de5df9e5e1378198b13eb3a [file] [log] [blame]
Jack Lucasbad77202020-02-03 18:21:29 -05001#!/bin/bash
2# ================================================================================
3# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
4# ================================================================================
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
18# 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")
22# 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.
24# Consul address with port in CONSUL variable
Jack Lucasbad77202020-02-03 18:21:29 -050025# Blueprints for components to be installed in /blueprints
26# Input files for components to be installed in /inputs
27# Configuration JSON files that need to be loaded into Consul in /dcae-configs
28# Consul is installed in /opt/consul/bin/consul, with base config in /opt/consul/config/00consul.json
29# Optionally, allows:
30# CM protocol in CMPROTO environment variable (defaults to HTTP)
31# CM port in CMPORT environment variable (defaults to 80)
32# If CMPROTO is set to "https", bootstrap will use HTTPS to communicate with CM. Otherwise,
33# it will use HTTP.
34# If CMPROTO is set to "https", the script assumes the CA cert needed to verify the cert
35# presented by CM is mounted at /certs/cacert.pem.
36
37# Set defaults for CM protocol and port
38CMPROTO=${CMPROTO:-http}
39CMPORT=${CMPORT:-80}
40
41# Set up additional parameters for using HTTPS
Jack Lucasa25c9232020-03-02 11:07:31 -050042CACERT="/certs/cacert.pem"
Jack Lucasbad77202020-02-03 18:21:29 -050043CFYTLS=""
44CURLTLS=""
45if [ $CMPROTO = "https" ]
46then
Jack Lucasa25c9232020-03-02 11:07:31 -050047 CFYTLS="--rest-certificate $CACERT --ssl"
48 CURLTLS="--cacert $CACERT"
Jack Lucasbad77202020-02-03 18:21:29 -050049fi
50
51### FUNCTION DEFINITIONS ###
52
53# keep_running: Keep running after bootstrap finishes or after error
54keep_running() {
55 echo $1
56 sleep infinity &
57 wait
58}
59
60# cm_hasany: Query Cloudify Manager and return 0 (true) if there are any entities matching the query
61# Used to see if something is already present on CM
62# $1 -- query fragment, for instance "plugins?archive_name=xyz.wgn" to get
63# the number of plugins that came from the archive file "xyz.wgn"
64function cm_hasany {
65 # We use _include=id to limit the amount of data the CM sends back
66 # We rely on the "metadata.pagination.total" field in the response
67 # for the total number of matching entities
68 COUNT=$(curl -Ss -H "Tenant: default_tenant" --user admin:${CMPASS} ${CURLTLS} "${CMPROTO}://${CMADDR}:${CMPORT}/api/v3.1/$1&_include=id" \
69 | /bin/jq .metadata.pagination.total)
70 if (( $COUNT > 0 ))
71 then
72 return 0
73 else
74 return 1
75 fi
76}
77
78# deploy: Deploy components if they're not already deployed
79# $1 -- name (for bp and deployment)
80# $2 -- blueprint file name
81# $3 -- inputs file name (optional)
82function deploy {
83 # Don't crash the script on error
84 set +e
85
86 # Upload blueprint if it's not already there
87 if cm_hasany "blueprints?id=$1"
88 then
89 echo blueprint $1 is already installed on ${CMADDR}
90 else
91 cfy blueprints upload -b $1 /blueprints/$2
92 fi
93
94 # Create deployment if it doesn't already exist
95 if cm_hasany "deployments?id=$1"
96 then
97 echo deployment $1 has already been created on ${CMADDR}
98 else
99 INPUTS=
100 if [ -n "$3" ]
101 then
102 INPUTS="-i/inputs/$3"
103 fi
104 cfy deployments create -b $1 ${INPUTS} $1
105 fi
106
107 # Run the install workflow if it hasn't been run already
108 # We don't have a completely certain way of determining this.
109 # We check to see if the deployment has any node instances
110 # that are in the 'uninitialized' or 'deleted' states. (Note that
111 # the & in the query acts as a logical OR for the multiple state values.)
112 # We'll try to install when a deployment has node instances in those states
113 if cm_hasany "node-instances?deployment_id=$1&state=uninitialized&state=deleted"
114 then
115 cfy executions start -d $1 install
116 else
117 echo deployment $1 appears to have had an install workflow executed already or is not ready for an install
118 fi
119}
120
Jack Lucasbad77202020-02-03 18:21:29 -0500121
122### END FUNCTION DEFINTIONS ###
123
124set -x
125
126# Make sure we keep the container alive after an error
127trap keep_running ERR
128
129set -e
130
Jack Lucasbad77202020-02-03 18:21:29 -0500131# Set up profile to access Cloudify Manager
132cfy profiles use -u admin -t default_tenant -p "${CMPASS}" ${CFYTLS} "${CMADDR}"
133
134# Output status, for debugging purposes
135cfy status
136
Jack Lucas01d60192020-06-17 17:11:17 -0400137# Store the CM password into a Cloudify secret
138cfy secret create -s ${CMPASS} cmpass
Jack Lucasbad77202020-02-03 18:21:29 -0500139
140# Load configurations into Consul KV store
141for config in /dcae-configs/*.json
142do
143 # The basename of the file is the Consul key
144 key=$(basename ${config} .json)
145 # Strip out comments, empty lines
146 egrep -v "^#|^$" ${config} > /tmp/dcae-upload
147 curl -v -X PUT -H "Content-Type: application/json" --data-binary @/tmp/dcae-upload ${CONSUL}/v1/kv/${key}
148done
149
Jack Lucasbad77202020-02-03 18:21:29 -0500150# After this point, failures should not stop the script or block later commands
151trap - ERR
152set +e
153
154# Initialize the DCAE postgres instance
155deploy pgaas_initdb k8s-pgaas-initdb.yaml k8s-pgaas-initdb-inputs.yaml
156
157# Deploy service components
vv770dee9fec72020-08-07 17:50:11 +0000158# tcagen2, ves, prh, hv-ves, datafile-collector can be deployed simultaneously
Vijay Venkatesh Kumar0bc07ad2020-02-27 04:45:49 +0000159deploy tcagen2 k8s-tcagen2.yaml k8s-tcagen2-inputs.yaml &
Pawelb03f33a2020-02-14 10:28:04 +0100160deploy ves-tls k8s-ves.yaml k8s-ves-inputs-tls.yaml &
Jack Lucasbad77202020-02-03 18:21:29 -0500161deploy prh k8s-prh.yaml k8s-prh-inputs.yaml &
162deploy hv-ves k8s-hv-ves.yaml k8s-hv_ves-inputs.yaml &
163# holmes_rules must be deployed before holmes_engine, but holmes_rules can go in parallel with other service components
164deploy holmes_rules k8s-holmes-rules.yaml k8s-holmes_rules-inputs.yaml
165deploy holmes_engine k8s-holmes-engine.yaml k8s-holmes_engine-inputs.yaml
166
167# Display deployments, for debugging purposes
168cfy deployments list
169
Jack Lucasa25c9232020-03-02 11:07:31 -0500170# Load blueprints into DCAE inventory as
171# DCAE service types
172. /scripts/inventory.sh
173for BP in /blueprints/*.yaml
174do
175 upload_service_type $BP $CACERT
176done
177
Jack Lucasbad77202020-02-03 18:21:29 -0500178# Continue running
179keep_running "Finished bootstrap steps."
180echo "Exiting!"