Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 1 | # -*- indent-tabs-mode: nil -*- # vi: set expandtab: |
Tony Hansen | 749bc2d | 2017-10-03 02:51:42 +0000 | [diff] [blame] | 2 | # |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 3 | # ============LICENSE_START==================================================== |
| 4 | # org.onap.dcae |
| 5 | # ============================================================================= |
| 6 | # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. |
| 7 | # ============================================================================= |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | # ============LICENSE_END====================================================== |
| 20 | |
| 21 | tosca_definitions_version: cloudify_dsl_1_3 |
| 22 | |
Tony Hansen | 749bc2d | 2017-10-03 02:51:42 +0000 | [diff] [blame] | 23 | description: |- |
Tony Hansen | 9be0c16 | 2017-10-31 16:01:10 +0000 | [diff] [blame] | 24 | This blueprint is used to install and to uninstall a two-VM central postgres as a platform service. |
Tony Hansen | 749bc2d | 2017-10-03 02:51:42 +0000 | [diff] [blame] | 25 | This blueprint depends upon the deployment of the pgaas_plugin and Consul. |
| 26 | |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 27 | imports: |
| 28 | - http://www.getcloudify.org/spec/cloudify/3.4/types.yaml |
| 29 | - http://www.getcloudify.org/spec/openstack-plugin/1.4/plugin.yaml |
| 30 | - http://www.getcloudify.org/spec/fabric-plugin/1.4.1/plugin.yaml |
| 31 | |
Tony Hansen | 1d01367 | 2017-10-06 21:01:05 +0000 | [diff] [blame] | 32 | - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/dnsdesig/dns_types.yaml" |
Tony Hansen | 6b903fe | 2017-09-29 17:29:52 +0000 | [diff] [blame] | 33 | - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/sshkeyshare/sshkey_types.yaml" |
Hansen, Tony (th1395) | 68765fc | 2018-04-27 00:37:31 +0000 | [diff] [blame] | 34 | - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/relationshipplugin/1.0.0/relationshipplugin_types.yaml" |
Hansen, Tony (th1395) | b936fb4 | 2018-03-29 14:28:59 +0000 | [diff] [blame] | 35 | - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/pgaas/1.1.0/pgaas_types.yaml" |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 36 | |
| 37 | inputs: |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 38 | blueprint_version: |
| 39 | type: string |
Hansen, Tony (th1395) | 68765fc | 2018-04-27 00:37:31 +0000 | [diff] [blame] | 40 | default: '2018-04-27T00:31:38+0000' |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 41 | |
| 42 | # pgaas-specific info |
| 43 | pgaas_cluster_name: |
| 44 | type: string |
| 45 | default: pstg |
| 46 | |
Tony Hansen | f5e39dd | 2017-10-11 18:08:57 +0000 | [diff] [blame] | 47 | {{ ONAPTEMPLATE_STANDARD_INPUTS_TYPES }} |
| 48 | |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 49 | vm_init_pgrs: |
| 50 | type: string |
| 51 | default: | |
| 52 | #!/bin/sh |
| 53 | echo All output will be found in /tmp/ins.out and /tmp/ins.err |
| 54 | exec > /tmp/ins.out 2> /tmp/ins.err |
| 55 | set -x |
| 56 | if [ "$(dnsdomainname 2>/dev/null)" = "" ] |
| 57 | then |
| 58 | echo WARNING WARNING WARNING |
| 59 | echo The DNS DHCP settings did not work properly. |
Tony Hansen | 73e66b9 | 2017-11-01 15:12:11 +0000 | [diff] [blame] | 60 | for i in $(seq 20) |
| 61 | do |
| 62 | echo Sleeping... |
| 63 | sleep 10 |
| 64 | if [ "$(dnsdomainname 2>/dev/null)" != "" ] |
| 65 | then break |
| 66 | fi |
| 67 | echo The DNS DHCP settings still did not work properly. |
| 68 | done |
| 69 | if [ "$(dnsdomainname 2>/dev/null)" = "" ] |
| 70 | then |
| 71 | echo Exiting |
| 72 | exit 1 |
| 73 | fi |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 74 | fi |
| 75 | |
| 76 | CONFDIR=/var/config/DCAE/chef/ |
| 77 | mkdir -p $CONFDIR |
| 78 | |
| 79 | CONF=$CONFDIR/pgaas-postgres.conf |
| 80 | cat <<EOF > $CONF |
| 81 | master: ${MASTER%%.*} |
| 82 | secondmaster: notused |
| 83 | DRTR_NODE_KSTOREFILE: /opt/app/dcae-certificate/keystore.jks |
| 84 | DRTR_NODE_KSTOREPASS: "No Certificate" |
| 85 | DRTR_NODE_PVTKEYPASS: "No Certificate" |
| 86 | PG_NODES: $PG_NODES |
| 87 | PG_JAVA_HOME : /opt/app/java/jdk/jdk170 |
| 88 | PG_CLUSTER: central |
| 89 | EOF |
| 90 | |
| 91 | apt-get update |
| 92 | |
| 93 | # invoking apt-get separately allows a failure to be ignored |
| 94 | for i in openjdk-7-jdk openjdk-8-jdk python-pip python3-pip curl gawk; do apt-get install -y $i;done |
| 95 | pip install pyyaml |
| 96 | |
| 97 | # prevent servers from starting |
| 98 | echo "exit 101" > /usr/sbin/policy-rc.d; chmod a+x /usr/sbin/policy-rc.d |
| 99 | |
| 100 | # invoking apt-get separately allows a failure to be ignored |
| 101 | for i in postgresql libpq5 repmgr python-psycopg2 python3-psycopg2 libgetopt-java; do apt-get install -y $i; done |
| 102 | |
| 103 | # allow servers to autostart again |
| 104 | rm -f /usr/sbin/policy-rc.d |
| 105 | |
| 106 | ( umask 077; sed 's/^/*:*:*:postgres:/' < /root/.pgrspw > ~postgres/.pgpass; chown postgres:postgres ~postgres/.pgpass ) |
| 107 | |
| 108 | if [ ! -f $CONF ] |
| 109 | then echo "$CONF does not exist" 1>&2; exit 1 |
| 110 | fi |
| 111 | |
| 112 | echo Look in /tmp/pgaas.out for output from installing PGaaS |
Tony Hansen | ffa416d | 2017-10-24 19:35:57 +0000 | [diff] [blame] | 113 | NEXUS={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_storage_pgaas_debs_releases }}/debs |
| 114 | for pkg in cdf.deb-1.0.0 pgaas.deb-1.0.0 |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 115 | do |
| 116 | OUT=/tmp/$pkg |
| 117 | curl -s -k -f -o $OUT $NEXUS/$pkg |
| 118 | dpkg --install $OUT |
| 119 | done |
| 120 | |
| 121 | case $(hostname) in |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 122 | *00 ) WRITE=-write ;; |
| 123 | *01 ) WRITE= ;; |
| 124 | esac |
Tony Hansen | bfff05b | 2017-11-01 21:10:10 +0000 | [diff] [blame] | 125 | curl -v -X PUT -H "Content-Type: application/json" "http://${LOCATION_PREFIX}cnsl00.${LOCATION_DOMAIN}:8500/v1/agent/service/register" -d "{\"name\" : \"${CLUSTER_NAME}${WRITE}\", \"Address\" : \"${LOCAL_IP}\", \"Port\" : 5432}" |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 126 | |
| 127 | echo ALL DONE |
| 128 | |
| 129 | node_templates: |
| 130 | key_pair: |
| 131 | type: cloudify.openstack.nodes.KeyPair |
| 132 | properties: |
| 133 | private_key_path: { get_input: key_filename } |
| 134 | use_external_resource: True |
| 135 | resource_id: { get_input: keypair } |
| 136 | openstack_config: &open_conf |
| 137 | get_input: openstack |
| 138 | private_net: |
| 139 | type: cloudify.openstack.nodes.Network |
| 140 | properties: |
| 141 | use_external_resource: True |
| 142 | resource_id: { get_input: private_net } |
| 143 | openstack_config: *open_conf |
| 144 | security_group: |
| 145 | type: cloudify.openstack.nodes.SecurityGroup |
| 146 | properties: |
| 147 | use_external_resource: True |
| 148 | resource_id: { get_input: security_group } |
| 149 | openstack_config: *open_conf |
| 150 | |
| 151 | sharedsshkey_pgrs: |
Tony Hansen | f5e39dd | 2017-10-11 18:08:57 +0000 | [diff] [blame] | 152 | type: ccsdk.nodes.ssh.keypair |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 153 | |
| 154 | fixedip_pgrs00: |
| 155 | type: cloudify.openstack.nodes.Port |
| 156 | properties: |
| 157 | port: |
| 158 | extra_dhcp_opts: |
| 159 | - opt_name: 'domain-name' |
| 160 | opt_value: { get_input: location_domain } |
| 161 | openstack_config: *open_conf |
| 162 | relationships: |
| 163 | - type: cloudify.relationships.contained_in |
| 164 | target: private_net |
| 165 | floatingip_pgrs00: |
| 166 | type: cloudify.openstack.nodes.FloatingIP |
| 167 | properties: |
| 168 | openstack_config: *open_conf |
| 169 | interfaces: |
| 170 | cloudify.interfaces.lifecycle: |
| 171 | create: |
| 172 | inputs: |
| 173 | args: |
| 174 | floating_network_name: { get_input: public_net } |
| 175 | dns_pgrs00: |
Tony Hansen | f5e39dd | 2017-10-11 18:08:57 +0000 | [diff] [blame] | 176 | type: ccsdk.nodes.dns.arecord |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 177 | properties: |
| 178 | fqdn: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] } |
| 179 | openstack: *open_conf |
| 180 | interfaces: |
| 181 | cloudify.interfaces.lifecycle: |
| 182 | create: |
| 183 | inputs: |
| 184 | args: |
| 185 | ip_addresses: |
| 186 | - { get_attribute: [ floatingip_pgrs00, floating_ip_address ] } |
| 187 | relationships: |
| 188 | - type: cloudify.relationships.depends_on |
| 189 | target: floatingip_pgrs00 |
| 190 | host_pgrs00: |
| 191 | type: cloudify.openstack.nodes.Server |
| 192 | properties: |
| 193 | install_agent: false |
| 194 | image: { get_input: ubuntu1604image_id } |
| 195 | flavor: { get_input: flavor_id } |
| 196 | management_network_name: { get_input: private_net } |
| 197 | openstack_config: *open_conf |
| 198 | interfaces: |
| 199 | cloudify.interfaces.lifecycle: |
| 200 | create: |
| 201 | inputs: |
| 202 | args: |
| 203 | name: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00' ] } |
| 204 | userdata: |
| 205 | concat: |
| 206 | - |- |
| 207 | #!/bin/sh |
| 208 | mkdir /root/.sshkey |
| 209 | echo ' |
| 210 | - { get_attribute: [ sharedsshkey_pgrs, public ] } |
| 211 | - |- |
| 212 | ' >/root/.sshkey/id_rsa.pub |
| 213 | echo ' |
| 214 | - { get_attribute: [ sharedsshkey_pgrs, base64private ] } |
| 215 | - |- |
| 216 | ' | base64 -d >/root/.sshkey/id_rsa |
| 217 | chmod 700 /root/.sshkey |
| 218 | chmod 600 /root/.sshkey/* |
| 219 | ( umask 077; echo -n postgres | cat - /root/.sshkey/id_rsa | md5sum | awk '{ print $1 }' > /root/.pgrspw ) |
| 220 | set -x |
| 221 | - "\n" |
| 222 | - "CLUSTER_NAME='" |
| 223 | - { get_input: pgaas_cluster_name } |
| 224 | - "'\n" |
| 225 | - "LOCATION_PREFIX='" |
| 226 | - { get_input: location_prefix } |
| 227 | - "'\n" |
| 228 | - "LOCATION_DOMAIN='" |
| 229 | - { get_input: location_domain } |
| 230 | - "'\n" |
| 231 | - "MASTER='" |
| 232 | - { get_property: [ dns_pgrs00, fqdn ] } |
| 233 | - "'\n" |
| 234 | - "LOCAL_IP='" |
Tony Hansen | bfff05b | 2017-11-01 21:10:10 +0000 | [diff] [blame] | 235 | - { get_attribute: [ floatingip_pgrs00, floating_ip_address ] } |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 236 | - "'\n" |
| 237 | - "PG_NODES='" |
| 238 | - { get_property: [ dns_pgrs00, fqdn ] } |
| 239 | - '|' |
| 240 | - { get_property: [ dns_pgrs01, fqdn ] } |
| 241 | - "'\n" |
| 242 | - { get_input: vm_init_pgrs } |
| 243 | relationships: |
| 244 | - type: cloudify.openstack.server_connected_to_port |
| 245 | target: fixedip_pgrs00 |
| 246 | - type: cloudify.openstack.server_connected_to_security_group |
| 247 | target: security_group |
| 248 | - type: cloudify.openstack.server_connected_to_floating_ip |
| 249 | target: floatingip_pgrs00 |
| 250 | - type: cloudify.openstack.server_connected_to_keypair |
| 251 | target: key_pair |
| 252 | - type: cloudify.relationships.depends_on |
| 253 | target: dns_pgrs00 |
| 254 | - type: cloudify.relationships.depends_on |
| 255 | target: sharedsshkey_pgrs |
| 256 | fixedip_pgrs01: |
| 257 | type: cloudify.openstack.nodes.Port |
| 258 | properties: |
| 259 | port: |
| 260 | extra_dhcp_opts: |
| 261 | - opt_name: 'domain-name' |
| 262 | opt_value: { get_input: location_domain } |
| 263 | openstack_config: *open_conf |
| 264 | relationships: |
| 265 | - type: cloudify.relationships.contained_in |
| 266 | target: private_net |
| 267 | floatingip_pgrs01: |
| 268 | type: cloudify.openstack.nodes.FloatingIP |
| 269 | properties: |
| 270 | openstack_config: *open_conf |
| 271 | interfaces: |
| 272 | cloudify.interfaces.lifecycle: |
| 273 | create: |
| 274 | inputs: |
| 275 | args: |
| 276 | floating_network_name: { get_input: public_net } |
| 277 | dns_pgrs01: |
Tony Hansen | f5e39dd | 2017-10-11 18:08:57 +0000 | [diff] [blame] | 278 | type: ccsdk.nodes.dns.arecord |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 279 | properties: |
| 280 | fqdn: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '01.', { get_input: location_domain } ] } |
| 281 | openstack: *open_conf |
| 282 | interfaces: |
| 283 | cloudify.interfaces.lifecycle: |
| 284 | create: |
| 285 | inputs: |
| 286 | args: |
| 287 | ip_addresses: |
| 288 | - { get_attribute: [ floatingip_pgrs01, floating_ip_address ] } |
| 289 | relationships: |
| 290 | - type: cloudify.relationships.depends_on |
| 291 | target: floatingip_pgrs01 |
| 292 | host_pgrs01: |
| 293 | type: cloudify.openstack.nodes.Server |
| 294 | properties: |
| 295 | install_agent: false |
| 296 | image: { get_input: ubuntu1604image_id } |
| 297 | flavor: { get_input: flavor_id } |
| 298 | management_network_name: { get_input: private_net } |
| 299 | openstack_config: *open_conf |
| 300 | interfaces: |
| 301 | cloudify.interfaces.lifecycle: |
| 302 | create: |
| 303 | inputs: |
| 304 | args: |
| 305 | name: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '01' ] } |
| 306 | userdata: |
| 307 | concat: |
| 308 | - |- |
| 309 | #!/bin/sh |
| 310 | mkdir /root/.sshkey |
| 311 | echo ' |
| 312 | - { get_attribute: [ sharedsshkey_pgrs, public ] } |
| 313 | - |- |
| 314 | ' >/root/.sshkey/id_rsa.pub |
| 315 | echo ' |
| 316 | - { get_attribute: [ sharedsshkey_pgrs, base64private ] } |
| 317 | - |- |
| 318 | ' | base64 -d >/root/.sshkey/id_rsa |
| 319 | chmod 700 /root/.sshkey |
| 320 | chmod 600 /root/.sshkey/* |
| 321 | ( umask 077; echo -n postgres | cat - /root/.sshkey/id_rsa | md5sum | awk '{ print $1 }' > /root/.pgrspw ) |
| 322 | set -x |
| 323 | - "\n" |
| 324 | - "CLUSTER_NAME='" |
| 325 | - { get_input: pgaas_cluster_name } |
| 326 | - "'\n" |
| 327 | - "LOCATION_PREFIX='" |
| 328 | - { get_input: location_prefix } |
| 329 | - "'\n" |
| 330 | - "LOCATION_DOMAIN='" |
| 331 | - { get_input: location_domain } |
| 332 | - "'\n" |
| 333 | - "MASTER='" |
| 334 | - { get_property: [ dns_pgrs00, fqdn ] } |
| 335 | - "'\n" |
| 336 | - "LOCAL_IP='" |
Tony Hansen | bfff05b | 2017-11-01 21:10:10 +0000 | [diff] [blame] | 337 | - { get_attribute: [ floatingip_pgrs01, floating_ip_address ] } |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 338 | - "'\n" |
| 339 | - "PG_NODES='" |
| 340 | - { get_property: [ dns_pgrs00, fqdn ] } |
| 341 | - '|' |
| 342 | - { get_property: [ dns_pgrs01, fqdn ] } |
| 343 | - "'\n" |
| 344 | - { get_input: vm_init_pgrs } |
| 345 | relationships: |
| 346 | - type: cloudify.openstack.server_connected_to_port |
| 347 | target: fixedip_pgrs01 |
| 348 | - type: cloudify.openstack.server_connected_to_security_group |
| 349 | target: security_group |
| 350 | - type: cloudify.openstack.server_connected_to_floating_ip |
| 351 | target: floatingip_pgrs01 |
| 352 | - type: cloudify.openstack.server_connected_to_keypair |
| 353 | target: key_pair |
| 354 | - type: cloudify.relationships.depends_on |
| 355 | target: dns_pgrs01 |
| 356 | - type: cloudify.relationships.depends_on |
| 357 | target: sharedsshkey_pgrs |
| 358 | |
| 359 | # CNAME records |
| 360 | dns_pgrs_rw: |
Tony Hansen | f5e39dd | 2017-10-11 18:08:57 +0000 | [diff] [blame] | 361 | type: ccsdk.nodes.dns.cnamerecord |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 362 | properties: |
| 363 | fqdn: { concat: [ { get_input: location_prefix }, '-', { get_input: pgaas_cluster_name }, '-write.', { get_input: location_domain } ] } |
| 364 | openstack: *open_conf |
| 365 | interfaces: |
| 366 | cloudify.interfaces.lifecycle: |
| 367 | create: |
| 368 | inputs: |
| 369 | args: |
| 370 | cname: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] } |
| 371 | |
| 372 | dns_pgrs_ro: |
Tony Hansen | f5e39dd | 2017-10-11 18:08:57 +0000 | [diff] [blame] | 373 | type: ccsdk.nodes.dns.cnamerecord |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 374 | properties: |
| 375 | fqdn: { concat: [ { get_input: location_prefix }, '-', { get_input: pgaas_cluster_name }, '.', { get_input: location_domain } ] } |
| 376 | openstack: *open_conf |
| 377 | interfaces: |
| 378 | cloudify.interfaces.lifecycle: |
| 379 | create: |
| 380 | inputs: |
| 381 | args: |
| 382 | cname: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] } |
| 383 | |
| 384 | # tie to pgaas_plugin database |
| 385 | pgaas_cluster: |
| 386 | type: dcae.nodes.pgaas.cluster |
| 387 | properties: |
| 388 | writerfqdn: { get_property: [ dns_pgrs_rw, fqdn ] } |
| 389 | readerfqdn: { get_property: [ dns_pgrs_ro, fqdn ] } |
| 390 | relationships: |
| 391 | - type: dcae.relationships.pgaas_cluster_uses_sshkeypair |
| 392 | target: sharedsshkey_pgrs |
| 393 | - type: cloudify.relationships.depends_on |
| 394 | target: dns_pgrs_rw |
| 395 | - type: cloudify.relationships.depends_on |
| 396 | target: dns_pgrs_ro |
| 397 | |
| 398 | outputs: |
| 399 | public_ip00: |
| 400 | value: { get_attribute: [host_pgrs00, ip] } |
| 401 | public_ip01: |
| 402 | value: { get_attribute: [host_pgrs01, ip] } |
| 403 | writerfqdn: |
| 404 | value: { get_property: [ dns_pgrs_rw, fqdn ] } |
| 405 | readerfqdn: |
| 406 | value: { get_property: [ dns_pgrs_ro, fqdn ] } |
| 407 | dns_pgrs00: |
| 408 | value: { get_property: [ dns_pgrs00, fqdn ] } |
| 409 | dns_pgrs01: |
| 410 | value: { get_property: [ dns_pgrs01, fqdn ] } |
Tony Hansen | f5e39dd | 2017-10-11 18:08:57 +0000 | [diff] [blame] | 411 | blueprint_version: |
Tony Hansen | a795b59 | 2017-09-29 01:15:29 +0000 | [diff] [blame] | 412 | value: { get_input: blueprint_version } |