Santiago Gil pushed to branch santigl/104-platform-matching at BuildGrid / buildgrid
Commits:
2 changed files:
Changes:
... | ... | @@ -50,7 +50,6 @@ class BotsInterface: |
50 | 50 |
register with the service, the old one should be closed along
|
51 | 51 |
with all its jobs.
|
52 | 52 |
"""
|
53 |
- |
|
54 | 53 |
bot_id = bot_session.bot_id
|
55 | 54 |
|
56 | 55 |
if bot_id == "":
|
... | ... | @@ -100,10 +99,25 @@ class BotsInterface: |
100 | 99 |
return bot_session
|
101 | 100 |
|
102 | 101 |
def _request_leases(self, bot_session):
|
103 |
- # TODO: Send worker capabilities to the scheduler!
|
|
104 | 102 |
# Only send one lease at a time currently.
|
105 | 103 |
if not bot_session.leases:
|
106 |
- leases = self._scheduler.request_job_leases({})
|
|
104 |
+ worker_capabilities = dict()
|
|
105 |
+ |
|
106 |
+ # TODO? Fail if there are no devices in the worker?
|
|
107 |
+ if bot_session.worker.devices:
|
|
108 |
+ # According to the spec:
|
|
109 |
+ # "The first device in the worker is the "primary device" -
|
|
110 |
+ # that is, the device running a bot and which is
|
|
111 |
+ # responsible for actually executing commands."
|
|
112 |
+ primary_device = bot_session.worker.devices[0]
|
|
113 |
+ |
|
114 |
+ for property in primary_device.properties:
|
|
115 |
+ if property.key not in worker_capabilities:
|
|
116 |
+ worker_capabilities[property.key] = set()
|
|
117 |
+ worker_capabilities[property.key].add(property.value)
|
|
118 |
+ |
|
119 |
+ leases = self._scheduler.request_job_leases(worker_capabilities)
|
|
120 |
+ |
|
107 | 121 |
if leases:
|
108 | 122 |
for lease in leases:
|
109 | 123 |
self._assigned_leases[bot_session.name].add(lease.id)
|
... | ... | @@ -285,19 +285,21 @@ class Scheduler: |
285 | 285 |
if not self.__queue:
|
286 | 286 |
return []
|
287 | 287 |
|
288 |
- # TODO: Try to match worker_capabilities with jobs properties (job.platform_requirements)
|
|
289 |
- job = self.__queue.pop()
|
|
288 |
+ # For now we only look at the first job in the queue.
|
|
289 |
+ # TODO: Try finding another job that is suitable for the worker.
|
|
290 |
+ if self._worker_is_capable(worker_capabilities, self.__queue[0]):
|
|
291 |
+ job = self.__queue.pop()
|
|
290 | 292 |
|
291 |
- self.__logger.info("Job scheduled to run: [%s]", job.name)
|
|
293 |
+ self.__logger.info("Job scheduled to run: [%s]", job.name)
|
|
292 | 294 |
|
293 |
- lease = job.lease
|
|
295 |
+ lease = job.lease
|
|
294 | 296 |
|
295 |
- if not lease:
|
|
296 |
- # For now, one lease at a time:
|
|
297 |
- lease = job.create_lease()
|
|
297 |
+ if not lease:
|
|
298 |
+ # For now, one lease at a time:
|
|
299 |
+ lease = job.create_lease()
|
|
298 | 300 |
|
299 |
- if lease:
|
|
300 |
- return [lease]
|
|
301 |
+ if lease:
|
|
302 |
+ return [lease]
|
|
301 | 303 |
|
302 | 304 |
return None
|
303 | 305 |
|
... | ... | @@ -627,3 +629,28 @@ class Scheduler: |
627 | 629 |
|
628 | 630 |
for message_queue in self.__build_metadata_queues:
|
629 | 631 |
message_queue.put(message)
|
632 |
+ |
|
633 |
+ def _worker_is_capable(self, worker_capabilities, job):
|
|
634 |
+ """Returns whether the worker is suitable to run the job."""
|
|
635 |
+ # TODO: Replace this with the logic defined in the Platform msg. standard.
|
|
636 |
+ |
|
637 |
+ job_requirements = job.platform_requirements
|
|
638 |
+ # For now we'll only check OS and ISA properties.
|
|
639 |
+ |
|
640 |
+ if not job_requirements:
|
|
641 |
+ return True
|
|
642 |
+ |
|
643 |
+ # OS:
|
|
644 |
+ worker_oses = worker_capabilities.get('os', set())
|
|
645 |
+ job_oses = job_requirements.get('os', set())
|
|
646 |
+ if job_oses and not (job_oses & worker_oses):
|
|
647 |
+ return False
|
|
648 |
+ |
|
649 |
+ # ISAs:
|
|
650 |
+ worker_isas = worker_capabilities.get('isa', [])
|
|
651 |
+ job_isas = job_requirements.get('isa', None)
|
|
652 |
+ |
|
653 |
+ if job_isas and not (job_isas & worker_isas):
|
|
654 |
+ return False
|
|
655 |
+ |
|
656 |
+ return True
|