Merge lp:~doanac/ubuntu-ci-services-itself/json-jsonp-status into lp:ubuntu-ci-services-itself

Proposed by Andy Doan
Status: Merged
Approved by: Chris Johnston
Approved revision: 301
Merged at revision: 299
Proposed branch: lp:~doanac/ubuntu-ci-services-itself/json-jsonp-status
Merge into: lp:ubuntu-ci-services-itself
Diff against target: 175 lines (+63/-0)
9 files modified
charms/precise/restish/config.yaml (+4/-0)
charms/precise/restish/hooks/hooks.py (+13/-0)
charms/precise/restish/metadata.yaml (+3/-0)
charms/precise/webui/hooks/hooks.py (+35/-0)
charms/precise/webui/metadata.yaml (+2/-0)
juju-deployer/branch-source-builder.yaml.tmpl (+1/-0)
juju-deployer/image-builder.yaml.tmpl (+1/-0)
juju-deployer/relations.yaml (+3/-0)
juju-deployer/test-runner.yaml.tmpl (+1/-0)
To merge this branch: bzr merge lp:~doanac/ubuntu-ci-services-itself/json-jsonp-status
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Andy Doan (community) Approve
Evan (community) Approve
Review via email: mp+208915@code.launchpad.net

Commit message

integrate monitoring api into webui

Provide a simple mechansim for the webui to get monitor the status of other services.
(restish only for this change)

Description of the change

provides the charming logic required to fix:

 https://bugs.launchpad.net/bugs/1285360

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:300
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/265/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/265/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Evan (ev) wrote :

Looks good. +1

review: Approve
Revision history for this message
Evan (ev) wrote :

110 +@hooks.hook('json_status-relation-changed')
111 +def json_status_relation_changed():
112 + json_status_relation_joined()

Minor nit, but couldn't you just decorate json_status_relation_joined() with hooks.hook('json_status-relation-changed')?

Revision history for this message
Andy Doan (doanac) wrote :

On 03/03/2014 03:10 AM, Evan Dandrea wrote:
> 110 +@hooks.hook('json_status-relation-changed')
> 111 +def json_status_relation_changed():
> 112 + json_status_relation_joined()
>
> Minor nit, but couldn't you just decorate json_status_relation_joined() with hooks.hook('json_status-relation-changed')?

I wasn't positive if was safe with the hooks.hook decorator to have it
twice for a function. I'm re-doplying this morning, so it should be easy
to find out :)

301. By Andy Doan

use one hook function for joined/changed

as noted by evan

Revision history for this message
Andy Doan (doanac) wrote :

