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