blob: 8089439599516d9b28ea8710e74f2692eb55d659 [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.
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
19# Install DCAE via Cloudify Manager
20# Expects:
21# CM address (IP or DNS) in CMADDR environment variable
22# CM password in CMPASS environment variable (assumes user is "admin")
23# ONAP common Kubernetes namespace in ONAP_NAMESPACE environment variable
24# If DCAE components are deployed in a separate Kubernetes namespace, that namespace in DCAE_NAMESPACE variable.
Jack Lucasec990602021-01-13 12:50:10 -050025# Blueprints for components to be installed in /blueprints
Jack Lucasbad77202020-02-03 18:21:29 -050026# Input files for components to be installed in /inputs
Jack Lucasbad77202020-02-03 18:21:29 -050027# Optionally, allows:
28# CM protocol in CMPROTO environment variable (defaults to HTTP)
29# CM port in CMPORT environment variable (defaults to 80)
30# If CMPROTO is set to "https", bootstrap will use HTTPS to communicate with CM. Otherwise,
31# it will use HTTP.
32# If CMPROTO is set to "https", the script assumes the CA cert needed to verify the cert
33# presented by CM is mounted at /certs/cacert.pem.
34
35# Set defaults for CM protocol and port
36CMPROTO=${CMPROTO:-http}
37CMPORT=${CMPORT:-80}
38
39# Set up additional parameters for using HTTPS
Jack Lucasa25c9232020-03-02 11:07:31 -050040CACERT="/certs/cacert.pem"
Jack Lucasbad77202020-02-03 18:21:29 -050041CFYTLS=""
42CURLTLS=""
43if [ $CMPROTO = "https" ]
44then
Jack Lucasa25c9232020-03-02 11:07:31 -050045 CFYTLS="--rest-certificate $CACERT --ssl"
46 CURLTLS="--cacert $CACERT"
Jack Lucasbad77202020-02-03 18:21:29 -050047fi
48
49### FUNCTION DEFINITIONS ###
50
51# keep_running: Keep running after bootstrap finishes or after error
52keep_running() {
53 echo $1
54 sleep infinity &
55 wait
56}
57
58# cm_hasany: Query Cloudify Manager and return 0 (true) if there are any entities matching the query
59# Used to see if something is already present on CM
60# $1 -- query fragment, for instance "plugins?archive_name=xyz.wgn" to get
61# the number of plugins that came from the archive file "xyz.wgn"
62function cm_hasany {
63 # We use _include=id to limit the amount of data the CM sends back
64 # We rely on the "metadata.pagination.total" field in the response
65 # for the total number of matching entities
66 COUNT=$(curl -Ss -H "Tenant: default_tenant" --user admin:${CMPASS} ${CURLTLS} "${CMPROTO}://${CMADDR}:${CMPORT}/api/v3.1/$1&_include=id" \
67 | /bin/jq .metadata.pagination.total)
68 if (( $COUNT > 0 ))
69 then
70 return 0
71 else
72 return 1
73 fi
74}
75
76# deploy: Deploy components if they're not already deployed
77# $1 -- name (for bp and deployment)
78# $2 -- blueprint file name
79# $3 -- inputs file name (optional)
80function deploy {
81 # Don't crash the script on error
82 set +e
83
84 # Upload blueprint if it's not already there
85 if cm_hasany "blueprints?id=$1"
86 then
87 echo blueprint $1 is already installed on ${CMADDR}
88 else
89 cfy blueprints upload -b $1 /blueprints/$2
90 fi
91
92 # Create deployment if it doesn't already exist
93 if cm_hasany "deployments?id=$1"
94 then
95 echo deployment $1 has already been created on ${CMADDR}
96 else
97 INPUTS=
98 if [ -n "$3" ]
99 then
100 INPUTS="-i/inputs/$3"
101 fi
102 cfy deployments create -b $1 ${INPUTS} $1
103 fi
104
105 # Run the install workflow if it hasn't been run already
106 # We don't have a completely certain way of determining this.
107 # We check to see if the deployment has any node instances
108 # that are in the 'uninitialized' or 'deleted' states. (Note that
109 # the & in the query acts as a logical OR for the multiple state values.)
110 # We'll try to install when a deployment has node instances in those states
111 if cm_hasany "node-instances?deployment_id=$1&state=uninitialized&state=deleted"
112 then
113 cfy executions start -d $1 install
114 else
115 echo deployment $1 appears to have had an install workflow executed already or is not ready for an install
116 fi
117}
118
Jack Lucasbad77202020-02-03 18:21:29 -0500119
120### END FUNCTION DEFINTIONS ###
121
122set -x
123
124# Make sure we keep the container alive after an error
125trap keep_running ERR
126
127set -e
128
Jack Lucasbad77202020-02-03 18:21:29 -0500129# Set up profile to access Cloudify Manager
130cfy profiles use -u admin -t default_tenant -p "${CMPASS}" ${CFYTLS} "${CMADDR}"
131
132# Output status, for debugging purposes
133cfy status
134
Jack Lucas01d60192020-06-17 17:11:17 -0400135# Store the CM password into a Cloudify secret
136cfy secret create -s ${CMPASS} cmpass
Jack Lucasbad77202020-02-03 18:21:29 -0500137
Jack Lucasbad77202020-02-03 18:21:29 -0500138# After this point, failures should not stop the script or block later commands
139trap - ERR
140set +e
141
142# Initialize the DCAE postgres instance
143deploy pgaas_initdb k8s-pgaas-initdb.yaml k8s-pgaas-initdb-inputs.yaml
144
145# Deploy service components
vv770dee9fec72020-08-07 17:50:11 +0000146# tcagen2, ves, prh, hv-ves, datafile-collector can be deployed simultaneously
Vijay Venkatesh Kumar0bc07ad2020-02-27 04:45:49 +0000147deploy tcagen2 k8s-tcagen2.yaml k8s-tcagen2-inputs.yaml &
Pawelb03f33a2020-02-14 10:28:04 +0100148deploy ves-tls k8s-ves.yaml k8s-ves-inputs-tls.yaml &
Jack Lucasbad77202020-02-03 18:21:29 -0500149deploy prh k8s-prh.yaml k8s-prh-inputs.yaml &
150deploy hv-ves k8s-hv-ves.yaml k8s-hv_ves-inputs.yaml &
151# holmes_rules must be deployed before holmes_engine, but holmes_rules can go in parallel with other service components
152deploy holmes_rules k8s-holmes-rules.yaml k8s-holmes_rules-inputs.yaml
153deploy holmes_engine k8s-holmes-engine.yaml k8s-holmes_engine-inputs.yaml
154
155# Display deployments, for debugging purposes
156cfy deployments list
157
Jack Lucasa25c9232020-03-02 11:07:31 -0500158# Load blueprints into DCAE inventory as
159# DCAE service types
160. /scripts/inventory.sh
161for BP in /blueprints/*.yaml
162do
163 upload_service_type $BP $CACERT
164done
165
Jack Lucasbad77202020-02-03 18:21:29 -0500166# Continue running
167keep_running "Finished bootstrap steps."
168echo "Exiting!"