Skip to content

Commit 71dfd61

Browse files
lnguyenjhunt
authored andcommitted
added link support (#5)
1 parent c98f160 commit 71dfd61

File tree

9 files changed

+36
-42
lines changed

9 files changed

+36
-42
lines changed

jobs/pgpool/spec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ templates:
1717
config/pcppass: config/.pcppass
1818
config/passwd: config/passwd
1919

20+
consumes:
21+
- name: db
22+
type: postgresql
23+
2024
properties:
2125
pgpool.debug:
2226
description: Enable extra debugging wherever possible. Intended for BOSH release maintainers.
@@ -26,9 +30,6 @@ properties:
2630
description: "A list of {username: ..., password: ...} objects for defining pgpool users"
2731
default: []
2832

29-
pgpool.backend.hosts:
30-
description: A list of backend host / IPs to pool connections to.
31-
default: []
3233
pgpool.backend.port:
3334
description: The port that the PostgreSQL backends are listening on
3435
default: 6432

jobs/pgpool/templates/config/pgpool.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
config['pcp_port'] ||= 9898
77
# FIXME: support for SSL key?
88

9-
backends = p('pgpool.backend.hosts', [])
9+
backends = link("db").instances
1010
if backends.empty? then
1111
raise "pgpool.backend.hosts property must define at least one postgres backend host!"
1212
end
@@ -32,8 +32,8 @@ connection_cache = on
3232
reset_query_list = 'ABORT; DISCARD ALL'
3333
pool_passwd = 'passwd'
3434

35-
<% backends.each_with_index do |backend, i| %>
36-
backend_host<%= i %> = <%= val(backend) %>
35+
<% link("db").instances.each_with_index do |instance, i| %>
36+
backend_host<%= i %> = <%= val(instance.address) %>
3737
backend_port<%= i %> = <%= val(p('pgpool.backend.port')) %>
3838
<% end %>
3939

jobs/postgres/spec

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ templates:
1717

1818
sql/setup-replication.sql: sql/setup-replication.sql
1919

20+
provides:
21+
- name: db
22+
type: postgresql
23+
properties:
24+
- postgres.config.port
25+
- pgpool.users
26+
27+
consumes:
28+
- name: db
29+
type: postgresql
30+
31+
2032
properties:
2133
postgres.config:
2234
description: A map of postgresql.conf configuration directives, keyed by name.
@@ -79,12 +91,6 @@ properties:
7991
postgres.replication.master:
8092
description: IP address of the preferred master node (should be the 0th postgres node's IP)
8193
default: ~
82-
postgres.replication.pool:
83-
description: List of all IP address of nodes in the replication pool (including the master)
84-
default: []
85-
postgres.pgpool.pool:
86-
description: List of all IP address of PGPoolII nodes that front this Postgres node
87-
default: []
8894

8995
pgpool.users:
9096
description: "A list of {username: ..., password: ...} objects for defining pgpool users"

jobs/postgres/templates/bin/ctl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
<%
33

4-
masterip = p('postgres.replication.master', '')
4+
masterip = link("db").instances.first.address
55
replication = p('postgres.replication.enabled', false) && masterip != ''
66
master = replication && spec.index == 0
77
port = p('postgres.config.port')

jobs/postgres/templates/config/hba.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ local all all md5
1010
<% end %>
1111

1212
# replication hosts
13-
<% p("postgres.replication.pool", []).each do |ip|
14-
%>host replication replication <%= ip %>/32 trust
13+
<% link("db").instances.each do |instance|
14+
%>host replication replication <%= instance.address %>/32 trust
1515
<% end %>
1616

1717
# user-configured acls

jobs/postgres/templates/config/postgresql.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# postgres main configuration
22
<%
3-
masterip = p('postgres.replication.master', '')
4-
replication = p('postgres.replication.enabled', false) && masterip != ''
3+
pgs = link("db").instances
4+
replication = p('postgres.replication.enabled', false) && pgs.size() > 1
55
master = replication && spec.index == 0
66

77
config = p('postgres.config', {})

jobs/smoke-tests/spec

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ name: smoke-tests
33
packages:
44
- postgres
55
- pgrt
6+
7+
consumes:
8+
- name: db
9+
type: postgresql
10+
611
templates:
712
bin/run: bin/run
813
helpers/ctl_setup.sh: helpers/ctl_setup.sh
914
helpers/ctl_utils.sh: helpers/ctl_utils.sh
1015
sql/pgbench_cleanup.sql: sql/pgbench_cleanup.sql
1116

1217
properties:
13-
postgres.smoke-tests.target.address:
14-
description: Hostname or IP address to run pgbench against, for generating load.
1518
postgres.smoke-tests.target.port:
1619
description: Port to run pgbench against, for generating load.
1720
default: 5432
@@ -28,12 +31,6 @@ properties:
2831
description: Port that PostgreSQL itself (not PGPoolII) is listening on, for replication health checking.
2932
default: 6432
3033

31-
postgres.smoke-tests.cluster.master:
32-
description: IP address of the write master in a replicated Postgres cluster.
33-
postgres.smoke-tests.cluster.slaves:
34-
description: List of IP addresses of the read slaves in a replicated Postgres cluster.
35-
default: []
36-
3734
postgres.smoke-tests.thresholds.replication-lag:
3835
description: Maximum allowable replication lag for any single read slave from master (in kb).
3936
default: 64

jobs/smoke-tests/templates/bin/run

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
22
<%
3-
master = p('postgres.smoke-tests.cluster.master')
3+
master = link("db").instances.first.address
44
slaves = []
5-
p('postgres.smoke-tests.cluster.slaves', []).each do |slave|
6-
if slave != master
7-
slaves.push(slave)
5+
link("db").instances.each do |instance|
6+
if instance.address != master
7+
slaves.push(instance.address)
88
end
99
end
1010
%>
@@ -35,7 +35,7 @@ echo "*:*:*:<%= p('postgres.smoke-tests.target.username') %>:<%= p('postgres.smo
3535
chmod 0600 ~/.pgpass
3636

3737
echo "INITIALIZING PGBENCH DATABASE"
38-
pgbench -h <%= p('postgres.smoke-tests.target.address') %> \
38+
pgbench -h <%= master %> \
3939
-p <%= p('postgres.smoke-tests.target.port') %> \
4040
-U <%= p('postgres.smoke-tests.target.username') %> \
4141
-i 2>&1
@@ -45,7 +45,7 @@ CPUS=$(grep -c ^processor /proc/cpuinfo)
4545
CLIENTS=<%= p('postgres.smoke-tests.target.clients') %>
4646
CLIENTS=$(( CLIENTS - (CLIENTS % CPUS) + CPUS ))
4747
time \
48-
pgbench -h <%= p('postgres.smoke-tests.target.address') %> \
48+
pgbench -h <%= master %> \
4949
-p <%= p('postgres.smoke-tests.target.port') %> \
5050
-U <%= p('postgres.smoke-tests.target.username') %> \
5151
-c ${CLIENTS} -j ${CPUS} -T 125 -C 2>&1 &
@@ -66,7 +66,7 @@ echo "pgbench exited $?"
6666
echo
6767

6868

69-
psql -h <%= p('postgres.smoke-tests.target.address') %> \
69+
psql -h <%= master %> \
7070
-p <%= p('postgres.smoke-tests.target.port') %> \
7171
-U <%= p('postgres.smoke-tests.target.username') %> \
7272
--file "/var/vcap/jobs/smoke-tests/sql/pgbench_cleanup.sql"

templates/jobs.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ jobs:
2424
port: 6432
2525
replication:
2626
enabled: true
27-
master: (( grab jobs.postgres.networks.postgres1.static_ips[0] ))
28-
pool: (( grab jobs.postgres.networks.postgres1.static_ips ))
29-
pgpool:
30-
pool: (( grab jobs.postgres.networks.postgres1.static_ips ))
3127
hba:
3228
- host all all 0.0.0.0/0 md5
3329
- host all all ::/0 md5
@@ -49,7 +45,6 @@ jobs:
4945
- username: smoke-tests
5046
password: if-ya-got-em
5147
backend:
52-
hosts: (( grab jobs.postgres.networks.postgres1.static_ips ))
5348
port: 6432
5449
config:
5550
port: 5432
@@ -71,17 +66,12 @@ jobs:
7166
postgres:
7267
smoke-tests:
7368
target:
74-
address: (( grab jobs.postgres.properties.postgres.replication.master ))
7569
port: 5432
7670
username: smoke-tests
7771
password: if-ya-got-em
7872
backend:
7973
port: 6432
8074

81-
cluster:
82-
master: (( grab jobs.postgres.properties.postgres.replication.master ))
83-
slaves: (( grab jobs.postgres.properties.postgres.replication.pool ))
84-
8575

8676

8777
networks: (( param "please set networks" ))

0 commit comments

Comments
 (0)