Jack Lucas | bad7720 | 2020-02-03 18:21:29 -0500 | [diff] [blame] | 1 | #!/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 Lucas | bad7720 | 2020-02-03 18:21:29 -0500 | [diff] [blame] | 25 | # 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 |
| 38 | CMPROTO=${CMPROTO:-http} |
| 39 | CMPORT=${CMPORT:-80} |
| 40 | |
| 41 | # Set up additional parameters for using HTTPS |
Jack Lucas | a25c923 | 2020-03-02 11:07:31 -0500 | [diff] [blame] | 42 | CACERT="/certs/cacert.pem" |
Jack Lucas | bad7720 | 2020-02-03 18:21:29 -0500 | [diff] [blame] | 43 | CFYTLS="" |
| 44 | CURLTLS="" |
| 45 | if [ $CMPROTO = "https" ] |
| 46 | then |
Jack Lucas | a25c923 | 2020-03-02 11:07:31 -0500 | [diff] [blame] | 47 | CFYTLS="--rest-certificate $CACERT --ssl" |
| 48 | CURLTLS="--cacert $CACERT" |
Jack Lucas | bad7720 | 2020-02-03 18:21:29 -0500 | [diff] [blame] | 49 | fi |
| 50 | |
| 51 | ### FUNCTION DEFINITIONS ### |
| 52 | |
| 53 | # keep_running: Keep running after bootstrap finishes or after error |
| 54 | keep_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" |
| 64 | function 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) |
| 82 | function 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 Lucas | bad7720 | 2020-02-03 18:21:29 -0500 | [diff] [blame] | 121 | |
| 122 | ### END FUNCTION DEFINTIONS ### |
| 123 | |
| 124 | set -x |
| 125 | |
| 126 | # Make sure we keep the container alive after an error |
| 127 | trap keep_running ERR |
| 128 | |
| 129 | set -e |
| 130 | |
Jack Lucas | bad7720 | 2020-02-03 18:21:29 -0500 | [diff] [blame] | 131 | # Set up profile to access Cloudify Manager |
| 132 | cfy profiles use -u admin -t default_tenant -p "${CMPASS}" ${CFYTLS} "${CMADDR}" |
| 133 | |
| 134 | # Output status, for debugging purposes |
| 135 | cfy status |
| 136 | |
Jack Lucas | 01d6019 | 2020-06-17 17:11:17 -0400 | [diff] [blame] | 137 | # Store the CM password into a Cloudify secret |
| 138 | cfy secret create -s ${CMPASS} cmpass |
Jack Lucas | bad7720 | 2020-02-03 18:21:29 -0500 | [diff] [blame] | 139 | |
| 140 | # Load configurations into Consul KV store |
| 141 | for config in /dcae-configs/*.json |
| 142 | do |
| 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} |
| 148 | done |
| 149 | |
Jack Lucas | bad7720 | 2020-02-03 18:21:29 -0500 | [diff] [blame] | 150 | # After this point, failures should not stop the script or block later commands |
| 151 | trap - ERR |
| 152 | set +e |
| 153 | |
| 154 | # Initialize the DCAE postgres instance |
| 155 | deploy pgaas_initdb k8s-pgaas-initdb.yaml k8s-pgaas-initdb-inputs.yaml |
| 156 | |
| 157 | # Deploy service components |
vv770d | ee9fec7 | 2020-08-07 17:50:11 +0000 | [diff] [blame] | 158 | # tcagen2, ves, prh, hv-ves, datafile-collector can be deployed simultaneously |
Vijay Venkatesh Kumar | 0bc07ad | 2020-02-27 04:45:49 +0000 | [diff] [blame] | 159 | deploy tcagen2 k8s-tcagen2.yaml k8s-tcagen2-inputs.yaml & |
Pawel | b03f33a | 2020-02-14 10:28:04 +0100 | [diff] [blame] | 160 | deploy ves-tls k8s-ves.yaml k8s-ves-inputs-tls.yaml & |
Jack Lucas | bad7720 | 2020-02-03 18:21:29 -0500 | [diff] [blame] | 161 | deploy prh k8s-prh.yaml k8s-prh-inputs.yaml & |
| 162 | deploy 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 |
| 164 | deploy holmes_rules k8s-holmes-rules.yaml k8s-holmes_rules-inputs.yaml |
| 165 | deploy holmes_engine k8s-holmes-engine.yaml k8s-holmes_engine-inputs.yaml |
| 166 | |
| 167 | # Display deployments, for debugging purposes |
| 168 | cfy deployments list |
| 169 | |
Jack Lucas | a25c923 | 2020-03-02 11:07:31 -0500 | [diff] [blame] | 170 | # Load blueprints into DCAE inventory as |
| 171 | # DCAE service types |
| 172 | . /scripts/inventory.sh |
| 173 | for BP in /blueprints/*.yaml |
| 174 | do |
| 175 | upload_service_type $BP $CACERT |
| 176 | done |
| 177 | |
Jack Lucas | bad7720 | 2020-02-03 18:21:29 -0500 | [diff] [blame] | 178 | # Continue running |
| 179 | keep_running "Finished bootstrap steps." |
| 180 | echo "Exiting!" |