add basic filtering on the job_artifact endpoint

This commit is contained in:
mdoglio 2014-02-07 15:05:42 +00:00
Родитель 0ae7b2dde7
Коммит b86e88fde7
4 изменённых файлов: 60 добавлений и 19 удалений

Просмотреть файл

@ -25,7 +25,6 @@ def test_artifact_detail(webapp, eleven_jobs_processed, sample_artifacts, jm):
assert resp.json["id"] == artifact["id"]
assert set(resp.json.keys()) == set([
"job_id",
"active_status",
"blob",
"type",
"id",

Просмотреть файл

@ -68,6 +68,12 @@ class JobsModel(TreeherderModelBase):
"job_id",
"bug_id",
"type"
],
"job_artifact": [
"id",
"job_id",
"name",
"type"
]
}
@ -202,13 +208,34 @@ class JobsModel(TreeherderModelBase):
)
return data
def get_job_artifact(self, id):
"""Return the job artifact blob by id."""
def get_job_artifact_list(self, offset, limit, conditions=None):
"""
Retrieve a list of job artifacts. The conditions parameter is a
dict containing a set of conditions for each key. e.g.:
{
'job_id': set([('IN', (1, 2))])
}
"""
replace_str, placeholders = self._process_conditions(
conditions, self.INDEXED_COLUMNS['job_artifact']
)
repl = [replace_str]
proc = "jobs.selects.get_job_artifact"
data = self.get_jobs_dhub().execute(
proc="jobs.selects.get_job_artifact",
placeholders=[id],
proc=proc,
replace=repl,
placeholders=placeholders,
limit="{0},{1}".format(offset, limit),
debug_show=self.DEBUG,
)
for artifact in data:
if artifact["type"] == "json":
artifact["blob"] = json.loads(artifact["blob"])
return data
def get_job_note(self, id):
@ -298,9 +325,6 @@ class JobsModel(TreeherderModelBase):
proc = "jobs.selects.get_bug_job_map"
print repl
print placeholders
data = self.get_jobs_dhub().execute(
proc=proc,
replace=repl,

Просмотреть файл

@ -299,8 +299,17 @@
"host":"read_host"
},
"get_job_artifact":{
"sql":"SELECT * from `job_artifact`
WHERE `id` = ?",
"sql":"SELECT
id,
job_id,
name,
`type`,
`blob`
FROM job_artifact
WHERE active_status = 'active'
REP0
ORDER BY id DESC, name
",
"host": "read_host"
},
"get_job_artifact_references":{

Просмотреть файл

@ -200,17 +200,26 @@ class ArtifactViewSet(viewsets.ViewSet):
@with_jobs
def retrieve(self, request, project, jm, pk=None):
"""
GET method implementation for an artifact blob
retrieve a single instance of job_artifact
"""
obj = jm.get_job_artifact(pk)
if obj:
art_obj = obj[0]
if art_obj["type"] == "json":
art_obj["blob"] = json.loads(art_obj["blob"])
return Response(art_obj)
filter = UrlQueryFilter({"id": pk})
objs = jm.get_job_artifact_list(0, 1, filter.conditions)
if objs:
return Response(objs[0])
else:
return Response("No artifact with id: {0}".format(pk), 404)
return Response("job_artifact {0} not found".format(pk), 404)
@with_jobs
def list(self, request, project, jm):
"""
return a list of job artifacts
"""
offset = int(request.QUERY_PARAMS.get('offset', 0))
count = int(request.QUERY_PARAMS.get('count', 10))
objs = jm.get_job_artifact_list(offset, count)
return Response(objs)