blob: 4a7e16a9f8c433a410cf0ee6b0fc757b9df999d8 [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 Hansen749bc2d2017-10-03 02:51:42 +000023description: |-
Tony Hansen9be0c162017-10-31 16:01:10 +000024 This blueprint is used to install and to uninstall a two-VM central postgres as a platform service.
Tony Hansen749bc2d2017-10-03 02:51:42 +000025 This blueprint depends upon the deployment of the pgaas_plugin and Consul.
26
Tony Hansena795b592017-09-29 01:15:29 +000027imports:
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 Hansen1d013672017-10-06 21:01:05 +000032 - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/dnsdesig/dns_types.yaml"
Tony Hansen6b903fe2017-09-29 17:29:52 +000033 - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/sshkeyshare/sshkey_types.yaml"
Hansen, Tony (th1395)68765fc2018-04-27 00:37:31 +000034 - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/relationshipplugin/1.0.0/relationshipplugin_types.yaml"
Hansen, Tony (th1395)b936fb42018-03-29 14:28:59 +000035 - "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/pgaas/1.1.0/pgaas_types.yaml"
Tony Hansena795b592017-09-29 01:15:29 +000036
37inputs:
Tony Hansena795b592017-09-29 01:15:29 +000038 blueprint_version:
39 type: string
Hansen, Tony (th1395)68765fc2018-04-27 00:37:31 +000040 default: '2018-04-27T00:31:38+0000'
Tony Hansena795b592017-09-29 01:15:29 +000041
42 # pgaas-specific info
43 pgaas_cluster_name:
44 type: string
45 default: pstg
46
Tony Hansenf5e39dd2017-10-11 18:08:57 +000047{{ ONAPTEMPLATE_STANDARD_INPUTS_TYPES }}
48
Tony Hansena795b592017-09-29 01:15:29 +000049 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 Hansen73e66b92017-11-01 15:12:11 +000060 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 Hansena795b592017-09-29 01:15:29 +000074 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 Hansenffa416d2017-10-24 19:35:57 +0000113 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 Hansena795b592017-09-29 01:15:29 +0000115 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 Hansena795b592017-09-29 01:15:29 +0000122 *00 ) WRITE=-write ;;
123 *01 ) WRITE= ;;
124 esac
Tony Hansenbfff05b2017-11-01 21:10:10 +0000125 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 +0000126
127 echo ALL DONE
128
129node_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 Hansenf5e39dd2017-10-11 18:08:57 +0000152 type: ccsdk.nodes.ssh.keypair
Tony Hansena795b592017-09-29 01:15:29 +0000153
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 Hansenf5e39dd2017-10-11 18:08:57 +0000176 type: ccsdk.nodes.dns.arecord
Tony Hansena795b592017-09-29 01:15:29 +0000177 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 Hansenbfff05b2017-11-01 21:10:10 +0000235 - { get_attribute: [ floatingip_pgrs00, floating_ip_address ] }
Tony Hansena795b592017-09-29 01:15:29 +0000236 - "'\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 Hansenf5e39dd2017-10-11 18:08:57 +0000278 type: ccsdk.nodes.dns.arecord
Tony Hansena795b592017-09-29 01:15:29 +0000279 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 Hansenbfff05b2017-11-01 21:10:10 +0000337 - { get_attribute: [ floatingip_pgrs01, floating_ip_address ] }
Tony Hansena795b592017-09-29 01:15:29 +0000338 - "'\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 Hansenf5e39dd2017-10-11 18:08:57 +0000361 type: ccsdk.nodes.dns.cnamerecord
Tony Hansena795b592017-09-29 01:15:29 +0000362 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 Hansenf5e39dd2017-10-11 18:08:57 +0000373 type: ccsdk.nodes.dns.cnamerecord
Tony Hansena795b592017-09-29 01:15:29 +0000374 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
398outputs:
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 Hansenf5e39dd2017-10-11 18:08:57 +0000411 blueprint_version:
Tony Hansena795b592017-09-29 01:15:29 +0000412 value: { get_input: blueprint_version }