blob: 0f4c15cba21a67a4b9f91f70edac522158e1cc7a [file] [log] [blame]
Jack Lucasbad77202020-02-03 18:21:29 -05001#!/bin/bash
2# ================================================================================
vv770dba21cba2021-03-29 19:30:30 +00003# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
Jack Lucasec990602021-01-13 12:50:10 -05004# Copyright (c) 2021 J. F. Lucas. All rights reserved.
Jack Lucasbad77202020-02-03 18:21:29 -05005# ================================================================================
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#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=========================================================
18
Jack Lucasfa2da722021-06-03 12:55:52 -040019# Prior to the "H" release, this bootstrap script was used to deploy DCAE components
20# during the initial DCAE installation process using Cloudify Manager with Cloudify
21# blueprints. Over the course of several releases, we have migrated these components to use Helm
22# deployment, starting with the DCAE "platform components" and, in the "H" release, the 4
23# DCAE microservices that are always launched when DCAE is deployed.
24#
25# For the "I" release, we are expecting to migrate all DCAE microservices to Helm deployment,
26# including the microservices that are launched on demand after initial DCAE installation.
27# We are continuing to provide support for Cloudify deployments during the "I" release. This
28# bootstrap script will deploy the Cloudify blueprint that initializes the Cloudify-based
29# DCAE postgres instance and will upload all of the DCAE Cloudify blueprints to the DCAE
30# inventory component. The bootstrap container will continue to run after its deployment and
31# upload work is complete. User can "exec" into the bootstrap container and use the Cloudify
32# "cfy" command to debug any issues related to Cloudify deployments.
33#
Jack Lucasbad77202020-02-03 18:21:29 -050034# Expects:
35# CM address (IP or DNS) in CMADDR environment variable
36# CM password in CMPASS environment variable (assumes user is "admin")
Jack Lucasec990602021-01-13 12:50:10 -050037# Blueprints for components to be installed in /blueprints
Jack Lucasbad77202020-02-03 18:21:29 -050038# Input files for components to be installed in /inputs
Jack Lucasbad77202020-02-03 18:21:29 -050039# Optionally, allows:
40# CM protocol in CMPROTO environment variable (defaults to HTTP)
41# CM port in CMPORT environment variable (defaults to 80)
42# If CMPROTO is set to "https", bootstrap will use HTTPS to communicate with CM. Otherwise,
43# it will use HTTP.
44# If CMPROTO is set to "https", the script assumes the CA cert needed to verify the cert
45# presented by CM is mounted at /certs/cacert.pem.
46
47# Set defaults for CM protocol and port
48CMPROTO=${CMPROTO:-http}
49CMPORT=${CMPORT:-80}
50
51# Set up additional parameters for using HTTPS
Jack Lucasa25c9232020-03-02 11:07:31 -050052CACERT="/certs/cacert.pem"
Jack Lucasbad77202020-02-03 18:21:29 -050053CFYTLS=""
54CURLTLS=""
55if [ $CMPROTO = "https" ]
56then
Jack Lucasa25c9232020-03-02 11:07:31 -050057 CFYTLS="--rest-certificate $CACERT --ssl"
58 CURLTLS="--cacert $CACERT"
Jack Lucasbad77202020-02-03 18:21:29 -050059fi
60
61### FUNCTION DEFINITIONS ###
62
63# keep_running: Keep running after bootstrap finishes or after error
64keep_running() {
65 echo $1
66 sleep infinity &
67 wait
68}
69
70# cm_hasany: Query Cloudify Manager and return 0 (true) if there are any entities matching the query
71# Used to see if something is already present on CM
72# $1 -- query fragment, for instance "plugins?archive_name=xyz.wgn" to get
73# the number of plugins that came from the archive file "xyz.wgn"
74function cm_hasany {
75 # We use _include=id to limit the amount of data the CM sends back
76 # We rely on the "metadata.pagination.total" field in the response
77 # for the total number of matching entities
78 COUNT=$(curl -Ss -H "Tenant: default_tenant" --user admin:${CMPASS} ${CURLTLS} "${CMPROTO}://${CMADDR}:${CMPORT}/api/v3.1/$1&_include=id" \
79 | /bin/jq .metadata.pagination.total)
80 if (( $COUNT > 0 ))
81 then
82 return 0
83 else
84 return 1
85 fi
86}
87
88# deploy: Deploy components if they're not already deployed
89# $1 -- name (for bp and deployment)
90# $2 -- blueprint file name
91# $3 -- inputs file name (optional)
92function deploy {
93 # Don't crash the script on error
94 set +e
95
96 # Upload blueprint if it's not already there
97 if cm_hasany "blueprints?id=$1"
98 then
99 echo blueprint $1 is already installed on ${CMADDR}
100 else
101 cfy blueprints upload -b $1 /blueprints/$2
102 fi
103
104 # Create deployment if it doesn't already exist
105 if cm_hasany "deployments?id=$1"
106 then
107 echo deployment $1 has already been created on ${CMADDR}
108 else
109 INPUTS=
110 if [ -n "$3" ]
111 then
112 INPUTS="-i/inputs/$3"
113 fi
114 cfy deployments create -b $1 ${INPUTS} $1
115 fi
116
117 # Run the install workflow if it hasn't been run already
118 # We don't have a completely certain way of determining this.
119 # We check to see if the deployment has any node instances
120 # that are in the 'uninitialized' or 'deleted' states. (Note that
121 # the & in the query acts as a logical OR for the multiple state values.)
122 # We'll try to install when a deployment has node instances in those states
123 if cm_hasany "node-instances?deployment_id=$1&state=uninitialized&state=deleted"
124 then
125 cfy executions start -d $1 install
126 else
127 echo deployment $1 appears to have had an install workflow executed already or is not ready for an install
128 fi
129}
130
Jack Lucasbad77202020-02-03 18:21:29 -0500131### END FUNCTION DEFINTIONS ###
132
133set -x
134
135# Make sure we keep the container alive after an error
136trap keep_running ERR
137
138set -e
139
Jack Lucasbad77202020-02-03 18:21:29 -0500140# Set up profile to access Cloudify Manager
141cfy profiles use -u admin -t default_tenant -p "${CMPASS}" ${CFYTLS} "${CMADDR}"
142
143# Output status, for debugging purposes
144cfy status
145
Jack Lucas01d60192020-06-17 17:11:17 -0400146# Store the CM password into a Cloudify secret
147cfy secret create -s ${CMPASS} cmpass
Jack Lucasbad77202020-02-03 18:21:29 -0500148
Jack Lucasbad77202020-02-03 18:21:29 -0500149# After this point, failures should not stop the script or block later commands
150trap - ERR
151set +e
152
153# Initialize the DCAE postgres instance
154deploy pgaas_initdb k8s-pgaas-initdb.yaml k8s-pgaas-initdb-inputs.yaml
155
Jack Lucasbad77202020-02-03 18:21:29 -0500156# Display deployments, for debugging purposes
157cfy deployments list
158
Jack Lucasa25c9232020-03-02 11:07:31 -0500159# Load blueprints into DCAE inventory as
160# DCAE service types
161. /scripts/inventory.sh
162for BP in /blueprints/*.yaml
163do
164 upload_service_type $BP $CACERT
165done
166
Jack Lucasbad77202020-02-03 18:21:29 -0500167# Continue running
168keep_running "Finished bootstrap steps."
169echo "Exiting!"