Martin Blanchard pushed to branch mablanch/149-leases-cancellation-status at BuildGrid / buildgrid
Commits:
-
a1ee2373
by Martin Blanchard at 2018-12-18T15:31:41Z
-
97e9d231
by Martin Blanchard at 2019-01-09T09:03:52Z
-
dc19f204
by Martin Blanchard at 2019-01-09T09:03:52Z
-
d7e793b0
by Martin Blanchard at 2019-01-09T09:03:52Z
-
aed13219
by Martin Blanchard at 2019-01-09T09:03:52Z
4 changed files:
- buildgrid/server/bots/instance.py
- buildgrid/server/job.py
- buildgrid/server/scheduler.py
- docs/source/using_buildstream.rst
Changes:
| ... | ... | @@ -83,7 +83,7 @@ class BotsInterface: |
| 83 | 83 |
self._check_bot_ids(bot_session.bot_id, name)
|
| 84 | 84 |
self._check_assigned_leases(bot_session)
|
| 85 | 85 |
|
| 86 |
- for lease in bot_session.leases:
|
|
| 86 |
+ for lease in list(bot_session.leases):
|
|
| 87 | 87 |
checked_lease = self._check_lease_state(lease)
|
| 88 | 88 |
if not checked_lease:
|
| 89 | 89 |
# TODO: Make sure we don't need this
|
| ... | ... | @@ -91,7 +91,10 @@ class BotsInterface: |
| 91 | 91 |
self._assigned_leases[name].remove(lease.id)
|
| 92 | 92 |
except KeyError:
|
| 93 | 93 |
pass
|
| 94 |
- lease.Clear()
|
|
| 94 |
+ |
|
| 95 |
+ self._scheduler.delete_job_lease(lease.id)
|
|
| 96 |
+ |
|
| 97 |
+ bot_session.leases.remove(lease)
|
|
| 95 | 98 |
|
| 96 | 99 |
self._request_leases(bot_session)
|
| 97 | 100 |
return bot_session
|
| ... | ... | @@ -117,7 +120,7 @@ class BotsInterface: |
| 117 | 120 |
|
| 118 | 121 |
try:
|
| 119 | 122 |
if self._scheduler.get_job_lease_cancelled(lease.id):
|
| 120 |
- lease.state.CopyFrom(LeaseState.CANCELLED.value)
|
|
| 123 |
+ lease.state = LeaseState.CANCELLED.value
|
|
| 121 | 124 |
return lease
|
| 122 | 125 |
except KeyError:
|
| 123 | 126 |
# Job does not exist, remove from bot.
|
| ... | ... | @@ -222,6 +222,13 @@ class Job: |
| 222 | 222 |
if self._lease is not None:
|
| 223 | 223 |
self.update_lease_state(LeaseState.CANCELLED)
|
| 224 | 224 |
|
| 225 |
+ def delete_lease(self):
|
|
| 226 |
+ """Discard the job's :class:Lease."""
|
|
| 227 |
+ self.__worker_start_timestamp.Clear()
|
|
| 228 |
+ self.__worker_completed_timestamp.Clear()
|
|
| 229 |
+ |
|
| 230 |
+ self._lease = None
|
|
| 231 |
+ |
|
| 225 | 232 |
def update_operation_stage(self, stage):
|
| 226 | 233 |
"""Operates a stage transition for the job's :class:Operation.
|
| 227 | 234 |
|
| ... | ... | @@ -62,18 +62,8 @@ class Scheduler: |
| 62 | 62 |
|
| 63 | 63 |
job.unregister_client(queue)
|
| 64 | 64 |
|
| 65 |
- if not job.n_clients and job.operation.done:
|
|
| 66 |
- del self.jobs[job_name]
|
|
| 67 |
- |
|
| 68 |
- if self._is_instrumented:
|
|
| 69 |
- self.__operations_by_stage[OperationStage.CACHE_CHECK].discard(job_name)
|
|
| 70 |
- self.__operations_by_stage[OperationStage.QUEUED].discard(job_name)
|
|
| 71 |
- self.__operations_by_stage[OperationStage.EXECUTING].discard(job_name)
|
|
| 72 |
- self.__operations_by_stage[OperationStage.COMPLETED].discard(job_name)
|
|
| 73 |
- |
|
| 74 |
- self.__leases_by_state[LeaseState.PENDING].discard(job_name)
|
|
| 75 |
- self.__leases_by_state[LeaseState.ACTIVE].discard(job_name)
|
|
| 76 |
- self.__leases_by_state[LeaseState.COMPLETED].discard(job_name)
|
|
| 65 |
+ if not job.n_clients and job.operation.done and not job.lease:
|
|
| 66 |
+ self._delete_job(job.name)
|
|
| 77 | 67 |
|
| 78 | 68 |
def queue_job(self, job, skip_cache_lookup=False):
|
| 79 | 69 |
self.jobs[job.name] = job
|
| ... | ... | @@ -199,6 +189,15 @@ class Scheduler: |
| 199 | 189 |
"""Returns true if the lease is cancelled"""
|
| 200 | 190 |
return self.jobs[job_name].lease_cancelled
|
| 201 | 191 |
|
| 192 |
+ def delete_job_lease(self, job_name):
|
|
| 193 |
+ """Discards the lease associated to a job."""
|
|
| 194 |
+ job = self.jobs[job_name]
|
|
| 195 |
+ |
|
| 196 |
+ self.jobs[job.name].delete_lease()
|
|
| 197 |
+ |
|
| 198 |
+ if not job.n_clients and job.operation.done:
|
|
| 199 |
+ self._delete_job(job.name)
|
|
| 200 |
+ |
|
| 202 | 201 |
def get_job_operation(self, job_name):
|
| 203 | 202 |
"""Returns the operation associated to job."""
|
| 204 | 203 |
return self.jobs[job_name].operation
|
| ... | ... | @@ -296,6 +295,20 @@ class Scheduler: |
| 296 | 295 |
|
| 297 | 296 |
# --- Private API ---
|
| 298 | 297 |
|
| 298 |
+ def _delete_job(self, job_name):
|
|
| 299 |
+ """Drops an entry from the internal list of jobs."""
|
|
| 300 |
+ del self.jobs[job_name]
|
|
| 301 |
+ |
|
| 302 |
+ if self._is_instrumented:
|
|
| 303 |
+ self.__operations_by_stage[OperationStage.CACHE_CHECK].discard(job_name)
|
|
| 304 |
+ self.__operations_by_stage[OperationStage.QUEUED].discard(job_name)
|
|
| 305 |
+ self.__operations_by_stage[OperationStage.EXECUTING].discard(job_name)
|
|
| 306 |
+ self.__operations_by_stage[OperationStage.COMPLETED].discard(job_name)
|
|
| 307 |
+ |
|
| 308 |
+ self.__leases_by_state[LeaseState.PENDING].discard(job_name)
|
|
| 309 |
+ self.__leases_by_state[LeaseState.ACTIVE].discard(job_name)
|
|
| 310 |
+ self.__leases_by_state[LeaseState.COMPLETED].discard(job_name)
|
|
| 311 |
+ |
|
| 299 | 312 |
def _update_job_operation_stage(self, job_name, operation_stage):
|
| 300 | 313 |
"""Requests a stage transition for the job's :class:Operations.
|
| 301 | 314 |
|
| ... | ... | @@ -4,9 +4,11 @@ |
| 4 | 4 |
BuildStream client
|
| 5 | 5 |
==================
|
| 6 | 6 |
|
| 7 |
-`BuildStream`_ is a free software tool for building and integrating software
|
|
| 7 |
+`BuildStream`_ is a free software tool for building and integrating software
|
|
| 8 | 8 |
stacks. It supports remote build execution using the remote execution API
|
| 9 |
-(REAPI) v2.
|
|
| 9 |
+(REAPI) v2. The project's documentation has a detailed section about its
|
|
| 10 |
+`remote execution subsystem architecture`_ that you are very recommanded to
|
|
| 11 |
+read first.
|
|
| 10 | 12 |
|
| 11 | 13 |
.. note::
|
| 12 | 14 |
|
| ... | ... | @@ -15,6 +17,7 @@ stacks. It supports remote build execution using the remote execution API |
| 15 | 17 |
remote execution.
|
| 16 | 18 |
|
| 17 | 19 |
.. _BuildStream: https://buildstream.build
|
| 20 |
+.. _remote execution subsystem architecture: https://buildstream.gitlab.io/buildstream/arch_remote_execution.html
|
|
| 18 | 21 |
.. _install it from sources: https://buildstream.build/source_install.html
|
| 19 | 22 |
|
| 20 | 23 |
|
| ... | ... | @@ -43,23 +46,23 @@ Project configuration |
| 43 | 46 |
In order to activate remote build execution at project-level, the project's
|
| 44 | 47 |
``project.conf`` file must declare two specific configuration nodes:
|
| 45 | 48 |
|
| 46 |
-- ``artifacts`` for `remote CAS endpoint details`_.
|
|
| 49 |
+- ``artifacts`` for `remote cache endpoint details`_.
|
|
| 47 | 50 |
- ``remote-execution`` for `remote execution endpoint details`_.
|
| 48 | 51 |
|
| 49 | 52 |
.. important::
|
| 50 | 53 |
|
| 51 | 54 |
BuildStream does not support multi-instance remote execution servers and will
|
| 52 | 55 |
always submit remote execution request omitting the instance name parameter.
|
| 53 |
- Thus, you must declare an unnamed `""` instance in your server configuration
|
|
| 56 |
+ Thus, you must declare an unnamed `''` instance in your server configuration
|
|
| 54 | 57 |
to workaround this.
|
| 55 | 58 |
|
| 56 | 59 |
.. important::
|
| 57 | 60 |
|
| 58 |
- If you are using BuildGrid's artifact server, the server instance **must**
|
|
| 59 |
- accept pushes from your client for remote execution to be possible.
|
|
| 61 |
+ If you are using BuildStream's artifact server, the server instance pointed
|
|
| 62 |
+ by the ``storage-service`` key **must** accept pushes from your client for
|
|
| 63 |
+ remote execution to be possible.
|
|
| 60 | 64 |
|
| 61 |
- |
|
| 62 |
-.. _remote CAS endpoint details: https://buildstream.gitlab.io/buildstream/install_artifacts.html#user-configuration
|
|
| 65 |
+.. _remote cache endpoint details: https://buildstream.gitlab.io/buildstream/format_project.html#artifact-server
|
|
| 63 | 66 |
.. _remote execution endpoint details: https://buildstream.gitlab.io/buildstream/format_project.html#remote-execution
|
| 64 | 67 |
|
| 65 | 68 |
|
| ... | ... | @@ -167,7 +170,15 @@ append at the end of the ``project.conf`` file from the root directory: |
| 167 | 170 |
push: true
|
| 168 | 171 |
|
| 169 | 172 |
remote-execution:
|
| 170 |
- url: http://localhost:50051
|
|
| 173 |
+ execution-service:
|
|
| 174 |
+ url: http://localhost:50051
|
|
| 175 |
+ storage-service:
|
|
| 176 |
+ url: http://localhost:50051
|
|
| 177 |
+ client-key: ''
|
|
| 178 |
+ client-cert: ''
|
|
| 179 |
+ server-cert: ''
|
|
| 180 |
+ action-cache-service:
|
|
| 181 |
+ url: http://localhost:50051
|
|
| 171 | 182 |
|
| 172 | 183 |
This activates BuildGrid's remote execution mode and points to the unnamed
|
| 173 | 184 |
remote execution server instance at ``localhost:50051``.
|
