1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
# -*- indent-tabs-mode: nil -*- # vi: set expandtab:
#
# ============LICENSE_START====================================================
# org.onap.dcae
# =============================================================================
# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
# =============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END======================================================
tosca_definitions_version: cloudify_dsl_1_3
description: |-
This blueprint is used to install and to uninstall a single-VM central postgres as a platform service.
This blueprint depends upon the deployment of the pgaas_plugin and Consul.
imports:
- http://www.getcloudify.org/spec/cloudify/3.4/types.yaml
- http://www.getcloudify.org/spec/openstack-plugin/1.4/plugin.yaml
- http://www.getcloudify.org/spec/fabric-plugin/1.4.1/plugin.yaml
- "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/dnsdesig/dns_types.yaml"
- "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/sshkeyshare/sshkey_types.yaml"
- "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/relationshipplugin/1.0.0/relationshipplugin_types.yaml"
- "{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/pgaas/1.1.0/pgaas_types.yaml"
inputs:
blueprint_version:
type: string
default: '2018-04-27T00:31:38+0000'
# pgaas-specific info
pgaas_cluster_name:
type: string
default: pgvm
{{ ONAPTEMPLATE_STANDARD_INPUTS_TYPES }}
vm_init_pgrs:
type: string
default: |
#!/bin/sh
echo All output will be found in /tmp/ins.out and /tmp/ins.err
exec > /tmp/ins.out 2> /tmp/ins.err
set -x
if [ "$(dnsdomainname 2>/dev/null)" = "" ]
then
echo WARNING WARNING WARNING
echo The DNS DHCP settings did not work properly.
for i in $(seq 20)
do
echo Sleeping...
sleep 10
if [ "$(dnsdomainname 2>/dev/null)" != "" ]
then break
fi
echo The DNS DHCP settings still did not work properly.
done
if [ "$(dnsdomainname 2>/dev/null)" = "" ]
then
echo Exiting
exit 1
fi
fi
CONFDIR=/var/config/DCAE/chef/
mkdir -p $CONFDIR
CONF=$CONFDIR/pgaas-postgres.conf
cat <<EOF > $CONF
master: ${MASTER%%.*}
secondmaster: notused
DRTR_NODE_KSTOREFILE: /opt/app/dcae-certificate/keystore.jks
DRTR_NODE_KSTOREPASS: "No Certificate"
DRTR_NODE_PVTKEYPASS: "No Certificate"
PG_NODES: $PG_NODES
PG_JAVA_HOME : /opt/app/java/jdk/jdk170
PG_CLUSTER: central
EOF
apt-get update
# invoking apt-get separately allows a failure to be ignored
for i in openjdk-7-jdk openjdk-8-jdk python-pip python3-pip curl gawk; do apt-get install -y $i;done
pip install pyyaml
# prevent servers from starting
echo "exit 101" > /usr/sbin/policy-rc.d; chmod a+x /usr/sbin/policy-rc.d
# invoking apt-get separately allows a failure to be ignored
for i in postgresql libpq5 repmgr python-psycopg2 python3-psycopg2 libgetopt-java; do apt-get install -y $i; done
# allow servers to autostart again
rm -f /usr/sbin/policy-rc.d
( umask 077; sed 's/^/*:*:*:postgres:/' < /root/.pgrspw > ~postgres/.pgpass; chown postgres:postgres ~postgres/.pgpass )
if [ ! -f $CONF ]
then echo "$CONF does not exist" 1>&2; exit 1
fi
echo Look in /tmp/pgaas.out for output from installing PGaaS
NEXUS={{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_storage_pgaas_debs_releases }}/debs
for pkg in cdf.deb-1.0.0 pgaas.deb-1.0.0
do
OUT=/tmp/$pkg
curl -s -k -f -o $OUT $NEXUS/$pkg
dpkg --install $OUT
done
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}\""
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}"
echo ALL DONE
node_templates:
key_pair:
type: cloudify.openstack.nodes.KeyPair
properties:
private_key_path: { get_input: key_filename }
use_external_resource: True
resource_id: { get_input: keypair }
openstack_config: &open_conf
get_input: openstack
private_net:
type: cloudify.openstack.nodes.Network
properties:
use_external_resource: True
resource_id: { get_input: private_net }
openstack_config: *open_conf
security_group:
type: cloudify.openstack.nodes.SecurityGroup
properties:
use_external_resource: True
resource_id: { get_input: security_group }
openstack_config: *open_conf
sharedsshkey_pgrs:
type: ccsdk.nodes.ssh.keypair
fixedip_pgrs00:
type: cloudify.openstack.nodes.Port
properties:
port:
extra_dhcp_opts:
- opt_name: 'domain-name'
opt_value: { get_input: location_domain }
openstack_config: *open_conf
relationships:
- type: cloudify.relationships.contained_in
target: private_net
floatingip_pgrs00:
type: cloudify.openstack.nodes.FloatingIP
properties:
openstack_config: *open_conf
interfaces:
cloudify.interfaces.lifecycle:
create:
inputs:
args:
floating_network_name: { get_input: public_net }
dns_pgrs00:
type: ccsdk.nodes.dns.arecord
properties:
fqdn: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
openstack: *open_conf
interfaces:
cloudify.interfaces.lifecycle:
create:
inputs:
args:
ip_addresses:
- { get_attribute: [ floatingip_pgrs00, floating_ip_address ] }
relationships:
- type: cloudify.relationships.depends_on
target: floatingip_pgrs00
host_pgrs00:
type: cloudify.openstack.nodes.Server
properties:
install_agent: false
image: { get_input: ubuntu1604image_id }
flavor: { get_input: flavor_id }
management_network_name: { get_input: private_net }
openstack_config: *open_conf
interfaces:
cloudify.interfaces.lifecycle:
create:
inputs:
args:
name: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00' ] }
userdata:
concat:
- |-
#!/bin/sh
mkdir /root/.sshkey
echo '
- { get_attribute: [ sharedsshkey_pgrs, public ] }
- |-
' >/root/.sshkey/id_rsa.pub
echo '
- { get_attribute: [ sharedsshkey_pgrs, base64private ] }
- |-
' | base64 -d >/root/.sshkey/id_rsa
chmod 700 /root/.sshkey
chmod 600 /root/.sshkey/*
( umask 077; echo -n postgres | cat - /root/.sshkey/id_rsa | md5sum | awk '{ print $1 }' > /root/.pgrspw )
set -x
- "\n"
- "CLUSTER_NAME='"
- { get_input: pgaas_cluster_name }
- "'\n"
- "LOCATION_PREFIX='"
- { get_input: location_prefix }
- "'\n"
- "LOCATION_DOMAIN='"
- { get_input: location_domain }
- "'\n"
- "MASTER='"
- { get_property: [ dns_pgrs00, fqdn ] }
- "'\n"
- "LOCAL_IP='"
- { get_attribute: [ floatingip_pgrs00, floating_ip_address ] }
- "'\n"
- "PG_NODES='"
- { get_property: [ dns_pgrs00, fqdn ] }
- "'\n"
- { get_input: vm_init_pgrs }
relationships:
- type: cloudify.openstack.server_connected_to_port
target: fixedip_pgrs00
- type: cloudify.openstack.server_connected_to_security_group
target: security_group
- type: cloudify.openstack.server_connected_to_floating_ip
target: floatingip_pgrs00
- type: cloudify.openstack.server_connected_to_keypair
target: key_pair
- type: cloudify.relationships.depends_on
target: dns_pgrs00
- type: cloudify.relationships.depends_on
target: sharedsshkey_pgrs
# CNAME records
dns_pgrs_rw:
type: ccsdk.nodes.dns.cnamerecord
properties:
fqdn: { concat: [ { get_input: location_prefix }, '-', { get_input: pgaas_cluster_name }, '-write.', { get_input: location_domain } ] }
openstack: *open_conf
interfaces:
cloudify.interfaces.lifecycle:
create:
inputs:
args:
cname: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
dns_pgrs_ro:
type: ccsdk.nodes.dns.cnamerecord
properties:
fqdn: { concat: [ { get_input: location_prefix }, '-', { get_input: pgaas_cluster_name }, '.', { get_input: location_domain } ] }
openstack: *open_conf
interfaces:
cloudify.interfaces.lifecycle:
create:
inputs:
args:
cname: { concat: [ { get_input: location_prefix }, { get_input: pgaas_cluster_name }, '00.', { get_input: location_domain } ] }
# tie to pgaas_plugin database
pgaas_cluster:
type: dcae.nodes.pgaas.cluster
properties:
writerfqdn: { get_property: [ dns_pgrs_rw, fqdn ] }
readerfqdn: { get_property: [ dns_pgrs_ro, fqdn ] }
relationships:
- type: dcae.relationships.pgaas_cluster_uses_sshkeypair
target: sharedsshkey_pgrs
- type: cloudify.relationships.depends_on
target: dns_pgrs_rw
- type: cloudify.relationships.depends_on
target: dns_pgrs_ro
outputs:
public_ip00:
value: { get_attribute: [host_pgrs00, ip] }
writerfqdn:
value: { get_property: [ dns_pgrs_rw, fqdn ] }
readerfqdn:
value: { get_property: [ dns_pgrs_ro, fqdn ] }
dns_pgrs00:
value: { get_property: [ dns_pgrs00, fqdn ] }
blueprint_version:
value: { get_input: blueprint_version }
|