Jack Lucas | 230ae89 | 2018-03-27 00:04:46 -0400 | [diff] [blame] | 1 | #!/bin/bash |
Jack Lucas | 5b12c6d | 2018-04-04 21:47:28 +0000 | [diff] [blame] | 2 | # ================================================================================ |
Jack Lucas | 5caf165 | 2019-02-08 14:21:58 -0500 | [diff] [blame] | 3 | # Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. |
Jack Lucas | 5b12c6d | 2018-04-04 21:47:28 +0000 | [diff] [blame] | 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 | |
Jack Lucas | 230ae89 | 2018-03-27 00:04:46 -0400 | [diff] [blame] | 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") |
Jack Lucas | 0a48eea | 2018-05-10 20:50:54 +0000 | [diff] [blame] | 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. |
Jack Lucas | 53f3110 | 2018-04-02 20:55:04 +0000 | [diff] [blame] | 24 | # Consul address with port in CONSUL variable |
Jack Lucas | 230ae89 | 2018-03-27 00:04:46 -0400 | [diff] [blame] | 25 | # Plugin wagon files in /wagons |
Jack Lucas | 53f3110 | 2018-04-02 20:55:04 +0000 | [diff] [blame] | 26 | # 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 Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 29 | # Consul is installed in /opt/consul/bin/consul, with base config in /opt/consul/config/00consul.json |
Jack Lucas | 230ae89 | 2018-03-27 00:04:46 -0400 | [diff] [blame] | 30 | |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 31 | ### FUNCTION DEFINITIONS ### |
| 32 | |
| 33 | # keep_running: Keep running after bootstrap finishes or after error |
| 34 | keep_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" |
| 44 | function 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) |
| 62 | function 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 |
| 103 | function 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 | |
| 116 | set -x |
| 117 | |
| 118 | # Make sure we keep the container alive after an error |
| 119 | trap keep_running ERR |
| 120 | |
| 121 | set -e |
Jack Lucas | 230ae89 | 2018-03-27 00:04:46 -0400 | [diff] [blame] | 122 | |
Jack Lucas | 5b12c6d | 2018-04-04 21:47:28 +0000 | [diff] [blame] | 123 | # Consul service registration data |
Jack Lucas | 53f3110 | 2018-04-02 20:55:04 +0000 | [diff] [blame] | 124 | CBS_REG='{"ID": "dcae-cbs0", "Name": "config_binding_service", "Address": "config-binding-service", "Port": 10000}' |
Jack Lucas | 5b12c6d | 2018-04-04 21:47:28 +0000 | [diff] [blame] | 125 | CBS_REG1='{"ID": "dcae-cbs1", "Name": "config-binding-service", "Address": "config-binding-service", "Port": 10000}' |
Jack Lucas | 5867fe1 | 2018-05-17 01:53:45 +0000 | [diff] [blame] | 126 | HE_REG='{"ID": "dcae-he0", "Name": "holmes-engine-mgmt", "Address": "holmes-engine-mgmt", "Port": 9102}' |
| 127 | HR_REG='{"ID": "dcae-hr0", "Name": "holmes-rule-mgmt", "Address": "holmes-rule-mgmt", "Port": 9101}' |
Jack Lucas | 0a48eea | 2018-05-10 20:50:54 +0000 | [diff] [blame] | 128 | PH_REG='{"ID": "dcae-ph0", "Name": "policy_handler", "Port": 25577, "Address": "policy-handler' |
Jack Lucas | bb206c7 | 2018-05-10 18:55:45 +0000 | [diff] [blame] | 129 | if [ ! -z "${DCAE_NAMESPACE}" ] |
| 130 | then |
| 131 | PH_REG="${PH_REG}.${DCAE_NAMESPACE}" |
| 132 | fi |
| 133 | PH_REG="${PH_REG}\"}" |
Jack Lucas | 5b12c6d | 2018-04-04 21:47:28 +0000 | [diff] [blame] | 134 | |
Jack Lucas | 5b12c6d | 2018-04-04 21:47:28 +0000 | [diff] [blame] | 135 | # Set up profile to access Cloudify Manager |
Jack Lucas | 230ae89 | 2018-03-27 00:04:46 -0400 | [diff] [blame] | 136 | cfy profiles use -u admin -t default_tenant -p "${CMPASS}" "${CMADDR}" |
| 137 | |
| 138 | # Output status, for debugging purposes |
| 139 | cfy status |
| 140 | |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 141 | # 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 |
| 149 | until curl http://${CONSUL}/v1/agent/services |
| 150 | do |
| 151 | echo Waiting for Consul API |
| 152 | sleep 60 |
| 153 | done |
| 154 | # Wait for a leader to be elected |
| 155 | until [[ "$(curl -Ss http://{$CONSUL}/v1/status/leader)" != '""' ]] |
| 156 | do |
| 157 | echo Waiting for leader |
| 158 | sleep 30 |
| 159 | done |
| 160 | |
| 161 | # Load configurations into Consul KV store |
Jack Lucas | 53f3110 | 2018-04-02 20:55:04 +0000 | [diff] [blame] | 162 | for config in /dcae-configs/*.json |
| 163 | do |
| 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} |
| 169 | done |
| 170 | |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 171 | # Put service registrations into the local Consul configuration directory |
Jack Lucas | 5caf165 | 2019-02-08 14:21:58 -0500 | [diff] [blame] | 172 | for sr in CBS_REG CBS_REG1 HE_REG HR_REG PH_REG |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 173 | do |
| 174 | echo '{"service" : ' ${!sr} ' }'> /opt/consul/config/${sr}.json |
| 175 | done |
| 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 Lucas | 5b12c6d | 2018-04-04 21:47:28 +0000 | [diff] [blame] | 179 | |
| 180 | # Store the CM password into a Cloudify secret |
| 181 | cfy secret create -s ${CMPASS} cmpass |
Jack Lucas | 53f3110 | 2018-04-02 20:55:04 +0000 | [diff] [blame] | 182 | |
Jack Lucas | 230ae89 | 2018-03-27 00:04:46 -0400 | [diff] [blame] | 183 | # Load plugins onto CM |
| 184 | for wagon in /wagons/*.wgn |
| 185 | do |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 186 | install_plugin ${wagon} |
Jack Lucas | 230ae89 | 2018-03-27 00:04:46 -0400 | [diff] [blame] | 187 | done |
| 188 | |
Jack Lucas | 45cb899 | 2018-08-22 19:29:40 +0000 | [diff] [blame] | 189 | # After this point, failures should not stop the script or block later commands |
| 190 | trap - ERR |
Lusheng Ji | dda9b82 | 2018-05-04 16:02:38 -0400 | [diff] [blame] | 191 | set +e |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 192 | |
Jack Lucas | 230ae89 | 2018-03-27 00:04:46 -0400 | [diff] [blame] | 193 | # Deploy platform components |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 194 | # Allow for some parallelism to speed up the process. Probably could be somewhat more aggressive. |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 195 | deploy pgaas_initdb k8s-pgaas-initdb.yaml k8s-pgaas-initdb-inputs.yaml & |
Vijay Venkatesh Kumar | d2c8212 | 2019-04-05 00:38:59 +0000 | [diff] [blame^] | 196 | deploy dashboard k8s-dashboard.yaml k8s-dashboard-inputs.yaml & |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 197 | PG_PID=$! |
Jack Lucas | 0025fda | 2019-01-17 13:53:56 -0500 | [diff] [blame] | 198 | wait ${PG_PID} |
Jack Lucas | bac8d42 | 2018-04-27 22:11:51 +0000 | [diff] [blame] | 199 | |
| 200 | # Deploy service components |
wasala | 4251730 | 2018-09-19 13:51:36 +0200 | [diff] [blame] | 201 | # tca, ves, prh, hv-ves, datafile-collector can be deployed simultaneously |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 202 | deploy tca k8s-tca.yaml k8s-tca-inputs.yaml & |
| 203 | deploy ves k8s-ves.yaml k8s-ves-inputs.yaml & |
vagrant | 6ccc560 | 2018-09-16 07:00:06 +0000 | [diff] [blame] | 204 | deploy snmptrap k8s-snmptrap.yaml k8s-snmptrap-inputs.yaml & |
| 205 | deploy prh k8s-prh.yaml k8s-prh-inputs.yaml & |
| 206 | deploy hv-ves k8s-hv-ves.yaml k8s-hv_ves-inputs.yaml & |
Paul Dennehy | 1fe9e4d | 2018-10-01 15:46:28 +0100 | [diff] [blame] | 207 | deploy datafile-collector k8s-datafile-collector.yaml k8s-datafile-collector-inputs.yaml & |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 208 | # holmes_rules must be deployed before holmes_engine, but holmes_rules can go in parallel with other service components |
Jack Lucas | 2415db8 | 2018-04-30 01:23:45 +0000 | [diff] [blame] | 209 | deploy holmes_rules k8s-holmes-rules.yaml k8s-holmes_rules-inputs.yaml |
| 210 | deploy holmes_engine k8s-holmes-engine.yaml k8s-holmes_engine-inputs.yaml |
Jack Lucas | 230ae89 | 2018-03-27 00:04:46 -0400 | [diff] [blame] | 211 | |
Jack Lucas | 53f3110 | 2018-04-02 20:55:04 +0000 | [diff] [blame] | 212 | # Display deployments, for debugging purposes |
| 213 | cfy deployments list |
Jack Lucas | b3350fa | 2018-08-17 12:58:51 +0000 | [diff] [blame] | 214 | |
| 215 | # Continue running |
| 216 | keep_running "Finished bootstrap steps." |
vagrant | 6ccc560 | 2018-09-16 07:00:06 +0000 | [diff] [blame] | 217 | echo "Exiting!" |