blob: d7b0cd00fd046bc7e58497f189e9256ba0da4b79 [file] [log] [blame]
Tony Hansena795b592017-09-29 01:15:29 +00001# -*- indent-tabs-mode: nil -*- # vi: set expandtab:
Tony Hansen749bc2d2017-10-03 02:51:42 +00002#
Tony Hansena795b592017-09-29 01:15:29 +00003# ============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
21tosca_definitions_version: cloudify_dsl_1_3
22
Tony Hansen6b903fe2017-09-29 17:29:52 +000023description: |-
Tony Hansena795b592017-09-29 01:15:29 +000024 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
35imports:
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
Tony Hansen1d013672017-10-06 21:01:05 +000040 - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/dnsdesig/dns_types.yaml"
Hansen, Tony (th1395)68765fc2018-04-27 00:37:31 +000041 - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/relationshipplugin/1.0.0/relationshipplugin_types.yaml"
Hansen, Tony (th1395)b936fb42018-03-29 14:28:59 +000042 - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/pgaas/1.1.0/pgaas_types.yaml"
Tony Hansena795b592017-09-29 01:15:29 +000043
44inputs:
Tony Hansena795b592017-09-29 01:15:29 +000045 blueprint_version:
46 type: string
Hansen, Tony (th1395)68765fc2018-04-27 00:37:31 +000047 default: '2018-04-27T00:31:38+0000'
Tony Hansena795b592017-09-29 01:15:29 +000048
49 # pgaas-specific info
50 pgaas_cluster_name:
51 type: string
52 default: pgcl
53
Tony Hansenf5e39dd2017-10-11 18:08:57 +000054{{ ONAPTEMPLATE_STANDARD_INPUTS_TYPES }}
55
Tony Hansena795b592017-09-29 01:15:29 +000056 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.
Tony Hansen73e66b92017-11-01 15:12:11 +000067 for i in $(seq 20)
68 do
69 echo Sleeping...
70 sleep 10
71 if [ "$(dnsdomainname 2>/dev/null)" != "" ]
72 then break
73 fi
74 echo The DNS DHCP settings still did not work properly.
75 done
76 if [ "$(dnsdomainname 2>/dev/null)" = "" ]
77 then
78 echo Exiting
79 exit 1
80 fi
Tony Hansena795b592017-09-29 01:15:29 +000081 fi
82
83 CONFDIR=/var/config/DCAE/chef/
84 mkdir -p $CONFDIR
85
86 CONF=$CONFDIR/pgaas-postgres.conf
87 cat <<EOF > $CONF
88 master: ${MASTER%%.*}
89 secondmaster: notused
90 DRTR_NODE_KSTOREFILE: /opt/app/dcae-certificate/keystore.jks
91 DRTR_NODE_KSTOREPASS: "No Certificate"
92 DRTR_NODE_PVTKEYPASS: "No Certificate"
93 PG_NODES: $PG_NODES
94 PG_JAVA_HOME : /opt/app/java/jdk/jdk170
95 PG_CLUSTER: central
96 EOF
97
98 apt-get update
99
100 # invoking apt-get separately allows a failure to be ignored
101 for i in openjdk-7-jdk openjdk-8-jdk python-pip python3-pip curl gawk; do apt-get install -y $i;done
102 pip install pyyaml
103
104 # prevent servers from starting
105 echo "exit 101" > /usr/sbin/policy-rc.d; chmod a+x /usr/sbin/policy-rc.d
106
107 # invoking apt-get separately allows a failure to be ignored
108 for i in postgresql libpq5 repmgr python-psycopg2 python3-psycopg2 libgetopt-java; do apt-get install -y $i; done
109
110 # allow servers to autostart again
111 rm -f /usr/sbin/policy-rc.d
112
113 ( umask 077; sed 's/^/*:*:*:postgres:/' < /root/.pgrspw > ~postgres/.pgpass; chown postgres:postgres ~postgres/.pgpass )
114
115 if [ ! -f $CONF ]
116 then echo "$CONF does not exist" 1>&2; exit 1
117 fi
118
119 echo Look in /tmp/pgaas.out for output from installing PGaaS
Tony Hansenffa416d2017-10-24 19:35:57 +0000120 NEXUS={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_storage_pgaas_debs_releases }}/debs
121 for pkg in cdf.deb-1.0.0 pgaas.deb-1.0.0
Tony Hansena795b592017-09-29 01:15:29 +0000122 do
123 OUT=/tmp/$pkg
124 curl -s -k -f -o $OUT $NEXUS/$pkg
125 dpkg --install $OUT
126 done
127
128 case $(hostname) in
Tony Hansena795b592017-09-29 01:15:29 +0000129 *00 ) WRITE=-write ;;
130 *01 ) WRITE= ;;
131 esac
Tony Hansenbfff05b2017-11-01 21:10:10 +0000132 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 Hansena795b592017-09-29 01:15:29 +0000133
134 echo ALL DONE
135
136node_templates:
137 key_pair:
138 type: cloudify.openstack.nodes.KeyPair
139 properties:
140 private_key_path: { get_input: key_filename }
141 use_external_resource: True
142 resource_id: { get_input: keypair }
143 openstack_config: &open_conf
144 get_input: openstack
145 private_net:
146 type: cloudify.openstack.nodes.Network
147 properties:
148 use_external_resource: True
149 resource_id: { get_input: private_net }
150 openstack_config: *open_conf
151 security_group:
152 type: cloudify.openstack.nodes.SecurityGroup
153 properties:
154 use_external_resource: True
155 resource_id: { get_input: security_group }
156 openstack_config: *open_conf
157
158 fixedip_pgrs00:
159 type: cloudify.openstack.nodes.Port
160 properties:
161 port:
162 extra_dhcp_opts:
163 - opt_name: 'domain-name'
164 opt_value: { get_input: location_domain }
165 openstack_config: *open_conf
166 relationships:
167 - type: cloudify.relationships.contained_in
168 target: private_net
169 floatingip_pgrs00:
170 type: cloudify.openstack.nodes.FloatingIP
171 properties:
172 openstack_config: *open_conf
173 interfaces:
174 cloudify.interfaces.lifecycle:
175 create:
176 inputs:
177 args:
178 floating_network_name: { get_input: public_net }
179 dns_pgrs00:
Tony Hansenf5e39dd2017-10-11 18:08:57 +0000180 type: ccsdk.nodes.dns.arecord
Tony Hansena795b592017-09-29 01:15:29 +0000181 properties:
182 fqdn: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
183 openstack: *open_conf
184 interfaces:
185 cloudify.interfaces.lifecycle:
186 create:
187 inputs:
188 args:
189 ip_addresses:
190 - { get_attribute: [ floatingip_pgrs00, floating_ip_address ] }
191 relationships:
192 - type: cloudify.relationships.depends_on
193 target: floatingip_pgrs00
194 host_pgrs00:
195 type: cloudify.openstack.nodes.Server
196 properties:
197 install_agent: false
198 image: { get_input: ubuntu1604image_id }
199 flavor: { get_input: flavor_id }
200 management_network_name: { get_input: private_net }
201 openstack_config: *open_conf
202 interfaces:
203 cloudify.interfaces.lifecycle:
204 create:
205 inputs:
206 args:
207 name: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00' ] }
208 userdata:
209 concat:
210 - |-
211 #!/bin/sh
212 mkdir /root/.sshkey
213 echo '
214 - { get_attribute: [ pgaas_cluster, public ] }
215 - |-
216 ' >/root/.sshkey/id_rsa.pub
217 echo '
218 - { get_attribute: [ pgaas_cluster, base64private ] }
219 - |-
220 ' | base64 -d >/root/.sshkey/id_rsa
221 chmod 700 /root/.sshkey
222 chmod 600 /root/.sshkey/*
223 ( umask 077; echo -n postgres | cat - /root/.sshkey/id_rsa | md5sum | awk '{ print $1 }' > /root/.pgrspw )
224 set -x
225 - "\n"
226 - "CLUSTER_NAME='"
227 - { get_input: pgaas_cluster_name }
228 - "'\n"
229 - "LOCATION_PREFIX='"
230 - { get_input: location_prefix }
231 - "'\n"
232 - "LOCATION_DOMAIN='"
233 - { get_input: location_domain }
234 - "'\n"
235 - "MASTER='"
236 - { get_property: [ dns_pgrs00, fqdn ] }
237 - "'\n"
238 - "LOCAL_IP='"
Tony Hansenbfff05b2017-11-01 21:10:10 +0000239 - { get_attribute: [ floatingip_pgrs00, floating_ip_address ] }
Tony Hansena795b592017-09-29 01:15:29 +0000240 - "'\n"
241 - "PG_NODES='"
242 - { get_property: [ dns_pgrs00, fqdn ] }
243 - '|'
244 - { get_property: [ dns_pgrs01, fqdn ] }
245 - "'\n"
246 - { get_input: vm_init_pgrs }
247 relationships:
248 - type: cloudify.openstack.server_connected_to_port
249 target: fixedip_pgrs00
250 - type: cloudify.openstack.server_connected_to_security_group
251 target: security_group
252 - type: cloudify.openstack.server_connected_to_floating_ip
253 target: floatingip_pgrs00
254 - type: cloudify.openstack.server_connected_to_keypair
255 target: key_pair
256 - type: cloudify.relationships.depends_on
257 target: dns_pgrs00
258 - type: cloudify.relationships.depends_on
259 target: pgaas_cluster
260 fixedip_pgrs01:
261 type: cloudify.openstack.nodes.Port
262 properties:
263 port:
264 extra_dhcp_opts:
265 - opt_name: 'domain-name'
266 opt_value: { get_input: location_domain }
267 openstack_config: *open_conf
268 relationships:
269 - type: cloudify.relationships.contained_in
270 target: private_net
271 floatingip_pgrs01:
272 type: cloudify.openstack.nodes.FloatingIP
273 properties:
274 openstack_config: *open_conf
275 interfaces:
276 cloudify.interfaces.lifecycle:
277 create:
278 inputs:
279 args:
280 floating_network_name: { get_input: public_net }
281 dns_pgrs01:
Tony Hansenf5e39dd2017-10-11 18:08:57 +0000282 type: ccsdk.nodes.dns.arecord
Tony Hansena795b592017-09-29 01:15:29 +0000283 properties:
284 fqdn: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '01.', { get_input: location_domain } ] }
285 openstack: *open_conf
286 interfaces:
287 cloudify.interfaces.lifecycle:
288 create:
289 inputs:
290 args:
291 ip_addresses:
292 - { get_attribute: [ floatingip_pgrs01, floating_ip_address ] }
293 relationships:
294 - type: cloudify.relationships.depends_on
295 target: floatingip_pgrs01
296 host_pgrs01:
297 type: cloudify.openstack.nodes.Server
298 properties:
299 install_agent: false
300 image: { get_input: ubuntu1604image_id }
301 flavor: { get_input: flavor_id }
302 management_network_name: { get_input: private_net }
303 openstack_config: *open_conf
304 interfaces:
305 cloudify.interfaces.lifecycle:
306 create:
307 inputs:
308 args:
309 name: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '01' ] }
310 userdata:
311 concat:
312 - |-
313 #!/bin/sh
314 mkdir /root/.sshkey
315 echo '
316 - { get_attribute: [ pgaas_cluster, public ] }
317 - |-
318 ' >/root/.sshkey/id_rsa.pub
319 echo '
320 - { get_attribute: [ pgaas_cluster, base64private ] }
321 - |-
322 ' | base64 -d >/root/.sshkey/id_rsa
323 chmod 700 /root/.sshkey
324 chmod 600 /root/.sshkey/*
325 ( umask 077; echo -n postgres | cat - /root/.sshkey/id_rsa | md5sum | awk '{ print $1 }' > /root/.pgrspw )
326 set -x
327 - "\n"
328 - "CLUSTER_NAME='"
329 - { get_input: pgaas_cluster_name }
330 - "'\n"
331 - "LOCATION_PREFIX='"
332 - { get_input: location_prefix }
333 - "'\n"
334 - "LOCATION_DOMAIN='"
335 - { get_input: location_domain }
336 - "'\n"
337 - "MASTER='"
338 - { get_property: [ dns_pgrs00, fqdn ] }
339 - "'\n"
340 - "LOCAL_IP='"
Tony Hansenbfff05b2017-11-01 21:10:10 +0000341 - { get_attribute: [ floatingip_pgrs01, floating_ip_address ] }
Tony Hansena795b592017-09-29 01:15:29 +0000342 - "'\n"
343 - "PG_NODES='"
344 - { get_property: [ dns_pgrs00, fqdn ] }
345 - '|'
346 - { get_property: [ dns_pgrs01, fqdn ] }
347 - "'\n"
348 - { get_input: vm_init_pgrs }
349 relationships:
350 - type: cloudify.openstack.server_connected_to_port
351 target: fixedip_pgrs01
352 - type: cloudify.openstack.server_connected_to_security_group
353 target: security_group
354 - type: cloudify.openstack.server_connected_to_floating_ip
355 target: floatingip_pgrs01
356 - type: cloudify.openstack.server_connected_to_keypair
357 target: key_pair
358 - type: cloudify.relationships.depends_on
359 target: dns_pgrs01
360 - type: cloudify.relationships.depends_on
361 target: pgaas_cluster
362
363 # cinder connections
364 volume_pgrs00:
365 type: cloudify.openstack.nodes.Volume
366 properties:
367 resource_id: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00' ] }
368 openstack_config: *open_conf
369 use_external_resource: True
370 relationships:
371 - type: cloudify.openstack.volume_attached_to_server
372 target: host_pgrs00
373
374 volume_pgrs01:
375 type: cloudify.openstack.nodes.Volume
376 properties:
377 resource_id: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '01' ] }
378 openstack_config: *open_conf
379 use_external_resource: True
380 relationships:
381 - type: cloudify.openstack.volume_attached_to_server
382 target: host_pgrs01
383
384 # CNAME records
385 dns_pgrs_rw:
Tony Hansenf5e39dd2017-10-11 18:08:57 +0000386 type: ccsdk.nodes.dns.cnamerecord
Tony Hansena795b592017-09-29 01:15:29 +0000387 properties:
388 fqdn: { concat: [ { get_input: location_prefix }, '-', { get_input: pgaas_cluster_name }, '-write.', { 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 dns_pgrs_ro:
Tony Hansenf5e39dd2017-10-11 18:08:57 +0000398 type: ccsdk.nodes.dns.cnamerecord
Tony Hansena795b592017-09-29 01:15:29 +0000399 properties:
400 fqdn: { concat: [ { get_input: location_prefix }, '-', { get_input: pgaas_cluster_name }, '.', { get_input: location_domain } ] }
401 openstack: *open_conf
402 interfaces:
403 cloudify.interfaces.lifecycle:
404 create:
405 inputs:
406 args:
407 cname: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
408
409 # tie to pgaas_plugin database
410 pgaas_cluster:
411 type: dcae.nodes.pgaas.cluster
412 properties:
413 writerfqdn: { get_property: [ dns_pgrs_rw, fqdn ] }
414 use_existing: true
415 relationships:
416 - type: cloudify.relationships.depends_on
417 target: dns_pgrs_rw
418 - type: cloudify.relationships.depends_on
419 target: dns_pgrs_ro
420
421outputs:
422 public_ip00:
423 value: { get_attribute: [host_pgrs00, ip] }
424 public_ip01:
425 value: { get_attribute: [host_pgrs01, ip] }
426 writerfqdn:
427 value: { get_property: [ dns_pgrs_rw, fqdn ] }
428 readerfqdn:
429 value: { get_property: [ dns_pgrs_ro, fqdn ] }
430 dns_pgrs00:
431 value: { get_property: [ dns_pgrs00, fqdn ] }
432 dns_pgrs01:
433 value: { get_property: [ dns_pgrs01, fqdn ] }
Tony Hansenf5e39dd2017-10-11 18:08:57 +0000434 blueprint_version:
Tony Hansena795b592017-09-29 01:15:29 +0000435 value: { get_input: blueprint_version }