Add compose status routes /compose/finished and /compose/failed
These will return a list of details about the finished or failed builds.
This commit is contained in:
parent
fd2aa7c79b
commit
91c6d1525d
@ -147,3 +147,32 @@ def queue_status(cfg):
|
||||
"new": [compose_detail(n) for n in new_queue],
|
||||
"run": [compose_detail(r) for r in run_queue]
|
||||
}
|
||||
|
||||
def build_status(cfg, status_filter=None):
|
||||
""" Return the details of finished or failed builds
|
||||
|
||||
:param cfg: Configuration settings
|
||||
:type cfg: ComposerConfig
|
||||
:param status_filter: What builds to return. None == all, "FINISHED", or "FAILED"
|
||||
:type status_filter: str
|
||||
:returns: A list of the build details (from compose_details)
|
||||
:rtype: list of dicts
|
||||
|
||||
This returns a list of build details for each of the matching builds on the
|
||||
system. It does not return the status of builds that have not been finished.
|
||||
Use queue_status() for those.
|
||||
"""
|
||||
if status_filter:
|
||||
status_filter = [status_filter]
|
||||
else:
|
||||
status_filter = ["FINISHED", "FAILED"]
|
||||
|
||||
results = []
|
||||
result_dir = joinpaths(cfg.get("composer", "lib_dir"), "results")
|
||||
for build in glob(result_dir + "/*"):
|
||||
log.debug("Checking status of build %s", build)
|
||||
|
||||
status = open(joinpaths(build, "STATUS"), "r").read().strip()
|
||||
if status in status_filter:
|
||||
results.append(compose_detail(build))
|
||||
return results
|
||||
|
@ -648,6 +648,51 @@ POST `/api/v0/recipes/tag/<recipe_name>`
|
||||
]
|
||||
}
|
||||
|
||||
`/api/v0/compose/finished`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Return the details on all of the finished composes on the system.
|
||||
|
||||
Example::
|
||||
|
||||
{
|
||||
"finished": [
|
||||
{
|
||||
"id": "70b84195-9817-4b8a-af92-45e380f39894",
|
||||
"recipe": "glusterfs",
|
||||
"status": "FINISHED",
|
||||
"timestamp": 1517351003.8210032,
|
||||
"version": "0.0.6"
|
||||
},
|
||||
{
|
||||
"id": "e695affd-397f-4af9-9022-add2636e7459",
|
||||
"recipe": "glusterfs",
|
||||
"status": "FINISHED",
|
||||
"timestamp": 1517362289.7193348,
|
||||
"version": "0.0.6"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
`/api/v0/compose/failed`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Return the details on all of the failed composes on the system.
|
||||
|
||||
Example::
|
||||
|
||||
{
|
||||
"finished": [
|
||||
{
|
||||
"id": "8c8435ef-d6bd-4c68-9bf1-a2ef832e6b1a",
|
||||
"recipe": "http-server",
|
||||
"status": "RUNNING",
|
||||
"timestamp": 1517523249.9301329,
|
||||
"version": "0.0.2"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
import logging
|
||||
@ -659,7 +704,7 @@ from pylorax.api.compose import start_build, compose_types
|
||||
from pylorax.api.crossdomain import crossdomain
|
||||
from pylorax.api.projects import projects_list, projects_info, projects_depsolve
|
||||
from pylorax.api.projects import modules_list, modules_info, ProjectsError
|
||||
from pylorax.api.queue import queue_status
|
||||
from pylorax.api.queue import queue_status, build_status
|
||||
from pylorax.api.recipes import list_branch_files, read_recipe_commit, recipe_filename, list_commits
|
||||
from pylorax.api.recipes import recipe_from_dict, recipe_from_toml, commit_recipe, delete_recipe, revert_recipe
|
||||
from pylorax.api.recipes import tag_recipe_commit, recipe_diff
|
||||
@ -1172,3 +1217,15 @@ def v0_api(api):
|
||||
def v0_compose_queue():
|
||||
"""Return the status of the new and running queues"""
|
||||
return jsonify(queue_status(api.config["COMPOSER_CFG"]))
|
||||
|
||||
@api.route("/api/v0/compose/finished")
|
||||
@crossdomain(origin="*")
|
||||
def v0_compose_finished():
|
||||
"""Return the list of finished composes"""
|
||||
return jsonify(finished=build_status(api.config["COMPOSER_CFG"], "FINISHED"))
|
||||
|
||||
@api.route("/api/v0/compose/failed")
|
||||
@crossdomain(origin="*")
|
||||
def v0_compose_failed():
|
||||
"""Return the list of failed composes"""
|
||||
return jsonify(failed=build_status(api.config["COMPOSER_CFG"], "FAILED"))
|
||||
|
Loading…
Reference in New Issue
Block a user