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