blob: be2d044bb630b1d668f00ff9b8c3cfd6de8af2aa [file] [log] [blame]
Tony Hansen9be0c162017-10-31 16:01:10 +00001# -*- 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
21tosca_definitions_version: cloudify_dsl_1_3
22
23description: |-
24 This blueprint is used to install and to uninstall a single-VM central postgres as a platform service.
25 This blueprint depends upon the deployment of the pgaas_plugin and Consul.
26
27imports:
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"
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 Hansen9be0c162017-10-31 16:01:10 +000036
37inputs:
38 blueprint_version:
39 type: string
Hansen, Tony (th1395)68765fc2018-04-27 00:37:31 +000040 default: '2018-04-27T00:31:38+0000'
Tony Hansen9be0c162017-10-31 16:01:10 +000041
42 # pgaas-specific info
43 pgaas_cluster_name:
44 type: string
45 default: pgvm
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.
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 Hansen9be0c162017-10-31 16:01:10 +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
113 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
115 do
116 OUT=/tmp/$pkg
117 curl -s -k -f -o $OUT $NEXUS/$pkg
118 dpkg --install $OUT
119 done
120
Tony Hansenbfff05b2017-11-01 21:10:10 +0000121 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}\""
122 curl -v -X PUT -H "Content-Type: application/json" "http://${LOCATION_PREFIX}cnsl00.${LOCATION_DOMAIN}:8500/v1/agent/service/register" -d "{\"name\" : \"${CLUSTER_NAME}\", \"Address\" : \"${LOCAL_IP}\", \"Port\" : 5432}"
Tony Hansen9be0c162017-10-31 16:01:10 +0000123
124 echo ALL DONE
125
126node_templates:
127 key_pair:
128 type: cloudify.openstack.nodes.KeyPair
129 properties:
130 private_key_path: { get_input: key_filename }
131 use_external_resource: True
132 resource_id: { get_input: keypair }
133 openstack_config: &open_conf
134 get_input: openstack
135 private_net:
136 type: cloudify.openstack.nodes.Network
137 properties:
138 use_external_resource: True
139 resource_id: { get_input: private_net }
140 openstack_config: *open_conf
141 security_group:
142 type: cloudify.openstack.nodes.SecurityGroup
143 properties:
144 use_external_resource: True
145 resource_id: { get_input: security_group }
146 openstack_config: *open_conf
147
148 sharedsshkey_pgrs:
149 type: ccsdk.nodes.ssh.keypair
150
151 fixedip_pgrs00:
152 type: cloudify.openstack.nodes.Port
153 properties:
154 port:
155 extra_dhcp_opts:
156 - opt_name: 'domain-name'
157 opt_value: { get_input: location_domain }
158 openstack_config: *open_conf
159 relationships:
160 - type: cloudify.relationships.contained_in
161 target: private_net
162 floatingip_pgrs00:
163 type: cloudify.openstack.nodes.FloatingIP
164 properties:
165 openstack_config: *open_conf
166 interfaces:
167 cloudify.interfaces.lifecycle:
168 create:
169 inputs:
170 args:
171 floating_network_name: { get_input: public_net }
172 dns_pgrs00:
173 type: ccsdk.nodes.dns.arecord
174 properties:
175 fqdn: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
176 openstack: *open_conf
177 interfaces:
178 cloudify.interfaces.lifecycle:
179 create:
180 inputs:
181 args:
182 ip_addresses:
183 - { get_attribute: [ floatingip_pgrs00, floating_ip_address ] }
184 relationships:
185 - type: cloudify.relationships.depends_on
186 target: floatingip_pgrs00
187 host_pgrs00:
188 type: cloudify.openstack.nodes.Server
189 properties:
190 install_agent: false
191 image: { get_input: ubuntu1604image_id }
192 flavor: { get_input: flavor_id }
193 management_network_name: { get_input: private_net }
194 openstack_config: *open_conf
195 interfaces:
196 cloudify.interfaces.lifecycle:
197 create:
198 inputs:
199 args:
200 name: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00' ] }
201 userdata:
202 concat:
203 - |-
204 #!/bin/sh
205 mkdir /root/.sshkey
206 echo '
207 - { get_attribute: [ sharedsshkey_pgrs, public ] }
208 - |-
209 ' >/root/.sshkey/id_rsa.pub
210 echo '
211 - { get_attribute: [ sharedsshkey_pgrs, base64private ] }
212 - |-
213 ' | base64 -d >/root/.sshkey/id_rsa
214 chmod 700 /root/.sshkey
215 chmod 600 /root/.sshkey/*
216 ( umask 077; echo -n postgres | cat - /root/.sshkey/id_rsa | md5sum | awk '{ print $1 }' > /root/.pgrspw )
217 set -x
218 - "\n"
219 - "CLUSTER_NAME='"
220 - { get_input: pgaas_cluster_name }
221 - "'\n"
222 - "LOCATION_PREFIX='"
223 - { get_input: location_prefix }
224 - "'\n"
225 - "LOCATION_DOMAIN='"
226 - { get_input: location_domain }
227 - "'\n"
228 - "MASTER='"
229 - { get_property: [ dns_pgrs00, fqdn ] }
230 - "'\n"
231 - "LOCAL_IP='"
Tony Hansenbfff05b2017-11-01 21:10:10 +0000232 - { get_attribute: [ floatingip_pgrs00, floating_ip_address ] }
Tony Hansen9be0c162017-10-31 16:01:10 +0000233 - "'\n"
234 - "PG_NODES='"
235 - { get_property: [ dns_pgrs00, fqdn ] }
236 - "'\n"
237 - { get_input: vm_init_pgrs }
238 relationships:
239 - type: cloudify.openstack.server_connected_to_port
240 target: fixedip_pgrs00
241 - type: cloudify.openstack.server_connected_to_security_group
242 target: security_group
243 - type: cloudify.openstack.server_connected_to_floating_ip
244 target: floatingip_pgrs00
245 - type: cloudify.openstack.server_connected_to_keypair
246 target: key_pair
247 - type: cloudify.relationships.depends_on
248 target: dns_pgrs00
249 - type: cloudify.relationships.depends_on
250 target: sharedsshkey_pgrs
251 # CNAME records
252 dns_pgrs_rw:
253 type: ccsdk.nodes.dns.cnamerecord
254 properties:
255 fqdn: { concat: [ { get_input: location_prefix }, '-', { get_input: pgaas_cluster_name }, '-write.', { get_input: location_domain } ] }
256 openstack: *open_conf
257 interfaces:
258 cloudify.interfaces.lifecycle:
259 create:
260 inputs:
261 args:
262 cname: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
263
264 dns_pgrs_ro:
265 type: ccsdk.nodes.dns.cnamerecord
266 properties:
267 fqdn: { concat: [ { get_input: location_prefix }, '-', { get_input: pgaas_cluster_name }, '.', { get_input: location_domain } ] }
268 openstack: *open_conf
269 interfaces:
270 cloudify.interfaces.lifecycle:
271 create:
272 inputs:
273 args:
274 cname: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
275
276 # tie to pgaas_plugin database
277 pgaas_cluster:
278 type: dcae.nodes.pgaas.cluster
279 properties:
280 writerfqdn: { get_property: [ dns_pgrs_rw, fqdn ] }
281 readerfqdn: { get_property: [ dns_pgrs_ro, fqdn ] }
282 relationships:
283 - type: dcae.relationships.pgaas_cluster_uses_sshkeypair
284 target: sharedsshkey_pgrs
285 - type: cloudify.relationships.depends_on
286 target: dns_pgrs_rw
287 - type: cloudify.relationships.depends_on
288 target: dns_pgrs_ro
289
290outputs:
291 public_ip00:
292 value: { get_attribute: [host_pgrs00, ip] }
293 writerfqdn:
294 value: { get_property: [ dns_pgrs_rw, fqdn ] }
295 readerfqdn:
296 value: { get_property: [ dns_pgrs_ro, fqdn ] }
297 dns_pgrs00:
298 value: { get_property: [ dns_pgrs00, fqdn ] }
299 blueprint_version:
300 value: { get_input: blueprint_version }