revno 301 fixes ev's comment. he's already acked the patch.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:301
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/267/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/267/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:301
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/271/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/271/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charms/precise/restish/config.yaml'
2--- charms/precise/restish/config.yaml 2014-02-18 23:42:52 +0000
3+++ charms/precise/restish/config.yaml 2014-03-03 17:27:54 +0000
4@@ -28,6 +28,10 @@
5 type: string
6 description: "PYTHONPATH specification for the service. Can include paths relative to local bzr directory"
7
8+ json_status_path:
9+ type: string
10+ description: "relative path of a URL that reports the health status of this service"
11+
12 # required for rabbitmq-server charm:
13 amqp-user:
14 type: string
15
16=== modified file 'charms/precise/restish/hooks/hooks.py'
17--- charms/precise/restish/hooks/hooks.py 2014-02-18 23:42:52 +0000
18+++ charms/precise/restish/hooks/hooks.py 2014-03-03 17:27:54 +0000
19@@ -135,6 +135,19 @@
20 pass
21
22
23+def json_status_relation_joined(config):
24+ path = config.get('json_status_path')
25+ if path:
26+ port = config['port']
27+ host = subprocess.check_output(['unit-get', 'public-address']).strip()
28+ if not host:
29+ juju_info('no public address found, using private')
30+ host = subprocess.check_output(
31+ ['unit-get', 'private-address']).strip()
32+ url = 'http://%s:%s/%s' % (host, port, path)
33+ _relation_set({'status-url': url})
34+
35+
36 def wsgi_relation_joined(config):
37 sdir = _service_dir(config)
38
39
40=== added symlink 'charms/precise/restish/hooks/json_status-relation-joined'
41=== target is u'hooks.py'
42=== modified file 'charms/precise/restish/metadata.yaml'
43--- charms/precise/restish/metadata.yaml 2014-01-16 16:52:53 +0000
44+++ charms/precise/restish/metadata.yaml 2014-03-03 17:27:54 +0000
45@@ -13,6 +13,9 @@
46 wsgi:
47 interface: wsgi
48 scope: container
49+ json_status:
50+ interface: json_status
51+ optional: true
52 requires:
53 amqp:
54 interface: rabbitmq
55
56=== modified file 'charms/precise/webui/hooks/hooks.py'
57--- charms/precise/webui/hooks/hooks.py 2014-02-17 10:13:29 +0000
58+++ charms/precise/webui/hooks/hooks.py 2014-03-03 17:27:54 +0000
59@@ -2,6 +2,7 @@
60
61 import distutils.dir_util
62 import grp
63+import json
64 import os
65 import pwd
66 import re
67@@ -26,12 +27,46 @@
68 site_name = "ci-airlines.canonical.com"
69 site_path = "/srv/{}".format(site_name)
70
71+json_status_file = os.path.join(site_path, 'status_urls.json')
72+
73 config_data = config_get()
74
75 web_uid = pwd.getpwnam('www-data')[2]
76 web_gid = grp.getgrnam('www-data')[2]
77
78
79+@hooks.hook('json_status-relation-joined')
80+@hooks.hook('json_status-relation-changed')
81+def json_status_relation_joined():
82+ url = charmhelpers.core.hookenv.relation_get('status-url')
83+ unit = charmhelpers.core.hookenv.remote_unit()
84+ log('status URL is: %s' % url)
85+
86+ data = {}
87+ if os.path.exists(json_status_file):
88+ data = json.load(open(json_status_file))
89+ data[charmhelpers.core.hookenv.relation_id()] = {
90+ 'url': url,
91+ 'unit': unit,
92+ }
93+
94+ with open(json_status_file, 'w') as f:
95+ json.dump(data, f)
96+
97+
98+@hooks.hook('json_status-relation-broken')
99+def json_status_relation_broken():
100+ if not os.path.exists(json_status_file):
101+ return
102+
103+ data = json.load(open(json_status_file))
104+ rid = charmhelpers.core.hookenv.relation_id()
105+ if rid in data:
106+ del data[rid]
107+ with open(json_status_file, 'w') as f:
108+ json.dump(data, f)
109+
110+
111 @hooks.hook()
112 def install():
113 if os.path.exists(site_path):
114
115=== added symlink 'charms/precise/webui/hooks/json_status-relation-broken'
116=== target is u'hooks.py'
117=== added symlink 'charms/precise/webui/hooks/json_status-relation-changed'
118=== target is u'hooks.py'
119=== added symlink 'charms/precise/webui/hooks/json_status-relation-joined'
120=== target is u'hooks.py'
121=== modified file 'charms/precise/webui/metadata.yaml'
122--- charms/precise/webui/metadata.yaml 2014-01-23 17:11:17 +0000
123+++ charms/precise/webui/metadata.yaml 2014-03-03 17:27:54 +0000
124@@ -10,3 +10,5 @@
125 website:
126 interface: http
127 scope: container
128+ json_status:
129+ interface: json_status
130
131=== modified file 'juju-deployer/branch-source-builder.yaml.tmpl'
132--- juju-deployer/branch-source-builder.yaml.tmpl 2014-02-25 23:16:13 +0000
133+++ juju-deployer/branch-source-builder.yaml.tmpl 2014-03-03 17:27:54 +0000
134@@ -10,6 +10,7 @@
135 python_path: ./branch-source-builder:./ci-utils
136 # need non-default package python-amqplib for this service
137 packages: "python-webtest python-mock python-jinja2 python-amqplib"
138+ json_status_path: api/v1/status
139 bsb-gunicorn:
140 charm: gunicorn
141 branch: lp:charms/precise/gunicorn@28
142
143=== modified file 'juju-deployer/image-builder.yaml.tmpl'
144--- juju-deployer/image-builder.yaml.tmpl 2014-02-28 09:25:47 +0000
145+++ juju-deployer/image-builder.yaml.tmpl 2014-03-03 17:27:54 +0000
146@@ -9,6 +9,7 @@
147 tarball: ${CI_PAYLOAD_URL}
148 python_path: ./image-builder:./ci-utils
149 packages: "python-webtest python-mock python-jinja2 python-amqplib"
150+ json_status_path: api/v1/status
151 imagebuild-gunicorn:
152 charm: gunicorn
153 branch: lp:charms/precise/gunicorn@28
154
155=== modified file 'juju-deployer/relations.yaml'
156--- juju-deployer/relations.yaml 2014-01-30 13:12:40 +0000
157+++ juju-deployer/relations.yaml 2014-03-03 17:27:54 +0000
158@@ -7,3 +7,6 @@
159 - ["imagebuild-restish:lander-jenkins", lander-jenkins-sub]
160 - ["ts-django:lander-jenkins", lander-jenkins-sub]
161 - ["tr-restish:lander-jenkins", lander-jenkins-sub]
162+ - ["imagebuild-restish:json_status", "webui-app:json_status"]
163+ - ["tr-restish:json_status", "webui-app:json_status"]
164+ - ["bsb-restish:json_status", "webui-app:json_status"]
165
166=== modified file 'juju-deployer/test-runner.yaml.tmpl'
167--- juju-deployer/test-runner.yaml.tmpl 2014-02-25 23:16:13 +0000
168+++ juju-deployer/test-runner.yaml.tmpl 2014-03-03 17:27:54 +0000
169@@ -14,6 +14,7 @@
170 branch: ${CI_BRANCH}
171 tarball: ${CI_PAYLOAD_URL}
172 python_path: test_runner:ci-utils
173+ json_status_path: api/v1/status
174
175 # python-webtest is required for tests
176

Subscribers

People subscribed via source and target branches