a1885f1f1de92daad28cc8eb5798cd898a85aa8f
[dcaegen2/platform/blueprints.git] / blueprints / pgaas-cluster.yaml-template
1 # -*- indent-tabs-mode: nil -*- # vi: set expandtab:
2 #
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
23 description: |-
24   This blueprint is used to install and to uninstall a central postgres as a platform service.
25   This blueprint depends upon the deployment of the pgaas_plugin, the PGaaS Cinder volume, and Consul.
26   This blueprint is part of a suite of three blueprints that allow a PGaaS
27   cluster to be created that has persistent databases stored in Cinder.
28   pgaas-disk allocates the cinder volumes. It must be run first.
29   pgaas-cluster creates the PG service and attaches the cinder volumes. It must be run second.
30   pgaas-database creates a database. It must be run third, for each persistent database.
31   If the cluster is uninstalled, the persistent databases are unaffected.
32   If a database blueprint is uninstalled, the persistent database goes away.
33   If the disk blueprint is uninstalled, all persistent databases go away, along with the server instance.
34
35 imports:
36   - http://www.getcloudify.org/spec/cloudify/3.4/types.yaml
37   - http://www.getcloudify.org/spec/openstack-plugin/1.4/plugin.yaml
38   - http://www.getcloudify.org/spec/fabric-plugin/1.4.1/plugin.yaml
39
40   - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/dnsdesig/dns_types.yaml"
41   - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/type_files/relationshipplugin/1/relationshipplugin_types.yaml"
42   - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/pgaas/pgaas_types.yaml"
43
44 inputs:
45   blueprint_version:
46     type: string
47     default: 'VERSION-STAMP-GOES-HERE'
48
49   # pgaas-specific info
50   pgaas_cluster_name:
51     type: string
52     default: pgcl
53
54 {{ ONAPTEMPLATE_STANDARD_INPUTS_TYPES }}
55
56   vm_init_pgrs:
57     type: string
58     default: |
59       #!/bin/sh
60       echo All output will be found in /tmp/ins.out and /tmp/ins.err
61       exec > /tmp/ins.out 2> /tmp/ins.err
62       set -x
63       if [ "$(dnsdomainname 2>/dev/null)" = "" ]
64       then
65         echo WARNING WARNING WARNING
66         echo The DNS DHCP settings did not work properly.
67         exit 1
68       fi
69
70       CONFDIR=/var/config/DCAE/chef/
71       mkdir -p $CONFDIR
72
73       CONF=$CONFDIR/pgaas-postgres.conf
74       cat <<EOF > $CONF
75       master: ${MASTER%%.*}
76       secondmaster: notused
77       DRTR_NODE_KSTOREFILE: /opt/app/dcae-certificate/keystore.jks
78       DRTR_NODE_KSTOREPASS: "No Certificate"
79       DRTR_NODE_PVTKEYPASS: "No Certificate"
80       PG_NODES: $PG_NODES
81       PG_JAVA_HOME : /opt/app/java/jdk/jdk170
82       PG_CLUSTER: central
83       EOF
84
85       apt-get update
86
87       # invoking apt-get separately allows a failure to be ignored
88       for i in openjdk-7-jdk openjdk-8-jdk python-pip python3-pip curl gawk; do apt-get install -y $i;done
89       pip install pyyaml
90
91       # prevent servers from starting
92       echo  "exit 101" > /usr/sbin/policy-rc.d; chmod a+x /usr/sbin/policy-rc.d
93
94       # invoking apt-get separately allows a failure to be ignored
95       for i in postgresql libpq5 repmgr python-psycopg2 python3-psycopg2 libgetopt-java; do apt-get install -y $i; done
96
97       # allow servers to autostart again
98       rm -f /usr/sbin/policy-rc.d
99
100       ( umask 077; sed 's/^/*:*:*:postgres:/' < /root/.pgrspw > ~postgres/.pgpass; chown postgres:postgres ~postgres/.pgpass )
101
102       if [ ! -f $CONF ]
103       then echo "$CONF does not exist" 1>&2; exit 1
104       fi
105
106       echo Look in /tmp/pgaas.out for output from installing PGaaS
107       NEXUS={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform }}/debs
108       for pkg in cdf_17.10.0-LATEST.deb pgaas_17.10.0-LATEST.deb
109       do
110           OUT=/tmp/$pkg
111           curl -s -k -f -o $OUT $NEXUS/$pkg
112           dpkg --install $OUT
113       done
114
115       case $(hostname) in
116       do
117         *00 ) WRITE=-write ;;
118         *01 ) WRITE= ;;
119       esac
120       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}"
121
122       echo ALL DONE
123
124 node_templates:
125   key_pair:
126     type: cloudify.openstack.nodes.KeyPair
127     properties:
128       private_key_path: { get_input: key_filename }
129       use_external_resource: True
130       resource_id: { get_input: keypair }
131       openstack_config: &open_conf
132         get_input: openstack
133   private_net:
134     type: cloudify.openstack.nodes.Network
135     properties:
136       use_external_resource: True
137       resource_id: { get_input: private_net }
138       openstack_config: *open_conf
139   security_group:
140     type: cloudify.openstack.nodes.SecurityGroup
141     properties:
142       use_external_resource: True
143       resource_id: { get_input: security_group }
144       openstack_config: *open_conf
145
146   fixedip_pgrs00:
147     type: cloudify.openstack.nodes.Port
148     properties:
149       port:
150         extra_dhcp_opts:
151           - opt_name: 'domain-name'
152             opt_value: { get_input: location_domain }
153       openstack_config: *open_conf
154     relationships:
155       - type: cloudify.relationships.contained_in
156         target: private_net
157   floatingip_pgrs00:
158     type: cloudify.openstack.nodes.FloatingIP
159     properties:
160       openstack_config: *open_conf
161     interfaces:
162       cloudify.interfaces.lifecycle:
163         create:
164           inputs:
165             args:
166               floating_network_name: { get_input: public_net }
167   dns_pgrs00:
168     type: ccsdk.nodes.dns.arecord
169     properties:
170       fqdn: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
171       openstack: *open_conf
172     interfaces:
173       cloudify.interfaces.lifecycle:
174         create:
175           inputs:
176             args:
177               ip_addresses:
178                 - { get_attribute: [ floatingip_pgrs00, floating_ip_address ] }
179     relationships:
180       - type: cloudify.relationships.depends_on
181         target: floatingip_pgrs00
182   host_pgrs00:
183     type: cloudify.openstack.nodes.Server
184     properties:
185       install_agent: false
186       image: { get_input: ubuntu1604image_id }
187       flavor: { get_input: flavor_id }
188       management_network_name: { get_input: private_net }
189       openstack_config: *open_conf
190     interfaces:
191       cloudify.interfaces.lifecycle:
192         create:
193           inputs:
194             args:
195               name: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00' ] }
196               userdata:
197                 concat:
198                   - |-
199                     #!/bin/sh
200                     mkdir /root/.sshkey
201                     echo '
202                   - { get_attribute: [ pgaas_cluster, public ] }
203                   - |-
204                     ' >/root/.sshkey/id_rsa.pub
205                     echo '
206                   - { get_attribute: [ pgaas_cluster, base64private ] }
207                   - |-
208                     ' | base64 -d >/root/.sshkey/id_rsa
209                     chmod 700 /root/.sshkey
210                     chmod 600 /root/.sshkey/*
211                     ( umask 077; echo -n postgres | cat - /root/.sshkey/id_rsa | md5sum | awk '{ print $1 }' > /root/.pgrspw )
212                     set -x
213                   - "\n"
214                   - "CLUSTER_NAME='"
215                   - { get_input: pgaas_cluster_name }
216                   - "'\n"
217                   - "LOCATION_PREFIX='"
218                   - { get_input: location_prefix }
219                   - "'\n"
220                   - "LOCATION_DOMAIN='"
221                   - { get_input: location_domain }
222                   - "'\n"
223                   - "MASTER='"
224                   - { get_property: [ dns_pgrs00, fqdn ] }
225                   - "'\n"
226                   - "LOCAL_IP='"
227                   - { get_attribute: [ host_pgrs00, ip ] }
228                   - "'\n"
229                   - "PG_NODES='"
230                   - { get_property: [ dns_pgrs00, fqdn ] }
231                   - '|'
232                   - { get_property: [ dns_pgrs01, fqdn ] }
233                   - "'\n"
234                   - { get_input: vm_init_pgrs }
235     relationships:
236       - type: cloudify.openstack.server_connected_to_port
237         target: fixedip_pgrs00
238       - type: cloudify.openstack.server_connected_to_security_group
239         target: security_group
240       - type: cloudify.openstack.server_connected_to_floating_ip
241         target: floatingip_pgrs00
242       - type: cloudify.openstack.server_connected_to_keypair
243         target: key_pair
244       - type: cloudify.relationships.depends_on
245         target: dns_pgrs00
246       - type: cloudify.relationships.depends_on
247         target: pgaas_cluster
248   fixedip_pgrs01:
249     type: cloudify.openstack.nodes.Port
250     properties:
251       port:
252         extra_dhcp_opts:
253           - opt_name: 'domain-name'
254             opt_value: { get_input: location_domain }
255       openstack_config: *open_conf
256     relationships:
257       - type: cloudify.relationships.contained_in
258         target: private_net
259   floatingip_pgrs01:
260     type: cloudify.openstack.nodes.FloatingIP
261     properties:
262       openstack_config: *open_conf
263     interfaces:
264       cloudify.interfaces.lifecycle:
265         create:
266           inputs:
267             args:
268               floating_network_name: { get_input: public_net }
269   dns_pgrs01:
270     type: ccsdk.nodes.dns.arecord
271     properties:
272       fqdn: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '01.', { get_input: location_domain } ] }
273       openstack: *open_conf
274     interfaces:
275       cloudify.interfaces.lifecycle:
276         create:
277           inputs:
278             args:
279               ip_addresses:
280                 - { get_attribute: [ floatingip_pgrs01, floating_ip_address ] }
281     relationships:
282       - type: cloudify.relationships.depends_on
283         target: floatingip_pgrs01
284   host_pgrs01:
285     type: cloudify.openstack.nodes.Server
286     properties:
287       install_agent: false
288       image: { get_input: ubuntu1604image_id }
289       flavor: { get_input: flavor_id }
290       management_network_name: { get_input: private_net }
291       openstack_config: *open_conf
292     interfaces:
293       cloudify.interfaces.lifecycle:
294         create:
295           inputs:
296             args:
297               name: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '01' ] }
298               userdata:
299                 concat:
300                   - |-
301                     #!/bin/sh
302                     mkdir /root/.sshkey
303                     echo '
304                   - { get_attribute: [ pgaas_cluster, public ] }
305                   - |-
306                     ' >/root/.sshkey/id_rsa.pub
307                     echo '
308                   - { get_attribute: [ pgaas_cluster, base64private ] }
309                   - |-
310                     ' | base64 -d >/root/.sshkey/id_rsa
311                     chmod 700 /root/.sshkey
312                     chmod 600 /root/.sshkey/*
313                     ( umask 077; echo -n postgres | cat - /root/.sshkey/id_rsa | md5sum | awk '{ print $1 }' > /root/.pgrspw )
314                     set -x
315                   - "\n"
316                   - "CLUSTER_NAME='"
317                   - { get_input: pgaas_cluster_name }
318                   - "'\n"
319                   - "LOCATION_PREFIX='"
320                   - { get_input: location_prefix }
321                   - "'\n"
322                   - "LOCATION_DOMAIN='"
323                   - { get_input: location_domain }
324                   - "'\n"
325                   - "MASTER='"
326                   - { get_property: [ dns_pgrs00, fqdn ] }
327                   - "'\n"
328                   - "LOCAL_IP='"
329                   - { get_attribute: [ host_pgrs01, ip ] }
330                   - "'\n"
331                   - "PG_NODES='"
332                   - { get_property: [ dns_pgrs00, fqdn ] }
333                   - '|'
334                   - { get_property: [ dns_pgrs01, fqdn ] }
335                   - "'\n"
336                   - { get_input: vm_init_pgrs }
337     relationships:
338       - type: cloudify.openstack.server_connected_to_port
339         target: fixedip_pgrs01
340       - type: cloudify.openstack.server_connected_to_security_group
341         target: security_group
342       - type: cloudify.openstack.server_connected_to_floating_ip
343         target: floatingip_pgrs01
344       - type: cloudify.openstack.server_connected_to_keypair
345         target: key_pair
346       - type: cloudify.relationships.depends_on
347         target: dns_pgrs01
348       - type: cloudify.relationships.depends_on
349         target: pgaas_cluster
350
351   # cinder connections
352   volume_pgrs00:
353     type: cloudify.openstack.nodes.Volume
354     properties:
355       resource_id: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00' ] }
356       openstack_config: *open_conf
357       use_external_resource: True
358     relationships:
359       - type: cloudify.openstack.volume_attached_to_server
360         target: host_pgrs00
361
362   volume_pgrs01:
363     type: cloudify.openstack.nodes.Volume
364     properties:
365       resource_id: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '01' ] }
366       openstack_config: *open_conf
367       use_external_resource: True
368     relationships:
369       - type: cloudify.openstack.volume_attached_to_server
370         target: host_pgrs01
371
372   # CNAME records
373   dns_pgrs_rw:
374     type: ccsdk.nodes.dns.cnamerecord
375     properties:
376       fqdn: { concat: [ { get_input: location_prefix }, '-', { get_input: pgaas_cluster_name }, '-write.', { get_input: location_domain } ] }
377       openstack: *open_conf
378     interfaces:
379       cloudify.interfaces.lifecycle:
380         create:
381           inputs:
382             args:
383               cname: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
384
385   dns_pgrs_ro:
386     type: ccsdk.nodes.dns.cnamerecord
387     properties:
388       fqdn: { concat: [ { get_input: location_prefix }, '-', { get_input: pgaas_cluster_name }, '.', { get_input: location_domain } ] }
389       openstack: *open_conf
390     interfaces:
391       cloudify.interfaces.lifecycle:
392         create:
393           inputs:
394             args:
395               cname: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
396
397   # tie to pgaas_plugin database
398   pgaas_cluster:
399     type: dcae.nodes.pgaas.cluster
400     properties:
401       writerfqdn: { get_property: [ dns_pgrs_rw, fqdn ] }
402       use_existing: true
403     relationships:
404       - type: cloudify.relationships.depends_on
405         target: dns_pgrs_rw
406       - type: cloudify.relationships.depends_on
407         target: dns_pgrs_ro
408
409 outputs:
410   public_ip00:
411     value: { get_attribute: [host_pgrs00, ip] }
412   public_ip01:
413     value: { get_attribute: [host_pgrs01, ip] }
414   writerfqdn:
415     value: { get_property: [ dns_pgrs_rw, fqdn ] }
416   readerfqdn:
417     value: { get_property: [ dns_pgrs_ro, fqdn ] }
418   dns_pgrs00:
419     value: { get_property: [ dns_pgrs00, fqdn ] }
420   dns_pgrs01:
421     value: { get_property: [ dns_pgrs01, fqdn ] }
422   blueprint_version:
423     value: { get_input: blueprint_version }