Merge lp://qastaging/~stylesen/lava-scheduler/more-xml-rpc-apis into lp://qastaging/lava-scheduler

Proposed by Senthil Kumaran S
Status: Merged
Merged at revision: 243
Proposed branch: lp://qastaging/~stylesen/lava-scheduler/more-xml-rpc-apis
Merge into: lp://qastaging/lava-scheduler
Diff against target: 173 lines (+150/-3)
1 file modified
lava_scheduler_app/api.py (+150/-3)
To merge this branch: bzr merge lp://qastaging/~stylesen/lava-scheduler/more-xml-rpc-apis
Reviewer Review Type Date Requested Status
Antonio Terceiro Approve
Zygmunt Krynicki (community) Needs Fixing
Linaro Validation Team Pending
Review via email: mp+158400@code.qastaging.launchpad.net

Description of the change

Add more xml-rpc APIs to make life easier in lava-scheduler. Following are new APIs added:

1) job_output(self, job_id)
2) all_devices(self)
3) all_device_types(self)
4) pending_jobs(self)

To post a comment you must log in.
Revision history for this message
Antonio Terceiro (terceiro) wrote :
Download full text (5.8 KiB)

Hi Senthil,

Cool that you already have something working here! I'm thinking about
shifting some items from my TODO list to you. :-)

> === modified file 'lava_scheduler_app/api.py'
> --- lava_scheduler_app/api.py 2012-05-09 05:57:15 +0000
> +++ lava_scheduler_app/api.py 2013-04-11 15:27:29 +0000
> @@ -1,15 +1,16 @@
> import xmlrpclib
> -
> from simplejson import JSONDecodeError
> -
> from linaro_django_xmlrpc.models import ExposedAPI
> -
> from lava_scheduler_app.models import (
> Device,
> DeviceType,
> JSONDataError,
> TestJob,
> )
> +from lava_scheduler_app.views import (
> + SumIfSQL,
> + SumIf
> +)
>
>
> class SchedulerAPI(ExposedAPI):
> @@ -51,3 +52,132 @@
> raise xmlrpclib.Fault(403, "Permission denied.")
> job.cancel()
> return True
> +
> + def job_output(self, job_id):
> + """
> + Name
> + ----
> + `job_output` (`job_id`)
> +
> + Description
> + -----------
> + Get the output of given job id.
> +
> + Arguments
> + ---------
> + `job_id`: string
> + Job id for which the output is required.
> +
> + Return value
> + ------------
> + This function returns an XML-RPC binary data of output file.
> + """
> +
> + job = TestJob.objects.get(pk=job_id)
> + return xmlrpclib.Binary(job.output_file().read())

Shouldn't this endpoint do some permission checking before just piping
the log to the client?

> + def all_devices(self):
> + """
> + Name
> + ----
> + `all_devices` ()
> +
> + Description
> + -----------
> + Get all the available devices with their state and type information.
> +
> + Arguments
> + ---------
> + None
> +
> + Return value
> + ------------
> + This function returns an XML-RPC array in which each item is a list of
> + device hostname, device type and device state. For example:
> +
> + [['qemu01', 'qemu', 'Idle'], ['panda01', 'panda', 'Idle']]
> + """
> +
> + device_list = []
> + devices = Device.objects.all()
> + for device in devices:
> + device_list.append((device.hostname,
> + device.device_type.name,
> + Device.STATUS_CHOICES[device.status][1]))
> + return device_list
> +

is it possible to get the status names in a way that looks like
programming identifier names (i.e. all lower case, no spaces etc)?

> + def all_device_types(self):
> + """
> + Name
> + ----
> + `all_device_types` ()
> +
> + Description
> + -----------
> + Get all the available device types with their state and count
> + information.
> +
> + Arguments
> + ---------
> + None
> +
> + Return value
> + ------------
> + This function returns an XML-RPC array in which each item is a dict
> + which contains name (device type), idle, busy, offline counts.
> + For example:
> +
> + [{'idle': 1, 'busy': 0, 'name': 'panda', 'offline': 0},
> +...

Read more...

Revision history for this message
Zygmunt Krynicki (zyga) wrote :

150 + jobs = TestJob.objects.all()
151 +
152 + for job in jobs:
153 + if job.status == 0:
154 + job_list.append((job.id, job.requested_device_type_id))
155 +

Please use the ORM for that, written without testing but probably close:

TestJob.objects.filter(status=0).value_list(['id', 'requested_device_type_id'])

The other API for job output begs to be a REST endpoint. XML-RPC is bad for shoving data like that

review: Needs Fixing
Revision history for this message
Antonio Terceiro (terceiro) wrote :

Cool :-)

I have just one comment; you can just do a small change to address it
and merge.

 review approve

> + def pending_jobs_by_device_type(self):
> + """
[snip]
> + """
> +
> + pending_jobs_by_device = {}
> +
> + jobs = TestJob.objects.filter(status=0).values_list(

I would use status=TestJob.SUBMITTED instead to make it clear what is
going on there.

> + 'requested_device_type_id').annotate(
> + pending_jobs=(Count('id')))
> + pending_jobs_by_device.update(dict(jobs))
> +
> + # Get rest of the devices and put number of pending jobs as 0.
> + device_types = DeviceType.objects.values_list('name', flat=True)
> + for device_type in device_types:
> + if device_type not in pending_jobs_by_device:
> + pending_jobs_by_device[device_type] = 0
> +
> + return pending_jobs_by_device

--
Antonio Terceiro
Software Engineer - Linaro
http://www.linaro.org

review: Approve
243. By Senthil Kumaran S

Add more xmlrpc APIs to make life easy.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches