Add /components API endpoint to zuul-web
This endpoint returns the list of components coming from Zookeeper. We need this in order to create a "component overview" page in the UI. Change-Id: I3a478e3f37000adde23bf4fa8b8bc1f38c975f1b
This commit is contained in:
parent
223893e3c2
commit
1df09a82ef
|
@ -227,6 +227,23 @@ class TestWeb(BaseTestWeb):
|
|||
self.assertIn('project-merge', status_jobs[1]['dependencies'])
|
||||
self.assertIn('project-merge', status_jobs[2]['dependencies'])
|
||||
|
||||
def test_web_components(self):
|
||||
"Test that we can retrieve the list of connected components"
|
||||
resp = self.get_url("api/components")
|
||||
data = resp.json()
|
||||
|
||||
# The list should contain one of each kind: executor, scheduler, web
|
||||
self.assertEqual(len(data), 3)
|
||||
self.assertEqual(len(data["executor"]), 1)
|
||||
self.assertEqual(len(data["scheduler"]), 1)
|
||||
self.assertEqual(len(data["web"]), 1)
|
||||
|
||||
# Each component should contain hostname and state information
|
||||
for key in ["hostname", "state"]:
|
||||
self.assertIn(key, data["executor"][0])
|
||||
self.assertIn(key, data["scheduler"][0])
|
||||
self.assertIn(key, data["web"][0])
|
||||
|
||||
def test_web_tenants(self):
|
||||
"Test that we can retrieve JSON status info"
|
||||
self.add_base_changes()
|
||||
|
|
|
@ -594,6 +594,7 @@ class ZuulWebAPI(object):
|
|||
return {
|
||||
'info': '/api/info',
|
||||
'connections': '/api/connections',
|
||||
'components': '/api/components',
|
||||
'tenants': '/api/tenants',
|
||||
'tenant_info': '/api/tenant/{tenant}/info',
|
||||
'status': '/api/tenant/{tenant}/status',
|
||||
|
@ -750,6 +751,21 @@ class ZuulWebAPI(object):
|
|||
resp.headers['Access-Control-Allow-Origin'] = '*'
|
||||
return ret
|
||||
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out(content_type="application/json; charset=utf-8")
|
||||
def components(self):
|
||||
ret = {}
|
||||
for kind, components in self.zuulweb.component_registry.all():
|
||||
for comp in components:
|
||||
comp_json = {
|
||||
"hostname": comp.hostname,
|
||||
"state": comp.state,
|
||||
}
|
||||
ret.setdefault(kind, []).append(comp_json)
|
||||
resp = cherrypy.response
|
||||
resp.headers["Access-Control-Allow-Origin"] = "*"
|
||||
return ret
|
||||
|
||||
def _getStatus(self, tenant):
|
||||
with self.status_lock:
|
||||
if tenant not in self.cache or \
|
||||
|
@ -1345,6 +1361,8 @@ class ZuulWeb(object):
|
|||
controller=api, action='info')
|
||||
route_map.connect('api', '/api/connections',
|
||||
controller=api, action='connections')
|
||||
route_map.connect('api', '/api/components',
|
||||
controller=api, action='components')
|
||||
route_map.connect('api', '/api/tenants',
|
||||
controller=api, action='tenants')
|
||||
route_map.connect('api', '/api/tenant/{tenant}/info',
|
||||
|
|
Loading…
Reference in New Issue